首页 > 开发 > Php > 正文

php escapeshellcmd多字节编码漏洞

2020-05-28 12:35:37
字体:
来源:转载
供稿:网友

漏洞公告在http://www.sektioneins.de/advisories/SE-2008-03.txt

PHP 5 <= 5.2.5

PHP 4 <= 4.4.8

一些允许如GBK,EUC-KR, SJIS等宽字节字符集的系统都可能受此影响,影响还是非常大的,国内的虚拟主机应该是通杀的,在测试完这个漏洞之后,发现还是十分有意思的,以前也有过对这种类型安全漏洞的研究,于是就把相关的漏洞解释和一些自己的想法都写出来,也希望国内的一些有漏洞的平台能迅速做出响应,修补漏洞。

这个漏洞出在php的用来转义命令行字符串的函数上,这些函数底层是用的php_escape_shell_cmd这个函数的,我们先来看看他的处理过程:

 

 /*{{{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;
}
/*}}}*/

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表