加入收藏 | 设为首页 | 会员中心 | 我要投稿 拼字网 - 核心网 (https://www.hexinwang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php escapeshellcmd多字节编码漏洞

发布时间:2022-02-25 16:45:43 所属栏目:PHP教程 来源:互联网
导读:漏洞公告在http://www.sektioneins.de/advisories/SE-2008-03.txt PHP 5 = 5.2.5 PHP 4 = 4.4.8 一些允许如GBK,EUC-KR, SJIS等宽字节字符集的系统都可能受此影响,影响还是非常大的,国内的虚拟主机应该是通杀的,在测试完这个漏洞之后,发现还是十分有意思
  漏洞公告在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;
  }
  /*}}}*/

(编辑:拼字网 - 核心网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!