2006-03-21 04:37:48 +00:00
|
|
|
module Msf
|
|
|
|
|
|
|
|
##
|
|
|
|
#
|
|
|
|
# This module defines all of the DB database tables
|
|
|
|
# and creates ActiveRecord objects for each one of them
|
|
|
|
#
|
|
|
|
##
|
|
|
|
|
|
|
|
class DBManager
|
|
|
|
|
2006-04-03 04:33:30 +00:00
|
|
|
class Lock
|
|
|
|
@@mutex = Mutex.new
|
|
|
|
def self.mutex
|
|
|
|
@@mutex
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# ActiveRecord/sqlite3 has locking issues when you update a table with a pending select
|
|
|
|
# This set of instance/class wrappers should prevent a table lock
|
2009-11-16 15:16:08 +00:00
|
|
|
# Straight up gangsta from spoon (ripped from BION)
|
2006-04-03 04:33:30 +00:00
|
|
|
module DBSave
|
|
|
|
|
2006-04-03 04:50:26 +00:00
|
|
|
def self.included(mod)
|
|
|
|
class << mod
|
|
|
|
def find(*args)
|
2009-11-29 23:36:40 +00:00
|
|
|
ActiveRecord::Base.connection_pool.clear_stale_cached_connections!
|
|
|
|
Lock.mutex.synchronize do
|
2006-04-03 04:50:26 +00:00
|
|
|
super(*args)
|
|
|
|
end
|
2009-11-14 22:11:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def save(*args)
|
2009-11-29 23:36:40 +00:00
|
|
|
ActiveRecord::Base.connection_pool.clear_stale_cached_connections!
|
|
|
|
Lock.mutex.synchronize do
|
2009-11-14 22:11:53 +00:00
|
|
|
super(*args)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2006-04-03 04:50:26 +00:00
|
|
|
end
|
2006-04-03 04:33:30 +00:00
|
|
|
end
|
2009-11-14 22:11:53 +00:00
|
|
|
|
2006-04-03 04:33:30 +00:00
|
|
|
end
|
|
|
|
|
2006-03-21 04:37:48 +00:00
|
|
|
# Host object definition
|
|
|
|
class Host < ActiveRecord::Base
|
2006-04-03 04:33:30 +00:00
|
|
|
include DBSave
|
2006-09-16 20:08:13 +00:00
|
|
|
has_many :services
|
2009-07-22 20:14:35 +00:00
|
|
|
has_many :clients
|
2009-07-22 13:37:14 +00:00
|
|
|
has_many :vulns
|
2006-03-21 04:37:48 +00:00
|
|
|
end
|
|
|
|
|
2009-07-22 20:14:35 +00:00
|
|
|
class Client < ActiveRecord::Base
|
|
|
|
include DBSave
|
|
|
|
belongs_to :host
|
|
|
|
|
|
|
|
def host
|
|
|
|
Host.find(:first, :conditions => [ "id = ?", host_id ])
|
2009-11-14 22:11:53 +00:00
|
|
|
end
|
2009-07-22 20:14:35 +00:00
|
|
|
end
|
|
|
|
|
2006-03-21 04:37:48 +00:00
|
|
|
# Service object definition
|
|
|
|
class Service < ActiveRecord::Base
|
2006-04-03 04:33:30 +00:00
|
|
|
include DBSave
|
2006-09-16 20:08:13 +00:00
|
|
|
has_many :vulns
|
|
|
|
belongs_to :host
|
2006-09-17 00:39:23 +00:00
|
|
|
|
|
|
|
def host
|
|
|
|
Host.find(:first, :conditions => [ "id = ?", host_id ])
|
2009-11-14 22:11:53 +00:00
|
|
|
end
|
2006-04-02 22:33:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Vuln object definition
|
|
|
|
class Vuln < ActiveRecord::Base
|
2006-04-03 04:33:30 +00:00
|
|
|
include DBSave
|
2009-07-22 13:37:14 +00:00
|
|
|
belongs_to :host
|
2006-09-16 20:08:13 +00:00
|
|
|
belongs_to :service
|
|
|
|
has_and_belongs_to_many :refs, :join_table => :vulns_refs
|
2006-09-17 00:39:23 +00:00
|
|
|
|
2006-04-02 22:33:34 +00:00
|
|
|
def service
|
|
|
|
Service.find(:first, :conditions => [ "id = ?", service_id ])
|
|
|
|
end
|
2006-09-17 00:39:23 +00:00
|
|
|
|
2006-04-02 22:33:34 +00:00
|
|
|
def host
|
2009-07-22 13:37:14 +00:00
|
|
|
Host.find(:first, :conditions => [ "id = ?", host_id ])
|
2006-04-02 22:33:34 +00:00
|
|
|
end
|
2006-03-21 04:37:48 +00:00
|
|
|
end
|
|
|
|
|
2006-09-16 20:08:13 +00:00
|
|
|
# Reference object definition
|
|
|
|
class Ref < ActiveRecord::Base
|
|
|
|
include DBSave
|
2006-09-17 00:39:23 +00:00
|
|
|
has_and_belongs_to_many :vulns, :join_table => :vulns_refs
|
2006-09-16 20:08:13 +00:00
|
|
|
end
|
|
|
|
|
2006-09-17 00:39:23 +00:00
|
|
|
# Reference object definition
|
|
|
|
class VulnRefs < ActiveRecord::Base
|
|
|
|
set_table_name 'vulns_refs'
|
|
|
|
include DBSave
|
|
|
|
end
|
2006-09-16 20:08:13 +00:00
|
|
|
|
2008-03-02 04:46:13 +00:00
|
|
|
|
|
|
|
# Service object definition
|
|
|
|
class Note < ActiveRecord::Base
|
|
|
|
include DBSave
|
|
|
|
belongs_to :host
|
|
|
|
|
|
|
|
def host
|
|
|
|
Host.find(:first, :conditions => [ "id = ?", host_id ])
|
2009-11-14 22:11:53 +00:00
|
|
|
end
|
2008-03-02 04:46:13 +00:00
|
|
|
end
|
|
|
|
|
2008-10-12 03:46:49 +00:00
|
|
|
|
2009-11-14 22:11:53 +00:00
|
|
|
# WMAP Request object definition
|
2008-10-12 03:46:49 +00:00
|
|
|
class Request < ::ActiveRecord::Base
|
|
|
|
include DBSave
|
|
|
|
# Magic.
|
|
|
|
end
|
|
|
|
|
|
|
|
# WMAP Target object definition
|
|
|
|
class Target < ::ActiveRecord::Base
|
|
|
|
include DBSave
|
|
|
|
# Magic.
|
|
|
|
end
|
2008-10-19 20:32:14 +00:00
|
|
|
|
2008-10-12 03:46:49 +00:00
|
|
|
|
2006-03-21 04:37:48 +00:00
|
|
|
end
|
2009-05-09 04:18:27 +00:00
|
|
|
end
|
2009-11-14 22:11:53 +00:00
|
|
|
|