Skip to content

Commit 4bd14ed

Browse files
committed
Uses a hash for options as opposed to numerous methods on blob
1 parent 3c11251 commit 4bd14ed

File tree

2 files changed

+38
-43
lines changed

2 files changed

+38
-43
lines changed

lib/rex/payloads/meterpreter/patch.rb

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ def patch_transport! blob, ssl
1919
blob[i, str.length] = str
2020
end
2121

22-
return blob
2322
end
2423

2524
# Replace the URL
@@ -31,7 +30,6 @@ def patch_url! blob, url
3130
blob[i, str.length] = str
3231
end
3332

34-
return blob
3533
end
3634

3735
# Replace the session expiration timeout
@@ -43,7 +41,6 @@ def patch_expiration! blob, expiration
4341
blob[i, str.length] = str
4442
end
4543

46-
return blob
4744
end
4845

4946
# Replace the session communication timeout
@@ -55,18 +52,17 @@ def patch_comm_timeout! blob, comm_timeout
5552
blob[i, str.length] = str
5653
end
5754

58-
return blob
5955
end
6056

6157
# Replace the user agent string with our option
6258
def patch_ua! blob, ua
6359

60+
ua = ua[0,255] + "\x00"
6461
i = blob.index("METERPRETER_UA\x00")
6562
if i
6663
blob[i, ua.length] = ua
6764
end
6865

69-
return blob
7066
end
7167

7268
# Activate a custom proxy
@@ -93,7 +89,6 @@ def patch_proxy! blob, proxyhost, proxyport, proxy_type
9389
end
9490
end
9591

96-
return blob
9792
end
9893

9994
# Proxy authentification
@@ -112,7 +107,27 @@ def patch_proxy_auth! blob, proxy_username, proxy_password, proxy_type
112107
blob[proxy_password_loc, proxy_password.length] = proxy_password
113108
end
114109

115-
return blob
110+
end
111+
112+
# 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,
121+
options[:proxyhost],
122+
options[:proxyport],
123+
options[:proxy_type]
124+
)
125+
blob.patch_proxy_auth!(blob,
126+
options[:proxy_username],
127+
options[:proxy_password],
128+
options[:proxy_type]
129+
)
130+
116131
end
117132

118133
end

lib/rex/post/meterpreter/client_core.rb

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -231,42 +231,22 @@ def migrate( pid )
231231

232232
if client.passive_service
233233

234-
blob.extend(Rex::Payloads::Meterpreter::Patch)
235-
236-
# Replace the transport string first (TRANSPORT_SOCKET_SSL)
237-
blob.patch_transport!(blob, client.ssl)
238-
239-
# Replace the URL
240-
blob.patch_url!(blob, self.client.url)
241-
242-
# Replace the session expiration timeout
243-
blob.patch_expiration!(blob, self.client.expiration)
244-
245-
# Replace the session communication timeout
246-
blob.patch_comm_timeout!(blob, self.client.comm_timeout)
247-
248-
# Replace the user agent string with our option
249-
blob.patch_ua!(
250-
blob,
251-
client.exploit_datastore['MeterpreterUserAgent'][0,255] + "\x00"
252-
)
253-
254-
# Activate a custom proxy
255-
blob.patch_proxy!(
256-
blob,
257-
client.exploit_datastore['PROXYHOST'],
258-
client.exploit_datastore['PROXYPORT'],
259-
client.exploit_datastore['PROXY_TYPE']
260-
)
261-
# Proxy authentication
262-
blob.patch_proxy_auth!(
263-
blob,
264-
client.exploit_datastore['PROXY_USERNAME'],
265-
client.exploit_datastore['PROXY_PASSWORD'],
266-
client.exploit_datastore['PROXY_TYPE']
267-
)
268-
269-
conn_id = self.client.conn_id
234+
blob.extend Rex::Payloads::Meterpreter::Patch
235+
236+
#
237+
# Patch options into metsrv for reverse HTTP payloads
238+
#
239+
blob.patch_passive_service! blob,
240+
:ssl => client.ssl,
241+
:url => self.client.url,
242+
:expiration => self.client.expiration,
243+
:comm_timeout => self.client.comm_timeout,
244+
:ua => client.exploit_datastore['MeterpreterUserAgent'],
245+
:proxyhost => client.exploit_datastore['PROXYHOST'],
246+
:proxyport => client.exploit_datastore['PROXYPORT'],
247+
:proxy_type => client.exploit_datastore['PROXY_TYPE'],
248+
:proxy_username => client.exploit_datastore['PROXY_USERNAME'],
249+
:proxy_password => client.exploit_datastore['PROXY_PASSWORD']
270250

271251
end
272252

0 commit comments

Comments
 (0)