metasploit-framework/plugins/db_tracker.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

70 lines
1.7 KiB
Ruby
Raw Permalink Normal View History

module Msf
###
#
2023-01-30 09:25:46 +08:00
# This class hooks all socket calls and updates the database with
# data gathered from the connection parameters
#
###
2023-01-30 09:25:46 +08:00
class Plugin::DB_Tracer < Msf::Plugin
2023-01-30 09:25:46 +08:00
###
#
# This class implements a socket communication tracker
#
###
class DBTracerEventHandler
include Rex::Socket::Comm::Events
2023-01-30 09:25:46 +08:00
def on_before_socket_create(comm, param); end
2023-01-30 09:25:46 +08:00
def on_socket_created(_comm, sock, param)
# Ignore local listening sockets
return if !sock.peerhost
2023-01-30 10:05:34 +08:00
if ((sock.peerhost != '0.0.0.0') && sock.peerport)
2023-01-30 09:25:46 +08:00
# Ignore sockets that didn't set up their context
# to hold the framework in 'Msf'
return if !param.context['Msf']
host = param.context['Msf'].db.find_or_create_host(host: sock.peerhost, state: Msf::HostState::Alive)
return if !host
param.context['Msf'].db.report_service(host: host, proto: param.proto, port: sock.peerport)
end
end
end
2023-01-30 09:25:46 +08:00
def initialize(framework, opts)
super
2023-01-30 09:25:46 +08:00
if !framework.db.active
raise PluginLoadError, 'The database backend has not been initialized'
end
2023-01-30 09:25:46 +08:00
framework.plugins.each do |plugin|
if plugin.instance_of?(Msf::Plugin::DB_Tracer)
raise PluginLoadError, 'This plugin should not be loaded more than once'
end
end
2023-01-30 09:25:46 +08:00
@eh = DBTracerEventHandler.new
Rex::Socket::Comm::Local.register_event_handler(@eh)
end
2023-01-30 09:25:46 +08:00
def cleanup
Rex::Socket::Comm::Local.deregister_event_handler(@eh)
end
2023-01-30 09:25:46 +08:00
def name
'db_tracker'
end
2023-01-30 09:25:46 +08:00
def desc
'Monitors socket calls and updates the database backend'
end
end
end