@@ -18,6 +18,7 @@ class EXE
18
18
require 'metasm'
19
19
require 'digest/sha1'
20
20
require 'msf/core/exe/segment_injector'
21
+ require 'msf/core/exe/segment_appender'
21
22
22
23
##
23
24
#
@@ -198,19 +199,25 @@ def self.to_win32pe(framework, code, opts = {})
198
199
return injector . generate_pe
199
200
end
200
201
202
+
203
+ # dead, dead code.
204
+
201
205
raise RuntimeError , "No .text section found in the template" unless text
202
206
203
207
unless text . contains_rva? ( pe . hdr . opt . AddressOfEntryPoint )
204
208
raise RuntimeError , "The .text section does not contain an entry point"
205
209
end
206
210
207
211
p_length = payload . length + 256
212
+
213
+ # If the .text section is too small, append a new section instead
208
214
if text . size < p_length
209
- fname = ::File . basename ( opts [ :template ] )
210
- msg = "The .text section for '#{ fname } ' is too small. "
211
- msg << "Minimum is #{ p_length . to_s } bytes, your .text section is " +
212
- "#{ text . size . to_s } bytes"
213
- raise RuntimeError , msg
215
+ appender = Msf ::Exe ::SegmentAppender . new ( {
216
+ :payload => code ,
217
+ :template => opts [ :template ] ,
218
+ :arch => :x86
219
+ } )
220
+ return appender . generate_pe
214
221
end
215
222
216
223
# Store some useful offsets
@@ -506,7 +513,8 @@ def self.to_win32pe_exe_sub(framework, code, opts = {})
506
513
def self . to_win64pe ( framework , code , opts = { } )
507
514
# Allow the user to specify their own EXE template
508
515
set_template_default ( opts , "template_x64_windows.exe" )
509
- #try to inject code into executable by adding a section without affecting executable behavior
516
+
517
+ # Try to inject code into executable by adding a section without affecting executable behavior
510
518
if opts [ :inject ]
511
519
injector = Msf ::Exe ::SegmentInjector . new ( {
512
520
:payload => code ,
@@ -515,8 +523,20 @@ def self.to_win64pe(framework, code, opts = {})
515
523
} )
516
524
return injector . generate_pe
517
525
end
526
+
518
527
opts [ :exe_type ] = :exe_sub
519
- exe_sub_method ( code , opts )
528
+ return exe_sub_method ( code , opts )
529
+
530
+ #
531
+ # TODO: 64-bit support is currently failing to stage
532
+ #
533
+ # Append a new section instead
534
+ # appender = Msf::Exe::SegmentAppender.new({
535
+ # :payload => code,
536
+ # :template => opts[:template],
537
+ # :arch => :x64
538
+ # })
539
+ # return appender.generate_pe
520
540
end
521
541
522
542
# Embeds shellcode within a Windows PE file implementing the Windows
0 commit comments