Skip to content

Commit 52b3025

Browse files
committed
Reworked to avoid extending String class on blob per hdm's rec.
1 parent 4bd14ed commit 52b3025

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

lib/rex/payloads/meterpreter/patch.rb

Lines changed: 16 additions & 16 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 patch_transport! blob, ssl
14+
def self.patch_transport! blob, ssl
1515

1616
i = blob.index("METERPRETER_TRANSPORT_SSL")
1717
if i
@@ -22,7 +22,7 @@ def patch_transport! blob, ssl
2222
end
2323

2424
# Replace the URL
25-
def patch_url! blob, url
25+
def self.patch_url! blob, url
2626

2727
i = blob.index("https://" + ("X" * 256))
2828
if i
@@ -33,7 +33,7 @@ def patch_url! blob, url
3333
end
3434

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

3838
i = blob.index([0xb64be661].pack("V"))
3939
if i
@@ -44,7 +44,7 @@ def patch_expiration! blob, expiration
4444
end
4545

4646
# Replace the session communication timeout
47-
def patch_comm_timeout! blob, comm_timeout
47+
def self.patch_comm_timeout! blob, comm_timeout
4848

4949
i = blob.index([0xaf79257f].pack("V"))
5050
if i
@@ -55,7 +55,7 @@ def patch_comm_timeout! blob, comm_timeout
5555
end
5656

5757
# Replace the user agent string with our option
58-
def patch_ua! blob, ua
58+
def self.patch_ua! blob, ua
5959

6060
ua = ua[0,255] + "\x00"
6161
i = blob.index("METERPRETER_UA\x00")
@@ -66,7 +66,7 @@ def patch_ua! blob, ua
6666
end
6767

6868
# Activate a custom proxy
69-
def patch_proxy! blob, proxyhost, proxyport, proxy_type
69+
def self.patch_proxy! blob, proxyhost, proxyport, proxy_type
7070

7171
i = blob.index("METERPRETER_PROXY\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
7272
if i
@@ -92,7 +92,7 @@ def patch_proxy! blob, proxyhost, proxyport, proxy_type
9292
end
9393

9494
# Proxy authentification
95-
def patch_proxy_auth! blob, proxy_username, proxy_password, proxy_type
95+
def self.patch_proxy_auth! blob, proxy_username, proxy_password, proxy_type
9696

9797
unless (proxy_username.nil? or proxy_username.empty?) or
9898
(proxy_password.nil? or proxy_password.empty?) or
@@ -110,19 +110,19 @@ def patch_proxy_auth! blob, proxy_username, proxy_password, proxy_type
110110
end
111111

112112
# Patch options into metsrv for reverse HTTP payloads
113-
def patch_passive_service! blob, options
114-
115-
blob.patch_transport! blob, options[:ssl]
116-
blob.patch_url! blob, options[:url]
117-
blob.patch_expiration! blob, options[:expiration]
118-
blob.patch_comm_timeout! blob, options[:comm_timeout]
119-
blob.patch_ua! blob, options[:ua]
120-
blob.patch_proxy!(blob,
113+
def self.patch_passive_service! blob, options
114+
115+
patch_transport! blob, options[:ssl]
116+
patch_url! blob, options[:url]
117+
patch_expiration! blob, options[:expiration]
118+
patch_comm_timeout! blob, options[:comm_timeout]
119+
patch_ua! blob, options[:ua]
120+
patch_proxy!(blob,
121121
options[:proxyhost],
122122
options[:proxyport],
123123
options[:proxy_type]
124124
)
125-
blob.patch_proxy_auth!(blob,
125+
patch_proxy_auth!(blob,
126126
options[:proxy_username],
127127
options[:proxy_password],
128128
options[:proxy_type]

lib/rex/post/meterpreter/client_core.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,10 @@ def migrate( pid )
231231

232232
if client.passive_service
233233

234-
blob.extend Rex::Payloads::Meterpreter::Patch
235-
236234
#
237235
# Patch options into metsrv for reverse HTTP payloads
238236
#
239-
blob.patch_passive_service! blob,
237+
Rex::Payloads::Meterpreter::Patch.patch_passive_service! blob,
240238
:ssl => client.ssl,
241239
:url => self.client.url,
242240
:expiration => self.client.expiration,

0 commit comments

Comments
 (0)