Revert "Replaces erroneous calls to get_service"

This commit is contained in:
adfoster-r7 2020-09-18 19:09:25 +01:00 committed by GitHub
parent 93290e1fa6
commit 9ef5822d3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 23 additions and 20 deletions

View File

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

View File

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

View File

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

View File

@ -33,6 +33,14 @@ module Msf::DBManager::Service
report_service(opts) report_service(opts)
end 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. # Record a service in the database.
# #

View File

@ -1562,6 +1562,9 @@ class Exploit < Msf::Module
if self.datastore['RPORT'] and self.options['RPORT'] if self.datastore['RPORT'] and self.options['RPORT']
info[:port] = self.datastore['RPORT'] info[:port] = self.datastore['RPORT']
if self.class.ancestors.include?(Msf::Exploit::Remote::Tcp)
info[:proto] = 'tcp'
end
end end
framework.db.report_exploit_failure(info) framework.db.report_exploit_failure(info)

View File

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

View File

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

View File

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

View File

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