漏洞公告在http://www.sektioneins.de/advisories/SE-2008-03.txt
PHP 5 <= 5.2.5
PHP 4 <= 4.4.8
一些允許如GBK,EUC-KR, SJIS等寬字節(jié)字符集的系統(tǒng)都可能受此影響,影響還是非常大的,國內(nèi)的虛擬主機應(yīng)該是通殺的,在測試完這個漏洞之后,發(fā)現(xiàn)還是十分有意思的,以前也有過對這種類型安全漏洞的研究,于是就把相關(guān)的漏洞解釋和一些自己的想法都寫出來,也希望國內(nèi)的一些有漏洞的平臺能迅速做出響應(yīng),修補漏洞。
這個漏洞出在php的用來轉(zhuǎn)義命令行字符串的函數(shù)上,這些函數(shù)底層是用的php_escape_shell_cmd這個函數(shù)的,我們先來看看他的處理過程:
 /*{{{php_escape_shell_cmd
Escapeallcharsthatcouldpossiblybeusedto
breakoutofashellcommand
Thisfunctionemalloc'sastringandreturnsthepointer.
Remembertoefreeitwhendonewithit.
*NOT*safeforbinarystrings
*/
char*php_escape_shell_cmd(char*str){
registerintx,y,l;
char*cmd;
char*p=NULL;
l=strlen(str);
cmd=safe_emalloc(2,l,1);
for(x=0,y=0;x<l;x ){
switch(str[x]){
case'"':
case''':
#ifndefPHP_WIN32
if(!p&&(p=memchr(str x 1,str[x],l-x-1))){
/*noop*/
}elseif(p&&*p==str[x]){
p=NULL;
}else{
cmd[y ]='';
}
cmd[y ]=str[x];
break;
#endif
case'#':/*Thisischaracter-setindependent*/
case'&':
case';':
case'`':
case'|':
case'*':
case'?':
case'~':
case'<':
case'>':
case'^':
case'(':
case')':
case'[':
case']':
case'{':
case'}':
case'$':
case'':
case'x0A':/*excludingthesetwo*/
case'xFF':
#ifdefPHP_WIN32
/*sinceWindowsdoesnotallowustoescapethesechars,justremovethem*/
case'%':
cmd[y ]='';
break;
#endif
cmd[y ]='';
/*fall-through*/
default:
cmd[y ]=str[x];
}
}
cmd[y]='';
returncmd;
}
/*}}}*/
新聞熱點
疑難解答