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
|
2006-04-03 04:50:26 +00:00
|
|
|
# Straight up gangsta shit from spoon (ripped from BION)
|
2006-04-03 04:33:30 +00:00
|
|
|
module DBSave
|
|
|
|
|
2006-04-03 04:50:26 +00:00
|
|
|
def save(*args)
|
|
|
|
Lock.mutex.synchronize do
|
|
|
|
super(*args)
|
|
|
|
end
|
|
|
|
end
|
2006-04-03 04:33:30 +00:00
|
|
|
|
2006-04-03 04:50:26 +00:00
|
|
|
def self.included(mod)
|
|
|
|
class << mod
|
|
|
|
def find(*args)
|
|
|
|
Lock.mutex.synchronize do
|
|
|
|
super(*args)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2006-04-03 04:33:30 +00:00
|
|
|
end
|
|
|
|
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
|
|
|
|
has_many :vulns, :through => :services
|
2006-03-21 04:37:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# 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 ])
|
|
|
|
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
|
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
|
|
|
|
Host.find(:first, :conditions => [ "id = ?", service.host_id ])
|
|
|
|
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 ])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-10-12 03:46:49 +00:00
|
|
|
|
|
|
|
# WMAP Request object definition
|
|
|
|
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
|
|
|
|
|
|
|
# WMAP Report object definition
|
|
|
|
class Report < ::ActiveRecord::Base
|
|
|
|
include DBSave
|
|
|
|
end
|
2008-10-12 03:46:49 +00:00
|
|
|
|
2006-03-21 04:37:48 +00:00
|
|
|
end
|
2008-10-19 21:03:39 +00:00
|
|
|
end
|