2006-04-03 06:33:34 +08:00
|
|
|
module Msf
|
2013-10-01 02:47:53 +08:00
|
|
|
###
|
|
|
|
#
|
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
|
2013-10-01 02:47:53 +08:00
|
|
|
#
|
|
|
|
###
|
|
|
|
|
2023-01-30 09:25:46 +08:00
|
|
|
class Plugin::DB_Tracer < Msf::Plugin
|
2013-10-01 02:47:53 +08:00
|
|
|
|
2023-01-30 09:25:46 +08:00
|
|
|
###
|
|
|
|
#
|
|
|
|
# This class implements a socket communication tracker
|
|
|
|
#
|
|
|
|
###
|
|
|
|
class DBTracerEventHandler
|
|
|
|
include Rex::Socket::Comm::Events
|
2013-10-01 02:47:53 +08:00
|
|
|
|
2023-01-30 09:25:46 +08:00
|
|
|
def on_before_socket_create(comm, param); end
|
2013-10-01 02:47:53 +08:00
|
|
|
|
2023-01-30 09:25:46 +08:00
|
|
|
def on_socket_created(_comm, sock, param)
|
|
|
|
# Ignore local listening sockets
|
|
|
|
return if !sock.peerhost
|
2013-10-01 02:47:53 +08:00
|
|
|
|
2023-01-30 10:05:34 +08:00
|
|
|
if ((sock.peerhost != '0.0.0.0') && sock.peerport)
|
2013-10-01 02:47:53 +08:00
|
|
|
|
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
|
2013-10-01 02:47:53 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-01-30 09:25:46 +08:00
|
|
|
def initialize(framework, opts)
|
|
|
|
super
|
2013-10-01 02:47:53 +08:00
|
|
|
|
2023-01-30 09:25:46 +08:00
|
|
|
if !framework.db.active
|
|
|
|
raise PluginLoadError, 'The database backend has not been initialized'
|
2013-10-01 02:47:53 +08:00
|
|
|
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
|
2013-10-01 02:47:53 +08:00
|
|
|
|
2023-01-30 09:25:46 +08:00
|
|
|
@eh = DBTracerEventHandler.new
|
|
|
|
Rex::Socket::Comm::Local.register_event_handler(@eh)
|
|
|
|
end
|
2013-10-01 02:47:53 +08:00
|
|
|
|
2023-01-30 09:25:46 +08:00
|
|
|
def cleanup
|
|
|
|
Rex::Socket::Comm::Local.deregister_event_handler(@eh)
|
|
|
|
end
|
2013-10-01 02:47:53 +08:00
|
|
|
|
2023-01-30 09:25:46 +08:00
|
|
|
def name
|
|
|
|
'db_tracker'
|
|
|
|
end
|
2006-04-03 06:33:34 +08:00
|
|
|
|
2023-01-30 09:25:46 +08:00
|
|
|
def desc
|
|
|
|
'Monitors socket calls and updates the database backend'
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2008-11-01 02:39:53 +08:00
|
|
|
end
|