Land #14171, Replace erroneous calls to get_service with calls to service

This commit is contained in:
Grant Willcox 2020-09-30 10:05:13 -05:00
commit 5986bc98f1
No known key found for this signature in database
GPG Key ID: D35E05C0F2B81E83
9 changed files with 27 additions and 19 deletions

View File

@ -3,8 +3,7 @@ module RemoteServiceDataService
SERVICE_MDM_CLASS = 'Mdm::Service'
def services(opts)
path = get_path_select(opts, SERVICE_API_PATH)
json_to_mdm_object(self.get_data(path, nil, opts), SERVICE_MDM_CLASS)
json_to_mdm_object(self.get_data(SERVICE_API_PATH, nil, opts), SERVICE_MDM_CLASS)
end
def report_service(opts)

View File

@ -38,12 +38,16 @@ module Msf::DBManager::ExploitAttempt
wspace = Msf::Util::DBManager.process_opts_workspace(opts, framework)
port = opts[:port]
prot = opts[:proto] || Msf::DBManager::DEFAULT_SERVICE_PROTO
proto = opts[:proto] || Msf::DBManager::DEFAULT_SERVICE_PROTO
svc = opts[:service]
# Look up the service as appropriate
if port and svc.nil?
svc = get_service(wspace, host, prot, port)
# only one result can be returned, as the +port+ field restricts potential results to a single service
svc = services(:workspace => wspace,
:hosts => {address: host},
:proto => proto,
:port => port).first
end
# Look up the host as appropriate

View File

@ -133,7 +133,11 @@ module Msf::DBManager::Note
host = get_host(:workspace => wspace, :host => addr)
end
if host and (opts[:port] and proto)
service = get_service(wspace, host, proto, opts[:port])
# only one result can be returned, as the +port+ field restricts potential results to a single service
service = services(:workspace => wspace,
:hosts => {address: host},
:proto => proto,
:port => opts[:port]).first
elsif opts[:service] and opts[:service].kind_of? ::Mdm::Service
service = opts[:service]
end

View File

@ -33,14 +33,6 @@ module Msf::DBManager::Service
report_service(opts)
end
def get_service(wspace, host, proto, port)
::ApplicationRecord.connection_pool.with_connection {
host = get_host(:workspace => wspace, :address => host)
return if !host
return host.services.find_by_proto_and_port(proto, port)
}
end
#
# Record a service in the database.
#

View File

@ -689,7 +689,11 @@ module Exploit::Remote::HttpClient
wspace = datastore['WORKSPACE'] ?
framework.db.find_workspace(datastore['WORKSPACE']) : framework.db.workspace
service = framework.db.get_service(wspace, rhost, 'tcp', rport)
# only one result can be returned, as the +port+ field restricts potential results to a single service
service = framework.db.services(:workspace => wspace,
:hosts => {address: rhost},
:proto => 'tcp',
:port => rport).first
return fprints unless service
# Order by note_id descending so the first value is the most recent

View File

@ -10,7 +10,6 @@ module ServiceServlet
def self.registered(app)
app.get ServiceServlet.api_path, &get_services
app.get ServiceServlet.api_path_with_id, &get_services
app.post ServiceServlet.api_path, &report_service
app.put ServiceServlet.api_path_with_id, &update_service
app.delete ServiceServlet.api_path, &delete_service

View File

@ -509,7 +509,10 @@ module Rex
address = resolve_address(host)
return unless address
# If we didn't create the service, we don't care about the site
service_object = db.get_service @args[:workspace], address, "tcp", port
service_object = db.services(:workspace => @args[:workspace],
:hosts => {address: address},
:proto => 'tcp',
:port => port).first
return unless service_object
web_site_info = {
:workspace => @args[:workspace],

View File

@ -287,7 +287,11 @@ module Rex
end
def check_for_existing_service(address,port)
db.get_service(@args[:workspace],address,"tcp",port)
# only one result can be returned, as the +port+ field restricts potential results to a single service
db.services(:workspace => @args[:workspace],
:hosts => {address: address},
:proto => 'tcp',
:port => port).first
end
def resolve_port(uri)

View File

@ -3,10 +3,9 @@ RSpec.shared_examples_for 'Msf::DBManager::Service' do
unless ENV['REMOTE_DB']
it { is_expected.to respond_to :delete_service }
it { is_expected.to respond_to :each_service }
it { is_expected.to respond_to :get_service }
end
it { is_expected.to respond_to :find_or_create_service }
it { is_expected.to respond_to :services }
it { is_expected.to respond_to :report_service }
end
end