Land #9857, Restore services search semantics

GSoC/Meterpreter_Web_Console
Brent Cook 2018-04-10 17:25:48 -05:00
commit 41a21def80
No known key found for this signature in database
GPG Key ID: 1FFAA0B24B708F96
3 changed files with 9 additions and 5 deletions

View File

@ -141,7 +141,10 @@ module Msf::DBManager::Service
# Returns a list of all services in the database # Returns a list of all services in the database
def services(opts) def services(opts)
opts.delete(:workspace) # Mdm::Service apparently doesn't have an upstream Mdm::Workspace association wspace = opts.delete(:workspace) || workspace
if wspace.kind_of? String
wspace = find_workspace(wspace)
end
search_term = opts.delete(:search_term) search_term = opts.delete(:search_term)
opts["hosts.address"] = opts.delete(:addresses) opts["hosts.address"] = opts.delete(:addresses)
opts.compact! opts.compact!
@ -149,9 +152,9 @@ module Msf::DBManager::Service
::ActiveRecord::Base.connection_pool.with_connection { ::ActiveRecord::Base.connection_pool.with_connection {
if search_term && !search_term.empty? if search_term && !search_term.empty?
column_search_conditions = Msf::Util::DBManager.create_all_column_search_conditions(Mdm::Service, search_term) column_search_conditions = Msf::Util::DBManager.create_all_column_search_conditions(Mdm::Service, search_term)
Mdm::Service.includes(:host).where(opts).where(column_search_conditions).order("hosts.address, port") wspace.services.includes(:host).where(opts).where(column_search_conditions).order("hosts.address, port")
else else
Mdm::Service.includes(:host).where(opts).order("hosts.address, port") wspace.services.includes(:host).where(opts).order("hosts.address, port")
end end
} }
end end

View File

@ -649,7 +649,7 @@ class Db
print_line " -c <col1,col2> Only show the given columns" print_line " -c <col1,col2> Only show the given columns"
print_line " -h,--help Show this help information" print_line " -h,--help Show this help information"
print_line " -s <name> Name of the service to add" print_line " -s <name> Name of the service to add"
print_line " -p <port> Port number of the service being added" print_line " -p <port> Search for a list of ports"
print_line " -r <protocol> Protocol type of the service being added [tcp|udp]" print_line " -r <protocol> Protocol type of the service being added [tcp|udp]"
print_line " -u,--up Only show services which are up" print_line " -u,--up Only show services which are up"
print_line " -o <file> Send output to a file in csv format" print_line " -o <file> Send output to a file in csv format"
@ -717,6 +717,7 @@ class Db
each_host_range_chunk(host_ranges) do |host_search| each_host_range_chunk(host_ranges) do |host_search|
break if !host_search.nil? && host_search.empty? break if !host_search.nil? && host_search.empty?
opts[:addresses] = host_search opts[:addresses] = host_search
opts[:port] = ports if ports
framework.db.services(framework.db.workspace, opts).each do |service| framework.db.services(framework.db.workspace, opts).each do |service|
host = service.host host = service.host

View File

@ -201,7 +201,7 @@ RSpec.describe Msf::Ui::Console::CommandDispatcher::Db do
" -c <col1,col2> Only show the given columns", " -c <col1,col2> Only show the given columns",
" -h,--help Show this help information", " -h,--help Show this help information",
" -s <name> Name of the service to add", " -s <name> Name of the service to add",
" -p <port> Port number of the service being added", " -p <port> Search for a list of ports",
" -r <protocol> Protocol type of the service being added [tcp|udp]", " -r <protocol> Protocol type of the service being added [tcp|udp]",
" -u,--up Only show services which are up", " -u,--up Only show services which are up",
" -o <file> Send output to a file in csv format", " -o <file> Send output to a file in csv format",