mirror of
https://github.com/rapid7/metasploit-framework
synced 2024-10-09 04:26:11 +02:00
Pull out common stuff in Util::EXE/MsfVenom tests
This commit is contained in:
parent
ffb28feaa9
commit
e330916744
@ -1993,12 +1993,12 @@ End Sub
|
|||||||
when 'elf'
|
when 'elf'
|
||||||
if (not plat or (plat.index(Msf::Module::Platform::Linux)))
|
if (not plat or (plat.index(Msf::Module::Platform::Linux)))
|
||||||
output = case arch
|
output = case arch
|
||||||
when ARCH_X86,nil then Msf::Util::EXE.to_linux_x86_elf(framework, code, exeopts)
|
when ARCH_X86,nil then to_linux_x86_elf(framework, code, exeopts)
|
||||||
when ARCH_X86_64 then Msf::Util::EXE.to_linux_x64_elf(framework, code, exeopts)
|
when ARCH_X86_64 then to_linux_x64_elf(framework, code, exeopts)
|
||||||
when ARCH_X64 then Msf::Util::EXE.to_linux_x64_elf(framework, code, exeopts)
|
when ARCH_X64 then to_linux_x64_elf(framework, code, exeopts)
|
||||||
when ARCH_ARMLE then Msf::Util::EXE.to_linux_armle_elf(framework, code, exeopts)
|
when ARCH_ARMLE then to_linux_armle_elf(framework, code, exeopts)
|
||||||
when ARCH_MIPSBE then Msf::Util::EXE.to_linux_mipsbe_elf(framework, code, exeopts)
|
when ARCH_MIPSBE then to_linux_mipsbe_elf(framework, code, exeopts)
|
||||||
when ARCH_MIPSLE then Msf::Util::EXE.to_linux_mipsle_elf(framework, code, exeopts)
|
when ARCH_MIPSLE then to_linux_mipsle_elf(framework, code, exeopts)
|
||||||
end
|
end
|
||||||
elsif(plat and (plat.index(Msf::Module::Platform::BSD)))
|
elsif(plat and (plat.index(Msf::Module::Platform::BSD)))
|
||||||
output = case arch
|
output = case arch
|
||||||
@ -2006,17 +2006,22 @@ End Sub
|
|||||||
end
|
end
|
||||||
elsif(plat and (plat.index(Msf::Module::Platform::Solaris)))
|
elsif(plat and (plat.index(Msf::Module::Platform::Solaris)))
|
||||||
output = case arch
|
output = case arch
|
||||||
when ARCH_X86,nil then Msf::Util::EXE.to_solaris_x86_elf(framework, code, exeopts)
|
when ARCH_X86,nil then to_solaris_x86_elf(framework, code, exeopts)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# this should really be 'jar'
|
||||||
|
when 'java'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
when 'macho'
|
when 'macho'
|
||||||
output = case arch
|
output = case arch
|
||||||
when ARCH_X86,nil then Msf::Util::EXE.to_osx_x86_macho(framework, code, exeopts)
|
when ARCH_X86,nil then to_osx_x86_macho(framework, code, exeopts)
|
||||||
when ARCH_X86_64 then Msf::Util::EXE.to_osx_x64_macho(framework, code, exeopts)
|
when ARCH_X86_64 then to_osx_x64_macho(framework, code, exeopts)
|
||||||
when ARCH_X64 then Msf::Util::EXE.to_osx_x64_macho(framework, code, exeopts)
|
when ARCH_X64 then to_osx_x64_macho(framework, code, exeopts)
|
||||||
when ARCH_ARMLE then Msf::Util::EXE.to_osx_arm_macho(framework, code, exeopts)
|
when ARCH_ARMLE then to_osx_arm_macho(framework, code, exeopts)
|
||||||
when ARCH_PPC then Msf::Util::EXE.to_osx_ppc_macho(framework, code, exeopts)
|
when ARCH_PPC then to_osx_ppc_macho(framework, code, exeopts)
|
||||||
end
|
end
|
||||||
|
|
||||||
when 'vba'
|
when 'vba'
|
||||||
|
7
msfvenom
7
msfvenom
@ -430,7 +430,7 @@ class MsfVenom
|
|||||||
# possible
|
# possible
|
||||||
when "war"
|
when "war"
|
||||||
exe = ::Msf::Util::EXE.to_executable_fmt(framework, @opts[:arch], @opts[:platform], payload_raw, @opts[:format], exeopts)
|
exe = ::Msf::Util::EXE.to_executable_fmt(framework, @opts[:arch], @opts[:platform], payload_raw, @opts[:format], exeopts)
|
||||||
if (!exe and payload.platform.platforms.index(::Msf::Module::Platform::Java))
|
if (!exe && payload.respond_to?(:generate_war))
|
||||||
exe = payload.generate_war.pack
|
exe = payload.generate_war.pack
|
||||||
else
|
else
|
||||||
exe = ::Msf::Util::EXE.to_jsp_war(exe)
|
exe = ::Msf::Util::EXE.to_jsp_war(exe)
|
||||||
@ -441,7 +441,7 @@ class MsfVenom
|
|||||||
# payload if possible
|
# payload if possible
|
||||||
when "java"
|
when "java"
|
||||||
exe = ::Msf::Util::EXE.to_executable_fmt(framework, @opts[:arch], @opts[:platform], payload_raw, @opts[:format], exeopts)
|
exe = ::Msf::Util::EXE.to_executable_fmt(framework, @opts[:arch], @opts[:platform], payload_raw, @opts[:format], exeopts)
|
||||||
if(!exe and payload.platform.platforms.index(::Msf::Module::Platform::Java))
|
if (!exe && payload.respond_to?(:generate_jar))
|
||||||
exe = payload.generate_jar.pack
|
exe = payload.generate_jar.pack
|
||||||
end
|
end
|
||||||
if exe
|
if exe
|
||||||
@ -451,7 +451,8 @@ class MsfVenom
|
|||||||
end
|
end
|
||||||
|
|
||||||
when *::Msf::Simple::Buffer.transform_formats
|
when *::Msf::Simple::Buffer.transform_formats
|
||||||
@out.write ::Msf::Simple::Buffer.transform(payload_raw, @opts[:format])
|
buf = ::Msf::Simple::Buffer.transform(payload_raw, @opts[:format])
|
||||||
|
@out.write buf
|
||||||
|
|
||||||
when *::Msf::Util::EXE.to_executable_fmt_formats
|
when *::Msf::Util::EXE.to_executable_fmt_formats
|
||||||
exe = ::Msf::Util::EXE.to_executable_fmt(framework, @opts[:arch], @opts[:platform], payload_raw, @opts[:format], exeopts)
|
exe = ::Msf::Util::EXE.to_executable_fmt(framework, @opts[:arch], @opts[:platform], payload_raw, @opts[:format], exeopts)
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
require 'msf/core'
|
require 'msf/core'
|
||||||
require 'msf/base/simple'
|
require 'msf/base/simple'
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Msf::Util::EXE do
|
describe Msf::Util::EXE do
|
||||||
|
|
||||||
@ -28,41 +29,9 @@ describe Msf::Util::EXE do
|
|||||||
bin.should == nil
|
bin.should == nil
|
||||||
end
|
end
|
||||||
|
|
||||||
platform_format_map = {
|
include_context 'Msf::Util::Exe'
|
||||||
"windows" => [
|
|
||||||
{ :format => "dll", :arch => "x86", :file_fp => /PE32 .*DLL/ },
|
|
||||||
{ :format => "dll", :arch => "x64", :file_fp => /PE32\+.*DLL/ },
|
|
||||||
{ :format => "exe", :arch => "x86", :file_fp => /PE32 / },
|
|
||||||
{ :format => "exe", :arch => "x64", :file_fp => /PE32\+/ },
|
|
||||||
{ :format => "exe-small", :arch => "x86", :file_fp => /PE32 / },
|
|
||||||
# No template for 64-bit exe-small. That's fine, we probably
|
|
||||||
# don't need one.
|
|
||||||
#{ :format => "exe-small", :arch => "x64", :file_fp => /PE32\+/ },
|
|
||||||
{ :format => "exe-only", :arch => "x86", :file_fp => /PE32 / },
|
|
||||||
{ :format => "exe-only", :arch => "x64", :file_fp => /PE32\+ / },
|
|
||||||
],
|
|
||||||
"linux" => [
|
|
||||||
{ :format => "elf", :arch => "x86", :file_fp => /ELF 32.*SYSV/ },
|
|
||||||
{ :format => "elf", :arch => "x64", :file_fp => /ELF 64.*SYSV/ },
|
|
||||||
{ :format => "elf", :arch => "armle", :file_fp => /ELF 32.*ARM/ },
|
|
||||||
{ :format => "elf", :arch => "mipsbe", :file_fp => /ELF 32-bit MSB executable, MIPS/ },
|
|
||||||
{ :format => "elf", :arch => "mipsle", :file_fp => /ELF 32-bit LSB executable, MIPS/ },
|
|
||||||
],
|
|
||||||
"bsd" => [
|
|
||||||
{ :format => "elf", :arch => "x86", :file_fp => /ELF 32.*BSD/ },
|
|
||||||
],
|
|
||||||
"solaris" => [
|
|
||||||
{ :format => "elf", :arch => "x86", :file_fp => /ELF 32/ },
|
|
||||||
],
|
|
||||||
"osx" => [
|
|
||||||
{ :format => "macho", :arch => "x86", :file_fp => /Mach-O.*i386/ },
|
|
||||||
{ :format => "macho", :arch => "x64", :file_fp => /Mach-O 64/ },
|
|
||||||
{ :format => "macho", :arch => "armle", :file_fp => /Mach-O.*acorn/, :pending => true },
|
|
||||||
{ :format => "macho", :arch => "ppc", :file_fp => /Mach-O.*ppc/, :pending => true },
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
platform_format_map.each do |plat, formats|
|
@platform_format_map.each do |plat, formats|
|
||||||
context "with platform=#{plat}" do
|
context "with platform=#{plat}" do
|
||||||
let(:platform) do
|
let(:platform) do
|
||||||
Msf::Module::PlatformList.transform(plat)
|
Msf::Module::PlatformList.transform(plat)
|
||||||
@ -95,12 +64,7 @@ describe Msf::Util::EXE do
|
|||||||
bin = subject.to_executable_fmt($framework, arch, platform, "\xcc", fmt, {})
|
bin = subject.to_executable_fmt($framework, arch, platform, "\xcc", fmt, {})
|
||||||
bin.should be_a String
|
bin.should be_a String
|
||||||
|
|
||||||
f = IO.popen("file -","w+")
|
verify_bin_fingerprint(format_hash, bin)
|
||||||
f.write(bin)
|
|
||||||
f.close_write
|
|
||||||
fp = f.read
|
|
||||||
f.close
|
|
||||||
fp.should =~ format_hash[:file_fp] if format_hash[:file_fp]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -33,7 +33,6 @@ describe MsfVenom do
|
|||||||
end
|
end
|
||||||
|
|
||||||
let(:framework) { @framework }
|
let(:framework) { @framework }
|
||||||
|
|
||||||
describe "#dump_encoders" do
|
describe "#dump_encoders" do
|
||||||
it "should list known encoders" do
|
it "should list known encoders" do
|
||||||
dump = venom.dump_encoders
|
dump = venom.dump_encoders
|
||||||
@ -140,6 +139,8 @@ describe MsfVenom do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "#generate" do
|
describe "#generate" do
|
||||||
|
include_context 'Msf::Util::Exe'
|
||||||
|
|
||||||
before { venom.parse_args(args) }
|
before { venom.parse_args(args) }
|
||||||
|
|
||||||
context "with 'exe' format" do
|
context "with 'exe' format" do
|
||||||
@ -165,6 +166,22 @@ describe MsfVenom do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@platform_format_map.each do |plat, formats|
|
||||||
|
formats.each do |format_hash|
|
||||||
|
context "with format=#{format_hash[:format]} platform=#{plat} arch=#{format_hash[:arch]}" do
|
||||||
|
# This will build executables with no payload. They won't work
|
||||||
|
# of course, but at least we can see that it is producing the
|
||||||
|
# correct file format for the given arch and platform.
|
||||||
|
let(:args) { %W! -p - -f #{format_hash[:format]} -a #{format_hash[:arch]} --platform #{plat} ! }
|
||||||
|
it "should print a #{format_hash[:format]} to stdout" do
|
||||||
|
venom.generate
|
||||||
|
output = stdout.string
|
||||||
|
verify_bin_fingerprint(format_hash, output)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user