Skip to content

Commit c5e452c

Browse files
committed
Patches UA and PROXY in metsrv when running migrate
1 parent 2967d85 commit c5e452c

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

lib/rex/post/meterpreter/client_core.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,48 @@ def migrate( pid )
228228

229229
if client.passive_service
230230

231+
# Replace the user agent string with our option
232+
i = blob.index("METERPRETER_UA\x00")
233+
if i
234+
str = client.exploit_datastore['MeterpreterUserAgent'][0,255] + "\x00"
235+
blob[i, str.length] = str
236+
end
237+
238+
# Activate a custom proxy
239+
i = blob.index("METERPRETER_PROXY\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
240+
if i
241+
if client.exploit_datastore['PROXYHOST']
242+
if client.exploit_datastore['PROXYHOST'].to_s != ""
243+
proxyhost = client.exploit_datastore['PROXYHOST'].to_s
244+
proxyport = client.exploit_datastore['PROXYPORT'].to_s || "8080"
245+
proxyinfo = proxyhost + ":" + proxyport
246+
if proxyport == "80"
247+
proxyinfo = proxyhost
248+
end
249+
if client.exploit_datastore['PROXY_TYPE'].to_s == 'HTTP'
250+
proxyinfo = 'http://' + proxyinfo
251+
else #socks
252+
proxyinfo = 'socks=' + proxyinfo
253+
end
254+
proxyinfo << "\x00"
255+
blob[i, proxyinfo.length] = proxyinfo
256+
#Optional authentification
257+
unless (client.exploit_datastore['PROXY_USERNAME'].nil? or datastore['PROXY_USERNAME'].empty?) or
258+
(client.exploit_datastore['PROXY_PASSWORD'].nil? or datastore['PROXY_PASSWORD'].empty?) or
259+
client.exploit_datastore['PROXY_TYPE'] == 'SOCKS'
260+
261+
proxy_username_loc = blob.index("METERPRETER_USERNAME_PROXY\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
262+
proxy_username = client.exploit_datastore['PROXY_USERNAME'] << "\x00"
263+
blob[proxy_username_loc, proxy_username.length] = proxy_username
264+
265+
proxy_password_loc = blob.index("METERPRETER_PASSWORD_PROXY\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
266+
proxy_password = client.exploit_datastore['PROXY_PASSWORD'] << "\x00"
267+
blob[proxy_password_loc, proxy_password.length] = proxy_password
268+
end
269+
end
270+
end
271+
end
272+
231273
# Replace the transport string first (TRANSPORT_SOCKET_SSL
232274
i = blob.index("METERPRETER_TRANSPORT_SSL")
233275
if i

0 commit comments

Comments
 (0)