Last active
October 24, 2020 12:24
-
-
Save JaciBrunning/5d6df78bbeed7cf947124160ceab4868 to your computer and use it in GitHub Desktop.
Metasploit Plugin for Filtering Hosts with nil services
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
# Filter hosts with nil services in msfconsole. | |
# Install by putting in `~/.msf4/plugins` and running `load filter_hosts.rb` | |
# Author: Jaci Brunning <[email protected]> | |
module Msf | |
class Plugin::FilterHosts < Msf::Plugin | |
def initialize(framework, opts) | |
super | |
add_console_dispatcher(FilterHostsCommandDispatcher) | |
end | |
def cleanup | |
remove_console_dispatcher("Filter Hosts") | |
end | |
def name | |
"Filter Hosts" | |
end | |
def desc | |
"Filter Hosts utils, clearing hosts with nil services" | |
end | |
class FilterHostsCommandDispatcher | |
include Msf::Ui::Console::CommandDispatcher | |
def name | |
"Filter Hosts" | |
end | |
def commands | |
{ | |
"hosts_filter" => "Filter hosts, deleting those with no sessions" | |
} | |
end | |
def cmd_hosts_filter | |
nil_service_hosts = Mdm::Host.where(service_count: 0) | |
print_status "Nil service hosts: #{nil_service_hosts.all.map(&:address).join(' ')}" | |
if nil_service_hosts.empty? | |
print_warning "No nil service hosts to delete!" | |
else | |
print_status "Delete these host? [y/n]" | |
usr_input = shell.input.gets | |
if usr_input.strip.downcase.start_with?("y") | |
destroyed = nil_service_hosts.destroy_all | |
print_good "Deleted #{destroyed.count} host(s)!" | |
else | |
print_status "Not deleting (user requested)" | |
end | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment