Files
metasploit-gs/plugins/db_tracker.rb
T

76 lines
1.5 KiB
Ruby
Raw Normal View History

2010-05-03 17:13:09 +00:00
#
# $Id$
# $Revision$
#
2006-04-02 22:33:34 +00:00
module Msf
###
2010-05-03 17:13:09 +00:00
#
2006-04-02 22:33:34 +00:00
# This class hooks all socket calls and updates the database with
# data gathered from the connection parameters
#
###
class Plugin::DB_Tracer < Msf::Plugin
###
#
# This class implements a socket communication tracker
#
###
class DBTracerEventHandler
include Rex::Socket::Comm::Events
def on_before_socket_create(comm, param)
end
def on_socket_created(comm, sock, param)
# Ignore local listening sockets
return if not sock.peerhost
if (sock.peerhost != '0.0.0.0' and sock.peerport)
2010-05-03 17:13:09 +00:00
# Ignore sockets that didn't set up their context
# to hold the framework in 'Msf'
return if not param.context['Msf']
2010-01-07 19:14:44 +00:00
host = param.context['Msf'].db.find_or_create_host(:host => sock.peerhost, :state => Msf::HostState::Alive)
2006-04-02 22:33:34 +00:00
return if not host
2010-05-03 17:13:09 +00:00
2010-01-07 19:14:44 +00:00
param.context['Msf'].db.report_service(:host => host, :proto => param.proto, :port => sock.peerport)
2006-04-02 22:33:34 +00:00
end
2010-05-03 17:13:09 +00:00
end
2006-04-02 22:33:34 +00:00
end
2010-05-03 17:13:09 +00:00
2006-04-02 22:33:34 +00:00
def initialize(framework, opts)
super
2010-05-03 17:13:09 +00:00
2006-04-02 22:33:34 +00:00
if(not framework.db.active)
raise PluginLoadError.new("The database backend has not been initialized")
end
framework.plugins.each { |plugin|
if (plugin.class == Msf::Plugin::DB_Tracer)
raise PluginLoadError.new("This plugin should not be loaded more than once")
end
}
2010-05-03 17:13:09 +00:00
2006-04-02 22:33:34 +00:00
@eh = DBTracerEventHandler.new
Rex::Socket::Comm::Local.register_event_handler(@eh)
end
def cleanup
Rex::Socket::Comm::Local.deregister_event_handler(@eh)
end
def name
"db_tracker"
end
def desc
"Monitors socket calls and updates the database backend"
end
end
end