2013-07-18 17:56:21 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
require 'msf/ui'
|
|
|
|
require 'msf/ui/console/command_dispatcher/db'
|
|
|
|
|
|
|
|
describe Msf::Ui::Console::CommandDispatcher::Db do
|
2013-09-30 18:47:53 +00:00
|
|
|
include_context 'Msf::DBManager'
|
|
|
|
include_context 'Msf::UIDriver'
|
2013-07-18 17:56:21 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
subject(:db) do
|
|
|
|
described_class.new(driver)
|
|
|
|
end
|
2013-07-18 17:56:21 +00:00
|
|
|
|
2014-07-28 14:19:09 +00:00
|
|
|
describe "#cmd_creds" do
|
|
|
|
describe "add-password" do
|
|
|
|
let(:username) { "username" }
|
|
|
|
let(:password) { "password" }
|
|
|
|
context "when no core exists" do
|
|
|
|
it "should add a Core" do
|
|
|
|
expect {
|
|
|
|
subject.cmd_creds("add-password", username, password)
|
|
|
|
}.to change{ Metasploit::Credential::Core.count }.by 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
context "when a core already exists" do
|
|
|
|
before(:each) do
|
|
|
|
priv = FactoryGirl.create(:metasploit_credential_password, data: password)
|
|
|
|
pub = FactoryGirl.create(:metasploit_credential_public, username: username)
|
|
|
|
core = FactoryGirl.create(:metasploit_credential_core,
|
2014-07-30 16:26:35 +00:00
|
|
|
origin: FactoryGirl.create(:metasploit_credential_origin_import),
|
2014-07-28 14:19:09 +00:00
|
|
|
private: priv,
|
|
|
|
public: pub,
|
|
|
|
realm: nil,
|
2014-07-30 16:26:35 +00:00
|
|
|
workspace: framework.db.workspace)
|
2014-07-28 14:19:09 +00:00
|
|
|
end
|
|
|
|
it "should not add a Core" do
|
|
|
|
expect {
|
|
|
|
subject.cmd_creds("add-password", username, password)
|
|
|
|
}.to_not change{ Metasploit::Credential::Core.count }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
describe "#cmd_workspace" do
|
|
|
|
describe "-h" do
|
|
|
|
it "should show a help message" do
|
|
|
|
db.cmd_workspace "-h"
|
|
|
|
@output.should =~ [
|
|
|
|
"Usage:",
|
|
|
|
" workspace List workspaces",
|
|
|
|
" workspace [name] Switch workspace",
|
|
|
|
" workspace -a [name] ... Add workspace(s)",
|
|
|
|
" workspace -d [name] ... Delete workspace(s)",
|
|
|
|
" workspace -r <old> <new> Rename workspace",
|
|
|
|
" workspace -h Show this help information"
|
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-07-18 17:56:21 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
describe "#cmd_hosts" do
|
|
|
|
describe "-h" do
|
|
|
|
it "should show a help message" do
|
|
|
|
db.cmd_hosts "-h"
|
|
|
|
@output.should =~ [
|
|
|
|
"Usage: hosts [ options ] [addr1 addr2 ...]",
|
|
|
|
"OPTIONS:",
|
|
|
|
" -a,--add Add the hosts instead of searching",
|
|
|
|
" -d,--delete Delete the hosts instead of searching",
|
|
|
|
" -c <col1,col2> Only show the given columns (see list below)",
|
|
|
|
" -h,--help Show this help information",
|
|
|
|
" -u,--up Only show hosts which are up",
|
|
|
|
" -o <file> Send output to a file in csv format",
|
|
|
|
" -R,--rhosts Set RHOSTS from the results of the search",
|
|
|
|
" -S,--search Search string to filter by",
|
2014-09-18 17:34:34 +00:00
|
|
|
"Available columns: address, arch, comm, comments, created_at, cred_count, detected_arch, exploit_attempt_count, host_detail_count, info, mac, name, note_count, os_flavor, os_lang, os_name, os_sp, purpose, scope, service_count, state, updated_at, virtual_host, vuln_count"
|
2013-09-30 18:47:53 +00:00
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-07-18 17:56:21 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
describe "#cmd_services" do
|
|
|
|
describe "-h" do
|
|
|
|
it "should show a help message" do
|
|
|
|
db.cmd_services "-h"
|
|
|
|
@output.should =~ [
|
|
|
|
"Usage: services [-h] [-u] [-a] [-r <proto>] [-p <port1,port2>] [-s <name1,name2>] [-o <filename>] [addr1 addr2 ...]",
|
|
|
|
" -a,--add Add the services instead of searching",
|
|
|
|
" -d,--delete Delete the services instead of searching",
|
|
|
|
" -c <col1,col2> Only show the given columns",
|
|
|
|
" -h,--help Show this help information",
|
|
|
|
" -s <name1,name2> Search for a list of service names",
|
|
|
|
" -p <port1,port2> Search for a list of ports",
|
|
|
|
" -r <protocol> Only show [tcp|udp] services",
|
|
|
|
" -u,--up Only show services which are up",
|
|
|
|
" -o <file> Send output to a file in csv format",
|
|
|
|
" -R,--rhosts Set RHOSTS from the results of the search",
|
|
|
|
" -S,--search Search string to filter by",
|
|
|
|
"Available columns: created_at, info, name, port, proto, state, updated_at"
|
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
describe "-p" do
|
|
|
|
before(:each) do
|
|
|
|
host = FactoryGirl.create(:mdm_host, :workspace => framework.db.workspace, :address => "192.168.0.1")
|
2014-07-22 14:47:35 +00:00
|
|
|
FactoryGirl.create(:mdm_service, :host => host, :port => 1024, name: 'Service1', proto: 'udp')
|
|
|
|
FactoryGirl.create(:mdm_service, :host => host, :port => 1025, name: 'Service2', proto: 'tcp')
|
|
|
|
FactoryGirl.create(:mdm_service, :host => host, :port => 1026, name: 'Service3', proto: 'udp')
|
2013-09-30 18:47:53 +00:00
|
|
|
end
|
|
|
|
it "should list services that are on a given port" do
|
|
|
|
db.cmd_services "-p", "1024,1025"
|
|
|
|
@output.should =~ [
|
|
|
|
"Services",
|
|
|
|
"========",
|
|
|
|
"",
|
2014-06-19 19:07:39 +00:00
|
|
|
"host port proto name state info",
|
|
|
|
"---- ---- ----- ---- ----- ----",
|
2014-07-22 14:47:35 +00:00
|
|
|
"192.168.0.1 1024 udp Service1 open ",
|
|
|
|
"192.168.0.1 1025 tcp Service2 open "
|
2013-09-30 18:47:53 +00:00
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
describe "-np" do
|
|
|
|
before(:each) do
|
|
|
|
host = FactoryGirl.create(:mdm_host, :workspace => framework.db.workspace, :address => "192.168.0.1")
|
|
|
|
FactoryGirl.create(:mdm_service, :host => host, :port => 1024)
|
|
|
|
FactoryGirl.create(:mdm_service, :host => host, :port => 1025)
|
|
|
|
FactoryGirl.create(:mdm_service, :host => host, :port => 1026)
|
|
|
|
end
|
|
|
|
it "should list services that are not on a given port" do
|
2014-08-26 20:17:00 +00:00
|
|
|
skip("refs redmine ticket #4821") {
|
2013-09-30 18:47:53 +00:00
|
|
|
db.cmd_services "-np", "1024"
|
2013-07-18 17:56:21 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
@output.should =~ [
|
|
|
|
"Services",
|
|
|
|
"========",
|
|
|
|
"",
|
|
|
|
"host port proto name state info",
|
|
|
|
"---- ---- ----- ---- ----- ----",
|
|
|
|
"192.168.0.1 1025 snmp open ",
|
|
|
|
"192.168.0.1 1026 snmp open "
|
|
|
|
]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-07-18 17:56:21 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
describe "#cmd_vulns" do
|
|
|
|
describe "-h" do
|
|
|
|
it "should show a help message" do
|
|
|
|
db.cmd_vulns "-h"
|
|
|
|
@output.should =~ [
|
|
|
|
"Print all vulnerabilities in the database",
|
|
|
|
"Usage: vulns [addr range]",
|
|
|
|
" -h,--help Show this help information",
|
|
|
|
" -p,--port <portspec> List vulns matching this port spec",
|
|
|
|
" -s <svc names> List vulns matching these service names",
|
|
|
|
" -S,--search Search string to filter by",
|
|
|
|
" -i,--info Display Vuln Info",
|
|
|
|
"Examples:",
|
|
|
|
" vulns -p 1-65536 # only vulns with associated services",
|
|
|
|
" vulns -p 1-65536 -s http # identified as http on any port"
|
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
2013-07-19 16:35:15 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
end
|
2013-07-19 16:35:15 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
describe "#cmd_notes" do
|
|
|
|
describe "-h" do
|
|
|
|
it "should show a help message" do
|
|
|
|
db.cmd_notes "-h"
|
|
|
|
@output.should =~ [
|
|
|
|
"Usage: notes [-h] [-t <type1,type2>] [-n <data string>] [-a] [addr range]",
|
|
|
|
" -a,--add Add a note to the list of addresses, instead of listing",
|
|
|
|
" -d,--delete Delete the hosts instead of searching",
|
|
|
|
" -n,--note <data> Set the data for a new note (only with -a)",
|
|
|
|
" -t <type1,type2> Search for a list of types",
|
|
|
|
" -h,--help Show this help information",
|
|
|
|
" -R,--rhosts Set RHOSTS from the results of the search",
|
|
|
|
" -S,--search Regular expression to match for search",
|
|
|
|
" --sort <field1,field2> Fields to sort by (case sensitive)",
|
|
|
|
"Examples:",
|
|
|
|
" notes --add -t apps -n 'winzip' 10.1.1.34 10.1.20.41",
|
|
|
|
" notes -t smb.fingerprint 10.1.1.34 10.1.20.41",
|
|
|
|
" notes -S 'nmap.nse.(http|rtsp)' --sort type,output"
|
|
|
|
]
|
2013-07-19 16:35:15 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
end
|
|
|
|
end
|
2013-07-19 16:35:15 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
end
|
2013-07-19 16:35:15 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
describe "#cmd_loot" do
|
|
|
|
describe "-h" do
|
|
|
|
it "should show a help message" do
|
|
|
|
db.cmd_loot "-h"
|
|
|
|
@output.should =~ [
|
|
|
|
"Usage: loot <options>",
|
|
|
|
" Info: loot [-h] [addr1 addr2 ...] [-t <type1,type2>]",
|
|
|
|
" Add: loot -f [fname] -i [info] -a [addr1 addr2 ...] [-t [type]",
|
|
|
|
" Del: loot -d [addr1 addr2 ...]",
|
|
|
|
" -a,--add Add loot to the list of addresses, instead of listing",
|
|
|
|
" -d,--delete Delete *all* loot matching host and type",
|
|
|
|
" -f,--file File with contents of the loot to add",
|
|
|
|
" -i,--info Info of the loot to add",
|
|
|
|
" -t <type1,type2> Search for a list of types",
|
|
|
|
" -h,--help Show this help information",
|
|
|
|
" -S,--search Search string to filter by"
|
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
2013-07-19 16:35:15 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
end
|
2013-07-19 16:35:15 +00:00
|
|
|
|
2014-07-28 14:19:09 +00:00
|
|
|
=begin
|
2013-09-30 18:47:53 +00:00
|
|
|
describe "#cmd_creds" do
|
|
|
|
describe "-h" do
|
|
|
|
it "should show a help message" do
|
|
|
|
db.cmd_creds "-h"
|
|
|
|
@output.should =~ [
|
|
|
|
"Usage: creds [addr range]",
|
2014-06-10 22:28:55 +00:00
|
|
|
"List credentials. If an address range is given, show only credentials with",
|
|
|
|
"logins on hosts within that range.",
|
2013-09-30 18:47:53 +00:00
|
|
|
" -h,--help Show this help information",
|
2013-11-19 20:07:41 +00:00
|
|
|
" -c,--columns Columns of interest",
|
2014-06-10 22:28:55 +00:00
|
|
|
" -P,--password <regex> List passwords that match this regex",
|
|
|
|
" -p,--port <portspec> List creds with logins on services matching this port spec",
|
|
|
|
" -s <svc names> List creds matching comma-separated service names",
|
|
|
|
" -u,--user <regex> List users that match this regex",
|
2013-09-30 18:47:53 +00:00
|
|
|
"Examples:",
|
2014-06-10 22:28:55 +00:00
|
|
|
" creds # Default, returns all credentials",
|
2013-09-30 18:47:53 +00:00
|
|
|
" creds 1.2.3.4/24 # nmap host specification",
|
|
|
|
" creds -p 22-25,445 # nmap port specification",
|
2014-06-10 22:28:55 +00:00
|
|
|
" creds -s ssh,smb # All creds associated with a login on SSH or SMB services"
|
2013-09-30 18:47:53 +00:00
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-07-28 14:19:09 +00:00
|
|
|
=end
|
2013-07-19 16:35:15 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
describe "#cmd_db_import" do
|
|
|
|
describe "-h" do
|
|
|
|
it "should show a help message" do
|
|
|
|
db.cmd_db_import "-h"
|
|
|
|
@output.should =~ [
|
|
|
|
"Usage: db_import <filename> [file2...]",
|
|
|
|
"Filenames can be globs like *.xml, or **/*.xml which will search recursively",
|
|
|
|
"Currently supported file types include:",
|
2014-05-08 08:05:49 +00:00
|
|
|
" Acunetix",
|
2013-09-30 18:47:53 +00:00
|
|
|
" Amap Log",
|
|
|
|
" Amap Log -m",
|
2014-05-08 08:05:49 +00:00
|
|
|
" Appscan",
|
2013-09-30 18:47:53 +00:00
|
|
|
" Burp Session XML",
|
2014-05-08 08:05:49 +00:00
|
|
|
" CI",
|
|
|
|
" Foundstone",
|
|
|
|
" FusionVM XML",
|
|
|
|
" IP Address List",
|
2013-09-30 18:47:53 +00:00
|
|
|
" IP360 ASPL",
|
|
|
|
" IP360 XML v3",
|
2014-05-08 08:05:49 +00:00
|
|
|
" Libpcap Packet Capture",
|
|
|
|
" Metasploit PWDump Export",
|
|
|
|
" Metasploit XML",
|
|
|
|
" Metasploit Zip Export",
|
2013-09-30 18:47:53 +00:00
|
|
|
" Microsoft Baseline Security Analyzer",
|
|
|
|
" NeXpose Simple XML",
|
|
|
|
" NeXpose XML Report",
|
2014-05-08 08:05:49 +00:00
|
|
|
" Nessus NBE Report",
|
|
|
|
" Nessus XML (v1)",
|
|
|
|
" Nessus XML (v2)",
|
|
|
|
" NetSparker XML",
|
|
|
|
" Nikto XML",
|
2013-09-30 18:47:53 +00:00
|
|
|
" Nmap XML",
|
|
|
|
" OpenVAS Report",
|
2014-05-08 08:05:49 +00:00
|
|
|
" OpenVAS XML",
|
2014-04-25 19:28:29 +00:00
|
|
|
" Outpost24 XML",
|
2013-09-30 18:47:53 +00:00
|
|
|
" Qualys Asset XML",
|
|
|
|
" Qualys Scan XML",
|
2014-05-08 08:05:49 +00:00
|
|
|
" Retina XML",
|
|
|
|
" Spiceworks CSV Export",
|
|
|
|
" Wapiti XML"
|
2013-09-30 18:47:53 +00:00
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-07-19 16:35:15 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
describe "#cmd_db_export" do
|
|
|
|
describe "-h" do
|
|
|
|
it "should show a help message" do
|
|
|
|
db.cmd_db_export "-h"
|
|
|
|
@output.should =~ [
|
|
|
|
"Usage:",
|
|
|
|
" db_export -f <format> [-a] [filename]",
|
|
|
|
" Format can be one of: xml, pwdump"
|
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-07-19 16:35:15 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
describe "#db_nmap" do
|
|
|
|
it "should have some specs describing its output"
|
|
|
|
end
|
2013-07-19 16:35:15 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
describe "#db_rebuild_cache" do
|
|
|
|
it "should have some specs describing its output"
|
|
|
|
end
|
2013-07-22 21:26:45 +00:00
|
|
|
end
|