metasploit-framework/lib/msf/core/db_objects.rb

126 lines
2.1 KiB
Ruby
Raw Normal View History

module Msf
##
#
# This module defines all of the DB database tables
# and creates ActiveRecord objects for each one of them
#
##
class DBManager
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
# Straight up gangsta from spoon (ripped from BION)
module DBSave
def self.included(mod)
class << mod
def find(*args)
ActiveRecord::Base.connection_pool.clear_stale_cached_connections!
super(*args)
end
def save(*args)
ActiveRecord::Base.connection_pool.clear_stale_cached_connections!
super(*args)
end
end
end
end
# Host object definition
class Host < ActiveRecord::Base
include DBSave
has_many :services
has_many :clients
has_many :vulns
end
class Client < ActiveRecord::Base
include DBSave
belongs_to :host
def host
Host.find(:first, :conditions => [ "id = ?", host_id ])
end
end
# Service object definition
class Service < ActiveRecord::Base
include DBSave
has_many :vulns
belongs_to :host
def host
Host.find(:first, :conditions => [ "id = ?", host_id ])
end
end
# Vuln object definition
class Vuln < ActiveRecord::Base
include DBSave
belongs_to :host
belongs_to :service
has_and_belongs_to_many :refs, :join_table => :vulns_refs
def service
Service.find(:first, :conditions => [ "id = ?", service_id ])
end
def host
Host.find(:first, :conditions => [ "id = ?", host_id ])
end
end
# Reference object definition
class Ref < ActiveRecord::Base
include DBSave
has_and_belongs_to_many :vulns, :join_table => :vulns_refs
end
# Reference object definition
class VulnRefs < ActiveRecord::Base
set_table_name 'vulns_refs'
include DBSave
end
# Service object definition
class Note < ActiveRecord::Base
include DBSave
belongs_to :host
def host
Host.find(:first, :conditions => [ "id = ?", host_id ])
end
end
# WMAP Request object definition
class Request < ::ActiveRecord::Base
include DBSave
# Magic.
end
# WMAP Target object definition
class Target < ::ActiveRecord::Base
include DBSave
# Magic.
end
end
end