Added @database to Dns::Server as a model reference.
This commit is contained in:
@@ -20,6 +20,7 @@ module BeEF
|
|||||||
def initialize
|
def initialize
|
||||||
super()
|
super()
|
||||||
@lock = Mutex.new
|
@lock = Mutex.new
|
||||||
|
@database = BeEF::Core::Models::Dns::Rule
|
||||||
end
|
end
|
||||||
|
|
||||||
# Adds a new DNS rule. If the rule already exists, its current ID is returned.
|
# Adds a new DNS rule. If the rule already exists, its current ID is returned.
|
||||||
@@ -48,7 +49,7 @@ module BeEF
|
|||||||
pattern = Regexp.new(rule[:pattern], Regexp::IGNORECASE)
|
pattern = Regexp.new(rule[:pattern], Regexp::IGNORECASE)
|
||||||
$VERBOSE = verbose
|
$VERBOSE = verbose
|
||||||
|
|
||||||
BeEF::Core::Models::Dns::Rule.first_or_create(
|
@database.first_or_create(
|
||||||
{ :resource => rule[:resource], :pattern => pattern.source },
|
{ :resource => rule[:resource], :pattern => pattern.source },
|
||||||
{ :response => rule[:response] }
|
{ :response => rule[:response] }
|
||||||
).id
|
).id
|
||||||
@@ -62,7 +63,7 @@ module BeEF
|
|||||||
# @return [Hash] hash representation of rule (empty hash if rule wasn't found)
|
# @return [Hash] hash representation of rule (empty hash if rule wasn't found)
|
||||||
def get_rule(id)
|
def get_rule(id)
|
||||||
@lock.synchronize do
|
@lock.synchronize do
|
||||||
rule = BeEF::Core::Models::Dns::Rule.get(id)
|
rule = @database.get(id)
|
||||||
rule.nil? ? {} : to_hash(rule)
|
rule.nil? ? {} : to_hash(rule)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -74,7 +75,7 @@ module BeEF
|
|||||||
# @return [Boolean] true if rule was removed, otherwise false
|
# @return [Boolean] true if rule was removed, otherwise false
|
||||||
def remove_rule!(id)
|
def remove_rule!(id)
|
||||||
@lock.synchronize do
|
@lock.synchronize do
|
||||||
rule = BeEF::Core::Models::Dns::Rule.get(id)
|
rule = @database.get(id)
|
||||||
rule.nil? ? false : rule.destroy
|
rule.nil? ? false : rule.destroy
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -90,14 +91,14 @@ module BeEF
|
|||||||
#
|
#
|
||||||
# @return [Array<Hash>] DNS ruleset (empty array if no rules are currently defined)
|
# @return [Array<Hash>] DNS ruleset (empty array if no rules are currently defined)
|
||||||
def get_ruleset
|
def get_ruleset
|
||||||
@lock.synchronize { BeEF::Core::Models::Dns::Rule.collect { |rule| to_hash(rule) } }
|
@lock.synchronize { @database.collect { |rule| to_hash(rule) } }
|
||||||
end
|
end
|
||||||
|
|
||||||
# Removes the entire DNS ruleset.
|
# Removes the entire DNS ruleset.
|
||||||
#
|
#
|
||||||
# @return [Boolean] true if ruleset was destroyed, otherwise false
|
# @return [Boolean] true if ruleset was destroyed, otherwise false
|
||||||
def remove_ruleset!
|
def remove_ruleset!
|
||||||
@lock.synchronize { BeEF::Core::Models::Dns::Rule.destroy }
|
@lock.synchronize { @database.destroy }
|
||||||
end
|
end
|
||||||
|
|
||||||
# Entry point for processing incoming DNS requests. Attempts to find a matching rule and
|
# Entry point for processing incoming DNS requests. Attempts to find a matching rule and
|
||||||
@@ -112,7 +113,7 @@ module BeEF
|
|||||||
|
|
||||||
catch (:done) do
|
catch (:done) do
|
||||||
# Find rules matching the requested resource class
|
# Find rules matching the requested resource class
|
||||||
resources = BeEF::Core::Models::Dns::Rule.all(:resource => resource)
|
resources = @database.all(:resource => resource)
|
||||||
throw :done if resources.length == 0
|
throw :done if resources.length == 0
|
||||||
|
|
||||||
# Narrow down search by finding a matching pattern
|
# Narrow down search by finding a matching pattern
|
||||||
|
|||||||
Reference in New Issue
Block a user