cleans & DRYs exploit/exe & util/exe & msfpayload

bug/bundler_fix
Joshua Smith 2014-10-23 01:10:38 -05:00
parent 5f19af67a8
commit f19b093529
3 changed files with 370 additions and 425 deletions

View File

@ -42,9 +42,7 @@ module Exploit::EXE
path ||= datastore['EXE::Custom']
print_status("Using custom payload #{path}, RHOST and RPORT settings will be ignored!")
datastore['DisablePayloadHandler'] = true
file = ::File.open(path,'rb')
exe = file.read(file.stat.size)
file.close
::File.open(path,'rb') {|f| exe = f.read(f.stat.size)}
exe
end
@ -58,16 +56,13 @@ module Exploit::EXE
pl ||= payload.encoded
# Fall back to x86...
if not opts[:arch] or opts[:arch].length < 1
opts[:arch] = [ ARCH_X86 ]
end
opts[:arch] = [ARCH_X86] if !opts[:arch] || opts[:arch].length < 1
# Ensure we have an array
if not opts[:arch].kind_of? Array
opts[:arch] = [ opts[:arch] ]
end
opts[:arch] = [opts[:arch]] unless opts[:arch].kind_of? Array
# Transform the PlatformList
if (opts[:platform].kind_of? Msf::Module::PlatformList)
if opts[:platform].kind_of? Msf::Module::PlatformList
opts[:platform] = opts[:platform].platforms
end
@ -89,7 +84,7 @@ module Exploit::EXE
#Ensure opts[:arch] is an array
opts[:arch] = [opts[:arch]] unless opts[:arch].kind_of? Array
if opts[:arch] and (opts[:arch].index(ARCH_X64) or opts[:arch].index(ARCH_X86_64))
if opts[:arch] && (opts[:arch].index(ARCH_X64) or opts[:arch].index(ARCH_X86_64))
exe = Msf::Util::EXE.to_win64pe_service(framework, pl, opts)
else
exe = Msf::Util::EXE.to_win32pe_service(framework, pl, opts)
@ -112,12 +107,12 @@ module Exploit::EXE
opts[:arch] = [opts[:arch]] unless opts[:arch].kind_of? Array
# NOTE: Only x86_64 linux is supported here.
if (plat.index(Msf::Module::Platform::Linux))
if opts[:arch] and (opts[:arch].index(ARCH_X64) or opts[:arch].index(ARCH_X86_64))
if plat.index(Msf::Module::Platform::Linux)
if opts[:arch] && (opts[:arch].index(ARCH_X64) || opts[:arch].index(ARCH_X86_64))
dll = Msf::Util::EXE.to_linux_x64_elf_dll(framework, pl,opts)
end
elsif (plat.index(Msf::Module::Platform::Windows))
if opts[:arch] and (opts[:arch].index(ARCH_X64) or opts[:arch].index(ARCH_X86_64))
elsif plat.index(Msf::Module::Platform::Windows)
if opts[:arch] && (opts[:arch].index(ARCH_X64) || opts[:arch].index(ARCH_X86_64))
dll = Msf::Util::EXE.to_win64pe_dll(framework, pl, opts)
else
dll = Msf::Util::EXE.to_win32pe_dll(framework, pl, opts)
@ -140,9 +135,7 @@ module Exploit::EXE
:uac => datastore['MSI::UAC']
})
msi = Msf::Util::EXE.to_exe_msi(framework, exe, opts)
return msi
Msf::Util::EXE.to_exe_msi(framework, exe, opts)
end
protected

File diff suppressed because it is too large Load Diff

View File

@ -54,9 +54,7 @@ $args.parse(ARGV) { |opt, idx, val|
end
}
if (cmd != "list" and rest.length < 2)
usage
end
usage if cmd != "list" && rest.length < 2
require 'msf/ui'
require 'msf/base'
@ -125,18 +123,18 @@ end
payload.datastore.merge! options
if (cmd =~ /^(p|y|r|d|c|h|j|x|b|v|w|n|o)$/)
fmt = 'perl' if (cmd =~ /^p$/)
fmt = 'ruby' if (cmd =~ /^y$/)
fmt = 'raw' if (cmd =~ /^(r|x|d|o)$/)
fmt = 'raw' if (cmd =~ /^v$/)
fmt = 'c' if (cmd =~ /^c$/)
fmt = 'csharp' if (cmd =~ /^h$/)
fmt = 'js_be' if (cmd =~ /^j$/ and Rex::Arch.endian(payload.arch) == ENDIAN_BIG)
fmt = 'js_le' if (cmd =~ /^j$/ and ! fmt)
fmt = 'java' if (cmd =~ /^b$/)
fmt = 'raw' if (cmd =~ /^w$/)
fmt = 'python' if (cmd =~ /^n$/)
if cmd =~ /^(p|y|r|d|c|h|j|x|b|v|w|n|o)$/
fmt = 'perl' if cmd =~ /^p$/
fmt = 'ruby' if cmd =~ /^y$/
fmt = 'raw' if cmd =~ /^(r|x|d|o)$/
fmt = 'raw' if cmd =~ /^v$/
fmt = 'c' if cmd =~ /^c$/
fmt = 'csharp' if cmd =~ /^h$/
fmt = 'js_be' if cmd =~ /^j$/ && Rex::Arch.endian(payload.arch) == ENDIAN_BIG
fmt = 'js_le' if cmd =~ /^j$/ && !fmt
fmt = 'java' if cmd =~ /^b$/
fmt = 'raw' if cmd =~ /^w$/
fmt = 'python' if cmd =~ /^n$/
enc = options['ENCODER']
begin
@ -151,7 +149,7 @@ if (cmd =~ /^(p|y|r|d|c|h|j|x|b|v|w|n|o)$/)
$stdout.binmode
if (cmd =~ /^x$/)
if cmd =~ /^x$/
note =
"Created by msfpayload (http://www.metasploit.com).\n" +
"Payload: " + payload.refname + "\n" +
@ -163,11 +161,11 @@ if (cmd =~ /^(p|y|r|d|c|h|j|x|b|v|w|n|o)$/)
exe = Msf::Util::EXE.to_executable($framework, arch, plat, buf)
if(!exe and plat.index(Msf::Module::Platform::Java))
if !exe && plat.index(Msf::Module::Platform::Java)
exe = payload.generate_jar.pack
end
if(exe)
if exe
$stderr.puts(note)
$stdout.write(exe)
exit(0)
@ -177,7 +175,7 @@ if (cmd =~ /^(p|y|r|d|c|h|j|x|b|v|w|n|o)$/)
exit(-1)
end
if(cmd =~ /^v$/)
if cmd =~ /^v$/
exe = Msf::Util::EXE.to_win32pe($framework, buf)
note =
"'Created by msfpayload (http://www.metasploit.com).\r\n" +
@ -190,7 +188,7 @@ if (cmd =~ /^(p|y|r|d|c|h|j|x|b|v|w|n|o)$/)
exit(0)
end
if(cmd =~ /^d$/)
if cmd =~ /^d$/
dll = Msf::Util::EXE.to_win32pe_dll($framework, buf)
note =
"Created by msfpayload (http://www.metasploit.com).\r\n" +
@ -198,7 +196,7 @@ if (cmd =~ /^(p|y|r|d|c|h|j|x|b|v|w|n|o)$/)
" Length: " + buf.length.to_s + "\r\n" +
"Options: " + options.inspect + "\r\n"
if(dll)
if dll
$stderr.puts(note)
$stdout.write(dll)
exit(0)
@ -208,7 +206,7 @@ if (cmd =~ /^(p|y|r|d|c|h|j|x|b|v|w|n|o)$/)
exit(-1)
end
if (cmd =~ /^o$/)
if cmd =~ /^o$/
so = Msf::Util::EXE.to_linux_x64_elf_dll($framework, buf)
note =
"Created by msfpayload (http://www.metasploit.com).\r\n" +
@ -216,7 +214,7 @@ if (cmd =~ /^(p|y|r|d|c|h|j|x|b|v|w|n|o)$/)
" Length: " + buf.length.to_s + "\r\n" +
"Options: " + options.inspect + "\r\n"
if(so)
if so
$stderr.puts(note)
$stdout.write(so)
exit(0)
@ -226,7 +224,7 @@ if (cmd =~ /^(p|y|r|d|c|h|j|x|b|v|w|n|o)$/)
exit(-1)
end
if(cmd =~ /^w$/)
if cmd =~ /^w$/
note =
"Created by msfpayload (http://www.metasploit.com).\n" +
"Payload: " + payload.refname + "\n" +
@ -244,7 +242,7 @@ if (cmd =~ /^(p|y|r|d|c|h|j|x|b|v|w|n|o)$/)
end
if(exe)
if exe
$stderr.puts(note)
$stdout.write(exe)
exit(0)
@ -256,7 +254,7 @@ if (cmd =~ /^(p|y|r|d|c|h|j|x|b|v|w|n|o)$/)
$stdout.write(buf)
elsif (cmd =~ /^(s|o)$/)
elsif cmd =~ /^(s|o)$/
payload.datastore.import_options_from_s(rest.join('_|_'), '_|_')
puts Msf::Serializer::ReadableText.dump_module(payload)