Merge branch 'cleanup/specs' of git://github.com/jlee-r7/metasploit-framework into jlee-r7-cleanup/specs
commit
d7e702891d
2
Rakefile
2
Rakefile
|
@ -37,7 +37,7 @@ namespace :yard do
|
|||
task :stats => :environment do
|
||||
stats = YARD::CLI::Stats.new
|
||||
yard_arguments = yard_options + ['--compact', '--list-undoc'] + yard_files
|
||||
stats.run *yard_arguments
|
||||
stats.run(*yard_arguments)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,97 @@
|
|||
|
||||
require 'msf/core/task_manager'
|
||||
|
||||
describe Msf::TaskManager do
|
||||
|
||||
let(:framework) do
|
||||
Msf::Framework.new
|
||||
end
|
||||
|
||||
let(:tm) do
|
||||
Msf::TaskManager.new(framework)
|
||||
end
|
||||
|
||||
it "should have attributes" do
|
||||
tm.should respond_to("processing")
|
||||
tm.should respond_to("queue")
|
||||
tm.should respond_to("thread")
|
||||
tm.should respond_to("framework")
|
||||
tm.should respond_to("processing=")
|
||||
tm.should respond_to("queue=")
|
||||
tm.should respond_to("thread=")
|
||||
tm.should respond_to("framework=")
|
||||
end
|
||||
|
||||
it "should initialize with an empty queue" do
|
||||
tm.queue.length.should == 0
|
||||
tm.backlog.should == 0
|
||||
tm.backlog.should == tm.queue.length
|
||||
end
|
||||
|
||||
it "should add items to the queue and process them" do
|
||||
tm.queue_proc(Proc.new{ })
|
||||
tm.backlog.should == 1
|
||||
t = Msf::TaskManager::Task.new(Proc.new { })
|
||||
tm.queue_task(t)
|
||||
tm.backlog.should == 2
|
||||
tm.start
|
||||
t.wait
|
||||
tm.backlog.should == 0
|
||||
end
|
||||
|
||||
it "should add items to the queue and flush them" do
|
||||
tm.queue_proc(Proc.new{ })
|
||||
tm.backlog.should == 1
|
||||
tm.queue_proc(Proc.new{ })
|
||||
tm.backlog.should == 2
|
||||
tm.flush
|
||||
tm.backlog.should == 0
|
||||
end
|
||||
|
||||
it "should start and stop" do
|
||||
t = Msf::TaskManager::Task.new(Proc.new { })
|
||||
tm.queue_task(t)
|
||||
tm.backlog.should == 1
|
||||
tm.start
|
||||
t.wait
|
||||
tm.backlog.should == 0
|
||||
tm.stop
|
||||
1.upto 100 do |cnt|
|
||||
tm.queue_proc(Proc.new{ })
|
||||
tm.backlog.should == cnt
|
||||
end
|
||||
t = Msf::TaskManager::Task.new(Proc.new { })
|
||||
tm.queue_task(t)
|
||||
tm.start
|
||||
t.wait
|
||||
tm.backlog.should == 0
|
||||
end
|
||||
|
||||
it "should handle task timeouts" do
|
||||
t = Msf::TaskManager::Task.new(Proc.new { sleep(30) })
|
||||
t.timeout = 0.1
|
||||
|
||||
tm.start
|
||||
tm.queue_task(t)
|
||||
t.wait
|
||||
|
||||
t.status.should == :timeout
|
||||
t.duration.should <= 1.0
|
||||
end
|
||||
|
||||
it "should handle task exceptions" do
|
||||
t = Msf::TaskManager::Task.new(Proc.new { asdf1234() })
|
||||
tm.start
|
||||
tm.queue_task(t)
|
||||
t.wait
|
||||
t.status.should == :dropped
|
||||
t.exception.class.should == ::NoMethodError
|
||||
|
||||
t = Msf::TaskManager::Task.new(Proc.new { return 12345 })
|
||||
tm.queue_task(t)
|
||||
t.wait
|
||||
t.status.should == :dropped
|
||||
t.exception.should be_a ::LocalJumpError
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,102 @@
|
|||
|
||||
require 'msf/core'
|
||||
require 'msf/base/simple'
|
||||
|
||||
describe Msf::Util::EXE do
|
||||
|
||||
subject do
|
||||
described_class
|
||||
end
|
||||
|
||||
$framework = Msf::Simple::Framework.create(
|
||||
:module_types => [ Msf::MODULE_NOP ],
|
||||
'DisableDatabase' => true
|
||||
)
|
||||
|
||||
context '.to_executable_fmt' do
|
||||
it "should output nil when given a bogus format" do
|
||||
bin = subject.to_executable_fmt($framework, "", "", "", "does not exist", {})
|
||||
|
||||
bin.should == nil
|
||||
end
|
||||
|
||||
platform_format_map = {
|
||||
"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\+/ },
|
||||
],
|
||||
"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/, :pending => true },
|
||||
],
|
||||
"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|
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
f = IO.popen("file -","w+")
|
||||
f.write(bin)
|
||||
f.close_write
|
||||
fp = f.read
|
||||
f.close
|
||||
fp.should =~ format_hash[:file_fp] if format_hash[:file_fp]
|
||||
end
|
||||
|
||||
it "returns nil when given bogus format for arch=#{arch}" do
|
||||
bin = subject.to_executable_fmt($framework, arch, platform, "\xcc", "asdf", {})
|
||||
bin.should == nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -1,8 +1,5 @@
|
|||
|
||||
require 'testbase'
|
||||
require 'rexml/document'
|
||||
require 'rex/parser/nmap_xml'
|
||||
require 'spec'
|
||||
|
||||
xml = '
|
||||
<?xml version="1.0" ?>
|
||||
|
@ -46,9 +43,9 @@ describe Rex::Parser::NmapXMLStreamParser do
|
|||
host["addrs"]["ipv4"].should == "192.168.0.1"
|
||||
end
|
||||
}
|
||||
REXML::Document.parse_stream(StringIO.new(xml), parser)
|
||||
it "should have found exactly one host" do
|
||||
total_hosts.should == 1
|
||||
end
|
||||
REXML::Document.parse_stream(StringIO.new(xml), parser)
|
||||
end
|
||||
|
|
@ -0,0 +1,104 @@
|
|||
require 'rex/socket/range_walker'
|
||||
|
||||
describe Rex::Socket::RangeWalker do
|
||||
it "should have a num_ips attribute" do
|
||||
walker = Rex::Socket::RangeWalker.new("")
|
||||
walker.should respond_to("num_ips")
|
||||
walker.should respond_to("length")
|
||||
walker.num_ips.should == walker.length
|
||||
end
|
||||
it "should handle single ipv6 addresses" do
|
||||
walker = Rex::Socket::RangeWalker.new("::1")
|
||||
walker.should be_valid
|
||||
walker.length.should == 1
|
||||
end
|
||||
|
||||
it "should handle ranges" do
|
||||
walker = Rex::Socket::RangeWalker.new("10.1.1.1-2")
|
||||
walker.should be_valid
|
||||
walker.length.should == 2
|
||||
walker.next_ip.should == "10.1.1.1"
|
||||
walker = Rex::Socket::RangeWalker.new("10.1-2.1.1-2")
|
||||
walker.should be_valid
|
||||
walker.length.should == 4
|
||||
walker = Rex::Socket::RangeWalker.new("10.1-2.3-4.5-6")
|
||||
walker.should be_valid
|
||||
walker.length.should == 8
|
||||
walker.should include("10.1.3.5")
|
||||
end
|
||||
|
||||
it "should default the lower bound of a range to 0" do
|
||||
walker = Rex::Socket::RangeWalker.new("10.1.3.-17")
|
||||
walker.should be_valid
|
||||
walker.length.should == 18
|
||||
walker = Rex::Socket::RangeWalker.new("10.1.3.-255")
|
||||
walker.should be_valid
|
||||
walker.length.should == 256
|
||||
end
|
||||
|
||||
it "should default the upper bound of a range to 255" do
|
||||
walker = Rex::Socket::RangeWalker.new("10.1.3.254-")
|
||||
walker.should be_valid
|
||||
walker.length.should == 2
|
||||
end
|
||||
|
||||
it "should take * to mean 0-255" do
|
||||
walker = Rex::Socket::RangeWalker.new("10.1.3.*")
|
||||
walker.should be_valid
|
||||
walker.length.should == 256
|
||||
walker.next_ip.should == "10.1.3.0"
|
||||
walker.should include("10.1.3.255")
|
||||
walker = Rex::Socket::RangeWalker.new("10.1.*.3")
|
||||
walker.should be_valid
|
||||
walker.length.should == 256
|
||||
walker.next_ip.should == "10.1.0.3"
|
||||
walker.should include("10.1.255.3")
|
||||
end
|
||||
|
||||
it "should handle lists" do
|
||||
#walker = Rex::Socket::RangeWalker.new("10.1.1.1,2")
|
||||
#walker.should be_valid
|
||||
#walker.length.should == 2
|
||||
walker = Rex::Socket::RangeWalker.new("10.1.1.1")
|
||||
walker.should be_valid
|
||||
walker.length.should == 1
|
||||
walker = Rex::Socket::RangeWalker.new("10.1.1.1,3")
|
||||
walker.should be_valid
|
||||
walker.length.should == 2
|
||||
walker.should_not include("10.1.1.2")
|
||||
end
|
||||
|
||||
it "should produce the same ranges with * and 0-255" do
|
||||
a = Rex::Socket::RangeWalker.new("10.1.3.*")
|
||||
b = Rex::Socket::RangeWalker.new("10.1.3.0-255")
|
||||
a.ranges.should eq(b.ranges)
|
||||
end
|
||||
|
||||
it "should handle ranges and lists together" do
|
||||
walker = Rex::Socket::RangeWalker.new("10.1.1.1-2,3")
|
||||
walker.should be_valid
|
||||
walker.length.should == 3
|
||||
walker = Rex::Socket::RangeWalker.new("10.1-2.1.1,2")
|
||||
walker.should be_valid
|
||||
walker.length.should == 4
|
||||
walker = Rex::Socket::RangeWalker.new("10.1,2.3,4.5,6")
|
||||
walker.length.should == 8
|
||||
end
|
||||
|
||||
it "should handle cidr" do
|
||||
31.downto 16 do |bits|
|
||||
walker = Rex::Socket::RangeWalker.new("10.1.1.1/#{bits}")
|
||||
walker.should be_valid
|
||||
walker.length.should == (2**(32-bits))
|
||||
end
|
||||
end
|
||||
|
||||
it "should yield all ips" do
|
||||
walker = Rex::Socket::RangeWalker.new("10.1.1.1,2,3")
|
||||
got = []
|
||||
walker.each { |ip|
|
||||
got.push ip
|
||||
}
|
||||
got.should == ["10.1.1.1", "10.1.1.2", "10.1.1.3"]
|
||||
end
|
||||
end
|
|
@ -1,131 +0,0 @@
|
|||
$:.push("../../lib")
|
||||
require 'rex'
|
||||
require 'rex/socket'
|
||||
require 'rex/socket/range_walker'
|
||||
|
||||
describe Rex::Socket::RangeWalker do
|
||||
it "should have a num_ips attribute" do
|
||||
walker = Rex::Socket::RangeWalker.new("")
|
||||
walker.should respond_to("num_ips")
|
||||
walker.should respond_to("length")
|
||||
walker.num_ips.should == walker.length
|
||||
end
|
||||
it "should handle single ipv6 addresses" do
|
||||
walker = Rex::Socket::RangeWalker.new("::1")
|
||||
walker.should be_valid
|
||||
walker.length.should == 1
|
||||
end
|
||||
it "should handle ranges" do
|
||||
walker = Rex::Socket::RangeWalker.new("10.1.1.1-2")
|
||||
walker.should be_valid
|
||||
walker.length.should == 2
|
||||
walker.next_ip.should == "10.1.1.1"
|
||||
walker = Rex::Socket::RangeWalker.new("10.1-2.1.1-2")
|
||||
walker.should be_valid
|
||||
walker.length.should == 4
|
||||
walker = Rex::Socket::RangeWalker.new("10.1-2.3-4.5-6")
|
||||
walker.should be_valid
|
||||
walker.length.should == 8
|
||||
walker.should include("10.1.3.5")
|
||||
# Slow test on a 3.06 GHz proc
|
||||
# ruby 1.9, ~ 11 seconds
|
||||
# ruby 1.8.7, ~ 24 seconds
|
||||
# ruby 1.8.6, ~ 23 seconds
|
||||
#walker = Rex::Socket::RangeWalker.new("10.0-255.0-255.0-255")
|
||||
#walker.should be_valid
|
||||
#walker.length.should == 256 * 256 * 256
|
||||
end
|
||||
it "should default the lower bound of a range to 0" do
|
||||
walker = Rex::Socket::RangeWalker.new("10.1.3.-17")
|
||||
walker.should be_valid
|
||||
walker.length.should == 18
|
||||
walker = Rex::Socket::RangeWalker.new("10.1.3.-255")
|
||||
walker.should be_valid
|
||||
walker.length.should == 256
|
||||
end
|
||||
it "should default the upper bound of a range to 255" do
|
||||
walker = Rex::Socket::RangeWalker.new("10.1.3.254-")
|
||||
walker.should be_valid
|
||||
walker.length.should == 2
|
||||
end
|
||||
it "should handle lists" do
|
||||
#walker = Rex::Socket::RangeWalker.new("10.1.1.1,2")
|
||||
#walker.should be_valid
|
||||
#walker.length.should == 2
|
||||
walker = Rex::Socket::RangeWalker.new("10.1.1.1")
|
||||
walker.should be_valid
|
||||
walker.length.should == 1
|
||||
walker = Rex::Socket::RangeWalker.new("10.1.1.1,3")
|
||||
walker.should be_valid
|
||||
walker.length.should == 2
|
||||
walker.should_not include("10.1.1.2")
|
||||
end
|
||||
it "should handle ranges and lists together" do
|
||||
walker = Rex::Socket::RangeWalker.new("10.1.1.1-2,3")
|
||||
walker.should be_valid
|
||||
walker.length.should == 3
|
||||
walker = Rex::Socket::RangeWalker.new("10.1-2.1.1,2")
|
||||
walker.should be_valid
|
||||
walker.length.should == 4
|
||||
walker = Rex::Socket::RangeWalker.new("10.1,2.3,4.5,6")
|
||||
walker.length.should == 8
|
||||
end
|
||||
it "should handle cidr" do
|
||||
walker = Rex::Socket::RangeWalker.new("10.1.1.1/31")
|
||||
walker.should be_valid
|
||||
walker.length.should == 2
|
||||
walker = Rex::Socket::RangeWalker.new("10.1.1.1/30")
|
||||
walker.should be_valid
|
||||
walker.length.should == 4
|
||||
walker = Rex::Socket::RangeWalker.new("10.1.1.1/29")
|
||||
walker.should be_valid
|
||||
walker.length.should == 8
|
||||
walker = Rex::Socket::RangeWalker.new("10.1.1.1/28")
|
||||
walker.should be_valid
|
||||
walker.length.should == 16
|
||||
walker = Rex::Socket::RangeWalker.new("10.1.1.1/27")
|
||||
walker.should be_valid
|
||||
walker.length.should == 32
|
||||
walker = Rex::Socket::RangeWalker.new("10.1.1.1/26")
|
||||
walker.should be_valid
|
||||
walker.length.should == 64
|
||||
walker = Rex::Socket::RangeWalker.new("10.1.1.1/25")
|
||||
walker.should be_valid
|
||||
walker.length.should == 128
|
||||
pending("Decide whether cidr_crack should include 0")
|
||||
walker = Rex::Socket::RangeWalker.new("10.1.1.1/24")
|
||||
walker.should be_valid
|
||||
walker.length.should == 256
|
||||
walker = Rex::Socket::RangeWalker.new("10.1.1.1/23")
|
||||
walker.should be_valid
|
||||
walker.length.should == 512
|
||||
end
|
||||
|
||||
it "should handle ipv6 cidr" do
|
||||
walker = Rex::Socket::RangeWalker.new("::1/127")
|
||||
walker.should be_valid
|
||||
walker.length.should == 2
|
||||
walker = Rex::Socket::RangeWalker.new("::1/122")
|
||||
walker.should be_valid
|
||||
walker.length.should == 2 ** 6
|
||||
walker = Rex::Socket::RangeWalker.new("::1/116")
|
||||
walker.should be_valid
|
||||
walker.length.should == 2 ** 12
|
||||
end
|
||||
|
||||
#it "should handle ipv6 ranges" do
|
||||
# pending("Need to define how this should be handled")
|
||||
# walker = Rex::Socket::RangeWalker.new("::1-::1:1")
|
||||
# walker.should be_valid
|
||||
# walker.length.should == 2 ** 16
|
||||
#end
|
||||
|
||||
it "should yield all ips" do
|
||||
walker = Rex::Socket::RangeWalker.new("10.1.1.1,2,3")
|
||||
got = []
|
||||
walker.each { |ip|
|
||||
got.push ip
|
||||
}
|
||||
got.should == ["10.1.1.1", "10.1.1.2", "10.1.1.3"]
|
||||
end
|
||||
end
|
|
@ -1,102 +0,0 @@
|
|||
$:.push("../../lib")
|
||||
|
||||
require 'testbase'
|
||||
require 'msf/core/task_manager'
|
||||
|
||||
describe Msf::TaskManager do
|
||||
it "should have attributes" do
|
||||
tm = Msf::TaskManager.new($msf)
|
||||
tm.should respond_to("processing")
|
||||
tm.should respond_to("queue")
|
||||
tm.should respond_to("thread")
|
||||
tm.should respond_to("framework")
|
||||
tm.should respond_to("processing=")
|
||||
tm.should respond_to("queue=")
|
||||
tm.should respond_to("thread=")
|
||||
tm.should respond_to("framework=")
|
||||
end
|
||||
|
||||
it "should initialize with an empty queue" do
|
||||
tm = Msf::TaskManager.new($msf)
|
||||
tm.queue.length.should == 0
|
||||
tm.backlog.should == 0
|
||||
tm.backlog.should == tm.queue.length
|
||||
end
|
||||
|
||||
it "should add items to the queue and process them" do
|
||||
tm = Msf::TaskManager.new($msf)
|
||||
tm.queue_proc(Proc.new{ })
|
||||
tm.backlog.should == 1
|
||||
tm.queue_proc(Proc.new{ })
|
||||
tm.backlog.should == 2
|
||||
tm.start
|
||||
sleep(0.5)
|
||||
tm.backlog.should == 0
|
||||
end
|
||||
|
||||
it "should add items to the queue and flush them" do
|
||||
tm = Msf::TaskManager.new($msf)
|
||||
tm.queue_proc(Proc.new{ })
|
||||
tm.backlog.should == 1
|
||||
tm.queue_proc(Proc.new{ })
|
||||
tm.backlog.should == 2
|
||||
tm.flush
|
||||
tm.backlog.should == 0
|
||||
end
|
||||
|
||||
it "should start and stop" do
|
||||
tm = Msf::TaskManager.new($msf)
|
||||
tm.queue_proc(Proc.new{ })
|
||||
tm.backlog.should == 1
|
||||
tm.start
|
||||
sleep(0.5)
|
||||
tm.backlog.should == 0
|
||||
tm.stop
|
||||
tm.queue_proc(Proc.new{ })
|
||||
tm.backlog.should == 1
|
||||
sleep(0.5)
|
||||
tm.queue_proc(Proc.new{ })
|
||||
tm.backlog.should == 2
|
||||
tm.start
|
||||
sleep(0.5)
|
||||
tm.backlog.should == 0
|
||||
end
|
||||
|
||||
it "should handle task timeouts" do
|
||||
tm = Msf::TaskManager.new($msf)
|
||||
t = Msf::TaskManager::Task.new(Proc.new { sleep(30) })
|
||||
t.timeout = 0.1
|
||||
|
||||
tm.start
|
||||
tm.queue_task(t)
|
||||
sleep(0.5)
|
||||
|
||||
t.status.should == :timeout
|
||||
t.duration.should <= 1.0
|
||||
end
|
||||
|
||||
it "should handle task exceptions" do
|
||||
tm = Msf::TaskManager.new($msf)
|
||||
t = Msf::TaskManager::Task.new(Proc.new { asdf1234() })
|
||||
|
||||
tm.start
|
||||
tm.queue_task(t)
|
||||
sleep(0.5)
|
||||
|
||||
t.status.should == :dropped
|
||||
t.exception.class.should == ::NoMethodError
|
||||
end
|
||||
|
||||
it "should handle a bad proc return" do
|
||||
tm = Msf::TaskManager.new($msf)
|
||||
t = Msf::TaskManager::Task.new(Proc.new { return 12345 })
|
||||
|
||||
tm.start
|
||||
tm.queue_task(t)
|
||||
sleep(0.5)
|
||||
|
||||
t.status.should == :done
|
||||
t.exception.should == nil
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue