updated meterpreter specs

git-svn-id: file:///home/svn/framework3/trunk@11491 4d416f70-5f16-0410-b530-b9f4589650da
unstable
Jonathan Cran 2011-01-06 20:48:56 +00:00
parent 152c380a13
commit 252832c1e1
4 changed files with 136 additions and 34 deletions

View File

@ -0,0 +1,85 @@
$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..', 'lib'))
$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..', 'test', 'lib'))
require 'fileutils'
require 'msftest'
require 'msf/base'
require 'meterpreter_spec_helper'
require 'meterpreter_specs'
module MsfTest
describe "JavaMeterpreter" do
# This include brings in all the spec helper methods
include MsfTest::MeterpreterSpecHelper
# This include brings in all the specs that are generic across the
# meterpreter platforms
include MsfTest::MeterpreterSpecs
before :all do
@verbose = true
@meterpreter_type = "java"
## Set up an outupt directory
@output_directory = "test_output_#{@meterpreter_type}"
if File.directory? @output_directory
FileUtils.rm_rf(@output_directory)
end
Dir.mkdir(@output_directory)
@default_file = "#{@output_directory}/default"
create_session_java
end
before :each do
end
after :each do
@session.init_ui(@input, @output)
## Clean Up
#FileUtils.rm_rf(@output_directory)
end
def create_session_java
## Setup for win32
@framework = Msf::Simple::Framework.create
test_modules_path = File.join(File.dirname(__FILE__), '..', '..', 'modules')
@framework.modules.add_module_path(test_modules_path)
@exploit_name = 'test/java_tester'
@payload_name = 'java/meterpreter/bind_tcp'
@input = Rex::Ui::Text::Input::Stdio.new
@output = Rex::Ui::Text::Output::File.new(@default_file)
# Initialize the exploit instance
exploit = @framework.exploits.create(@exploit_name)
## Fire it off against a known-vulnerable host
@session = exploit.exploit_simple(
'Options' => {},
'Payload' => @payload_name,
'LocalInput' => @input,
'LocalOutput' => @output)
puts @session.inspect
## If a session came back, try to interact with it.
if @session
@session.load_stdapi
else
raise Exception "Couldn't get a session!"
end
end
end
end

View File

@ -4,9 +4,19 @@ module MeterpreterSpecHelper
def self.included(base)
base.class_eval do
def generic_failure_strings
['fail', 'error', 'exception']
end
def generic_failure_exception_strings
['nserror.dll'] ##ugh, this is dependent on the target
end
def hlp_run_command_check_output(name,command,success_strings=[],fail_strings=[], fail_exception_strings=[])
fail_strings = fail_strings | generic_failure_strings
fail_exception_strings = fail_exception_strings | generic_failure_exception_strings
temp_command_file = "#{@output_directory}/#{name}"
command_output = Rex::Ui::Text::Output::File.new(temp_command_file)
@ -23,7 +33,7 @@ module MeterpreterSpecHelper
data = hlp_file_to_string(temp_command_file)
## Ugh, this is ghetto.
x = MsfTestCaseHelper.new
x = MsfTestCaseHelper.new(@debug)
x.complete?(data,"meterpreter_functional_test_start","meterpreter_functional_test_end").should be_true
x.all_successes_exist?(data, success_strings).should be_true
x.no_failures_exist?(data, fail_strings, fail_exception_strings ).should be_true

View File

@ -4,37 +4,6 @@ module MeterpreterSpecs
def self.included(base)
base.class_eval do
it "should not error when running help" do
success_strings = [ 'Core Commands',
'Stdapi: File system Commands',
'Stdapi: Networking Commands',
'Stdapi: System Commands',
'Stdapi: User interface Commands',
'Priv: Elevate Commands',
'Priv: Password database Commands',
'Priv: Timestomp Commands' ]
hlp_run_command_check_output("help","help", success_strings)
end
it "should not error when running the help shortcut" do
success_strings = [ 'Core Commands',
'Stdapi: File system Commands',
'Stdapi: Networking Commands',
'Stdapi: System Commands',
'Stdapi: User interface Commands',
'Priv: Elevate Commands',
'Priv: Password database Commands',
'Priv: Timestomp Commands' ]
hlp_run_command_check_output("help_shortcut","?", success_strings)
end
it "should not error when taking a screenshot" do
success_strings = [ 'Screenshot saved to' ]
hlp_run_command_check_output("screenshot","screenshot", success_strings)
end
it "should not error when running each command" do
commands = [ "?",
"background",
@ -103,10 +72,37 @@ module MeterpreterSpecs
## Run each command, check for execeptions
commands.each do |command|
hlp_run_command_check_output("#{command}_basic",command)
hlp_run_command_check_output("basic_#{command}",command)
end
end
it "should not error when running help" do
success_strings = [ 'Core Commands',
'Stdapi: File system Commands',
'Stdapi: Networking Commands',
'Stdapi: System Commands',
'Stdapi: User interface Commands']
hlp_run_command_check_output("help","help", success_strings)
end
it "should not error when running the help shortcut" do
success_strings = [ 'Core Commands',
'Stdapi: File system Commands',
'Stdapi: Networking Commands',
'Stdapi: System Commands',
'Stdapi: User interface Commands' ]
hlp_run_command_check_output("help_shortcut","?", success_strings)
end
it "should not error when taking a screenshot" do
success_strings = [ 'Screenshot saved to' ]
hlp_run_command_check_output("screenshot","screenshot", success_strings)
end
it "should not error when checking for background channels" do
success_strings = [ 'No active channels.' ]
hlp_run_command_check_output("channel_list_empty","channel -l", success_strings)

View File

@ -26,6 +26,17 @@ module WindowsMeterpreterSpecs
FileUtils.rm(filename)
end
it "should show the priv commands when running help" do
success_strings = ['Priv: Elevate Commands',
'Priv: Password database Commands',
'Priv: Timestomp Commands' ]
hlp_run_command_check_output("help_shortcut","help", success_strings)
end
end
end