Skip to content

Commit 3c11251

Browse files
committed
Mitigates excessive use of lookup operator (hopefully adds clarity)
1 parent e55dab3 commit 3c11251

File tree

2 files changed

+16
-26
lines changed

2 files changed

+16
-26
lines changed

lib/rex/payloads/meterpreter/patch.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module Meterpreter
1111
module Patch
1212

1313
# Replace the transport string
14-
def self.patch_transport blob, ssl
14+
def patch_transport! blob, ssl
1515

1616
i = blob.index("METERPRETER_TRANSPORT_SSL")
1717
if i
@@ -23,7 +23,7 @@ def self.patch_transport blob, ssl
2323
end
2424

2525
# Replace the URL
26-
def self.patch_url blob, url
26+
def patch_url! blob, url
2727

2828
i = blob.index("https://" + ("X" * 256))
2929
if i
@@ -35,7 +35,7 @@ def self.patch_url blob, url
3535
end
3636

3737
# Replace the session expiration timeout
38-
def self.patch_expiration blob, expiration
38+
def patch_expiration! blob, expiration
3939

4040
i = blob.index([0xb64be661].pack("V"))
4141
if i
@@ -47,7 +47,7 @@ def self.patch_expiration blob, expiration
4747
end
4848

4949
# Replace the session communication timeout
50-
def self.patch_comm_timeout blob, comm_timeout
50+
def patch_comm_timeout! blob, comm_timeout
5151

5252
i = blob.index([0xaf79257f].pack("V"))
5353
if i
@@ -59,7 +59,7 @@ def self.patch_comm_timeout blob, comm_timeout
5959
end
6060

6161
# Replace the user agent string with our option
62-
def self.patch_ua blob, ua
62+
def patch_ua! blob, ua
6363

6464
i = blob.index("METERPRETER_UA\x00")
6565
if i
@@ -70,7 +70,7 @@ def self.patch_ua blob, ua
7070
end
7171

7272
# Activate a custom proxy
73-
def self.patch_proxy blob, proxyhost, proxyport, proxy_type
73+
def patch_proxy! blob, proxyhost, proxyport, proxy_type
7474

7575
i = blob.index("METERPRETER_PROXY\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
7676
if i
@@ -97,7 +97,7 @@ def self.patch_proxy blob, proxyhost, proxyport, proxy_type
9797
end
9898

9999
# Proxy authentification
100-
def self.patch_proxy_auth blob, proxy_username, proxy_password, proxy_type
100+
def patch_proxy_auth! blob, proxy_username, proxy_password, proxy_type
101101

102102
unless (proxy_username.nil? or proxy_username.empty?) or
103103
(proxy_password.nil? or proxy_password.empty?) or

lib/rex/post/meterpreter/client_core.rb

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -231,45 +231,35 @@ def migrate( pid )
231231

232232
if client.passive_service
233233

234+
blob.extend(Rex::Payloads::Meterpreter::Patch)
235+
234236
# Replace the transport string first (TRANSPORT_SOCKET_SSL)
235-
blob = Rex::Payloads::Meterpreter::Patch.patch_transport(
236-
blob,
237-
client.ssl
238-
)
237+
blob.patch_transport!(blob, client.ssl)
239238

240239
# Replace the URL
241-
blob = Rex::Payloads::Meterpreter::Patch.patch_url(
242-
blob,
243-
self.client.url
244-
)
240+
blob.patch_url!(blob, self.client.url)
245241

246242
# Replace the session expiration timeout
247-
blob = Rex::Payloads::Meterpreter::Patch.patch_expiration(
248-
blob,
249-
self.client.expiration
250-
)
243+
blob.patch_expiration!(blob, self.client.expiration)
251244

252245
# Replace the session communication timeout
253-
blob = Rex::Payloads::Meterpreter::Patch.patch_comm_timeout(
254-
blob,
255-
self.client.comm_timeout
256-
)
246+
blob.patch_comm_timeout!(blob, self.client.comm_timeout)
257247

258248
# Replace the user agent string with our option
259-
blob, i = Rex::Payloads::Meterpreter::Patch.patch_ua(
249+
blob.patch_ua!(
260250
blob,
261251
client.exploit_datastore['MeterpreterUserAgent'][0,255] + "\x00"
262252
)
263253

264254
# Activate a custom proxy
265-
blob, i = Rex::Payloads::Meterpreter::Patch.patch_proxy(
255+
blob.patch_proxy!(
266256
blob,
267257
client.exploit_datastore['PROXYHOST'],
268258
client.exploit_datastore['PROXYPORT'],
269259
client.exploit_datastore['PROXY_TYPE']
270260
)
271261
# Proxy authentication
272-
blob = Rex::Payloads::Meterpreter::Patch.patch_proxy_auth(
262+
blob.patch_proxy_auth!(
273263
blob,
274264
client.exploit_datastore['PROXY_USERNAME'],
275265
client.exploit_datastore['PROXY_PASSWORD'],

0 commit comments

Comments
 (0)