Fix msfvenom -c

Also cleans up some dirty ifs that should be cases.

[SeeRM #7298]
unstable
James Lee 2012-10-16 19:14:01 -05:00
parent 1a0e53dcbb
commit e2cf22add7
1 changed files with 35 additions and 38 deletions

View File

@ -312,7 +312,8 @@ opts[:badchars] = Rex::Text.hex_to_raw(opts[:badchars]) if opts[:
# set the defaults unless something is already set by the user # set the defaults unless something is already set by the user
if opts[:payload] != 'stdin' if opts[:payload] != 'stdin'
opts[:arch] ||= payload.arch[0] opts[:arch] ||= payload.arch[0]
opts[:platform] ||= Msf::Module::PlatformList.transform(payload.platform.platforms) # If it's not stdin, we'll already have a PlatfromList
opts[:platform] ||= payload.platform
else else
# defaults for stdin payloads users should define them # defaults for stdin payloads users should define them
unless opts[:arch] unless opts[:arch]
@ -325,6 +326,8 @@ else
end end
end end
# After this point, we will have set a platform, even if it's wrong.
opts[:format] ||= 'ruby' opts[:format] ||= 'ruby'
opts[:encoder] ||= nil opts[:encoder] ||= nil
opts[:encode] ||= !(opts[:badchars].nil? or opts[:badchars].empty?) opts[:encode] ||= !(opts[:badchars].nil? or opts[:badchars].empty?)
@ -351,7 +354,7 @@ exeopts = { :inject => opts[:inject], :template_path => path, :template => altex
# If we were given addshellcode for a win32 payload, # If we were given addshellcode for a win32 payload,
# create a double-payload; one running in one thread, one running in the other # create a double-payload; one running in one thread, one running in the other
if opts[:addshellcode] and opts[:platform].include?(Msf::Module::Platform::Windows) and opts[:arch] == 'x86' if opts[:addshellcode] and opts[:platform].platforms.include?(Msf::Module::Platform::Windows) and opts[:arch] == 'x86'
payload_raw = Msf::Util::EXE.win32_rwx_exec_thread(payload_raw,0,'end') payload_raw = Msf::Util::EXE.win32_rwx_exec_thread(payload_raw,0,'end')
file = ::File.new(opts[:addshellcode]) file = ::File.new(opts[:addshellcode])
file.binmode file.binmode
@ -450,52 +453,46 @@ when /java/i
print_error("Could not generate payload format") print_error("Could not generate payload format")
end end
when /elf/i when /elf/i
if (not opts[:platform] or (opts[:platform].index(Msf::Module::Platform::Linux))) if (opts[:platform].index(Msf::Module::Platform::Linux))
if opts[:arch] =~ /x64/ elf = case opts[:arch]
elf = Msf::Util::EXE.to_linux_x64_elf($framework, payload_raw, exeopts) when /x64/; Msf::Util::EXE.to_linux_x64_elf($framework, payload_raw, exeopts)
elsif opts[:arch] =~ /x86/ when /x86/; Msf::Util::EXE.to_linux_x86_elf($framework, payload_raw, exeopts)
elf = Msf::Util::EXE.to_linux_x86_elf($framework, payload_raw, exeopts) when /arm/; Msf::Util::EXE.to_linux_armle_elf($framework, payload_raw, exeopts)
elsif opts[:arch] =~ /arm/
elf = Msf::Util::EXE.to_linux_armle_elf($framework, payload_raw, exeopts)
else
print_error("This format does not support that architecture")
exit
end end
elsif(opts[:platform].index(Msf::Module::Platform::BSD)) elsif(opts[:platform].index(Msf::Module::Platform::BSD))
if opts[:arch] =~ /x86/ elf = case opts[:arch]
elf = Msf::Util::EXE.to_bsd_x86_elf($framework, payload_raw, exeopts) when /x86/; Msf::Util::EXE.to_bsd_x86_elf($framework, payload_raw, exeopts)
else
print_error("This format does not support that architecture")
exit
end end
elsif(opts[:platform].index(Msf::Module::Platform::Solaris)) elsif(opts[:platform].index(Msf::Module::Platform::Solaris))
if opts[:arch] =~ /x86/ elf = case opts[:arch]
elf = Msf::Util::EXE.to_solaris_x86_elf($framework, payload_raw, exeopts) when /x86/; Msf::Util::EXE.to_solaris_x86_elf($framework, payload_raw, exeopts)
else end
end
if elf.nil?
print_error("This format does not support that architecture") print_error("This format does not support that architecture")
exit exit
end end
end
$stdout.write elf $stdout.write elf
when /macho/i when /macho/i
if opts[:arch] =~ /x64/ bin = case opts[:arch]
bin = Msf::Util::EXE.to_osx_x64_macho($framework, payload_raw, exeopts) when /x64/; Msf::Util::EXE.to_osx_x64_macho($framework, payload_raw, exeopts)
elsif opts[:arch] =~ /x86/ when /x86/; Msf::Util::EXE.to_osx_x86_macho($framework, payload_raw, exeopts)
bin = Msf::Util::EXE.to_osx_x86_macho($framework, payload_raw, exeopts) when /arm/; Msf::Util::EXE.to_osx_arm_macho($framework, payload_raw, exeopts)
elsif opts[:arch] =~ /arm/ when /ppc/; Msf::Util::EXE.to_osx_ppc_macho($framework, payload_raw, exeopts)
bin = Msf::Util::EXE.to_osx_arm_macho($framework, payload_raw, exeopts) end
elsif opts[:arch] =~ /ppc/ if bin.nil?
bin = Msf::Util::EXE.to_osx_ppc_macho($framework, payload_raw, exeopts)
else
print_error("This format does not support that architecture") print_error("This format does not support that architecture")
exit exit
end end
$stdout.write bin $stdout.write bin
when /dll/i when /dll/i
if opts[:arch] == "x86" dll = case opts[:arch]
dll = Msf::Util::EXE.to_win32pe_dll($framework, payload_raw) when /x86/; Msf::Util::EXE.to_win32pe_dll($framework, payload_raw)
elsif opts[:arch] == "x86_64" when /x64/; Msf::Util::EXE.to_win64pe_dll($framework, payload_raw)
dll = Msf::Util::EXE.to_win64pe_dll($framework, payload_raw) end
if dll.nil?
print_error("This format does not support that architecture")
exit
end end
$stdout.write dll $stdout.write dll