@@ -58,33 +58,25 @@ def initialize(info = {})
58
58
] , Msf ::Handler ::ReverseHttp )
59
59
end
60
60
61
- # Toggle for IPv4 vs IPv6 mode
62
- #
63
- def ipv6?
64
- Rex ::Socket . is_ipv6? ( datastore [ 'LHOST' ] )
65
- end
66
-
67
61
# Determine where to bind the server
68
62
#
69
63
# @return [String]
70
64
def listener_address
71
- if datastore [ 'ReverseListenerBindAddress' ] . to_s . empty?
72
- bindaddr = ( ipv6? ) ? '::' : '0.0.0.0'
65
+ if datastore [ 'ReverseListenerBindAddress' ] . to_s == ""
66
+ bindaddr = Rex :: Socket . is_ipv6? ( datastore [ 'LHOST' ] ) ? '::' : '0.0.0.0'
73
67
else
74
68
bindaddr = datastore [ 'ReverseListenerBindAddress' ]
75
69
end
76
70
77
71
bindaddr
78
72
end
79
73
74
+ # Return a URI suitable for placing in a payload
75
+ #
80
76
# @return [String] A URI of the form +scheme://host:port/+
81
77
def listener_uri
82
- if ipv6?
83
- listen_host = "[#{ listener_address } ]"
84
- else
85
- listen_host = listener_address
86
- end
87
- "#{ scheme } ://#{ listen_host } :#{ datastore [ 'LPORT' ] } /"
78
+ uri_host = Rex ::Socket . is_ipv6? ( listener_address ) ? "[#{ listener_address } ]" : listener_address
79
+ "#{ scheme } ://#{ uri_host } :#{ datastore [ 'LPORT' ] } /"
88
80
end
89
81
90
82
# Return a URI suitable for placing in a payload.
@@ -192,22 +184,24 @@ def lookup_proxy_settings
192
184
info [ :port ] = ( datastore [ 'PROXY_PORT' ] || 8080 ) . to_i
193
185
info [ :type ] = datastore [ 'PROXY_TYPE' ] . to_s
194
186
195
- if info [ :port ] == 80
196
- info [ :info ] = info [ :host ]
197
- else
198
- info [ :info ] = "#{ info [ :host ] } : #{ info [ :port ] } "
187
+ uri_host = info [ :host ]
188
+
189
+ if Rex :: Socket . is_ipv6? ( uri_host )
190
+ uri_host = "[ #{ info [ :host ] } ] "
199
191
end
200
192
201
- if info [ :type ] == "HTTP"
193
+ info [ :info ] = "#{ uri_host } :#{ info [ :port ] } "
194
+
195
+ if info [ :type ] == "SOCKS"
196
+ info [ :info ] = "socks=#{ info [ :info ] } "
197
+ else
202
198
info [ :info ] = "http://#{ info [ :info ] } "
203
199
if datastore [ 'PROXY_USERNAME' ] . to_s != ""
204
200
info [ :username ] = datastore [ 'PROXY_USERNAME' ] . to_s
205
201
end
206
202
if datastore [ 'PROXY_PASSWORD' ] . to_s != ""
207
203
info [ :password ] = datastore [ 'PROXY_PASSWORD' ] . to_s
208
204
end
209
- else
210
- info [ :info ] = "socks=#{ info [ :info ] } "
211
205
end
212
206
213
207
@proxy_settings = info
@@ -242,7 +236,7 @@ def on_request(cli, req, obj)
242
236
blob . sub! ( 'HTTP_COMMUNICATION_TIMEOUT = 300' , "HTTP_COMMUNICATION_TIMEOUT = #{ datastore [ 'SessionCommunicationTimeout' ] } " )
243
237
blob . sub! ( 'HTTP_USER_AGENT = None' , "HTTP_USER_AGENT = '#{ var_escape . call ( datastore [ 'MeterpreterUserAgent' ] ) } '" )
244
238
245
- if @proxy_settings [ :host ] && @proxy_settings [ :type ] == "HTTP"
239
+ if @proxy_settings [ :host ]
246
240
blob . sub! ( 'HTTP_PROXY = None' , "HTTP_PROXY = '#{ var_escape . call ( @proxy_settings [ :info ] ) } '" )
247
241
end
248
242
0 commit comments