2013-04-17 19:26:16 +00:00
|
|
|
# -*- coding:binary -*-
|
2012-10-18 16:40:44 +00:00
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
require 'msf/base/simple'
|
2013-07-03 17:25:15 +00:00
|
|
|
require 'spec_helper'
|
2012-10-18 16:40:44 +00:00
|
|
|
|
2013-07-05 21:58:19 +00:00
|
|
|
require 'support/shared/contexts/msf/util/exe'
|
|
|
|
|
2012-10-18 16:40:44 +00:00
|
|
|
describe Msf::Util::EXE do
|
|
|
|
|
|
|
|
subject do
|
|
|
|
described_class
|
|
|
|
end
|
|
|
|
|
|
|
|
$framework = Msf::Simple::Framework.create(
|
|
|
|
:module_types => [ Msf::MODULE_NOP ],
|
|
|
|
'DisableDatabase' => true
|
|
|
|
)
|
|
|
|
|
2013-06-18 21:15:29 +00:00
|
|
|
describe '.win32_rwx_exec' do
|
|
|
|
it "should contain the shellcode" do
|
|
|
|
bin = subject.win32_rwx_exec("asdfjklASDFJKL")
|
|
|
|
bin.should include("asdfjklASDFJKL")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.to_executable_fmt' do
|
2012-10-18 16:40:44 +00:00
|
|
|
it "should output nil when given a bogus format" do
|
|
|
|
bin = subject.to_executable_fmt($framework, "", "", "", "does not exist", {})
|
|
|
|
|
|
|
|
bin.should == nil
|
|
|
|
end
|
|
|
|
|
2013-07-03 17:25:15 +00:00
|
|
|
include_context 'Msf::Util::Exe'
|
|
|
|
|
|
|
|
@platform_format_map.each do |plat, formats|
|
2012-10-18 16:40:44 +00:00
|
|
|
context "with platform=#{plat}" do
|
|
|
|
let(:platform) do
|
|
|
|
Msf::Module::PlatformList.transform(plat)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should output nil when given bogus format" do
|
|
|
|
bin = subject.to_executable_fmt($framework, formats.first[:arch], platform, "\xcc", "asdf", {})
|
|
|
|
bin.should == nil
|
|
|
|
end
|
|
|
|
it "should output nil when given bogus arch" do
|
|
|
|
bin = subject.to_executable_fmt($framework, "asdf", platform, "\xcc", formats.first[:format], {})
|
|
|
|
bin.should == nil
|
|
|
|
end
|
2013-06-19 22:10:31 +00:00
|
|
|
[ ARCH_X86, ARCH_X64, ARCH_X86_64, ARCH_PPC, ARCH_MIPSLE, ARCH_MIPSBE, ARCH_ARMLE ].each do |arch|
|
|
|
|
it "returns nil when given bogus format for arch=#{arch}" do
|
|
|
|
bin = subject.to_executable_fmt($framework, arch, platform, "\xcc", "asdf", {})
|
|
|
|
end
|
|
|
|
end
|
2012-10-18 16:40:44 +00:00
|
|
|
|
|
|
|
formats.each do |format_hash|
|
|
|
|
fmt = format_hash[:format]
|
|
|
|
arch = format_hash[:arch]
|
|
|
|
|
|
|
|
if format_hash[:pending]
|
|
|
|
pending "returns an executable when given arch=#{arch}, fmt=#{fmt}"
|
|
|
|
next
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns an executable when given arch=#{arch}, fmt=#{fmt}" do
|
|
|
|
bin = subject.to_executable_fmt($framework, arch, platform, "\xcc", fmt, {})
|
|
|
|
bin.should be_a String
|
|
|
|
|
2013-07-03 17:25:15 +00:00
|
|
|
verify_bin_fingerprint(format_hash, bin)
|
2012-10-18 16:40:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2013-04-17 19:26:16 +00:00
|
|
|
|
2012-10-18 16:40:44 +00:00
|
|
|
end
|
|
|
|
|