2010-06-06 03:53:07 +00:00
|
|
|
#
|
2010-06-09 18:41:58 +00:00
|
|
|
# Web assessment for the metasploit framework
|
2012-02-03 21:43:21 +00:00
|
|
|
# Efrain Torres - et[ ] metasploit.com 2012
|
2010-06-06 03:53:07 +00:00
|
|
|
#
|
2010-06-09 18:41:58 +00:00
|
|
|
# $Id$
|
|
|
|
# $Revision$
|
|
|
|
#
|
2010-06-06 03:53:07 +00:00
|
|
|
|
|
|
|
require 'rabal/tree'
|
2012-02-03 21:43:21 +00:00
|
|
|
require 'msf/core/rpc/v10/client'
|
|
|
|
#require 'fileutils'
|
2010-06-06 03:53:07 +00:00
|
|
|
|
|
|
|
module Msf
|
|
|
|
|
|
|
|
class Plugin::Wmap < Msf::Plugin
|
|
|
|
class WmapCommandDispatcher
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2013-03-07 19:40:50 +00:00
|
|
|
attr_accessor :wmapmodules # Enabled Wmap modules
|
2012-02-03 21:43:21 +00:00
|
|
|
attr_accessor :targets # Targets
|
2013-03-07 19:40:50 +00:00
|
|
|
attr_accessor :lastsites # Temp location of previously obtained sites
|
2012-02-03 21:43:21 +00:00
|
|
|
attr_accessor :rpcarr # Array or rpc connections
|
2013-03-07 19:40:50 +00:00
|
|
|
attr_accessor :njobs # Max number of jobs
|
2012-02-03 21:43:21 +00:00
|
|
|
attr_accessor :nmaxdisplay # Flag to stop displaying the same mesg
|
|
|
|
attr_accessor :runlocal # Flag to run local modules only
|
|
|
|
attr_accessor :masstop # Flag to stop everything
|
|
|
|
attr_accessor :killwhenstop # Kill process when exiting
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2010-06-06 03:53:07 +00:00
|
|
|
include Msf::Ui::Console::CommandDispatcher
|
|
|
|
|
|
|
|
def name
|
2012-02-03 21:43:21 +00:00
|
|
|
"wmap"
|
2010-06-06 03:53:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# The initial command set
|
|
|
|
#
|
|
|
|
def commands
|
|
|
|
{
|
2011-02-04 05:57:26 +00:00
|
|
|
"wmap_targets" => "Manage targets",
|
|
|
|
"wmap_sites" => "Manage sites",
|
2012-02-03 21:43:21 +00:00
|
|
|
"wmap_nodes" => "Manage nodes",
|
|
|
|
"wmap_run" => "Test targets",
|
|
|
|
"wmap_modules" => "Manage wmap modules",
|
2012-02-21 04:59:26 +00:00
|
|
|
"wmap_vulns" => "Display web vulns",
|
2010-06-06 03:53:07 +00:00
|
|
|
}
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-21 04:59:26 +00:00
|
|
|
def cmd_wmap_vulns(*args)
|
|
|
|
args.push("-h") if args.length == 0
|
|
|
|
|
|
|
|
while (arg = args.shift)
|
|
|
|
case arg
|
|
|
|
when '-l'
|
|
|
|
view_vulns
|
|
|
|
return
|
|
|
|
when '-h'
|
|
|
|
print_status("Usage: wmap_vulns [options]")
|
|
|
|
print_line("\t-h Display this help text")
|
|
|
|
print_line("\t-l Display web vulns table")
|
|
|
|
|
|
|
|
print_line("")
|
|
|
|
return
|
|
|
|
else
|
|
|
|
print_error("Unknown flag.")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
def cmd_wmap_modules(*args)
|
|
|
|
args.push("-h") if args.length == 0
|
|
|
|
|
|
|
|
while (arg = args.shift)
|
|
|
|
case arg
|
|
|
|
when '-l'
|
|
|
|
view_modules
|
|
|
|
return
|
|
|
|
when '-r'
|
|
|
|
load_wmap_modules(true)
|
|
|
|
return
|
|
|
|
when '-h'
|
|
|
|
print_status("Usage: wmap_modules [options]")
|
|
|
|
print_line("\t-h Display this help text")
|
|
|
|
print_line("\t-l List all wmap enabled modules")
|
|
|
|
print_line("\t-r Reload wmap modules")
|
|
|
|
|
|
|
|
print_line("")
|
|
|
|
return
|
|
|
|
else
|
|
|
|
print_error("Unknown flag.")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2010-06-06 03:53:07 +00:00
|
|
|
|
|
|
|
def cmd_wmap_targets(*args)
|
|
|
|
args.push("-h") if args.length == 0
|
|
|
|
|
|
|
|
while (arg = args.shift)
|
|
|
|
case arg
|
2011-10-23 11:56:13 +00:00
|
|
|
when '-c'
|
2013-03-07 19:40:50 +00:00
|
|
|
self.targets = Hash.new()
|
2011-02-04 05:57:26 +00:00
|
|
|
when '-l'
|
|
|
|
view_targets
|
|
|
|
return
|
2011-10-23 11:56:13 +00:00
|
|
|
when '-t'
|
2011-02-04 05:57:26 +00:00
|
|
|
process_urls(args.shift)
|
2012-02-03 21:43:21 +00:00
|
|
|
when '-d'
|
|
|
|
process_ids(args.shift)
|
2010-06-06 03:53:07 +00:00
|
|
|
when '-h'
|
|
|
|
print_status("Usage: wmap_targets [options]")
|
|
|
|
print_line("\t-h Display this help text")
|
2011-02-04 05:57:26 +00:00
|
|
|
print_line("\t-t [urls] Define target sites (vhost1,url[space]vhost2,url) ")
|
2013-03-07 19:40:50 +00:00
|
|
|
print_line("\t-d [ids] Define target sites (id1, id2, id3 ...)")
|
2011-02-04 05:57:26 +00:00
|
|
|
print_line("\t-c Clean target sites list")
|
|
|
|
print_line("\t-l List all target sites")
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2010-06-06 03:53:07 +00:00
|
|
|
print_line("")
|
|
|
|
return
|
2011-02-04 05:57:26 +00:00
|
|
|
else
|
|
|
|
print_error("Unknown flag.")
|
|
|
|
return
|
2010-06-06 03:53:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
def cmd_wmap_sites(*args)
|
2010-06-06 03:53:07 +00:00
|
|
|
args.push("-h") if args.length == 0
|
|
|
|
|
|
|
|
while (arg = args.shift)
|
|
|
|
case arg
|
2011-02-04 05:57:26 +00:00
|
|
|
when '-a'
|
|
|
|
s = add_web_site(args.shift)
|
|
|
|
if s
|
2011-10-23 11:56:13 +00:00
|
|
|
print_status("Site created.")
|
2011-02-04 05:57:26 +00:00
|
|
|
else
|
|
|
|
print_error("Unable to create site")
|
2011-10-23 11:56:13 +00:00
|
|
|
end
|
2013-03-07 19:57:03 +00:00
|
|
|
when '-d'
|
2013-03-11 00:47:05 +00:00
|
|
|
del_idx = args
|
2013-03-07 19:57:03 +00:00
|
|
|
if del_idx
|
2013-03-11 22:40:14 +00:00
|
|
|
delete_sites(del_idx.select {|d| d =~ /^[0-9]*$/}.map(&:to_i).uniq)
|
2013-03-11 03:55:15 +00:00
|
|
|
return
|
2013-03-07 19:57:03 +00:00
|
|
|
else
|
|
|
|
print_error("Provide index of site to delete")
|
|
|
|
end
|
2011-02-04 05:57:26 +00:00
|
|
|
when '-l'
|
|
|
|
view_sites
|
|
|
|
return
|
|
|
|
when '-s'
|
|
|
|
u = args.shift
|
|
|
|
l = args.shift
|
|
|
|
s = args.shift
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
if not u
|
|
|
|
return
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
if l == nil or l.empty?
|
|
|
|
l = 200
|
|
|
|
s = true
|
|
|
|
else
|
|
|
|
l = l.to_i
|
|
|
|
s = false
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
if u.include? 'http'
|
|
|
|
# Parameters are in url form
|
|
|
|
view_site_tree(u,l,s)
|
|
|
|
else
|
2013-03-07 19:57:03 +00:00
|
|
|
# Parameters are digits
|
|
|
|
if !self.lastsites or self.lastsites.length == 0
|
2012-02-03 21:43:21 +00:00
|
|
|
view_sites
|
|
|
|
print_status ("Web sites ids. referenced from previous table.")
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
target_whitelist = []
|
|
|
|
ids = u.to_s.split(/,/)
|
|
|
|
|
|
|
|
ids.each do |id|
|
|
|
|
next if id.to_s.strip.empty?
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
if id.to_i > self.lastsites.length
|
2013-03-07 19:40:50 +00:00
|
|
|
print_error("Skipping id #{id}...")
|
2012-02-03 21:43:21 +00:00
|
|
|
else
|
|
|
|
target_whitelist << self.lastsites[id.to_i]
|
|
|
|
#print_status("Loading #{self.lastsites[id.to_i]}.")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Skip the DB entirely if no matches
|
|
|
|
return if target_whitelist.length == 0
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
if not self.targets
|
2013-03-07 19:40:50 +00:00
|
|
|
self.targets = Hash.new()
|
2012-02-03 21:43:21 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
target_whitelist.each do |ent|
|
|
|
|
view_site_tree(ent,l,s)
|
2013-03-07 19:40:50 +00:00
|
|
|
end
|
2012-02-03 21:43:21 +00:00
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
return
|
2010-06-06 03:53:07 +00:00
|
|
|
when '-h'
|
2011-02-04 05:57:26 +00:00
|
|
|
print_status("Usage: wmap_sites [options]")
|
2012-02-03 21:43:21 +00:00
|
|
|
print_line("\t-h Display this help text")
|
|
|
|
print_line("\t-a [url] Add site (vhost,url)")
|
2013-03-11 22:40:14 +00:00
|
|
|
print_line("\t-d [ids] Delete sites (separate ids with space)")
|
2012-02-03 21:43:21 +00:00
|
|
|
print_line("\t-l List all available sites")
|
|
|
|
print_line("\t-s [id] Display site structure (vhost,url|ids) (level)")
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2010-06-06 03:53:07 +00:00
|
|
|
print_line("")
|
|
|
|
return
|
2011-02-04 05:57:26 +00:00
|
|
|
else
|
|
|
|
print_error("Unknown flag.")
|
|
|
|
return
|
2010-06-06 03:53:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
def cmd_wmap_nodes(*args)
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
if not self.rpcarr
|
2013-03-07 19:40:50 +00:00
|
|
|
self.rpcarr=Hash.new()
|
2012-02-03 21:43:21 +00:00
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
args.push("-h") if args.length == 0
|
|
|
|
|
|
|
|
while (arg = args.shift)
|
|
|
|
case arg
|
|
|
|
when '-a'
|
|
|
|
h = args.shift
|
|
|
|
r = args.shift
|
|
|
|
s = args.shift
|
|
|
|
u = args.shift
|
|
|
|
p = args.shift
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
res = rpc_add_node(h,r,s,u,p,false)
|
|
|
|
if res
|
|
|
|
print_status("Node created.")
|
|
|
|
else
|
|
|
|
print_error("Unable to create node")
|
|
|
|
end
|
|
|
|
when '-c'
|
|
|
|
idref = args.shift
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
if not idref
|
|
|
|
print_error("No id defined")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if idref.upcase == 'ALL'
|
|
|
|
print_status("All nodes removed")
|
2013-03-07 19:40:50 +00:00
|
|
|
self.rpcarr = Hash.new()
|
2012-02-03 21:43:21 +00:00
|
|
|
else
|
|
|
|
idx=0
|
|
|
|
self.rpcarr.each do |k,v|
|
|
|
|
if idx == idref.to_i
|
|
|
|
self.rpcarr.delete(k)
|
2013-03-07 19:40:50 +00:00
|
|
|
print_status("Node deleted #{k}")
|
2012-02-03 21:43:21 +00:00
|
|
|
end
|
|
|
|
idx += 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
when '-d'
|
|
|
|
host = args.shift
|
|
|
|
port = args.shift
|
|
|
|
user = args.shift
|
|
|
|
pass = args.shift
|
|
|
|
dbname = args.shift
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
res = rpc_db_nodes(host,port,user,pass,dbname)
|
|
|
|
if res
|
|
|
|
print_status("OK.")
|
|
|
|
else
|
|
|
|
print_error("Error")
|
2013-03-07 19:40:50 +00:00
|
|
|
end
|
2012-02-03 21:43:21 +00:00
|
|
|
when '-l'
|
|
|
|
rpc_list_nodes
|
|
|
|
return
|
|
|
|
when '-j'
|
|
|
|
rpc_view_jobs
|
2013-03-07 19:40:50 +00:00
|
|
|
return
|
2012-02-03 21:43:21 +00:00
|
|
|
when '-k'
|
|
|
|
node = args.shift
|
|
|
|
jid = args.shift
|
|
|
|
rpc_kill_node(node,jid)
|
2013-03-07 19:40:50 +00:00
|
|
|
return
|
2012-02-03 21:43:21 +00:00
|
|
|
when '-h'
|
|
|
|
print_status("Usage: wmap_nodes [options]")
|
|
|
|
print_line("\t-h Display this help text")
|
|
|
|
print_line("\t-c id Remove id node (Use ALL for ALL nodes")
|
|
|
|
print_line("\t-a host port ssl user pass Add node")
|
|
|
|
print_line("\t-d host port user pass db Force all nodes to connect to db")
|
|
|
|
print_line("\t-j View detailed jobs")
|
|
|
|
print_line("\t-k ALL|id ALL|job_id Kill jobs on node")
|
|
|
|
print_line("\t-l List all current nodes")
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
print_line("")
|
|
|
|
return
|
|
|
|
else
|
|
|
|
print_error("Unknown flag.")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
def cmd_wmap_run(*args)
|
|
|
|
# Stop everything
|
|
|
|
self.masstop = false
|
|
|
|
self.killwhenstop = true
|
2013-03-07 19:40:50 +00:00
|
|
|
|
|
|
|
trap("INT") {
|
2012-02-03 21:43:21 +00:00
|
|
|
print_error("Stopping execution...")
|
|
|
|
self.masstop = true
|
|
|
|
if self.killwhenstop
|
|
|
|
rpc_kill_node('ALL','ALL')
|
|
|
|
end
|
|
|
|
}
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
# Max numbers of concurrent jobs per node
|
|
|
|
self.njobs = 25
|
|
|
|
self.nmaxdisplay = false
|
|
|
|
self.runlocal = false
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
# Formating
|
|
|
|
sizeline = 60
|
|
|
|
|
|
|
|
wmap_show = 2**0
|
|
|
|
wmap_expl = 2**1
|
|
|
|
|
|
|
|
# Exclude files can be modified by setting datastore['WMAP_EXCLUDE']
|
|
|
|
wmap_exclude_files = '.*\.(gif|jpg|png*)$'
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
run_wmap_ssl = true
|
|
|
|
run_wmap_server = true
|
|
|
|
run_wmap_dir_file = true
|
|
|
|
run_wmap_query = true
|
|
|
|
run_wmap_unique_query = true
|
|
|
|
run_wmap_generic = true
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
# If module supports datastore['VERBOSE']
|
|
|
|
moduleverbose = false
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
showprogress = false
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
if not self.rpcarr
|
2013-03-07 19:40:50 +00:00
|
|
|
self.rpcarr = Hash.new()
|
2012-02-03 21:43:21 +00:00
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
if not run_wmap_ssl
|
|
|
|
print_status("Loading of wmap ssl modules disabled.")
|
|
|
|
end
|
|
|
|
if not run_wmap_server
|
|
|
|
print_status("Loading of wmap server modules disabled.")
|
2011-10-23 11:56:13 +00:00
|
|
|
end
|
|
|
|
if not run_wmap_dir_file
|
2011-02-04 05:57:26 +00:00
|
|
|
print_status("Loading of wmap dir and file modules disabled.")
|
|
|
|
end
|
|
|
|
if not run_wmap_query
|
|
|
|
print_status("Loading of wmap query modules disabled.")
|
2011-10-23 11:56:13 +00:00
|
|
|
end
|
|
|
|
if not run_wmap_unique_query
|
2011-02-04 05:57:26 +00:00
|
|
|
print_status("Loading of wmap unique query modules disabled.")
|
2011-10-23 11:56:13 +00:00
|
|
|
end
|
|
|
|
if not run_wmap_generic
|
2011-02-04 05:57:26 +00:00
|
|
|
print_status("Loading of wmap generic modules disabled.")
|
2011-10-23 11:56:13 +00:00
|
|
|
end
|
|
|
|
|
2010-06-06 03:53:07 +00:00
|
|
|
stamp = Time.now.to_f
|
|
|
|
mode = 0
|
|
|
|
|
|
|
|
eprofile = []
|
|
|
|
using_p = false
|
2011-02-06 20:35:27 +00:00
|
|
|
using_m = false
|
2012-02-18 02:56:55 +00:00
|
|
|
usinginipath = false
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2011-02-06 20:35:27 +00:00
|
|
|
mname = ''
|
2012-02-18 02:56:55 +00:00
|
|
|
inipathname = '/'
|
2010-06-06 03:53:07 +00:00
|
|
|
|
|
|
|
args.push("-h") if args.length == 0
|
|
|
|
|
|
|
|
while (arg = args.shift)
|
|
|
|
case arg
|
|
|
|
when '-t'
|
2011-02-04 05:57:26 +00:00
|
|
|
mode |= wmap_show
|
2010-06-06 03:53:07 +00:00
|
|
|
when '-e'
|
2011-02-04 05:57:26 +00:00
|
|
|
mode |= wmap_expl
|
2010-06-06 03:53:07 +00:00
|
|
|
|
|
|
|
profile = args.shift
|
|
|
|
|
|
|
|
if profile
|
|
|
|
print_status("Using profile #{profile}.")
|
|
|
|
|
|
|
|
begin
|
|
|
|
File.open(profile).each do |str|
|
|
|
|
if not str.include? '#'
|
|
|
|
# Not a comment
|
|
|
|
modname = str.strip
|
|
|
|
if not modname.empty?
|
|
|
|
eprofile << modname
|
|
|
|
end
|
|
|
|
end
|
|
|
|
using_p = true
|
|
|
|
end
|
|
|
|
rescue
|
|
|
|
print_error("Profile not found or invalid.")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
else
|
|
|
|
print_status("Using ALL wmap enabled modules.")
|
|
|
|
end
|
2011-02-06 20:35:27 +00:00
|
|
|
when '-m'
|
|
|
|
mode |= wmap_expl
|
|
|
|
|
|
|
|
mname = args.shift
|
|
|
|
|
|
|
|
if mname
|
|
|
|
print_status("Using module #{mname}.")
|
|
|
|
end
|
|
|
|
using_m = true
|
2012-02-18 02:56:55 +00:00
|
|
|
when '-p'
|
|
|
|
mode |= wmap_expl
|
|
|
|
|
|
|
|
inipathname = args.shift
|
|
|
|
|
|
|
|
if inipathname
|
|
|
|
print_status("Using initial path #{inipathname}.")
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
usinginipath = true
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2010-06-06 03:53:07 +00:00
|
|
|
when '-h'
|
|
|
|
print_status("Usage: wmap_run [options]")
|
2012-02-03 21:43:21 +00:00
|
|
|
print_line("\t-h Display this help text")
|
|
|
|
print_line("\t-t Show all enabled modules")
|
|
|
|
print_line("\t-m [regex] Launch only modules that name match provided regex.")
|
2012-02-18 02:56:55 +00:00
|
|
|
print_line("\t-p [regex] Only test path defined by regex.")
|
2012-02-03 21:43:21 +00:00
|
|
|
print_line("\t-e [/path/to/profile] Launch profile modules against all matched targets.")
|
|
|
|
print_line("\t (No profile file runs all enabled modules.)")
|
2010-06-06 03:53:07 +00:00
|
|
|
print_line("")
|
|
|
|
return
|
2012-02-03 21:43:21 +00:00
|
|
|
else
|
2013-03-07 19:40:50 +00:00
|
|
|
print_error("Unknown flag")
|
2012-02-03 21:43:21 +00:00
|
|
|
return
|
2010-06-06 03:53:07 +00:00
|
|
|
end
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
if (self.rpcarr.length == 0) and (mode & wmap_show == 0)
|
|
|
|
print_error("NO WMAP NODES DEFINED. Executing local modules")
|
|
|
|
self.runlocal = true
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
if self.targets == nil
|
|
|
|
print_error("Targets have not been selected.")
|
|
|
|
return
|
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
|
|
|
|
if self.targets.keys.length == 0
|
2011-02-04 05:57:26 +00:00
|
|
|
print_error("Targets have not been selected.")
|
2010-06-06 03:53:07 +00:00
|
|
|
return
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
execmod = true
|
|
|
|
if (mode & wmap_show != 0)
|
|
|
|
execmod = false
|
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
self.targets.each_with_index do |t, idx|
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
selected_host = t[1][:host]
|
|
|
|
selected_port = t[1][:port]
|
|
|
|
selected_ssl = t[1][:ssl]
|
|
|
|
selected_vhost = t[1][:vhost]
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
print_status ("Testing target:")
|
|
|
|
print_status ("\tSite: #{selected_vhost} (#{selected_host})")
|
|
|
|
print_status ("\tPort: #{selected_port} SSL: #{selected_ssl}")
|
2012-02-03 21:43:21 +00:00
|
|
|
print_line '='* sizeline
|
2011-02-04 05:57:26 +00:00
|
|
|
print_status("Testing started. #{(Time.now )}")
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
if not selected_ssl
|
|
|
|
run_wmap_ssl = false
|
|
|
|
#print_status ("Target is not SSL. SSL modules disabled.")
|
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
# wmap_dir, wmap_file
|
2013-03-07 19:40:50 +00:00
|
|
|
matches = Hash.new()
|
2010-06-06 03:53:07 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
# wmap_server
|
2013-03-07 19:40:50 +00:00
|
|
|
matches1 = Hash.new()
|
2010-06-06 03:53:07 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
# wmap_query
|
2013-03-07 19:40:50 +00:00
|
|
|
matches2 = Hash.new()
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
# wmap_ssl
|
2013-03-07 19:40:50 +00:00
|
|
|
matches3 = Hash.new()
|
2010-06-06 03:53:07 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
# wmap_unique_query
|
2013-03-07 19:40:50 +00:00
|
|
|
matches5 = Hash.new()
|
2010-06-06 03:53:07 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
# wmap_generic
|
2013-03-07 19:40:50 +00:00
|
|
|
matches10 = Hash.new()
|
2010-06-06 03:53:07 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
# OPTIONS
|
2011-02-04 05:57:26 +00:00
|
|
|
opt_str = nil
|
2012-02-18 02:56:55 +00:00
|
|
|
jobify = false
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
# This will be clean later
|
|
|
|
load_wmap_modules(false)
|
|
|
|
|
|
|
|
self.wmapmodules.each do |w|
|
|
|
|
case w[2]
|
|
|
|
when :wmap_server
|
|
|
|
if run_wmap_server
|
|
|
|
matches1[w]=true
|
|
|
|
end
|
|
|
|
when :wmap_query
|
|
|
|
if run_wmap_query
|
|
|
|
matches2[w]=true
|
2011-02-04 05:57:26 +00:00
|
|
|
end
|
2012-02-03 21:43:21 +00:00
|
|
|
when :wmap_unique_query
|
|
|
|
if run_wmap_unique_query
|
|
|
|
matches5[w]=true
|
|
|
|
end
|
|
|
|
when :wmap_generic
|
|
|
|
if run_wmap_generic
|
|
|
|
matches10[w]=true
|
|
|
|
end
|
|
|
|
when :wmap_dir, :wmap_file
|
|
|
|
if run_wmap_dir_file
|
|
|
|
matches[w]=true
|
|
|
|
end
|
|
|
|
when :wmap_ssl
|
|
|
|
if run_wmap_ssl
|
2013-03-07 19:40:50 +00:00
|
|
|
matches3[w]=true
|
2012-02-03 21:43:21 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
# Black Hole
|
2011-02-04 05:57:26 +00:00
|
|
|
end
|
|
|
|
end
|
2010-06-06 03:53:07 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
# Execution order (orderid)
|
|
|
|
matches = sort_by_orderid(matches)
|
|
|
|
matches1 = sort_by_orderid(matches1)
|
|
|
|
matches2 = sort_by_orderid(matches2)
|
|
|
|
matches3 = sort_by_orderid(matches3)
|
|
|
|
matches5 = sort_by_orderid(matches5)
|
|
|
|
matches10 = sort_by_orderid(matches10)
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
#
|
|
|
|
# Handle modules that need to be run before all tests IF SERVER is SSL, once usually again the SSL web server.
|
2012-02-03 21:43:21 +00:00
|
|
|
# :wmap_ssl
|
2011-02-04 05:57:26 +00:00
|
|
|
#
|
2011-10-23 11:56:13 +00:00
|
|
|
|
|
|
|
print_status "\n=[ SSL testing ]="
|
2012-02-03 21:43:21 +00:00
|
|
|
print_line "=" * sizeline
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
if not selected_ssl
|
|
|
|
print_status ("Target is not SSL. SSL modules disabled.")
|
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
idx = 0
|
|
|
|
matches3.each_key do |xref|
|
2012-02-03 21:43:21 +00:00
|
|
|
if self.masstop
|
|
|
|
print_error("STOPPED.")
|
|
|
|
return
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
|
|
|
# Module not part of profile or not match
|
|
|
|
if ( using_p and eprofile.include? xref[0].split('/').last ) or (using_m and xref[0].to_s.match(mname)) or (not using_m and not using_p)
|
2012-02-03 21:43:21 +00:00
|
|
|
idx += 1
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
begin
|
|
|
|
# Module options hash
|
2013-03-07 19:40:50 +00:00
|
|
|
modopts = Hash.new()
|
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
#
|
2012-02-03 21:43:21 +00:00
|
|
|
# The code is just a proof-of-concept and will be expanded in the future
|
2011-02-04 05:57:26 +00:00
|
|
|
#
|
2012-02-03 21:43:21 +00:00
|
|
|
print_status "Module #{xref[0]}"
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
if (mode & wmap_expl != 0)
|
2011-02-04 05:57:26 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
#
|
|
|
|
# For modules to have access to the global datastore
|
|
|
|
# i.e. set -g DOMAIN test.com
|
|
|
|
#
|
|
|
|
self.framework.datastore.each do |gkey,gval|
|
|
|
|
modopts[gkey]=gval
|
|
|
|
end
|
2011-02-04 05:57:26 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
#
|
|
|
|
# Parameters passed in hash xref
|
|
|
|
#
|
|
|
|
modopts['RHOST'] = selected_host
|
|
|
|
modopts['RHOSTS'] = selected_host
|
|
|
|
modopts['RPORT'] = selected_port.to_s
|
|
|
|
modopts['SSL'] = selected_ssl
|
|
|
|
modopts['VHOST'] = selected_vhost.to_s
|
|
|
|
modopts['VERBOSE'] = moduleverbose
|
|
|
|
modopts['ShowProgress'] = showprogress
|
|
|
|
modopts['RunAsJob'] = jobify
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
begin
|
|
|
|
if execmod
|
|
|
|
rpcnode = rpc_round_exec(xref[0],xref[1], modopts, self.njobs)
|
2011-02-04 05:57:26 +00:00
|
|
|
end
|
2012-02-03 21:43:21 +00:00
|
|
|
rescue ::Exception
|
|
|
|
print_status(" >> Exception during launch from #{xref[0]}: #{$!}")
|
2013-03-07 19:40:50 +00:00
|
|
|
end
|
2010-06-06 03:53:07 +00:00
|
|
|
end
|
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
rescue ::Exception
|
|
|
|
print_status(" >> Exception from #{xref[0]}: #{$!}")
|
|
|
|
end
|
2010-06-06 03:53:07 +00:00
|
|
|
end
|
2011-02-04 05:57:26 +00:00
|
|
|
end
|
2010-06-06 03:53:07 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
#
|
|
|
|
# Handle modules that need to be run before all tests, once usually again the web server.
|
2012-02-03 21:43:21 +00:00
|
|
|
# :wmap_server
|
2011-02-04 05:57:26 +00:00
|
|
|
#
|
2011-10-23 11:56:13 +00:00
|
|
|
print_status "\n=[ Web Server testing ]="
|
2012-02-03 21:43:21 +00:00
|
|
|
print_line "=" * sizeline
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
idx = 0
|
|
|
|
matches1.each_key do |xref|
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
if self.masstop
|
|
|
|
print_error("STOPPED.")
|
|
|
|
return
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
|
|
|
# Module not part of profile or not match
|
|
|
|
if ( using_p and eprofile.include? xref[0].split('/').last ) or (using_m and xref[0].to_s.match(mname)) or (not using_m and not using_p)
|
2012-02-03 21:43:21 +00:00
|
|
|
idx += 1
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
begin
|
|
|
|
# Module options hash
|
2013-03-07 19:40:50 +00:00
|
|
|
modopts = Hash.new()
|
2010-06-06 03:53:07 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
#
|
2012-02-03 21:43:21 +00:00
|
|
|
# The code is just a proof-of-concept and will be expanded in the future
|
2011-02-04 05:57:26 +00:00
|
|
|
#
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
print_status "Module #{xref[0]}"
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
if (mode & wmap_expl != 0)
|
2010-06-06 03:53:07 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
#
|
|
|
|
# For modules to have access to the global datastore
|
|
|
|
# i.e. set -g DOMAIN test.com
|
|
|
|
#
|
|
|
|
self.framework.datastore.each do |gkey,gval|
|
|
|
|
modopts[gkey]=gval
|
|
|
|
end
|
2010-06-06 03:53:07 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
#
|
|
|
|
# Parameters passed in hash xref
|
|
|
|
#
|
|
|
|
modopts['RHOST'] = selected_host
|
|
|
|
modopts['RHOSTS'] = selected_host
|
|
|
|
modopts['RPORT'] = selected_port.to_s
|
|
|
|
modopts['SSL'] = selected_ssl
|
|
|
|
modopts['VHOST'] = selected_vhost.to_s
|
|
|
|
modopts['VERBOSE'] = moduleverbose
|
|
|
|
modopts['ShowProgress'] = showprogress
|
|
|
|
modopts['RunAsJob'] = jobify
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
begin
|
|
|
|
if execmod
|
|
|
|
rpcnode = rpc_round_exec(xref[0],xref[1], modopts, self.njobs)
|
2011-02-04 05:57:26 +00:00
|
|
|
end
|
2012-02-03 21:43:21 +00:00
|
|
|
rescue ::Exception
|
|
|
|
print_status(" >> Exception during launch from #{xref[0]}: #{$!}")
|
2013-03-07 19:40:50 +00:00
|
|
|
end
|
2010-06-06 03:53:07 +00:00
|
|
|
end
|
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
rescue ::Exception
|
|
|
|
print_status(" >> Exception from #{xref[0]}: #{$!}")
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
end
|
2011-02-04 05:57:26 +00:00
|
|
|
end
|
2010-06-06 03:53:07 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
#
|
|
|
|
# Handle modules to be run at every path/file
|
2012-02-03 21:43:21 +00:00
|
|
|
# wmap_dir, wmap_file
|
2011-02-04 05:57:26 +00:00
|
|
|
#
|
2011-10-23 11:56:13 +00:00
|
|
|
print_status "\n=[ File/Dir testing ]="
|
2012-02-03 21:43:21 +00:00
|
|
|
print_line "=" * sizeline
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
idx = 0
|
|
|
|
matches.each_key do |xref|
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
if self.masstop
|
|
|
|
print_error("STOPPED.")
|
|
|
|
return
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
|
|
|
# Module not part of profile or not match
|
|
|
|
if ( using_p and eprofile.include? xref[0].split('/').last ) or (using_m and xref[0].to_s.match(mname)) or (not using_m and not using_p)
|
2012-02-03 21:43:21 +00:00
|
|
|
idx+=1
|
2010-06-06 03:53:07 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
begin
|
|
|
|
# Module options hash
|
2013-03-07 19:40:50 +00:00
|
|
|
modopts = Hash.new()
|
2010-06-06 03:53:07 +00:00
|
|
|
|
|
|
|
#
|
2012-02-03 21:43:21 +00:00
|
|
|
# The code is just a proof-of-concept and will be expanded in the future
|
2010-06-06 03:53:07 +00:00
|
|
|
#
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
print_status "Module #{xref[0]}"
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
if (mode & wmap_expl != 0)
|
|
|
|
#
|
|
|
|
# For modules to have access to the global datastore
|
|
|
|
# i.e. set -g DOMAIN test.com
|
|
|
|
#
|
|
|
|
self.framework.datastore.each do |gkey,gval|
|
|
|
|
modopts[gkey]=gval
|
|
|
|
end
|
2010-06-06 03:53:07 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
#
|
|
|
|
# Parameters passed in hash xref
|
|
|
|
#
|
|
|
|
modopts['RHOST'] = selected_host
|
|
|
|
modopts['RHOSTS'] = selected_host
|
|
|
|
modopts['RPORT'] = selected_port.to_s
|
|
|
|
modopts['SSL'] = selected_ssl
|
|
|
|
modopts['VHOST'] = selected_vhost.to_s
|
|
|
|
modopts['VERBOSE'] = moduleverbose
|
|
|
|
modopts['ShowProgress'] = showprogress
|
|
|
|
modopts['RunAsJob'] = jobify
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
#
|
|
|
|
# Run the plugins that only need to be
|
|
|
|
# launched once.
|
|
|
|
#
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
wtype = xref[2]
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
h = self.framework.db.workspace.hosts.find_by_address(selected_host)
|
|
|
|
s = h.services.find_by_port(selected_port)
|
|
|
|
w = s.web_sites.find_by_vhost(selected_vhost)
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
test_tree = load_tree(w)
|
|
|
|
test_tree.each do |node|
|
2011-02-04 05:57:26 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
if self.masstop
|
|
|
|
print_error("STOPPED.")
|
|
|
|
return
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
p = node.current_path
|
|
|
|
testpath = Pathname.new(p)
|
|
|
|
strpath = testpath.cleanpath(false).to_s
|
2011-02-04 05:57:26 +00:00
|
|
|
|
|
|
|
#
|
2012-02-03 21:43:21 +00:00
|
|
|
# Fixing paths
|
2011-02-04 05:57:26 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
if node.is_leaf? and not node.is_root?
|
|
|
|
#
|
2012-02-03 21:43:21 +00:00
|
|
|
# Later we can add here more checks to see if its a file
|
2011-02-04 05:57:26 +00:00
|
|
|
#
|
2012-02-03 21:43:21 +00:00
|
|
|
else
|
|
|
|
if node.is_root?
|
|
|
|
strpath = "/"
|
2011-02-04 05:57:26 +00:00
|
|
|
else
|
2012-02-03 21:43:21 +00:00
|
|
|
strpath = strpath.chomp + "/"
|
2011-02-04 05:57:26 +00:00
|
|
|
end
|
2012-02-03 21:43:21 +00:00
|
|
|
end
|
2011-02-04 05:57:26 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
strpath = strpath.gsub("//", "/")
|
|
|
|
#print_status("Testing path: #{strpath}")
|
2011-02-04 05:57:26 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
#
|
|
|
|
# Launch plugin depending module type.
|
|
|
|
# Module type depends on main input type.
|
|
|
|
# Code may be the same but it depend on final
|
|
|
|
# versions of plugins
|
|
|
|
#
|
|
|
|
|
|
|
|
case wtype
|
|
|
|
when :wmap_file
|
|
|
|
if node.is_leaf? and not node.is_root?
|
|
|
|
#
|
|
|
|
# Check if an exclusion regex has been defined
|
|
|
|
#
|
|
|
|
if self.framework.datastore['WMAP_EXCLUDE']
|
|
|
|
excludefilestr = self.framework.datastore['WMAP_EXCLUDE']
|
2011-02-04 05:57:26 +00:00
|
|
|
else
|
2012-02-03 21:43:21 +00:00
|
|
|
excludefilestr = wmap_exclude_files
|
|
|
|
end
|
|
|
|
|
|
|
|
if not strpath.match(excludefilestr)
|
2013-03-07 19:40:50 +00:00
|
|
|
if (not usinginipath) or (usinginipath and strpath.match(inipathname))
|
2012-02-18 02:56:55 +00:00
|
|
|
modopts['PATH'] = strpath
|
|
|
|
print_status("Path: #{strpath}")
|
|
|
|
|
|
|
|
begin
|
|
|
|
if execmod
|
|
|
|
rpcnode = rpc_round_exec(xref[0],xref[1], modopts, self.njobs)
|
|
|
|
end
|
|
|
|
rescue ::Exception
|
|
|
|
print_status(" >> Exception during launch from #{xref[0]}: #{$!}")
|
2013-03-07 19:40:50 +00:00
|
|
|
end
|
2012-02-18 02:56:55 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
when :wmap_dir
|
2012-02-19 05:51:02 +00:00
|
|
|
if (node.is_leaf? and not strpath.include? ".") or node.is_root? or not node.is_leaf?
|
2013-03-07 19:40:50 +00:00
|
|
|
if (not usinginipath) or (usinginipath and strpath.match(inipathname))
|
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
modopts['PATH'] = strpath
|
|
|
|
print_status("Path: #{strpath}")
|
2011-02-04 05:57:26 +00:00
|
|
|
|
|
|
|
begin
|
2012-02-03 21:43:21 +00:00
|
|
|
if execmod
|
2012-02-18 02:56:55 +00:00
|
|
|
rpcnode = rpc_round_exec(xref[0],xref[1], modopts, njobs)
|
2012-02-03 21:43:21 +00:00
|
|
|
end
|
2011-02-04 05:57:26 +00:00
|
|
|
rescue ::Exception
|
2012-02-03 21:43:21 +00:00
|
|
|
print_status(" >> Exception during launch from #{xref[0]}: #{$!}")
|
|
|
|
end
|
2012-02-18 02:56:55 +00:00
|
|
|
end
|
2011-02-04 05:57:26 +00:00
|
|
|
end
|
|
|
|
end
|
2010-06-06 03:53:07 +00:00
|
|
|
end
|
|
|
|
end
|
2012-02-03 21:43:21 +00:00
|
|
|
rescue ::Exception
|
|
|
|
print_status(" >> Exception from #{xref[0]}: #{$!}")
|
2011-02-04 05:57:26 +00:00
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
end
|
2011-02-04 05:57:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Run modules for each request to play with URI with UNIQUE query parameters.
|
2012-02-03 21:43:21 +00:00
|
|
|
# wmap_unique_query
|
2011-02-04 05:57:26 +00:00
|
|
|
#
|
2011-10-23 11:56:13 +00:00
|
|
|
print_status "\n=[ Unique Query testing ]="
|
2012-02-03 21:43:21 +00:00
|
|
|
print_line "=" * sizeline
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
idx = 0
|
|
|
|
matches5.each_key do |xref|
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
if self.masstop
|
|
|
|
print_error("STOPPED.")
|
|
|
|
return
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
|
|
|
# Module not part of profile or not match
|
|
|
|
if ( using_p and eprofile.include? xref[0].split('/').last ) or (using_m and xref[0].to_s.match(mname)) or (not using_m and not using_p)
|
2012-02-03 21:43:21 +00:00
|
|
|
idx += 1
|
2010-06-06 03:53:07 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
begin
|
|
|
|
# Module options hash
|
2013-03-07 19:40:50 +00:00
|
|
|
modopts = Hash.new()
|
2010-06-06 03:53:07 +00:00
|
|
|
|
|
|
|
#
|
2012-02-03 21:43:21 +00:00
|
|
|
# The code is just a proof-of-concept and will be expanded in the future
|
2010-06-06 03:53:07 +00:00
|
|
|
#
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
print_status "Module #{xref[0]}"
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
if (mode & wmap_expl != 0)
|
2011-02-04 05:57:26 +00:00
|
|
|
#
|
2012-02-03 21:43:21 +00:00
|
|
|
# For modules to have access to the global datastore
|
|
|
|
# i.e. set -g DOMAIN test.com
|
2011-02-04 05:57:26 +00:00
|
|
|
#
|
2012-02-03 21:43:21 +00:00
|
|
|
self.framework.datastore.each do |gkey,gval|
|
|
|
|
modopts[gkey]=gval
|
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
#
|
|
|
|
# Parameters passed in hash xref
|
|
|
|
#
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
modopts['RHOST'] = selected_host
|
|
|
|
modopts['RHOSTS'] = selected_host
|
|
|
|
modopts['RPORT'] = selected_port.to_s
|
|
|
|
modopts['SSL'] = selected_ssl
|
|
|
|
modopts['VHOST'] = selected_vhost.to_s
|
|
|
|
modopts['VERBOSE'] = moduleverbose
|
|
|
|
modopts['ShowProgress'] = showprogress
|
|
|
|
modopts['RunAsJob'] = jobify
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
#
|
|
|
|
# Run the plugins for each request that have a distinct
|
|
|
|
# GET/POST URI QUERY string.
|
|
|
|
#
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2013-03-07 19:40:50 +00:00
|
|
|
utest_query = Hash.new()
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
h = self.framework.db.workspace.hosts.find_by_address(selected_host)
|
|
|
|
s = h.services.find_by_port(selected_port)
|
|
|
|
w = s.web_sites.find_by_vhost(selected_vhost)
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
w.web_forms.each do |form|
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
if self.masstop
|
|
|
|
print_error("STOPPED.")
|
|
|
|
return
|
2011-10-23 11:56:13 +00:00
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2010-06-06 03:53:07 +00:00
|
|
|
#
|
2012-02-03 21:43:21 +00:00
|
|
|
# Only test unique query strings by comparing signature to previous tested signatures 'path,p1,p2,pn'
|
2010-06-06 03:53:07 +00:00
|
|
|
#
|
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
datastr = ""
|
|
|
|
typestr = ""
|
2010-06-06 03:53:07 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
temparr = []
|
|
|
|
|
|
|
|
#print_status "---------"
|
|
|
|
#print_status form.params
|
|
|
|
#print_status "+++++++++"
|
|
|
|
|
|
|
|
form.params.each do |p|
|
|
|
|
pn, pv, pt = p
|
|
|
|
if pn
|
2013-03-07 19:40:50 +00:00
|
|
|
if not pn.empty?
|
2012-02-03 21:43:21 +00:00
|
|
|
if not pv or pv.empty?
|
|
|
|
#TODO add value based on param name
|
|
|
|
pv = "aaa"
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-18 02:56:55 +00:00
|
|
|
#temparr << pn.to_s + "=" + Rex::Text.uri_encode(pv.to_s)
|
|
|
|
temparr << pn.to_s + "=" + pv.to_s
|
2010-06-06 03:53:07 +00:00
|
|
|
end
|
|
|
|
else
|
2013-03-07 19:40:50 +00:00
|
|
|
print_error("Blank parameter name. Form #{form.path}")
|
|
|
|
end
|
2012-02-03 21:43:21 +00:00
|
|
|
end
|
2010-06-06 03:53:07 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
datastr = temparr.join("&") if (temparr and not temparr.empty?)
|
|
|
|
|
|
|
|
if (utest_query.has_key?(signature(form.path,datastr)) == false)
|
|
|
|
|
|
|
|
modopts['METHOD'] = form.method.upcase
|
|
|
|
modopts['PATH'] = form.path
|
|
|
|
modopts['QUERY'] = form.query
|
|
|
|
if form.method.upcase == 'GET'
|
|
|
|
modopts['QUERY'] = datastr
|
|
|
|
modopts['DATA'] = ""
|
2010-06-06 03:53:07 +00:00
|
|
|
end
|
2012-02-03 21:43:21 +00:00
|
|
|
if form.method.upcase == 'POST'
|
2013-03-07 19:40:50 +00:00
|
|
|
modopts['DATA'] = datastr
|
2012-02-03 21:43:21 +00:00
|
|
|
end
|
|
|
|
modopts['TYPES'] = typestr
|
2010-06-06 03:53:07 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
#
|
|
|
|
# TODO: Add headers, etc.
|
|
|
|
#
|
2013-03-07 19:40:50 +00:00
|
|
|
if (not usinginipath) or (usinginipath and form.path.match(inipathname))
|
|
|
|
|
2012-02-18 02:56:55 +00:00
|
|
|
print_status "Path #{form.path}"
|
|
|
|
#print_status("Unique PATH #{modopts['PATH']}")
|
|
|
|
#print_status("Unique GET #{modopts['QUERY']}")
|
|
|
|
#print_status("Unique POST #{modopts['DATA']}")
|
|
|
|
#print_status("MODOPTS: #{modopts}")
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2012-02-18 02:56:55 +00:00
|
|
|
begin
|
|
|
|
if execmod
|
|
|
|
rpcnode = rpc_round_exec(xref[0],xref[1], modopts, self.njobs)
|
2013-03-07 19:40:50 +00:00
|
|
|
end
|
2012-02-18 02:56:55 +00:00
|
|
|
utest_query[signature(form.path,datastr)]=1
|
|
|
|
rescue ::Exception
|
|
|
|
print_status(" >> Exception during launch from #{xref[0]}: #{$!}")
|
|
|
|
end
|
2012-02-03 21:43:21 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
#print_status("Already tested")
|
|
|
|
end
|
2010-06-06 03:53:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
rescue ::Exception
|
|
|
|
print_status(" >> Exception from #{xref[0]}: #{$!}")
|
|
|
|
end
|
2010-06-06 03:53:07 +00:00
|
|
|
end
|
2011-02-04 05:57:26 +00:00
|
|
|
end
|
2010-06-06 03:53:07 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
#
|
|
|
|
# Run modules for each request to play with URI query parameters.
|
|
|
|
# This approach will reduce the complexity of the Tree used before
|
|
|
|
# and will make this shotgun implementation much simple.
|
2012-02-03 21:43:21 +00:00
|
|
|
# wmap_query
|
2011-02-04 05:57:26 +00:00
|
|
|
#
|
2011-10-23 11:56:13 +00:00
|
|
|
print_status "\n=[ Query testing ]="
|
2012-02-03 21:43:21 +00:00
|
|
|
print_line "=" * sizeline
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
idx = 0
|
|
|
|
matches2.each_key do |xref|
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
if self.masstop
|
|
|
|
print_error("STOPPED.")
|
|
|
|
return
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
|
|
|
# Module not part of profile or not match
|
|
|
|
if not ( using_p and eprofile.include? xref[0].split('/').last ) or (using_m and xref[0].to_s.match(mname)) or (not using_m and not using_p)
|
2012-02-03 21:43:21 +00:00
|
|
|
idx += 1
|
2010-06-06 03:53:07 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
begin
|
|
|
|
# Module options hash
|
2013-03-07 19:40:50 +00:00
|
|
|
modopts = Hash.new()
|
2010-06-06 03:53:07 +00:00
|
|
|
|
|
|
|
#
|
2012-02-03 21:43:21 +00:00
|
|
|
# The code is just a proof-of-concept and will be expanded in the future
|
2010-06-06 03:53:07 +00:00
|
|
|
#
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
print_status "Module #{xref[0]}"
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
if (mode & wmap_expl != 0)
|
2011-02-04 05:57:26 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
#
|
|
|
|
# For modules to have access to the global datastore
|
|
|
|
# i.e. set -g DOMAIN test.com
|
|
|
|
#
|
|
|
|
self.framework.datastore.each do |gkey,gval|
|
|
|
|
modopts[gkey]=gval
|
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
#
|
|
|
|
# Parameters passed in hash xref
|
|
|
|
#
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
modopts['RHOST'] = selected_host
|
|
|
|
modopts['RHOSTS'] = selected_host
|
|
|
|
modopts['RPORT'] = selected_port.to_s
|
|
|
|
modopts['SSL'] = selected_ssl
|
|
|
|
modopts['VHOST'] = selected_vhost.to_s
|
|
|
|
modopts['VERBOSE'] = moduleverbose
|
|
|
|
modopts['ShowProgress'] = showprogress
|
|
|
|
modopts['RunAsJob'] = jobify
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
#
|
|
|
|
# Run the plugins for each request that have a distinct
|
|
|
|
# GET/POST URI QUERY string.
|
|
|
|
#
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
h = self.framework.db.workspace.hosts.find_by_address(selected_host)
|
|
|
|
s = h.services.find_by_port(selected_port)
|
|
|
|
w = s.web_sites.find_by_vhost(selected_vhost)
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
w.web_forms.each do |req|
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
if self.masstop
|
|
|
|
print_error("STOPPED.")
|
|
|
|
return
|
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
datastr = ""
|
|
|
|
typestr = ""
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
temparr = []
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
req.params.each do |p|
|
|
|
|
pn, pv, pt = p
|
|
|
|
if pn
|
2013-03-07 19:40:50 +00:00
|
|
|
if not pn.empty?
|
2012-02-03 21:43:21 +00:00
|
|
|
if not pv or pv.empty?
|
|
|
|
#TODO add value based on param name
|
|
|
|
pv = "aaa"
|
|
|
|
end
|
2012-02-18 02:56:55 +00:00
|
|
|
#temparr << pn.to_s + "=" + Rex::Text.uri_encode(pv.to_s)
|
|
|
|
temparr << pn.to_s + "=" + pv.to_s
|
2012-02-03 21:43:21 +00:00
|
|
|
end
|
|
|
|
else
|
2013-03-07 19:40:50 +00:00
|
|
|
print_error("Blank parameter name. Form #{req.path}")
|
|
|
|
end
|
2012-02-03 21:43:21 +00:00
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
datastr = temparr.join("&") if (temparr and not temparr.empty?)
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
modopts['METHOD'] = req.method.upcase
|
|
|
|
modopts['PATH'] = req.path
|
|
|
|
if req.method.upcase == 'GET'
|
|
|
|
modopts['QUERY'] = datastr
|
|
|
|
modopts['DATA'] = ""
|
|
|
|
end
|
|
|
|
modopts['DATA'] = datastr if req.method.upcase == 'POST'
|
|
|
|
modopts['TYPES'] = typestr
|
2010-06-06 03:53:07 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
#
|
|
|
|
# TODO: Add method, headers, etc.
|
|
|
|
#
|
2013-03-07 19:40:50 +00:00
|
|
|
if (not usinginipath) or (usinginipath and req.path.match(inipathname))
|
|
|
|
|
2012-02-18 02:56:55 +00:00
|
|
|
print_status "Path #{req.path}"
|
|
|
|
#print_status("Query PATH #{modopts['PATH']}")
|
|
|
|
#print_status("Query GET #{modopts['QUERY']}")
|
|
|
|
#print_status("Query POST #{modopts['DATA']}")
|
|
|
|
#print_status("Query TYPES #{typestr}")
|
2010-06-06 03:53:07 +00:00
|
|
|
|
2012-02-18 02:56:55 +00:00
|
|
|
begin
|
|
|
|
if execmod
|
|
|
|
rpcnode = rpc_round_exec(xref[0],xref[1], modopts, self.njobs)
|
|
|
|
end
|
|
|
|
rescue ::Exception
|
|
|
|
print_status(" >> Exception during launch from #{xref[0]}: #{$!}")
|
2010-06-06 03:53:07 +00:00
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
end
|
2010-06-06 03:53:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
rescue ::Exception
|
|
|
|
print_status(" >> Exception from #{xref[0]}: #{$!}")
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
end
|
2011-02-04 05:57:26 +00:00
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
#
|
|
|
|
# Handle modules that need to be after all tests, once.
|
|
|
|
# Good place to have modules that analize the test results and/or
|
|
|
|
# launch exploits.
|
2012-02-03 21:43:21 +00:00
|
|
|
# :wmap_generic
|
2011-02-04 05:57:26 +00:00
|
|
|
#
|
2011-10-23 11:56:13 +00:00
|
|
|
print_status "\n=[ General testing ]="
|
2012-02-03 21:43:21 +00:00
|
|
|
print_line "=" * sizeline
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
idx = 0
|
|
|
|
matches10.each_key do |xref|
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
if self.masstop
|
|
|
|
print_error("STOPPED.")
|
|
|
|
return
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
|
|
|
# Module not part of profile or not match
|
|
|
|
if not ( using_p and eprofile.include? xref[0].split('/').last ) or (using_m and xref[0].to_s.match(mname)) or (not using_m and not using_p)
|
2012-02-03 21:43:21 +00:00
|
|
|
idx += 1
|
2010-06-06 03:53:07 +00:00
|
|
|
|
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
begin
|
|
|
|
# Module options hash
|
2013-03-07 19:40:50 +00:00
|
|
|
modopts = Hash.new()
|
2011-02-04 05:57:26 +00:00
|
|
|
|
2010-06-06 03:53:07 +00:00
|
|
|
#
|
2012-02-03 21:43:21 +00:00
|
|
|
# The code is just a proof-of-concept and will be expanded in the future
|
2010-06-06 03:53:07 +00:00
|
|
|
#
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
print_status "Module #{xref[0]}"
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
if (mode & wmap_expl != 0)
|
2010-06-06 03:53:07 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
#
|
|
|
|
# For modules to have access to the global datastore
|
|
|
|
# i.e. set -g DOMAIN test.com
|
|
|
|
#
|
|
|
|
self.framework.datastore.each do |gkey,gval|
|
|
|
|
modopts[gkey]=gval
|
|
|
|
end
|
2010-06-06 03:53:07 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
#
|
|
|
|
# Parameters passed in hash xref
|
|
|
|
#
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
modopts['RHOST'] = selected_host
|
|
|
|
modopts['RHOSTS'] = selected_host
|
|
|
|
modopts['RPORT'] = selected_port.to_s
|
|
|
|
modopts['SSL'] = selected_ssl
|
|
|
|
modopts['VHOST'] = selected_vhost.to_s
|
|
|
|
modopts['VERBOSE'] = moduleverbose
|
|
|
|
modopts['ShowProgress'] = showprogress
|
|
|
|
modopts['RunAsJob'] = jobify
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
#
|
|
|
|
# Run the plugins that only need to be
|
|
|
|
# launched once.
|
|
|
|
#
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
begin
|
|
|
|
if execmod
|
|
|
|
rpcnode = rpc_round_exec(xref[0],xref[1], modopts, self.njobs)
|
2010-06-06 03:53:07 +00:00
|
|
|
end
|
2012-02-03 21:43:21 +00:00
|
|
|
rescue ::Exception
|
|
|
|
print_status(" >> Exception during launch from #{xref[0]}: #{$!}")
|
2013-03-07 19:40:50 +00:00
|
|
|
end
|
2010-06-06 03:53:07 +00:00
|
|
|
end
|
2011-02-04 05:57:26 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
rescue ::Exception
|
|
|
|
print_status(" >> Exception from #{xref[0]}: #{$!}")
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
end
|
2011-02-04 05:57:26 +00:00
|
|
|
end
|
2010-06-06 03:53:07 +00:00
|
|
|
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
if (mode & wmap_expl != 0)
|
|
|
|
print_line "+" * sizeline
|
2013-03-07 19:40:50 +00:00
|
|
|
|
|
|
|
if not self.runlocal
|
2012-02-03 21:43:21 +00:00
|
|
|
if execmod
|
|
|
|
rpc_list_nodes()
|
|
|
|
print_status("Note: Use wmap_nodes -l to list node status for completion")
|
|
|
|
end
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-19 07:01:01 +00:00
|
|
|
print_line("Launch completed in #{(Time.now.to_f - stamp)} seconds.")
|
2012-02-03 21:43:21 +00:00
|
|
|
print_line "+" * sizeline
|
2010-06-06 03:53:07 +00:00
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
print_status("Done.")
|
2010-06-06 03:53:07 +00:00
|
|
|
end
|
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
# EOM
|
2011-10-23 11:56:13 +00:00
|
|
|
end
|
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
def view_targets
|
|
|
|
if self.targets == nil or self.targets.keys.length == 0
|
|
|
|
print_status "No targets have been defined"
|
|
|
|
return
|
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
indent = ' '
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
tbl = Rex::Ui::Text::Table.new(
|
|
|
|
'Indent' => indent.length,
|
|
|
|
'Header' => 'Defined targets',
|
|
|
|
'Columns' =>
|
|
|
|
[
|
|
|
|
'Id',
|
|
|
|
'Vhost',
|
|
|
|
'Host',
|
|
|
|
'Port',
|
|
|
|
'SSL',
|
|
|
|
'Path',
|
|
|
|
])
|
|
|
|
|
|
|
|
self.targets.each_with_index { |t, idx|
|
2012-02-20 00:24:23 +00:00
|
|
|
tbl << [ idx.to_s, t[1][:vhost], t[1][:host], t[1][:port], t[1][:ssl], "\t"+t[1][:path].to_s ]
|
2011-02-04 05:57:26 +00:00
|
|
|
}
|
2010-06-06 03:53:07 +00:00
|
|
|
|
2011-10-23 11:56:13 +00:00
|
|
|
print_status tbl.to_s + "\n"
|
2011-02-04 05:57:26 +00:00
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2013-03-11 03:55:15 +00:00
|
|
|
def delete_sites(wmap_index)
|
2013-03-07 19:57:03 +00:00
|
|
|
idx = 0
|
2013-03-11 03:55:15 +00:00
|
|
|
to_del = {}
|
|
|
|
# Rebuild the index from wmap_sites -l
|
2013-03-07 19:57:03 +00:00
|
|
|
self.framework.db.hosts.each do |bdhost|
|
|
|
|
bdhost.services.each do |serv|
|
|
|
|
serv.web_sites.each do |web|
|
2013-03-11 03:55:15 +00:00
|
|
|
# If the index of this site matches any deletion index,
|
|
|
|
# add to our hash, saving the index for later output
|
|
|
|
to_del[idx] = web if wmap_index.any? {|w| w.to_i == idx}
|
|
|
|
idx += 1
|
2013-03-07 19:57:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-03-11 03:55:15 +00:00
|
|
|
to_del.each do |widx,wsite|
|
|
|
|
if wsite.delete
|
|
|
|
print_status("Deleted #{wsite.vhost} on #{wsite.service.host.address} at index #{widx}")
|
|
|
|
else
|
|
|
|
print_error("Could note delete {wsite.vhost} on #{wsite.service.host.address} at index #{widx}")
|
|
|
|
end
|
|
|
|
end
|
2013-03-07 19:57:03 +00:00
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
def view_sites
|
2012-02-03 21:43:21 +00:00
|
|
|
# Clean temporary sites list
|
|
|
|
self.lastsites = []
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
indent = ' '
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
tbl = Rex::Ui::Text::Table.new(
|
|
|
|
'Indent' => indent.length,
|
|
|
|
'Header' => 'Available sites',
|
|
|
|
'Columns' =>
|
|
|
|
[
|
|
|
|
'Id',
|
|
|
|
'Host',
|
|
|
|
'Vhost',
|
|
|
|
'Port',
|
2012-02-03 21:43:21 +00:00
|
|
|
'Proto',
|
2011-02-04 05:57:26 +00:00
|
|
|
'# Pages',
|
|
|
|
'# Forms',
|
|
|
|
])
|
|
|
|
|
2011-10-23 11:56:13 +00:00
|
|
|
idx = 0
|
2011-02-04 05:57:26 +00:00
|
|
|
self.framework.db.hosts.each do |bdhost|
|
|
|
|
bdhost.services.each do |serv|
|
|
|
|
serv.web_sites.each do |web|
|
2011-10-23 11:56:13 +00:00
|
|
|
c = web.web_pages.count
|
2011-02-04 05:57:26 +00:00
|
|
|
f = web.web_forms.count
|
2012-02-03 21:43:21 +00:00
|
|
|
tbl << [ idx.to_s, bdhost.address, web.vhost, serv.port, serv.name, c.to_s, f.to_s ]
|
2011-02-04 05:57:26 +00:00
|
|
|
idx += 1
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
turl = web.vhost + "," + serv.name + "://" +bdhost.address.to_s + ":" + serv.port.to_s + "/"
|
2013-03-07 19:40:50 +00:00
|
|
|
self.lastsites << turl
|
2010-06-06 03:53:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2011-10-23 11:56:13 +00:00
|
|
|
print_status tbl.to_s + "\n"
|
2010-06-06 03:53:07 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
# Reusing code from hdmoore
|
|
|
|
#
|
|
|
|
# Allow the URL to be supplied as VHOST,URL if a custom VHOST
|
|
|
|
# should be used. This allows for things like:
|
|
|
|
# localhost,http://192.168.0.2/admin/
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
def add_web_site(url)
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
vhost = nil
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
# Allow the URL to be supplied as VHOST,URL if a custom VHOST
|
|
|
|
# should be used. This allows for things like:
|
|
|
|
# localhost,http://192.168.0.2/admin/
|
|
|
|
|
|
|
|
if url !~ /^http/
|
|
|
|
vhost,url = url.split(",", 2)
|
|
|
|
if url.to_s.empty?
|
|
|
|
url = vhost
|
|
|
|
vhost = nil
|
2010-06-06 03:53:07 +00:00
|
|
|
end
|
2011-02-04 05:57:26 +00:00
|
|
|
end
|
2010-06-06 03:53:07 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
# Prefix http:// when the URL has no specified parameter
|
|
|
|
if url !~ /^[a-z0-9A-Z]+:\/\//
|
|
|
|
url = "http://" + url
|
|
|
|
end
|
2010-06-06 03:53:07 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
uri = URI.parse(url) rescue nil
|
|
|
|
if not uri
|
|
|
|
print_error("Could not understand URL: #{url}")
|
2011-10-23 11:56:13 +00:00
|
|
|
return
|
2011-02-04 05:57:26 +00:00
|
|
|
end
|
2010-06-06 03:53:07 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
if uri.scheme !~ /^https?/
|
|
|
|
print_error("Only http and https URLs are accepted: #{url}")
|
|
|
|
return
|
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
ssl = false
|
|
|
|
if uri.scheme == 'https'
|
|
|
|
ssl = true
|
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
site = self.framework.db.report_web_site(:wait => true, :host => uri.host, :port => uri.port, :vhost => vhost, :ssl => ssl)
|
2010-06-06 03:53:07 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
return site
|
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
# Code by hdm. Modified two lines by et
|
|
|
|
#
|
|
|
|
def process_urls(urlstr)
|
|
|
|
|
|
|
|
target_whitelist = []
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
urls = urlstr.to_s.split(/\s+/)
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
|
|
|
|
urls.each do |url|
|
|
|
|
next if url.to_s.strip.empty?
|
|
|
|
vhost = nil
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
# Allow the URL to be supplied as VHOST,URL if a custom VHOST
|
|
|
|
# should be used. This allows for things like:
|
|
|
|
# localhost,http://192.168.0.2/admin/
|
|
|
|
|
|
|
|
if url !~ /^http/
|
|
|
|
vhost,url = url.split(",", 2)
|
|
|
|
if url.to_s.empty?
|
|
|
|
url = vhost
|
|
|
|
vhost = nil
|
2010-06-06 03:53:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
# Prefix http:// when the URL has no specified parameter
|
|
|
|
if url !~ /^[a-z0-9A-Z]+:\/\//
|
|
|
|
url = "http://" + url
|
|
|
|
end
|
2010-06-06 03:53:07 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
uri = URI.parse(url) rescue nil
|
|
|
|
if not uri
|
|
|
|
print_error("Could not understand URL: #{url}")
|
|
|
|
next
|
|
|
|
end
|
2010-06-06 03:53:07 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
if uri.scheme !~ /^https?/
|
|
|
|
print_error("Only http and https URLs are accepted: #{url}")
|
|
|
|
next
|
|
|
|
end
|
2010-06-06 03:53:07 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
target_whitelist << [vhost || uri.host, uri]
|
2010-06-06 03:53:07 +00:00
|
|
|
end
|
2010-06-09 18:41:58 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
# Skip the DB entirely if no matches
|
|
|
|
return if target_whitelist.length == 0
|
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
if not self.targets
|
|
|
|
# First time targets are defined
|
2013-03-07 19:40:50 +00:00
|
|
|
self.targets = Hash.new()
|
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
target_whitelist.each do |ent|
|
|
|
|
vhost,target = ent
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
host = self.framework.db.workspace.hosts.find_by_address(target.host)
|
|
|
|
if not host
|
|
|
|
print_error("No matching host for #{target.host}")
|
|
|
|
next
|
|
|
|
end
|
|
|
|
serv = host.services.find_by_port_and_proto(target.port, 'tcp')
|
|
|
|
if not serv
|
|
|
|
print_error("No matching service for #{target.host}:#{target.port}")
|
|
|
|
next
|
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
|
|
|
|
#print_status "aaa"
|
|
|
|
#print_status framework.db.workspace.name
|
|
|
|
|
2012-04-19 15:22:31 +00:00
|
|
|
sites = serv.web_sites.where('vhost = ? and service_id = ?', vhost, serv.id)
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
sites.each do |site|
|
2012-02-03 21:43:21 +00:00
|
|
|
# Initial defaul path
|
|
|
|
inipath = target.path
|
|
|
|
if target.path.empty?
|
2013-03-07 19:40:50 +00:00
|
|
|
inipath = '/'
|
2012-02-03 21:43:21 +00:00
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
#site.web_forms.find_all_by_path(target.path).each do |form|
|
2012-02-03 21:43:21 +00:00
|
|
|
ckey = [ site.vhost, host.address, serv.port, inipath].join("|")
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
if not self.targets[ckey]
|
|
|
|
self.targets[ckey] = WebTarget.new
|
|
|
|
self.targets[ckey].merge!({
|
|
|
|
:vhost => site.vhost,
|
|
|
|
:host => host.address,
|
|
|
|
:port => serv.port,
|
|
|
|
:ssl => (serv.name == "https"),
|
2012-02-03 21:43:21 +00:00
|
|
|
:path => inipath
|
2011-02-04 05:57:26 +00:00
|
|
|
})
|
2012-02-03 21:43:21 +00:00
|
|
|
#self.targets[ckey][inipath] = []
|
|
|
|
else
|
2013-03-07 19:40:50 +00:00
|
|
|
print_status("Target already set in targets list.")
|
2011-02-04 05:57:26 +00:00
|
|
|
end
|
2010-06-06 03:53:07 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
# Store the form object in the hash for this path
|
2012-02-03 21:43:21 +00:00
|
|
|
#self.targets[ckey][inipath] << inipath
|
2011-02-04 05:57:26 +00:00
|
|
|
#end
|
|
|
|
end
|
2010-06-06 03:53:07 +00:00
|
|
|
end
|
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
# Code by hdm. Modified two lines by et
|
2013-03-07 19:40:50 +00:00
|
|
|
# lastsites contains a temporary array with vhost,url strings so the id can be
|
|
|
|
# referenced in the array and prevent new sites added in the db to corrupt previous id list.
|
2012-02-03 21:43:21 +00:00
|
|
|
def process_ids(idsstr)
|
|
|
|
|
2013-03-07 19:40:50 +00:00
|
|
|
if !self.lastsites or self.lastsites.length == 0
|
2012-02-03 21:43:21 +00:00
|
|
|
view_sites
|
|
|
|
print_status ("Web sites ids. referenced from previous table.")
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
target_whitelist = []
|
|
|
|
ids = idsstr.to_s.split(/,/)
|
|
|
|
|
|
|
|
ids.each do |id|
|
|
|
|
next if id.to_s.strip.empty?
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
if id.to_i > self.lastsites.length
|
2013-03-07 19:40:50 +00:00
|
|
|
print_error("Skipping id #{id}...")
|
2012-02-03 21:43:21 +00:00
|
|
|
else
|
|
|
|
target_whitelist << self.lastsites[id.to_i]
|
|
|
|
print_status("Loading #{self.lastsites[id.to_i]}.")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Skip the DB entirely if no matches
|
|
|
|
return if target_whitelist.length == 0
|
|
|
|
|
|
|
|
if not self.targets
|
2013-03-07 19:40:50 +00:00
|
|
|
self.targets = Hash.new()
|
2012-02-03 21:43:21 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
target_whitelist.each do |ent|
|
|
|
|
process_urls(ent)
|
2013-03-07 19:40:50 +00:00
|
|
|
end
|
2012-02-03 21:43:21 +00:00
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
def view_site_tree(urlstr, md, ld)
|
2013-03-07 19:40:50 +00:00
|
|
|
if not urlstr
|
2012-02-03 21:43:21 +00:00
|
|
|
return
|
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
site_whitelist = []
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
urls = urlstr.to_s.split(/\s+/)
|
|
|
|
|
|
|
|
urls.each do |url|
|
|
|
|
next if url.to_s.strip.empty?
|
|
|
|
vhost = nil
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
# Allow the URL to be supplied as VHOST,URL if a custom VHOST
|
|
|
|
# should be used. This allows for things like:
|
|
|
|
# localhost,http://192.168.0.2/admin/
|
|
|
|
|
|
|
|
if url !~ /^http/
|
|
|
|
vhost,url = url.split(",", 2)
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
if url.to_s.empty?
|
|
|
|
url = vhost
|
|
|
|
vhost = nil
|
|
|
|
end
|
|
|
|
end
|
2010-06-06 03:53:07 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
# Prefix http:// when the URL has no specified parameter
|
|
|
|
if url !~ /^[a-z0-9A-Z]+:\/\//
|
|
|
|
url = "http://" + url
|
|
|
|
end
|
2010-06-06 03:53:07 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
uri = URI.parse(url) rescue nil
|
|
|
|
if not uri
|
|
|
|
print_error("Could not understand URL: #{url}")
|
|
|
|
next
|
|
|
|
end
|
2010-06-06 03:53:07 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
if uri.scheme !~ /^https?/
|
|
|
|
print_error("Only http and https URLs are accepted: #{url}")
|
|
|
|
next
|
|
|
|
end
|
2010-06-06 03:53:07 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
site_whitelist << [vhost || uri.host, uri]
|
|
|
|
end
|
2010-06-06 03:53:07 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
# Skip the DB entirely if no matches
|
|
|
|
return if site_whitelist.length == 0
|
|
|
|
|
2013-03-07 19:40:50 +00:00
|
|
|
vsites = Hash.new()
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
site_whitelist.each do |ent|
|
|
|
|
vhost,target = ent
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
host = self.framework.db.workspace.hosts.find_by_address(target.host)
|
|
|
|
if not host
|
|
|
|
print_error("No matching host for #{target.host}")
|
|
|
|
next
|
|
|
|
end
|
|
|
|
serv = host.services.find_by_port_and_proto(target.port, 'tcp')
|
|
|
|
if not serv
|
|
|
|
print_error("No matching service for #{target.host}:#{target.port}")
|
|
|
|
next
|
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2013-03-07 19:57:03 +00:00
|
|
|
sites = serv.web_sites.where('vhost = ? and service_id = ?', vhost, serv.id)
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
sites.each do |site|
|
|
|
|
t = load_tree(site)
|
2012-02-03 21:43:21 +00:00
|
|
|
print_tree(t,target.host,md,ld)
|
2011-02-04 05:57:26 +00:00
|
|
|
print_line("\n")
|
2010-06-06 03:53:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2010-06-06 03:53:07 +00:00
|
|
|
#
|
2011-02-04 05:57:26 +00:00
|
|
|
# Load website structure into a tree
|
2010-06-06 03:53:07 +00:00
|
|
|
#
|
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
def load_tree(s)
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
pathchr = '/'
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
wtree = Tree.new(s.vhost)
|
|
|
|
|
2011-10-23 11:56:13 +00:00
|
|
|
# Load site pages
|
2011-02-04 05:57:26 +00:00
|
|
|
s.web_pages.find(:all, :order => 'path').each do |req|
|
|
|
|
tarray = req.path.to_s.split(pathchr)
|
|
|
|
tarray.delete("")
|
|
|
|
tpath = Pathname.new(pathchr)
|
|
|
|
tarray.each do |df|
|
|
|
|
wtree.add_at_path(tpath.to_s,df)
|
|
|
|
tpath = tpath + Pathname.new(df.to_s)
|
|
|
|
end
|
2010-06-06 03:53:07 +00:00
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
# Load site forms
|
|
|
|
s.web_forms.each do |req|
|
|
|
|
tarray = req.path.to_s.split(pathchr)
|
|
|
|
tarray.delete("")
|
|
|
|
tpath = Pathname.new(pathchr)
|
|
|
|
tarray.each do |df|
|
|
|
|
wtree.add_at_path(tpath.to_s,df)
|
|
|
|
tpath = tpath + Pathname.new(df.to_s)
|
2010-06-06 03:53:07 +00:00
|
|
|
end
|
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
return wtree
|
2010-06-06 03:53:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
2011-02-04 05:57:26 +00:00
|
|
|
# Print Tree structure. Still ugly
|
2010-06-06 03:53:07 +00:00
|
|
|
#
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
def print_tree(tree, ip, maxlevel, limitlevel)
|
2011-02-04 05:57:26 +00:00
|
|
|
initab = " " * 4
|
|
|
|
indent = 6
|
|
|
|
if tree != nil and tree.depth <= maxlevel
|
|
|
|
print initab + (" " * indent * tree.depth)
|
|
|
|
if tree.depth > 0
|
2011-10-23 11:56:13 +00:00
|
|
|
print "|"+("-" * (indent-1))+"/"
|
2011-02-04 05:57:26 +00:00
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
if tree.depth >= 0
|
2011-02-04 05:57:26 +00:00
|
|
|
if tree.depth == 0
|
2012-02-03 21:43:21 +00:00
|
|
|
print "[#{tree.name}] (#{ip})\n"+initab+(" " * indent)+"\n"
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
else
|
|
|
|
c = tree.children.count
|
|
|
|
if c > 0
|
|
|
|
print tree.name + " (" + c.to_s+")\n"
|
|
|
|
else
|
|
|
|
print tree.name + "\n"
|
2011-10-23 11:56:13 +00:00
|
|
|
end
|
2011-02-04 05:57:26 +00:00
|
|
|
end
|
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
tree.children.each_pair do |name,child|
|
2012-02-03 21:43:21 +00:00
|
|
|
print_tree(child,ip,maxlevel,limitlevel)
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
end
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
def signature(fpath,fquery)
|
|
|
|
hsig = Hash.new()
|
|
|
|
|
|
|
|
hsig = queryparse(fquery)
|
|
|
|
|
|
|
|
#
|
|
|
|
# Signature of the form ',p1,p2,pn' then to be appended to path: path,p1,p2,pn
|
|
|
|
#
|
|
|
|
|
|
|
|
sigstr = fpath + "," + hsig.map{|p| p[0].to_s}.join(",")
|
|
|
|
end
|
|
|
|
|
|
|
|
def queryparse(query)
|
|
|
|
params = Hash.new()
|
|
|
|
|
|
|
|
query.split(/[&;]/n).each do |pairs|
|
|
|
|
key, value = pairs.split('=',2)
|
|
|
|
if params.has_key?(key)
|
|
|
|
#Error
|
|
|
|
else
|
|
|
|
params[key] = value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
params
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
def rpc_add_node(host,port,ssl,user,pass,bypass_exist)
|
|
|
|
|
|
|
|
if not self.rpcarr
|
2013-03-07 19:40:50 +00:00
|
|
|
self.rpcarr = Hash.new()
|
2012-02-03 21:43:21 +00:00
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
begin
|
|
|
|
istr = "#{host}|#{port}|#{ssl}|#{user}|#{pass}"
|
|
|
|
if self.rpcarr.has_key?(istr) and not bypass_exist and self.rpcarr[istr] != nil
|
|
|
|
print_error("Connection already exists #{istr}")
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
temprpc = ::Msf::RPC::Client.new(
|
|
|
|
:host => host,
|
|
|
|
:port => port,
|
|
|
|
:ssl => ssl
|
|
|
|
)
|
|
|
|
rescue
|
|
|
|
print_error "Unable to connect"
|
|
|
|
#raise ConnectionError
|
|
|
|
return
|
2013-03-07 19:40:50 +00:00
|
|
|
end
|
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
res = temprpc.login( user , pass)
|
2013-03-07 19:40:50 +00:00
|
|
|
|
|
|
|
if not res
|
2012-02-03 21:43:21 +00:00
|
|
|
print_error("Unable to authenticate to #{host}:#{port}.")
|
|
|
|
return
|
|
|
|
else
|
|
|
|
res = temprpc.call('core.version')
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
|
|
|
print_status("Connected to #{host}:#{port} [#{res['version']}].")
|
2012-02-03 21:43:21 +00:00
|
|
|
self.rpcarr[istr] = temprpc
|
|
|
|
end
|
|
|
|
rescue
|
|
|
|
print_error("Unable to connect")
|
|
|
|
end
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
def local_module_exec(mod,mtype, opts, nmaxjobs)
|
|
|
|
jobify = false
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
modinst = framework.modules.create(mod)
|
|
|
|
|
|
|
|
if(not modinst)
|
|
|
|
print_error("Unknown module")
|
|
|
|
return
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
sess = nil
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
case mtype
|
|
|
|
when 'auxiliary'
|
|
|
|
Msf::Simple::Auxiliary.run_simple(modinst, {
|
|
|
|
'Action' => opts['ACTION'],
|
|
|
|
'LocalOutput' => driver.output,
|
|
|
|
'RunAsJob' => jobify,
|
|
|
|
'Options' => opts
|
|
|
|
})
|
|
|
|
when 'exploit'
|
2012-05-18 22:20:59 +00:00
|
|
|
if not opts['PAYLOAD']
|
|
|
|
opts['PAYLOAD'] = WmapCommandDispatcher::Exploit.choose_payload(modinst, opts['TARGET'])
|
|
|
|
end
|
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
sess = Msf::Simple::Exploit.exploit_simple(modinst, {
|
|
|
|
'Payload' => opts['PAYLOAD'],
|
|
|
|
'Target' => opts['TARGET'],
|
|
|
|
'LocalOutput' => driver.output,
|
|
|
|
'RunAsJob' => jobify,
|
|
|
|
'Options' => opts
|
|
|
|
})
|
2012-02-18 02:56:55 +00:00
|
|
|
else
|
|
|
|
print_error("Wrong mtype.")
|
2012-02-03 21:43:21 +00:00
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
if sess
|
|
|
|
if (jobify == false and sess.interactive?)
|
|
|
|
print_line
|
|
|
|
driver.run_single("sessions -q -i #{sess.sid}")
|
2013-03-07 19:40:50 +00:00
|
|
|
else
|
2012-02-03 21:43:21 +00:00
|
|
|
print_status("Session #{sess.sid} created in the background.")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
def rpc_round_exec(mod,mtype, opts, nmaxjobs)
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
res = nil
|
|
|
|
idx = 0
|
2013-03-07 19:40:50 +00:00
|
|
|
|
|
|
|
if active_rpc_nodes == 0
|
2012-02-03 21:43:21 +00:00
|
|
|
if not self.runlocal
|
2013-03-07 19:40:50 +00:00
|
|
|
print_error("All active nodes not working or removed")
|
|
|
|
return
|
2012-02-03 21:43:21 +00:00
|
|
|
end
|
|
|
|
res = true
|
|
|
|
else
|
|
|
|
rpc_reconnect_nodes()
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
if self.masstop
|
|
|
|
return
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
while not res
|
|
|
|
if active_rpc_nodes == 0
|
|
|
|
print_error("All active nodes not working or removed")
|
2013-03-07 19:40:50 +00:00
|
|
|
return
|
2012-02-03 21:43:21 +00:00
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
#find the node with less jobs load.
|
|
|
|
minjobs = nmaxjobs
|
|
|
|
minconn = nil
|
|
|
|
nid = 0
|
|
|
|
self.rpcarr.each do |k,rpccon|
|
|
|
|
if not rpccon
|
|
|
|
print_error("Skipping inactive node #{nid} #{k}")
|
2013-03-07 19:40:50 +00:00
|
|
|
else
|
2012-02-03 21:43:21 +00:00
|
|
|
begin
|
|
|
|
currentjobs = rpccon.call('job.list').length
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
if currentjobs < minjobs
|
|
|
|
minconn = rpccon
|
|
|
|
minjobs = currentjobs
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
if currentjobs == nmaxjobs
|
|
|
|
if self.nmaxdisplay == false
|
|
|
|
print_error("Node #{nid} reached max number of jobs #{nmaxjobs}")
|
|
|
|
print_error("Waiting for available node/slot...")
|
|
|
|
self.nmaxdisplay = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
#print_status("Node #{nid} #currentjobs #{currentjobs} #min #{minjobs}")
|
|
|
|
rescue
|
|
|
|
print_error("Unable to connect. Node #{tarr[0]}:#{tarr[1]}")
|
|
|
|
self.rpcarr[k]=nil
|
2013-03-07 19:40:50 +00:00
|
|
|
|
|
|
|
if active_rpc_nodes == 0
|
2012-02-03 21:43:21 +00:00
|
|
|
print_error("All active nodes ,not working or removed")
|
|
|
|
return
|
|
|
|
else
|
2013-03-07 19:40:50 +00:00
|
|
|
print_error("Sending job to next node")
|
2012-02-03 21:43:21 +00:00
|
|
|
next
|
2013-03-07 19:40:50 +00:00
|
|
|
end
|
2012-02-03 21:43:21 +00:00
|
|
|
end
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
nid += 1
|
2012-02-03 21:43:21 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if minjobs < nmaxjobs
|
|
|
|
res=minconn.call('module.execute', mtype, mod, opts)
|
|
|
|
self.nmaxdisplay = false
|
|
|
|
#print_status(">>>#{res} #{mod}")
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
if res
|
2012-02-19 07:01:01 +00:00
|
|
|
if res.has_key?("job_id")
|
|
|
|
return
|
|
|
|
else
|
2013-03-07 19:40:50 +00:00
|
|
|
print_error("Unable to execute module in node #{k} #{res}")
|
2012-02-19 07:01:01 +00:00
|
|
|
end
|
2012-02-03 21:43:21 +00:00
|
|
|
end
|
|
|
|
else
|
2013-03-07 19:40:50 +00:00
|
|
|
#print_status("Max number of jobs #{nmaxjobs} reached in node #{k}")
|
2012-02-03 21:43:21 +00:00
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
idx += 1
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
|
|
|
if self.runlocal and not self.masstop
|
2012-02-03 21:43:21 +00:00
|
|
|
local_module_exec(mod,mtype, opts, nmaxjobs)
|
|
|
|
end
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
def rpc_db_nodes(host,port,user,pass,name)
|
2013-03-07 19:40:50 +00:00
|
|
|
rpc_reconnect_nodes()
|
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
if active_rpc_nodes == 0
|
|
|
|
print_error("No active nodes at this time")
|
|
|
|
return
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
|
|
|
self.rpcarr.each do |k,v|
|
2012-02-03 21:43:21 +00:00
|
|
|
if v
|
|
|
|
res = v.call('db.driver',{:driver => 'postgresql'})
|
|
|
|
res = v.call('db.connect',{:database => name, :host => host, :port => port, :username => user, :password => pass})
|
|
|
|
res = v.call('db.status')
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
if res['db'] == name
|
|
|
|
print_status("db_connect #{res} #{host}:#{port} OK")
|
|
|
|
else
|
|
|
|
print_error("Error db_connect #{res} #{host}:#{port}")
|
|
|
|
end
|
|
|
|
else
|
|
|
|
print_error("No connection to node #{k}")
|
2013-03-07 19:40:50 +00:00
|
|
|
end
|
2012-02-03 21:43:21 +00:00
|
|
|
end
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
def rpc_reconnect_nodes()
|
|
|
|
begin
|
|
|
|
# Sucky 5 mins token timeout.
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
idx = nil
|
|
|
|
self.rpcarr.each do |k,rpccon|
|
|
|
|
if rpccon
|
|
|
|
idx = k
|
|
|
|
begin
|
|
|
|
currentjobs = rpccon.call('job.list').length
|
|
|
|
rescue
|
|
|
|
tarr = k.split("|")
|
2013-03-07 19:40:50 +00:00
|
|
|
rflag = false
|
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
res = rpccon.login(tarr[3],tarr[4])
|
2013-03-07 19:40:50 +00:00
|
|
|
|
|
|
|
if res
|
2012-02-03 21:43:21 +00:00
|
|
|
rflag = true
|
|
|
|
print_error("Reauth to node #{tarr[0]}:#{tarr[1]}")
|
|
|
|
break
|
|
|
|
else
|
|
|
|
raise ConnectionError
|
|
|
|
end
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
end
|
2012-02-03 21:43:21 +00:00
|
|
|
end
|
|
|
|
rescue
|
|
|
|
print_error("ERROR CONNECTING TO NODE. Disabling #{idx} use wmap_nodes -a to reconnect")
|
|
|
|
self.rpcarr[idx] = nil
|
|
|
|
if active_rpc_nodes == 0
|
|
|
|
print_error("No active nodes")
|
|
|
|
self.masstop = true
|
|
|
|
else
|
|
|
|
#blah
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
end
|
2012-02-03 21:43:21 +00:00
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
def rpc_kill_node(i,j)
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
if not i
|
|
|
|
print_error("Nodes not defined")
|
|
|
|
return
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
if not j
|
|
|
|
print_error("Node jobs defined")
|
|
|
|
return
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
rpc_reconnect_nodes()
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
if active_rpc_nodes == 0
|
|
|
|
print_error("No active nodes at this time")
|
|
|
|
return
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
idx=0
|
|
|
|
self.rpcarr.each do |k,rpccon|
|
2013-03-07 19:40:50 +00:00
|
|
|
if idx == i.to_i or i.upcase == 'ALL'
|
2012-02-03 21:43:21 +00:00
|
|
|
#begin
|
|
|
|
if not rpccon
|
|
|
|
print_error("No connection to node #{idx}")
|
|
|
|
else
|
|
|
|
n = rpccon.call('job.list')
|
|
|
|
n.each do |id,name|
|
|
|
|
if j==id.to_s or j.upcase == 'ALL'
|
|
|
|
rpccon.call('job.stop',id)
|
|
|
|
print_status("Node #{idx} Killed job id #{id} #{name}")
|
2013-03-07 19:40:50 +00:00
|
|
|
end
|
2012-02-03 21:43:21 +00:00
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
end
|
2012-02-03 21:43:21 +00:00
|
|
|
#rescue
|
|
|
|
# print_error("No connection")
|
|
|
|
#end
|
2010-06-06 03:53:07 +00:00
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
idx += 1
|
2012-02-03 21:43:21 +00:00
|
|
|
end
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
def rpc_view_jobs()
|
|
|
|
indent = ' '
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
rpc_reconnect_nodes()
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
if active_rpc_nodes == 0
|
|
|
|
print_error("No active nodes at this time")
|
|
|
|
return
|
2010-06-06 03:53:07 +00:00
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
idx=0
|
2013-03-07 19:40:50 +00:00
|
|
|
self.rpcarr.each do |k,rpccon|
|
2012-02-03 21:43:21 +00:00
|
|
|
if not rpccon
|
|
|
|
print_status("[Node ##{idx}: #{k} DISABLED/NO CONNECTION]")
|
|
|
|
else
|
2013-03-07 19:40:50 +00:00
|
|
|
|
|
|
|
arrk = k.split('|')
|
2012-02-03 21:43:21 +00:00
|
|
|
print_status("[Node ##{idx}: #{arrk[0]} Port:#{arrk[1]} SSL:#{arrk[2]} User:#{arrk[3]}]")
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
begin
|
|
|
|
n = rpccon.call('job.list')
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
tbl = Rex::Ui::Text::Table.new(
|
|
|
|
'Indent' => indent.length,
|
|
|
|
'Header' => 'Jobs',
|
|
|
|
'Columns' =>
|
|
|
|
[
|
|
|
|
'Id',
|
|
|
|
'Job name',
|
2012-02-20 00:24:23 +00:00
|
|
|
'Target',
|
2012-02-19 07:01:01 +00:00
|
|
|
'PATH',
|
2012-02-03 21:43:21 +00:00
|
|
|
])
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
n.each do |id,name|
|
2013-03-07 19:40:50 +00:00
|
|
|
jinfo = rpccon.call('job.info',id)
|
2012-02-19 07:01:01 +00:00
|
|
|
dstore = jinfo['datastore']
|
2012-02-20 00:24:23 +00:00
|
|
|
tbl << [ id.to_s, name,dstore['VHOST']+":"+dstore['RPORT'],dstore['PATH']]
|
2012-02-03 21:43:21 +00:00
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
print_status tbl.to_s + "\n"
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
rescue
|
|
|
|
print_status("[Node ##{idx} #{k} DISABLED/NO CONNECTION]")
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
end
|
|
|
|
idx += 1
|
|
|
|
end
|
2010-06-06 03:53:07 +00:00
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
# Modified from http://stackoverflow.com/questions/946738/detect-key-press-non-blocking-w-o-getc-gets-in-ruby
|
2013-03-07 19:40:50 +00:00
|
|
|
def quit?
|
|
|
|
begin
|
|
|
|
while c = driver.input.read_nonblock(1)
|
|
|
|
print_status("Quited")
|
|
|
|
return true if c == 'Q'
|
|
|
|
end
|
|
|
|
false
|
|
|
|
rescue Errno::EINTR
|
|
|
|
false
|
|
|
|
rescue Errno::EAGAIN
|
|
|
|
false
|
|
|
|
rescue EOFError
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
def rpc_mon_nodes()
|
|
|
|
# Pretty monitor
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-03-15 17:27:01 +00:00
|
|
|
color = self.opts["ConsoleDriver"].output.supports_color? rescue false
|
2013-03-07 19:40:50 +00:00
|
|
|
|
|
|
|
colors = [
|
2013-03-07 19:57:03 +00:00
|
|
|
'%grn',
|
|
|
|
'%blu',
|
|
|
|
'%yel',
|
|
|
|
'%whi'
|
2013-03-07 19:40:50 +00:00
|
|
|
]
|
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
#begin
|
|
|
|
loop do
|
|
|
|
rpc_reconnect_nodes()
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
idx = 0
|
2013-03-07 19:40:50 +00:00
|
|
|
self.rpcarr.each do |k,rpccon|
|
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
arrk = k.split('|')
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
v = "NOCONN"
|
|
|
|
n = 1
|
|
|
|
c = '%red'
|
2013-03-07 19:40:50 +00:00
|
|
|
|
|
|
|
if not rpccon
|
2012-02-03 21:43:21 +00:00
|
|
|
v = "NOCONN"
|
|
|
|
n = 1
|
|
|
|
c = '%red'
|
2013-03-07 19:40:50 +00:00
|
|
|
else
|
2012-02-03 21:43:21 +00:00
|
|
|
begin
|
|
|
|
v = ""
|
|
|
|
c = '%blu'
|
|
|
|
rescue
|
|
|
|
v = "ERROR"
|
|
|
|
c = '%red'
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
begin
|
|
|
|
n = rpccon.call('job.list').length
|
|
|
|
c = '%blu'
|
|
|
|
rescue
|
|
|
|
n = 1
|
|
|
|
v = "NOCONN"
|
|
|
|
c = '%red'
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
end
|
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
#begin
|
|
|
|
if not @stdio
|
|
|
|
@stdio = Rex::Ui::Text::Output::Stdio.new
|
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
if color == true
|
|
|
|
@stdio.auto_color
|
|
|
|
else
|
|
|
|
@stdio.disable_color
|
|
|
|
end
|
|
|
|
msg = "[#{idx}] #{"%bld#{c}||%clr"*n} #{n} #{v}\n"
|
|
|
|
@stdio.print_raw(@stdio.substitute_colors(msg))
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
#rescue
|
|
|
|
#blah
|
|
|
|
#end
|
|
|
|
sleep(2)
|
|
|
|
idx += 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
#rescue
|
|
|
|
# print_status("End.")
|
|
|
|
#end
|
2013-03-07 19:40:50 +00:00
|
|
|
end
|
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
def rpc_list_nodes()
|
|
|
|
indent = ' '
|
2011-02-04 05:57:26 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
tbl = Rex::Ui::Text::Table.new(
|
|
|
|
'Indent' => indent.length,
|
|
|
|
'Header' => 'Nodes',
|
|
|
|
'Columns' =>
|
|
|
|
[
|
|
|
|
'Id',
|
|
|
|
'Host',
|
|
|
|
'Port',
|
|
|
|
'SSL',
|
|
|
|
'User',
|
|
|
|
'Pass',
|
|
|
|
'Status',
|
|
|
|
'#jobs',
|
|
|
|
])
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
idx=0
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
rpc_reconnect_nodes()
|
2013-03-07 19:40:50 +00:00
|
|
|
|
|
|
|
self.rpcarr.each do |k,rpccon|
|
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
arrk = k.split('|')
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
if not rpccon
|
|
|
|
v = "NOCONN"
|
|
|
|
n = ""
|
2013-03-07 19:40:50 +00:00
|
|
|
else
|
2012-02-03 21:43:21 +00:00
|
|
|
begin
|
|
|
|
v = rpccon.call('core.version')['version']
|
|
|
|
rescue
|
|
|
|
v = "ERROR"
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
begin
|
|
|
|
n = rpccon.call('job.list').length
|
|
|
|
rescue
|
|
|
|
n = ""
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
end
|
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
tbl << [ idx.to_s, arrk[0], arrk[1], arrk[2], arrk[3], arrk[4], v, n]
|
|
|
|
idx += 1
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
print_status tbl.to_s + "\n"
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
def active_rpc_nodes
|
2013-03-07 19:40:50 +00:00
|
|
|
if self.rpcarr.length == 0
|
2012-02-03 21:43:21 +00:00
|
|
|
return 0
|
|
|
|
else
|
2013-03-07 19:40:50 +00:00
|
|
|
idx = 0
|
2012-02-03 21:43:21 +00:00
|
|
|
self.rpcarr.each do |k,conn|
|
|
|
|
if conn
|
2013-03-07 19:40:50 +00:00
|
|
|
idx += 1
|
2012-02-03 21:43:21 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return idx
|
2013-03-07 19:40:50 +00:00
|
|
|
end
|
2012-02-03 21:43:21 +00:00
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
def view_modules
|
|
|
|
indent = ' '
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
wmaptype = [:wmap_ssl,
|
|
|
|
:wmap_server,
|
|
|
|
:wmap_dir,
|
|
|
|
:wmap_file,
|
|
|
|
:wmap_unique_query,
|
|
|
|
:wmap_query,
|
|
|
|
:wmap_generic
|
|
|
|
]
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
if not self.wmapmodules
|
|
|
|
load_wmap_modules(true)
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
wmaptype.each do |modt|
|
|
|
|
|
|
|
|
tbl = Rex::Ui::Text::Table.new(
|
|
|
|
'Indent' => indent.length,
|
|
|
|
'Header' => modt.to_s,
|
|
|
|
'Columns' =>
|
|
|
|
[
|
|
|
|
'Name',
|
|
|
|
'OrderID',
|
|
|
|
])
|
2013-03-07 19:40:50 +00:00
|
|
|
|
|
|
|
idx = 0
|
2012-02-03 21:43:21 +00:00
|
|
|
self.wmapmodules.each do |w|
|
|
|
|
oid = w[3]
|
|
|
|
if w[3] == 0xFFFFFF
|
|
|
|
oid = ":last"
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
|
|
|
if w[2] == modt
|
2012-02-03 21:43:21 +00:00
|
|
|
tbl << [w[0],oid]
|
|
|
|
idx += 1
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
end
|
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
print_status tbl.to_s + "\n"
|
|
|
|
end
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
# Yes sorting hashes dont make sense but actually it does when you are enumerating one. And
|
|
|
|
# sort_by of a hash returns an array so this is the reason for this ugly piece of code
|
|
|
|
def sort_by_orderid(m)
|
2013-03-07 19:40:50 +00:00
|
|
|
temphash=Hash.new()
|
2012-02-03 21:43:21 +00:00
|
|
|
temparr=[]
|
2013-03-07 19:40:50 +00:00
|
|
|
|
|
|
|
temparr = m.sort_by do |xref,v|
|
|
|
|
xref[3]
|
2012-02-03 21:43:21 +00:00
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
temparr.each do |b|
|
2013-03-07 19:40:50 +00:00
|
|
|
temphash[b[0]] = b[1]
|
2012-02-03 21:43:21 +00:00
|
|
|
end
|
|
|
|
temphash
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
# Load all wmap modules
|
|
|
|
def load_wmap_modules(reload)
|
|
|
|
if reload or not self.wmapmodules
|
|
|
|
print_status("Loading wmap modules...")
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
self.wmapmodules=[]
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
idx = 0
|
|
|
|
[ [ framework.auxiliary, 'auxiliary' ], [framework.exploits, 'exploit' ] ].each do |mtype|
|
|
|
|
# Scan all exploit modules for matching references
|
|
|
|
mtype[0].each_module do |n,m|
|
|
|
|
e = m.new
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
# Only include wmap_enabled plugins
|
|
|
|
if e.respond_to?("wmap_enabled")
|
|
|
|
penabled = e.wmap_enabled
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
if penabled
|
|
|
|
self.wmapmodules << [mtype[1]+'/'+n,mtype[1],e.wmap_type,e.orderid]
|
|
|
|
idx += 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
print_status("#{idx} wmap enabled modules loaded.")
|
2013-03-07 19:40:50 +00:00
|
|
|
end
|
2012-02-03 21:43:21 +00:00
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-21 04:59:26 +00:00
|
|
|
def view_vulns
|
|
|
|
framework.db.hosts.each do |host|
|
2013-03-07 19:40:50 +00:00
|
|
|
host.services.each do |serv|
|
2012-02-21 04:59:26 +00:00
|
|
|
serv.web_sites.each do |site|
|
|
|
|
site.web_vulns.each do |wv|
|
|
|
|
print_status("+ [#{host.address}] (#{site.vhost}): #{wv.category} #{wv.path}")
|
|
|
|
print_status("\t#{wv.name} #{wv.description}")
|
|
|
|
print_status("\t#{wv.method} #{wv.proof}")
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
end
|
2012-02-21 04:59:26 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-02-04 05:57:26 +00:00
|
|
|
end
|
2010-06-06 03:53:07 +00:00
|
|
|
|
2011-02-04 05:57:26 +00:00
|
|
|
class WebTarget < ::Hash
|
|
|
|
def to_url
|
|
|
|
proto = self[:ssl] ? "https" : "http"
|
|
|
|
"#{proto}://#{self[:host]}:#{self[:port]}#{self[:path]}"
|
2010-06-06 03:53:07 +00:00
|
|
|
end
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2010-06-06 03:53:07 +00:00
|
|
|
def initialize(framework, opts)
|
|
|
|
super
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2012-03-15 17:27:01 +00:00
|
|
|
color = self.opts["ConsoleDriver"].output.supports_color? rescue false
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-18 02:56:55 +00:00
|
|
|
wmapversion = '1.5.1'
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-18 02:56:55 +00:00
|
|
|
wmapbanner = "%red\n.-.-.-..-.-.-..---..---.%clr\n"
|
|
|
|
wmapbanner += "%red| | | || | | || | || |-'%clr\n"
|
2013-03-07 19:40:50 +00:00
|
|
|
wmapbanner += "%red`-----'`-'-'-'`-^-'`-'%clr\n"
|
2012-02-03 21:43:21 +00:00
|
|
|
wmapbanner += "[WMAP #{wmapversion}] === et [ ] metasploit.com 2012\n"
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
if not @stdio
|
|
|
|
@stdio = Rex::Ui::Text::Output::Stdio.new
|
|
|
|
end
|
|
|
|
|
|
|
|
if color == true
|
|
|
|
@stdio.auto_color
|
|
|
|
else
|
|
|
|
@stdio.disable_color
|
|
|
|
end
|
2013-03-07 19:40:50 +00:00
|
|
|
|
2012-02-03 21:43:21 +00:00
|
|
|
@stdio.print_raw(@stdio.substitute_colors(wmapbanner))
|
2011-02-04 05:57:26 +00:00
|
|
|
|
2010-06-06 03:53:07 +00:00
|
|
|
add_console_dispatcher(WmapCommandDispatcher)
|
2012-02-03 21:43:21 +00:00
|
|
|
#print_status("#{wmapbanner}")
|
2010-06-06 03:53:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def cleanup
|
2012-02-03 21:43:21 +00:00
|
|
|
remove_console_dispatcher('wmap')
|
2010-06-06 03:53:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def name
|
|
|
|
"wmap"
|
|
|
|
end
|
|
|
|
|
|
|
|
def desc
|
|
|
|
"Web assessment plugin"
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
end
|
2011-02-04 05:57:26 +00:00
|
|
|
|
2010-06-06 03:53:07 +00:00
|
|
|
end
|