Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
h00die committed Sep 20, 2023
1 parent e8d73c1 commit 2d1c443
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 20 deletions.
55 changes: 37 additions & 18 deletions lib/msf/ui/console/command_dispatcher/db.rb
Original file line number Diff line number Diff line change
Expand Up @@ -784,42 +784,61 @@ def cmd_db_stats(*args)
}
}
)

total_hosts = 0
total_services = 0
total_vulns = 0
total_notes = 0
total_creds = 0
total_tickets = 0

ordered_workspaces.map do |workspace|
total_creds += framework.db.creds(workspace: workspace.name).count
total_tickets += ticket_search([],nil, workspace).count

hosts = workspace.hosts.count
services = workspace.services.count
vulns = workspace.vulns.count
notes = workspace.notes.count
creds = framework.db.creds(workspace: workspace.name).count # workspace.creds.count.to_fs(:delimited) is always 0 for whatever reason
kerbs = ticket_search([nil], nil, :workspace => workspace).count

total_hosts += hosts
total_services += services
total_vulns += vulns
total_notes += notes
total_creds += creds
total_tickets += kerbs

tbl << [
current_workspace.id == workspace.id,
workspace.id,
workspace.name,
workspace.hosts.count.to_fs(:delimited),
workspace.services.count.to_fs(:delimited),
workspace.hosts.count > 0 ? (workspace.services.count.to_f / workspace.hosts.count).truncate(2) : 0,
workspace.vulns.count.to_fs(:delimited),
workspace.hosts.count > 0 ? (workspace.vulns.count.to_f / workspace.hosts.count).truncate(2) : 0,
workspace.notes.count.to_fs(:delimited),
framework.db.creds(workspace: workspace.name).count.to_fs(:delimited), # workspace.creds.count.to_fs(:delimited) is always 0 for whatever reason
ticket_search([],nil, workspace).count.to_fs(:delimited)
hosts.to_fs(:delimited),
services.to_fs(:delimited),
hosts > 0 ? (services.to_f / hosts).truncate(2) : 0,
vulns.to_fs(:delimited),
hosts > 0 ? (vulns.to_f / hosts).truncate(2) : 0,
notes.to_fs(:delimited),
creds.to_fs(:delimited),
kerbs.to_fs(:delimited)
]
end

# total row
tbl << [
"",
"Total",
::Mdm::Workspace.count.to_fs(:delimited),
::Mdm::Host.count.to_fs(:delimited),
::Mdm::Service.count.to_fs(:delimited),
::Mdm::Host.count> 0 ? (::Mdm::Service.count.to_f / ::Mdm::Host.count).truncate(2) : 0,
::Mdm::Vuln.count.to_fs(:delimited),
::Mdm::Host.count > 0 ? (::Mdm::Vuln.count.to_f / ::Mdm::Host.count).truncate(2) : 0,
::Mdm::Note.count.to_fs(:delimited),
ordered_workspaces.length.to_fs(:delimited),
total_hosts.to_fs(:delimited),
total_services.to_fs(:delimited),
total_hosts > 0 ? (total_services.to_f / total_hosts).truncate(2) : 0,
total_vulns,
total_hosts > 0 ? (total_vulns.to_f / total_hosts).truncate(2) : 0,
total_notes,
total_creds.to_fs(:delimited),
total_tickets.to_fs(:delimited)
]

puts tbl.to_s
print_line tbl.to_s
end

def cmd_services(*args)
Expand Down
4 changes: 2 additions & 2 deletions lib/msf/ui/console/command_dispatcher/db/klist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,9 @@ def set_activation_status(mode, tickets)
# @param [Array<Rex::Socket::RangeWalker>] host_ranges Search for tickets associated with these hosts
# @param [Array<Integer>, nil] id_search List of ticket IDs to search for
# @param [Workspace] workspace to search against
# @option [Symbol] :workspace The framework.db.workspace to search against (optional)
# @return [Array<Msf::Exploit::Remote::Kerberos::Ticket::Storage::StoredTicket>]
def ticket_search(host_ranges, id_search, workspace = framework.db.workspace)
def ticket_search(host_ranges, id_search, workspace: framework.db.workspace)
ticket_results = []

# Iterating over each id here since the remote db doesn't support bulk id searches
Expand All @@ -191,7 +192,6 @@ def ticket_search(host_ranges, id_search, workspace = framework.db.workspace)
else
each_host_range_chunk(host_ranges) do |host_search|
next if host_search&.empty?

ticket_results += kerberos_ticket_storage.tickets(
workspace: workspace,
host: host_search
Expand Down

0 comments on commit 2d1c443

Please sign in to comment.