2006-03-21 04:37:48 +00:00
|
|
|
require 'fileutils'
|
2006-05-30 15:44:48 +00:00
|
|
|
require 'msf/ui/console/command_dispatcher/db'
|
|
|
|
|
2006-03-21 04:37:48 +00:00
|
|
|
|
|
|
|
module Msf
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
# This class intializes the database db with a shiny new
|
|
|
|
# SQLite3 database instance.
|
|
|
|
#
|
|
|
|
###
|
|
|
|
|
|
|
|
class Plugin::DBSQLite3 < Msf::Plugin
|
|
|
|
|
2006-03-21 05:29:26 +00:00
|
|
|
###
|
|
|
|
#
|
|
|
|
# This class implements an event handler for db events
|
|
|
|
#
|
|
|
|
###
|
|
|
|
class DBEventHandler
|
|
|
|
def on_db_host(context, host)
|
2006-05-30 15:44:48 +00:00
|
|
|
# puts "New host event: #{host.address}"
|
2006-03-21 05:29:26 +00:00
|
|
|
end
|
2006-04-02 22:33:34 +00:00
|
|
|
|
|
|
|
def on_db_service(context, service)
|
2006-04-03 04:33:30 +00:00
|
|
|
# puts "New service event: host=#{service.host.address} port=#{service.port} proto=#{service.proto} state=#{service.state}"
|
2006-04-02 22:33:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def on_db_vuln(context, vuln)
|
2006-05-30 15:44:48 +00:00
|
|
|
# puts "New vuln event: host=#{vuln.host.address} port=#{vuln.service.port} proto=#{vuln.service.proto} name=#{vuln.name}"
|
2006-04-02 22:33:34 +00:00
|
|
|
end
|
2006-03-21 05:29:26 +00:00
|
|
|
end
|
|
|
|
|
2006-03-21 04:37:48 +00:00
|
|
|
###
|
|
|
|
#
|
2006-05-30 15:44:48 +00:00
|
|
|
# Inherit the database command set
|
2006-03-21 04:37:48 +00:00
|
|
|
#
|
|
|
|
###
|
|
|
|
class ConsoleCommandDispatcher
|
|
|
|
include Msf::Ui::Console::CommandDispatcher
|
2006-05-30 15:44:48 +00:00
|
|
|
include Msf::Ui::Console::CommandDispatcher::Db
|
2006-03-21 04:37:48 +00:00
|
|
|
end
|
|
|
|
|
2006-05-30 15:44:48 +00:00
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
# Database specific initialization goes here
|
|
|
|
#
|
|
|
|
###
|
|
|
|
|
2006-03-21 04:37:48 +00:00
|
|
|
def initialize(framework, opts)
|
|
|
|
super
|
|
|
|
|
|
|
|
odb = File.join(Msf::Config.install_root, "data", "sql", "sqlite3.db")
|
|
|
|
ndb = File.join(Msf::Config.install_root, "current.db")
|
|
|
|
|
|
|
|
if (File.exists?(ndb))
|
|
|
|
File.unlink(ndb)
|
|
|
|
end
|
|
|
|
|
|
|
|
FileUtils.copy(odb, ndb)
|
|
|
|
|
|
|
|
if (not framework.db.connect("adapter" => "sqlite3", "dbfile" => ndb))
|
2006-04-02 22:33:34 +00:00
|
|
|
File.unlink(ndb)
|
|
|
|
raise PluginLoadError.new("Failed to connect to the database")
|
2006-03-21 04:37:48 +00:00
|
|
|
end
|
|
|
|
|
2006-03-21 05:29:26 +00:00
|
|
|
@dbh = DBEventHandler.new
|
|
|
|
|
2006-03-21 04:37:48 +00:00
|
|
|
add_console_dispatcher(ConsoleCommandDispatcher)
|
2006-03-21 05:29:26 +00:00
|
|
|
framework.events.add_db_subscriber(@dbh)
|
|
|
|
|
2006-03-21 04:37:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def cleanup
|
2006-03-21 05:29:26 +00:00
|
|
|
framework.events.remove_db_subscriber(@dbh)
|
2006-04-02 22:33:34 +00:00
|
|
|
remove_console_dispatcher('Database Backend')
|
2006-03-21 04:37:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# This method returns a short, friendly name for the plugin.
|
|
|
|
#
|
|
|
|
def name
|
|
|
|
"db_sqlite3"
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# This method returns a brief description of the plugin. It should be no
|
|
|
|
# more than 60 characters, but there are no hard limits.
|
|
|
|
#
|
|
|
|
def desc
|
2006-04-02 22:33:34 +00:00
|
|
|
"Loads a new sqlite3 database backend"
|
2006-03-21 04:37:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|