diff --git a/lib/metasploit/framework/data_service/proxy/service_data_proxy.rb b/lib/metasploit/framework/data_service/proxy/service_data_proxy.rb index c2954e9a34..8d28969ffe 100644 --- a/lib/metasploit/framework/data_service/proxy/service_data_proxy.rb +++ b/lib/metasploit/framework/data_service/proxy/service_data_proxy.rb @@ -9,4 +9,19 @@ module ServiceDataProxy end end -end \ No newline at end of file + def services(wspace = workspace, only_up = false, proto = nil, addresses = nil, ports = nil, names = nil) + begin + data_service = self.get_data_service() + opts = {} + opts[:workspace] = wspace + opts[:only_up] = only_up + opts[:proto] = proto + opts[:address] = addresses + opts[:ports] = ports + opts[:names] = names + data_service.services(opts) + rescue Exception => e + elog "Problem retrieving services: #{e.message}" + end + end +end diff --git a/lib/metasploit/framework/data_service/remote/http/remote_service_data_service.rb b/lib/metasploit/framework/data_service/remote/http/remote_service_data_service.rb index 9c4889af8e..6a714a5a47 100644 --- a/lib/metasploit/framework/data_service/remote/http/remote_service_data_service.rb +++ b/lib/metasploit/framework/data_service/remote/http/remote_service_data_service.rb @@ -1,7 +1,12 @@ module RemoteServiceDataService - SERVICE_API_PATH = '/api/v1/services' + SERVICE_API_PATH = '/api/v1/services' + SERVICE_MDM_CLASS = 'Mdm::Service' def report_service(opts) self.post_data_async(SERVICE_API_PATH, opts) end -end \ No newline at end of file + + def services(opts) + json_to_mdm_object(self.get_data(SERVICE_API_PATH, nil, opts), SERVICE_MDM_CLASS, []) + end +end diff --git a/lib/msf/core/db_manager/http/servlet/service_servlet.rb b/lib/msf/core/db_manager/http/servlet/service_servlet.rb index 569a118fc3..88abbad414 100644 --- a/lib/msf/core/db_manager/http/servlet/service_servlet.rb +++ b/lib/msf/core/db_manager/http/servlet/service_servlet.rb @@ -5,6 +5,7 @@ module ServiceServlet end def self.registered(app) + app.get ServiceServlet.api_path, &get_services app.post ServiceServlet.api_path, &report_service end @@ -12,11 +13,16 @@ module ServiceServlet private ####### - def self.get_host + def self.get_services lambda { begin opts = parse_json_request(request, false) - data = get_db().hosts(opts) + data = get_db().services(opts[:workspace], + opts[:only_up], + opts[:proto], + opts[:address], + opts[:ports], + opts[:names]) set_json_response(data) rescue Exception => e set_error_on_response(e) @@ -30,4 +36,4 @@ module ServiceServlet exec_report_job(request, &job) } end -end \ No newline at end of file +end