Skip to content

Commit e3c5303

Browse files
author
agix
committed
Merge pull request #1 from todb-r7/exe_only_patch
Exe only patch : avoid merge conflict and don't use win32pe_only everywhere by default.
2 parents 23b6890 + 1873053 commit e3c5303

File tree

1 file changed

+15
-23
lines changed

1 file changed

+15
-23
lines changed

lib/msf/util/exe.rb

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
# -*- coding: binary -*-
2-
##
3-
# $Id$
4-
##
52

6-
###
7-
#
8-
# framework-util-exe
9-
# --------------
3+
module Msf
4+
module Util
5+
106
#
117
# The class provides methods for creating and encoding executable file
128
# formats for various platforms. It is a replacement for the previous
139
# code in Rex::Text
1410
#
15-
###
16-
17-
module Msf
18-
module Util
1911
class EXE
2012

2113
require 'rex'
@@ -74,7 +66,7 @@ def self.to_executable(framework, arch, plat, code='', opts={})
7466
if (arch.index(ARCH_X86))
7567

7668
if (plat.index(Msf::Module::Platform::Windows))
77-
return to_win32pe_only(framework, code, opts)
69+
return to_win32pe(framework, code, opts)
7870
end
7971

8072
if (plat.index(Msf::Module::Platform::Linux))
@@ -368,19 +360,19 @@ def self.to_win32pe_only(framework, code, opts={})
368360

369361
sections_header = []
370362
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]] }
371-
363+
372364

373365
#look for section with entry point
374366
sections_header.each do |sec|
375367
virtualAddress = sec[1][0xc,0x4].unpack('L')[0]
376368
sizeOfRawData = sec[1][0x10,0x4].unpack('L')[0]
377369
characteristics = sec[1][0x24,0x4].unpack('L')[0]
378370
if pe.hdr.opt.AddressOfEntryPoint >= virtualAddress && pe.hdr.opt.AddressOfEntryPoint < virtualAddress+sizeOfRawData
379-
#put this section writable
380-
characteristics|=0x80000000
381-
newcharacteristics = [characteristics].pack('L')
382-
exe[sec[0],newcharacteristics.length]=newcharacteristics
383-
end
371+
#put this section writable
372+
characteristics|=0x80000000
373+
newcharacteristics = [characteristics].pack('L')
374+
exe[sec[0],newcharacteristics.length]=newcharacteristics
375+
end
384376
end
385377

386378
#put the shellcode at the entry point, overwriting template
@@ -936,7 +928,7 @@ def self.to_vba(framework,code,opts={})
936928
end
937929

938930
def self.to_win32pe_vba(framework, code, opts={})
939-
to_exe_vba(to_win32pe_only(framework, code, opts))
931+
to_exe_vba(to_win32pe(framework, code, opts))
940932
end
941933

942934
def self.to_exe_vbs(exes = '', opts={})
@@ -1204,15 +1196,15 @@ def self.to_win32pe_psh(framework, code, opts={})
12041196
end
12051197

12061198
def self.to_win32pe_vbs(framework, code, opts={})
1207-
to_exe_vbs(to_win32pe_only(framework, code, opts), opts)
1199+
to_exe_vbs(to_win32pe(framework, code, opts), opts)
12081200
end
12091201

12101202
def self.to_win32pe_asp(framework, code, opts={})
1211-
to_exe_asp(to_win32pe_only(framework, code, opts), opts)
1203+
to_exe_asp(to_win32pe(framework, code, opts), opts)
12121204
end
12131205

12141206
def self.to_win32pe_aspx(framework, code, opts={})
1215-
to_exe_aspx(to_win32pe_only(framework, code, opts), opts)
1207+
to_exe_aspx(to_win32pe(framework, code, opts), opts)
12161208
end
12171209

12181210
# Creates a jar file that drops the provided +exe+ into a random file name
@@ -1940,7 +1932,7 @@ def self.to_executable_fmt(framework, arch, plat, code, fmt, exeopts)
19401932
output = Msf::Util::EXE.to_vba(framework, code, exeopts)
19411933

19421934
when 'vba-exe'
1943-
exe = Msf::Util::EXE.to_win32pe_only(framework, code, exeopts)
1935+
exe = Msf::Util::EXE.to_win32pe(framework, code, exeopts)
19441936
output = Msf::Util::EXE.to_exe_vba(exe)
19451937

19461938
when 'vbs'

0 commit comments

Comments
 (0)