Skip to content

Commit f19b093

Browse files
committed
cleans & DRYs exploit/exe & util/exe & msfpayload
1 parent 5f19af6 commit f19b093

File tree

3 files changed

+365
-420
lines changed

3 files changed

+365
-420
lines changed

lib/msf/core/exploit/exe.rb

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ def get_custom_exe(path=nil)
4242
path ||= datastore['EXE::Custom']
4343
print_status("Using custom payload #{path}, RHOST and RPORT settings will be ignored!")
4444
datastore['DisablePayloadHandler'] = true
45-
file = ::File.open(path,'rb')
46-
exe = file.read(file.stat.size)
47-
file.close
45+
::File.open(path,'rb') {|f| exe = f.read(f.stat.size)}
4846
exe
4947
end
5048

@@ -58,16 +56,13 @@ def generate_payload_exe(opts = {})
5856
pl ||= payload.encoded
5957

6058
# Fall back to x86...
61-
if not opts[:arch] or opts[:arch].length < 1
62-
opts[:arch] = [ ARCH_X86 ]
63-
end
59+
opts[:arch] = [ARCH_X86] if !opts[:arch] || opts[:arch].length < 1
60+
6461
# Ensure we have an array
65-
if not opts[:arch].kind_of? Array
66-
opts[:arch] = [ opts[:arch] ]
67-
end
62+
opts[:arch] = [opts[:arch]] unless opts[:arch].kind_of? Array
6863

6964
# Transform the PlatformList
70-
if (opts[:platform].kind_of? Msf::Module::PlatformList)
65+
if opts[:platform].kind_of? Msf::Module::PlatformList
7166
opts[:platform] = opts[:platform].platforms
7267
end
7368

@@ -89,7 +84,7 @@ def generate_payload_exe_service(opts = {})
8984
#Ensure opts[:arch] is an array
9085
opts[:arch] = [opts[:arch]] unless opts[:arch].kind_of? Array
9186

92-
if opts[:arch] and (opts[:arch].index(ARCH_X64) or opts[:arch].index(ARCH_X86_64))
87+
if opts[:arch] && (opts[:arch].index(ARCH_X64) or opts[:arch].index(ARCH_X86_64))
9388
exe = Msf::Util::EXE.to_win64pe_service(framework, pl, opts)
9489
else
9590
exe = Msf::Util::EXE.to_win32pe_service(framework, pl, opts)
@@ -112,12 +107,12 @@ def generate_payload_dll(opts = {})
112107
opts[:arch] = [opts[:arch]] unless opts[:arch].kind_of? Array
113108

114109
# NOTE: Only x86_64 linux is supported here.
115-
if (plat.index(Msf::Module::Platform::Linux))
116-
if opts[:arch] and (opts[:arch].index(ARCH_X64) or opts[:arch].index(ARCH_X86_64))
110+
if plat.index(Msf::Module::Platform::Linux)
111+
if opts[:arch] && (opts[:arch].index(ARCH_X64) || opts[:arch].index(ARCH_X86_64))
117112
dll = Msf::Util::EXE.to_linux_x64_elf_dll(framework, pl,opts)
118113
end
119-
elsif (plat.index(Msf::Module::Platform::Windows))
120-
if opts[:arch] and (opts[:arch].index(ARCH_X64) or opts[:arch].index(ARCH_X86_64))
114+
elsif plat.index(Msf::Module::Platform::Windows)
115+
if opts[:arch] && (opts[:arch].index(ARCH_X64) || opts[:arch].index(ARCH_X86_64))
121116
dll = Msf::Util::EXE.to_win64pe_dll(framework, pl, opts)
122117
else
123118
dll = Msf::Util::EXE.to_win32pe_dll(framework, pl, opts)
@@ -140,9 +135,7 @@ def generate_payload_msi(opts = {})
140135
:uac => datastore['MSI::UAC']
141136
})
142137

143-
msi = Msf::Util::EXE.to_exe_msi(framework, exe, opts)
144-
145-
return msi
138+
Msf::Util::EXE.to_exe_msi(framework, exe, opts)
146139
end
147140

148141
protected

0 commit comments

Comments
 (0)