Skip to content

Commit daa8b8a

Browse files
committed
Use Metasploit-Payloads Crypto to decrypt payloads
1 parent b428736 commit daa8b8a

File tree

7 files changed

+12
-17
lines changed

7 files changed

+12
-17
lines changed

lib/msf/core/payload/windows/dll_inject.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,8 @@ def handle_connection_stage(conn, opts = {})
205205
data = library_name + "\x00"
206206

207207
begin
208-
File.open(library_path, "rb") { |f|
209-
data += f.read
210-
}
208+
encrypted_contents = ::File.binread(library_path)
209+
data += ::MetasploitPayloads::Crypto.decrypt(ciphertext: encrypted_contents)
211210
rescue
212211
print_error("Failed to load DLL: #{$!}.")
213212

lib/msf/core/post/windows/reflective_dll_injection.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def inject_dll_into_process(process, dll_path, loader_name: 'ReflectiveLoader',
7878
# @return [Array] Tuple of allocated memory address and offset to the
7979
# +ReflectiveLoader+ function.
8080
def inject_dll_data_into_process(process, dll_data, loader_name: 'ReflectiveLoader', loader_ordinal: EXPORT_REFLECTIVELOADER)
81-
decrypted_dll_data = ::MetasploitPayloads.decrypt_payload(payload: dll_data)
81+
decrypted_dll_data = ::MetasploitPayloads::Crypto.decrypt(ciphertext: dll_data)
8282
offset = load_rdi_dll_from_data(decrypted_dll_data, loader_name: loader_name, loader_ordinal: loader_ordinal)
8383
dll_mem = inject_into_process(process, decrypted_dll_data)
8484

lib/msf/core/reflective_dll_loader.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module Msf::ReflectiveDLLLoader
2525
# +ReflectiveLoader+ function within the DLL.
2626
def load_rdi_dll(dll_path, loader_name: 'ReflectiveLoader', loader_ordinal: EXPORT_REFLECTIVELOADER)
2727
encrypted_dll = ::File.binread(dll_path)
28-
dll = ::MetasploitPayloads.decrypt_payload(payload: encrypted_dll)
28+
dll = ::MetasploitPayloads::Crypto.decrypt(ciphertext: encrypted_dll)
2929

3030
offset = parse_pe(dll, loader_name: loader_name, loader_ordinal: loader_ordinal)
3131

@@ -43,7 +43,7 @@ def load_rdi_dll(dll_path, loader_name: 'ReflectiveLoader', loader_ordinal: EXPO
4343
#
4444
# @return [Integer] offset to the +ReflectiveLoader+ function within the DLL.
4545
def load_rdi_dll_from_data(dll_data, loader_name: 'ReflectiveLoader', loader_ordinal: EXPORT_REFLECTIVELOADER)
46-
decrypted_dll_data = ::MetasploitPayloads.decrypt_payload(payload: dll_data)
46+
decrypted_dll_data = ::MetasploitPayloads::Crypto.decrypt(ciphertext: dll_data)
4747
offset = parse_pe(decrypted_dll_data, loader_name: loader_name, loader_ordinal: loader_ordinal)
4848

4949
unless offset

lib/rex/post/meterpreter/client_core.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def load_library(opts)
258258
end
259259

260260
if library_image
261-
decrypted_library_image = ::MetasploitPayloads.decrypt_payload(payload: library_image)
261+
decrypted_library_image = ::MetasploitPayloads::Crypto.decrypt(ciphertext: library_image)
262262
request.add_tlv(TLV_TYPE_DATA, decrypted_library_image, false, client.capabilities[:zlib])
263263
else
264264
raise RuntimeError, "Failed to serialize library #{library_path}.", caller

lib/rex/post/meterpreter/extensions/priv/priv.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def getsystem(technique=TECHNIQUE[:any])
8383
end
8484

8585
encrypted_elevator_data = ::File.binread(elevator_path)
86-
elevator_data = ::MetasploitPayloads.decrypt_payload(payload: encrypted_elevator_data)
86+
elevator_data = ::MetasploitPayloads::Crypto.decrypt(ciphertext: encrypted_elevator_data)
8787

8888
request.add_tlv(TLV_TYPE_ELEVATE_SERVICE_DLL, elevator_data)
8989
request.add_tlv(TLV_TYPE_ELEVATE_SERVICE_LENGTH, elevator_data.length)

lib/rex/post/meterpreter/extensions/stdapi/ui.rb

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,8 @@ def screenshot( quality=50 )
185185
raise RuntimeError, "screenshot.x64.dll not found", caller
186186
end
187187

188-
screenshot_dll = ''
189-
::File.open( screenshot_path, 'rb' ) do |f|
190-
screenshot_dll += f.read( f.stat.size )
191-
end
188+
encrypted_screenshot_dll = ::File.binread(screenshot_path)
189+
screenshot_dll = ::MetasploitPayloads::Crypto.decrypt(ciphertext: encrypted_screenshot_dll)
192190

193191
request.add_tlv( TLV_TYPE_DESKTOP_SCREENSHOT_PE64DLL_BUFFER, screenshot_dll, false, true )
194192
end
@@ -199,10 +197,8 @@ def screenshot( quality=50 )
199197
raise RuntimeError, "screenshot.x86.dll not found", caller
200198
end
201199

202-
screenshot_dll = ''
203-
::File.open( screenshot_path, 'rb' ) do |f|
204-
screenshot_dll += f.read( f.stat.size )
205-
end
200+
encrypted_screenshot_dll = ::File.binread(screenshot_path)
201+
screenshot_dll = ::MetasploitPayloads::Crypto.decrypt(ciphertext: encrypted_screenshot_dll)
206202

207203
request.add_tlv( TLV_TYPE_DESKTOP_SCREENSHOT_PE32DLL_BUFFER, screenshot_dll, false, true )
208204
end

modules/exploits/windows/local/ms15_078_atmfd_bof.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ def exploit
385385

386386
print_status("Reflectively injecting the exploit DLL into #{process.pid}...")
387387
encrypted_dll = ::File.binread(library_path)
388-
dll = ::MetasploitPayloads.decrypt_payload(payload: encrypted_dll)
388+
dll = ::MetasploitPayloads::Crypto.decrypt(ciphertext: encrypted_dll)
389389

390390
patch_win32k_offsets(dll)
391391
patch_nt_offsets(dll)

0 commit comments

Comments
 (0)