Repository navigation
Expand file tree
/
Copy pathstats.rb
More file actions
89 lines (73 loc) · 2.38 KB
/
Copy pathstats.rb
File metadata and controls
89 lines (73 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#
# $Id$
#
module Msf
class Plugin::Stats < Msf::Plugin
class ConsoleCommandDispatcher
include Msf::Ui::Console::CommandDispatcher
def name
"Stats"
end
def commands
{
"top_ports" => "Print top X ports by count (default top 10)",
"count_all" => "Print the number of hosts and services in the workspace",
"count_hosts" => "Print the number of hosts in the workspace",
"count_services" => "Print the number of services in the workspace",
}
end
# Print top X ports by count (default top 10)
def cmd_top_ports(num = 10)
print_line("Top #{num} open ports:")
print_line("Rank | Port | Count | Module?")
print_line("-------------------------------")
# Generate port list in descending order of frequency
services = self.framework.db.workspace.services.where(state: "open")
top = Hash.new(0)
services.each do |service|
top[service.port] += 1
end
top = top.sort_by {|k,v| v}.reverse
# Display table of results
i = 1
top.each do |port,count|
has_module = Msf::Modules::Metadata::Cache.instance.find(
{"port"=>[[port.to_s], []]}
).count > 0 ? "Yes" : "No"
#next if has_module == "No"
print_line("\##{i}".ljust(5, " ") + " | " + "#{port}".ljust(5, " ") + " | " + "#{count}".ljust(5, " ") + " | " + has_module)
break if i == num.to_i
i += 1
end
end # cmd_top_ports
def cmd_count_all
cmd_count_hosts()
cmd_count_services()
end
def cmd_count_hosts
hosts_all = self.framework.db.workspace.hosts
hosts_alive = self.framework.db.workspace.hosts.where(state: "alive")
print_line("#{hosts_all.length} total hosts (#{hosts_alive.length} alive)")
end
def cmd_count_services
services_all = self.framework.db.workspace.services
services_open = self.framework.db.workspace.services.where(state: "open")
print_line("#{services_all.length} total services (#{services_open.length} open)")
end
end # Class ConsoleCommandDispatcher
def initialize(framework, opts)
super
add_console_dispatcher(ConsoleCommandDispatcher)
end
def cleanup
remove_console_dispatcher('Stats')
end
def name
"stats"
end
def desc
"Provides commands for gathering various statistics about the current workspace."
end
protected
end
end