Enable GET for /endpoint/ID for each model
parent
026ddad9d8
commit
4da27d2bff
|
@ -2,8 +2,14 @@ module Msf::DBManager::Cred
|
||||||
# This methods returns a list of all credentials in the database
|
# This methods returns a list of all credentials in the database
|
||||||
def creds(opts)
|
def creds(opts)
|
||||||
query = nil
|
query = nil
|
||||||
wspace = Msf::Util::DBManager.process_opts_workspace(opts, framework)
|
|
||||||
::ActiveRecord::Base.connection_pool.with_connection {
|
::ActiveRecord::Base.connection_pool.with_connection {
|
||||||
|
# If we have the ID, there is no point in creating a complex query.
|
||||||
|
if opts[:id] && !opts[:id].empty?
|
||||||
|
return Array.wrap(Metasploit::Credential::Core.find(opts[:id]))
|
||||||
|
end
|
||||||
|
|
||||||
|
wspace = Msf::Util::DBManager.process_opts_workspace(opts, framework)
|
||||||
|
|
||||||
query = Metasploit::Credential::Core.where( workspace_id: wspace.id )
|
query = Metasploit::Credential::Core.where( workspace_id: wspace.id )
|
||||||
query = query.includes(:private, :public, :logins).references(:private, :public, :logins)
|
query = query.includes(:private, :public, :logins).references(:private, :public, :logins)
|
||||||
query = query.includes(logins: [ :service, { service: :host } ])
|
query = query.includes(logins: [ :service, { service: :host } ])
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
module Msf::DBManager::Event
|
module Msf::DBManager::Event
|
||||||
def events(wspace=workspace)
|
def events(wspace=workspace)
|
||||||
::ActiveRecord::Base.connection_pool.with_connection {
|
::ActiveRecord::Base.connection_pool.with_connection {
|
||||||
|
# If we have the ID, there is no point in creating a complex query.
|
||||||
|
if opts[:id] && !opts[:id].empty?
|
||||||
|
return Array.wrap(Mdm::Event.find(opts[:id]))
|
||||||
|
end
|
||||||
|
|
||||||
wspace.events.find :all, :order => 'created_at ASC'
|
wspace.events.find :all, :order => 'created_at ASC'
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -128,12 +128,16 @@ module Msf::DBManager::Host
|
||||||
# Returns a list of all hosts in the database
|
# Returns a list of all hosts in the database
|
||||||
def hosts(opts)
|
def hosts(opts)
|
||||||
::ActiveRecord::Base.connection_pool.with_connection {
|
::ActiveRecord::Base.connection_pool.with_connection {
|
||||||
|
# If we have the ID, there is no point in creating a complex query.
|
||||||
|
if opts[:id] && !opts[:id].empty?
|
||||||
|
return Array.wrap(Mdm::Host.find(opts[:id]))
|
||||||
|
end
|
||||||
|
|
||||||
wspace = Msf::Util::DBManager.process_opts_workspace(opts, framework)
|
wspace = Msf::Util::DBManager.process_opts_workspace(opts, framework)
|
||||||
|
|
||||||
conditions = {}
|
conditions = {}
|
||||||
conditions[:state] = [Msf::HostState::Alive, Msf::HostState::Unknown] if opts[:non_dead]
|
conditions[:state] = [Msf::HostState::Alive, Msf::HostState::Unknown] if opts[:non_dead]
|
||||||
conditions[:address] = opts[:address] if opts[:address] && !opts[:address].empty?
|
conditions[:address] = opts[:address] if opts[:address] && !opts[:address].empty?
|
||||||
conditions[:id] = opts[:id] if opts[:id] && !opts[:id].empty?
|
|
||||||
|
|
||||||
if opts[:search_term] && !opts[:search_term].empty?
|
if opts[:search_term] && !opts[:search_term].empty?
|
||||||
column_search_conditions = Msf::Util::DBManager.create_all_column_search_conditions(Mdm::Host, opts[:search_term])
|
column_search_conditions = Msf::Util::DBManager.create_all_column_search_conditions(Mdm::Host, opts[:search_term])
|
||||||
|
|
|
@ -9,7 +9,7 @@ module LootServlet
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.registered(app)
|
def self.registered(app)
|
||||||
app.get LootServlet.api_path, &get_loot
|
app.get LootServlet.api_path_with_id, &get_loot
|
||||||
app.post LootServlet.api_path, &report_loot
|
app.post LootServlet.api_path, &report_loot
|
||||||
app.put LootServlet.api_path_with_id, &update_loot
|
app.put LootServlet.api_path_with_id, &update_loot
|
||||||
app.delete LootServlet.api_path, &delete_loot
|
app.delete LootServlet.api_path, &delete_loot
|
||||||
|
|
|
@ -9,7 +9,7 @@ module ServiceServlet
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.registered(app)
|
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.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
|
||||||
|
|
|
@ -4,8 +4,12 @@ module SessionEventServlet
|
||||||
'/api/v1/session-events'
|
'/api/v1/session-events'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.api_path_with_id
|
||||||
|
"#{SessionEventServlet.api_path}/?:id?"
|
||||||
|
end
|
||||||
|
|
||||||
def self.registered(app)
|
def self.registered(app)
|
||||||
app.get SessionEventServlet.api_path, &get_session_event
|
app.get SessionEventServlet.api_path_with_id, &get_session_event
|
||||||
app.post SessionEventServlet.api_path, &report_session_event
|
app.post SessionEventServlet.api_path, &report_session_event
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,11 @@ module Msf::DBManager::Loot
|
||||||
search_term = opts.delete(:search_term)
|
search_term = opts.delete(:search_term)
|
||||||
|
|
||||||
::ActiveRecord::Base.connection_pool.with_connection {
|
::ActiveRecord::Base.connection_pool.with_connection {
|
||||||
|
# If we have the ID, there is no point in creating a complex query.
|
||||||
|
if opts[:id] && !opts[:id].empty?
|
||||||
|
return Array.wrap(Mdm::Loot.find(opts[:id]))
|
||||||
|
end
|
||||||
|
|
||||||
wspace = Msf::Util::DBManager.process_opts_workspace(opts, framework)
|
wspace = Msf::Util::DBManager.process_opts_workspace(opts, framework)
|
||||||
opts[:workspace_id] = wspace.id
|
opts[:workspace_id] = wspace.id
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,11 @@ module Msf::DBManager::Note
|
||||||
#
|
#
|
||||||
def notes(opts)
|
def notes(opts)
|
||||||
::ActiveRecord::Base.connection_pool.with_connection {
|
::ActiveRecord::Base.connection_pool.with_connection {
|
||||||
|
# If we have the ID, there is no point in creating a complex query.
|
||||||
|
if opts[:id] && !opts[:id].empty?
|
||||||
|
return Array.wrap(Mdm::Note.find(opts[:id]))
|
||||||
|
end
|
||||||
|
|
||||||
wspace = Msf::Util::DBManager.process_opts_workspace(opts, framework)
|
wspace = Msf::Util::DBManager.process_opts_workspace(opts, framework)
|
||||||
|
|
||||||
data = opts.delete(:data)
|
data = opts.delete(:data)
|
||||||
|
|
|
@ -143,14 +143,19 @@ module Msf::DBManager::Service
|
||||||
|
|
||||||
# Returns a list of all services in the database
|
# Returns a list of all services in the database
|
||||||
def services(opts)
|
def services(opts)
|
||||||
wspace = Msf::Util::DBManager.process_opts_workspace(opts, framework)
|
|
||||||
|
|
||||||
search_term = opts.delete(:search_term)
|
search_term = opts.delete(:search_term)
|
||||||
|
|
||||||
order_args = [:port]
|
order_args = [:port]
|
||||||
order_args.unshift(Mdm::Host.arel_table[:address]) if opts.key?(:hosts)
|
order_args.unshift(Mdm::Host.arel_table[:address]) if opts.key?(:hosts)
|
||||||
|
|
||||||
::ActiveRecord::Base.connection_pool.with_connection {
|
::ActiveRecord::Base.connection_pool.with_connection {
|
||||||
|
# If we have the ID, there is no point in creating a complex query.
|
||||||
|
if opts[:id] && !opts[:id].empty?
|
||||||
|
return Array.wrap(Mdm::Service.find(opts[:id]))
|
||||||
|
end
|
||||||
|
|
||||||
|
wspace = Msf::Util::DBManager.process_opts_workspace(opts, framework)
|
||||||
|
|
||||||
if search_term && !search_term.empty?
|
if search_term && !search_term.empty?
|
||||||
column_search_conditions = Msf::Util::DBManager.create_all_column_search_conditions(Mdm::Service, search_term)
|
column_search_conditions = Msf::Util::DBManager.create_all_column_search_conditions(Mdm::Service, search_term)
|
||||||
wspace.services.includes(:host).where(opts).where(column_search_conditions).order(*order_args)
|
wspace.services.includes(:host).where(opts).where(column_search_conditions).order(*order_args)
|
||||||
|
|
|
@ -8,6 +8,11 @@ module Msf::DBManager::Session
|
||||||
return if not active
|
return if not active
|
||||||
|
|
||||||
::ActiveRecord::Base.connection_pool.with_connection {
|
::ActiveRecord::Base.connection_pool.with_connection {
|
||||||
|
# If we have the ID, there is no point in creating a complex query.
|
||||||
|
if opts[:id] && !opts[:id].empty?
|
||||||
|
return Array.wrap(Mdm::Session.find(opts[:id]))
|
||||||
|
end
|
||||||
|
|
||||||
wspace = Msf::Util::DBManager.process_opts_workspace(opts, framework)
|
wspace = Msf::Util::DBManager.process_opts_workspace(opts, framework)
|
||||||
|
|
||||||
search_term = opts.delete(:search_term)
|
search_term = opts.delete(:search_term)
|
||||||
|
|
|
@ -2,6 +2,10 @@ module Msf::DBManager::SessionEvent
|
||||||
|
|
||||||
def session_events(opts)
|
def session_events(opts)
|
||||||
::ActiveRecord::Base.connection_pool.with_connection {
|
::ActiveRecord::Base.connection_pool.with_connection {
|
||||||
|
# If we have the ID, there is no point in creating a complex query.
|
||||||
|
if opts[:id] && !opts[:id].empty?
|
||||||
|
return Array.wrap(Mdm::SessionEvent.find(opts[:id]))
|
||||||
|
end
|
||||||
conditions = {}
|
conditions = {}
|
||||||
|
|
||||||
Mdm::SessionEvent.all
|
Mdm::SessionEvent.all
|
||||||
|
|
|
@ -236,6 +236,11 @@ module Msf::DBManager::Vuln
|
||||||
#
|
#
|
||||||
def vulns(opts)
|
def vulns(opts)
|
||||||
::ActiveRecord::Base.connection_pool.with_connection {
|
::ActiveRecord::Base.connection_pool.with_connection {
|
||||||
|
# If we have the ID, there is no point in creating a complex query.
|
||||||
|
if opts[:id] && !opts[:id].empty?
|
||||||
|
return Array.wrap(Mdm::Vuln.find(opts[:id]))
|
||||||
|
end
|
||||||
|
|
||||||
wspace = Msf::Util::DBManager.process_opts_workspace(opts, framework)
|
wspace = Msf::Util::DBManager.process_opts_workspace(opts, framework)
|
||||||
|
|
||||||
search_term = opts.delete(:search_term)
|
search_term = opts.delete(:search_term)
|
||||||
|
|
|
@ -23,6 +23,11 @@ module Msf::DBManager::VulnAttempt
|
||||||
#
|
#
|
||||||
def vuln_attempts(opts)
|
def vuln_attempts(opts)
|
||||||
::ActiveRecord::Base.connection_pool.with_connection {
|
::ActiveRecord::Base.connection_pool.with_connection {
|
||||||
|
# If we have the ID, there is no point in creating a complex query.
|
||||||
|
if opts[:id] && !opts[:id].empty?
|
||||||
|
return Array.wrap(Mdm::VulnAttempt.find(opts[:id]))
|
||||||
|
end
|
||||||
|
|
||||||
# 'workspace' is not a valid attribute for Mdm::VulnAttempt. Remove it.
|
# 'workspace' is not a valid attribute for Mdm::VulnAttempt. Remove it.
|
||||||
Msf::Util::DBManager.delete_opts_workspace(opts)
|
Msf::Util::DBManager.delete_opts_workspace(opts)
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,11 @@ module Msf::DBManager::Workspace
|
||||||
|
|
||||||
def workspaces(opts = {})
|
def workspaces(opts = {})
|
||||||
::ActiveRecord::Base.connection_pool.with_connection {
|
::ActiveRecord::Base.connection_pool.with_connection {
|
||||||
|
# If we have the ID, there is no point in creating a complex query.
|
||||||
|
if opts[:id] && !opts[:id].empty?
|
||||||
|
return Array.wrap(Mdm::Workspace.find(opts[:id]))
|
||||||
|
end
|
||||||
|
|
||||||
search_term = opts.delete(:search_term)
|
search_term = opts.delete(:search_term)
|
||||||
# Passing these values to the search will cause exceptions, so remove them if they accidentally got passed in.
|
# Passing these values to the search will cause exceptions, so remove them if they accidentally got passed in.
|
||||||
Msf::Util::DBManager.delete_opts_workspace(opts)
|
Msf::Util::DBManager.delete_opts_workspace(opts)
|
||||||
|
|
Loading…
Reference in New Issue