Skip to content

Commit e55dab3

Browse files
committed
Refactored expiration and timeout logic in client_core.rb
1 parent b7714c9 commit e55dab3

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

lib/rex/payloads/meterpreter/patch.rb

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

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

1616
i = blob.index("METERPRETER_TRANSPORT_SSL")
1717
if i
1818
str = ssl ? "METERPRETER_TRANSPORT_HTTPS\x00" : "METERPRETER_TRANSPORT_HTTP\x00"
1919
blob[i, str.length] = str
2020
end
2121

22+
return blob
23+
end
24+
25+
# Replace the URL
26+
def self.patch_url blob, url
27+
2228
i = blob.index("https://" + ("X" * 256))
2329
if i
2430
str = url
2531
blob[i, str.length] = str
2632
end
2733

34+
return blob
35+
end
36+
37+
# Replace the session expiration timeout
38+
def self.patch_expiration blob, expiration
39+
2840
i = blob.index([0xb64be661].pack("V"))
2941
if i
3042
str = [ expiration ].pack("V")
3143
blob[i, str.length] = str
3244
end
3345

46+
return blob
47+
end
48+
49+
# Replace the session communication timeout
50+
def self.patch_comm_timeout blob, comm_timeout
51+
3452
i = blob.index([0xaf79257f].pack("V"))
3553
if i
3654
str = [ comm_timeout ].pack("V")
@@ -48,7 +66,7 @@ def self.patch_ua blob, ua
4866
blob[i, ua.length] = ua
4967
end
5068

51-
return blob, i
69+
return blob
5270
end
5371

5472
# Activate a custom proxy
@@ -75,7 +93,7 @@ def self.patch_proxy blob, proxyhost, proxyport, proxy_type
7593
end
7694
end
7795

78-
return blob, i, proxyinfo
96+
return blob
7997
end
8098

8199
# Proxy authentification

lib/rex/post/meterpreter/client_core.rb

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,24 @@ def migrate( pid )
234234
# Replace the transport string first (TRANSPORT_SOCKET_SSL)
235235
blob = Rex::Payloads::Meterpreter::Patch.patch_transport(
236236
blob,
237-
client.ssl,
238-
self.client.url,
239-
self.client.expiration,
237+
client.ssl
238+
)
239+
240+
# Replace the URL
241+
blob = Rex::Payloads::Meterpreter::Patch.patch_url(
242+
blob,
243+
self.client.url
244+
)
245+
246+
# Replace the session expiration timeout
247+
blob = Rex::Payloads::Meterpreter::Patch.patch_expiration(
248+
blob,
249+
self.client.expiration
250+
)
251+
252+
# Replace the session communication timeout
253+
blob = Rex::Payloads::Meterpreter::Patch.patch_comm_timeout(
254+
blob,
240255
self.client.comm_timeout
241256
)
242257

0 commit comments

Comments
 (0)