refactor out of db_manager and into web_services

GSoC/Meterpreter_Web_Console
Erin Bleiweiss 2018-07-24 15:25:23 -05:00
parent 2215cab7df
commit ffe4dbcc19
5 changed files with 14 additions and 9 deletions

View File

@ -44,7 +44,6 @@ class Msf::DBManager
autoload :IPAddress, 'msf/core/db_manager/ip_address'
autoload :Loot, 'msf/core/db_manager/loot'
autoload :Migration, 'msf/core/db_manager/migration'
autoload :Module, 'msf/core/db_manager/module'
autoload :ModuleCache, 'msf/core/db_manager/module_cache'
autoload :Note, 'msf/core/db_manager/note'
autoload :Ref, 'msf/core/db_manager/ref'
@ -82,7 +81,6 @@ class Msf::DBManager
include Msf::DBManager::IPAddress
include Msf::DBManager::Loot
include Msf::DBManager::Migration
include Msf::DBManager::Module
include Msf::DBManager::ModuleCache
include Msf::DBManager::Note
include Msf::DBManager::Ref

View File

@ -11,7 +11,6 @@ require 'msf/core/db_manager/http/servlet/note_servlet'
require 'msf/core/db_manager/http/servlet/vuln_servlet'
require 'msf/core/db_manager/http/servlet/event_servlet'
require 'msf/core/db_manager/http/servlet/web_servlet'
require 'msf/core/db_manager/http/servlet/module_servlet'
require 'msf/core/db_manager/http/servlet/msf_servlet'
require 'msf/core/db_manager/http/servlet/workspace_servlet'
require 'msf/core/db_manager/http/servlet/service_servlet'
@ -24,6 +23,7 @@ require 'msf/core/db_manager/http/servlet/nmap_servlet'
require 'msf/core/db_manager/http/servlet/db_export_servlet'
require 'msf/core/db_manager/http/servlet/vuln_attempt_servlet'
require 'msf/core/db_manager/http/servlet/user_servlet'
require 'msf/core/web_services/servlet/module_search_servlet'
class MetasploitApiApp < Sinatra::Base
helpers ServletHelper
@ -35,7 +35,6 @@ class MetasploitApiApp < Sinatra::Base
register VulnServlet
register EventServlet
register WebServlet
register ModuleServlet
register MsfServlet
register NoteServlet
register WorkspaceServlet
@ -49,6 +48,7 @@ class MetasploitApiApp < Sinatra::Base
register DbExportServlet
register VulnAttemptServlet
register UserServlet
register ModuleSearchServlet
configure do
set :sessions, {key: 'msf-ws.session', expire_after: 300}

View File

@ -0,0 +1,5 @@
class Msf::WebServices
autoload :ModuleSearch, 'msf/core/web_services/module_search'
extend Msf::WebServices::ModuleSearch
end

View File

@ -1,6 +1,6 @@
module Msf::DBManager::Module
module Msf::WebServices::ModuleSearch
def modules(opts)
def search_modules(opts)
raise ::ArgumentError, "At least one search parameter must be provided." if opts.dup.except!(:fields).empty?
search_results = []
metadata = Msf::Modules::Metadata::Cache.instance.get_metadata

View File

@ -1,11 +1,13 @@
module ModuleServlet
require 'msf/core/web_services'
module ModuleSearchServlet
def self.api_path
'/api/v1/modules'
end
def self.registered(app)
app.get ModuleServlet.api_path, &search_modules
app.get ModuleSearchServlet.api_path, &search_modules
end
#######
@ -17,7 +19,7 @@ module ModuleServlet
warden.authenticate!
begin
sanitized_params = sanitize_params(params)
data = get_db.modules(sanitized_params)
data = Msf::WebServices.search_modules(sanitized_params)
set_json_response(data)
rescue => e
set_error_on_response(e)