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'
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
def report_service(opts)

View File

@ -19,4 +19,4 @@ module ServiceDataService
def delete_service(opts)
raise 'ServiceDataService#delete_service is not implemented'
end
end
end

View File

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

View File

@ -132,11 +132,8 @@ module Msf::DBManager::Note
if addr and not host
host = get_host(:workspace => wspace, :host => addr)
end
if host and 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},
:port => opts[:port]).first
if host and (opts[:port] and proto)
service = get_service(wspace, host, proto, opts[:port])
elsif opts[:service] and opts[:service].kind_of? ::Mdm::Service
service = opts[:service]
end

View File

@ -33,6 +33,14 @@ 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

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

View File

@ -689,10 +689,7 @@ module Exploit::Remote::HttpClient
wspace = datastore['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.services(:workspace => wspace,
:hosts => {address: rhost},
:port => rport).first
service = framework.db.get_service(wspace, rhost, 'tcp', rport)
return fprints unless service
# 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)
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

@ -287,10 +287,7 @@ module Rex
end
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.services(:workspace => @args[:workspace],
:hosts => {address: address},
:port => port).first
db.get_service(@args[:workspace],address,"tcp",port)
end
def resolve_port(uri)

View File

@ -3,9 +3,10 @@ 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