Forked from SchellerCyberSecurity/analyze_load_ignore_discovery_login_creds.rb
Last active
November 16, 2017 19:43
-
-
Save gschneider-r7/1e1e547be80936fb14a36f92abbfbba9 to your computer and use it in GitHub Desktop.
Nexpose Analyze Enging Load w/o Discovery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'io/console' | |
require 'nexpose' | |
include Nexpose | |
def get_console(prompt="Console IP: ") | |
print prompt | |
gets.chomp | |
end | |
def get_username(prompt="User: ") | |
print prompt | |
gets.chomp | |
end | |
def get_password(prompt="Password: ") | |
print prompt | |
STDIN.noecho(&:gets).chomp | |
end | |
@console = get_console | |
@username = get_username | |
@password = get_password | |
nsc = Connection.new(@console, @username, @password) | |
nsc.login | |
at_exit { nsc.logout } | |
asset_count = {} | |
engine_load = {} | |
nsc.sites.each do |site| | |
config = Site.load(nsc, site.id) | |
next if config.scan_template_name =~ /discover/ | |
asset_count[site.id] = nsc.list_site_devices(site.id).count | |
last_scan = nsc.last_scan(site.id) | |
next if last_scan.nil? | |
engine_load[last_scan.engine_id] ||= 0 | |
engine_load[last_scan.engine_id] += asset_count[site.id] | |
end | |
total_assets = asset_count.values.reduce(0) { |acc, count| acc += count } | |
engines = nsc.engines | |
engine_load.each do |id, count| | |
engine = engines.find { |eng| eng.id == id } | |
if engine.nil? | |
puts "Could not find engine with ID #{id}" | |
next | |
end | |
percent = '%.2f' % (count.to_f / total_assets * 100) | |
puts "#{name} : #{count} (#{percent}%)" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment