From 18c0f879fa521e79af497a439a1b14d2da519400 Mon Sep 17 00:00:00 2001 From: sinn3r Date: Tue, 30 Jul 2013 21:31:53 -0500 Subject: [PATCH] More code coverage for msfcli_spec --- msfcli | 4 +- spec/msfcli_spec.rb | 127 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 129 insertions(+), 2 deletions(-) diff --git a/msfcli b/msfcli index 3cd0dfe032..23674498fa 100755 --- a/msfcli +++ b/msfcli @@ -428,10 +428,10 @@ class Msfcli $stdout.puts("#{stat} #{code[1]}") else - $stderr.puts("Check failed: The state could not be determined.") + $stdout.puts("Check failed: The state could not be determined.") end rescue - $stderr.puts("Check failed: #{$!}") + $stdout.puts("Check failed: #{$!}") end end diff --git a/spec/msfcli_spec.rb b/spec/msfcli_spec.rb index 5d941fcff9..9c0f925ae4 100644 --- a/spec/msfcli_spec.rb +++ b/spec/msfcli_spec.rb @@ -24,6 +24,49 @@ describe Msfcli do end context "Class methods" do + context ".initialize" do + it "should give me the correct module name in key :module_name after object initialization" do + args = "multi/handler payload=windows/meterpreter/reverse_tcp lhost=127.0.0.1 E" + cli = Msfcli.new(args.split(' ')) + cli.instance_variable_get(:@args)[:module_name].should eq('multi/handler') + end + + it "should give me the correct mode in key :mode after object initialization" do + args = "multi/handler payload=windows/meterpreter/reverse_tcp lhost=127.0.0.1 E" + cli = Msfcli.new(args.split(' ')) + cli.instance_variable_get(:@args)[:mode].should eq('E') + end + + it "should give me the correct module parameters after object initialization" do + args = "multi/handler payload=windows/meterpreter/reverse_tcp lhost=127.0.0.1 E" + cli = Msfcli.new(args.split(' ')) + cli.instance_variable_get(:@args)[:params].should eq(['payload=windows/meterpreter/reverse_tcp', 'lhost=127.0.0.1']) + end + + it "should give me an exploit name without the prefix 'exploit'" do + args = "exploit/windows/browser/ie_cbutton_uaf payload=windows/meterpreter/reverse_tcp lhost=127.0.0.1 E" + cli = Msfcli.new(args.split(' ')) + cli.instance_variable_get(:@args)[:module_name].should eq("windows/browser/ie_cbutton_uaf") + end + + it "should give me an exploit name without the prefix 'exploits'" do + args = "exploits/windows/browser/ie_cbutton_uaf payload=windows/meterpreter/reverse_tcp lhost=127.0.0.1 E" + cli = Msfcli.new(args.split(' ')) + cli.instance_variable_get(:@args)[:module_name].should eq("windows/browser/ie_cbutton_uaf") + end + + it "should set mode 's' (summary)" do + args = "multi/handler payload=windows/meterpreter/reverse_tcp s" + cli = Msfcli.new(args.split(' ')) + cli.instance_variable_get(:@args)[:mode].should eq('s') + end + + it "should set mode 'h' (help) as default" do + args = "multi/handler" + cli = Msfcli.new(args.split(' ')) + cli.instance_variable_get(:@args)[:mode].should eq('h') + end + end context ".usage" do it "should see a help menu" do @@ -207,5 +250,89 @@ describe Msfcli do end end + context ".engage_mode" do + it "should show me the summary of module auxiliary/scanner/http/http_version" do + args = 'auxiliary/scanner/http/http_version s' + stdout = get_stdout { + cli = Msfcli.new(args.split(' ')) + m = cli.init_modules + cli.engage_mode(m) + } + + stdout.should =~ /Module: auxiliary\/scanner\/http\/http_version/ + end + + it "should show me the options of module auxiliary/scanner/http/http_version" do + args = 'auxiliary/scanner/http/http_version O' + stdout = get_stdout { + cli = Msfcli.new(args.split(' ')) + m = cli.init_modules + cli.engage_mode(m) + } + + stdout.should =~ /The target address range or CIDR identifier/ + end + + it "should show me the IDS options of module auxiliary/scanner/http/http_version" do + args = 'auxiliary/scanner/http/http_version I' + stdout = get_stdout { + cli = Msfcli.new(args.split(' ')) + m = cli.init_modules + cli.engage_mode(m) + } + stdout.should =~ /Insert fake relative directories into the uri/ + end + + it "should show me the targets available for module windows/browser/ie_cbutton_uaf" do + args = "windows/browser/ie_cbutton_uaf T" + stdout = get_stdout { + cli = Msfcli.new(args.split(' ')) + m = cli.init_modules + cli.engage_mode(m) + } + stdout.should =~ /IE 8 on Windows 7/ + end + + it "should try to run the check function of an exploit" do + args = "windows/smb/ms08_067_netapi rhost=0.0.0.1 C" # Some BS IP so we can fail + stdout = get_stdout { + cli = Msfcli.new(args.split(' ')) + m = cli.init_modules + cli.engage_mode(m) + } + stdout.should =~ /failed/ + end + + it "should warn my auxiliary module isn't supported by mode 'p' (show payloads)" do + args = 'auxiliary/scanner/http/http_version p' + stdout = get_stdout { + cli = Msfcli.new(args.split(' ')) + m = cli.init_modules + cli.engage_mode(m) + } + stdout.should =~ /This type of module does not support payloads/ + end + + it "should warn my auxiliary module isn't supported by mode 't' (show targets)" do + args = 'auxiliary/scanner/http/http_version t' + stdout = get_stdout { + cli = Msfcli.new(args.split(' ')) + m = cli.init_modules + cli.engage_mode(m) + } + stdout.should =~ /This type of module does not support targets/ + end + + it "should warn my exploit module isn't supported by mode 'ac' (show actions)" do + args = 'windows/browser/ie_cbutton_uaf ac' + stdout = get_stdout { + cli = Msfcli.new(args.split(' ')) + m = cli.init_modules + cli.engage_mode(m) + } + stdout.should =~ /This type of module does not support actions/ + end + end + end end \ No newline at end of file