Began adding support for RESTful API beginning with /api/dns/rules.
This commit is contained in:
@@ -10,10 +10,19 @@ module API
|
||||
|
||||
module NameserverHandler
|
||||
|
||||
BeEF::API::Registrar.instance.register(BeEF::Extension::DNS::API::NameserverHandler,
|
||||
BeEF::API::Server,
|
||||
'pre_http_start')
|
||||
BeEF::API::Registrar.instance.register(
|
||||
BeEF::Extension::DNS::API::NameserverHandler,
|
||||
BeEF::API::Server,
|
||||
'pre_http_start'
|
||||
)
|
||||
|
||||
BeEF::API::Registrar.instance.register(
|
||||
BeEF::Extension::DNS::API::NameserverHandler,
|
||||
BeEF::API::Server,
|
||||
'mount_handler'
|
||||
)
|
||||
|
||||
# Begins main DNS server run-loop at BeEF startup
|
||||
def self.pre_http_start(http_hook_server)
|
||||
config = BeEF::Core::Configuration.instance
|
||||
|
||||
@@ -28,6 +37,11 @@ module API
|
||||
print_info "DNS Server: #{address}:#{port}"
|
||||
end
|
||||
|
||||
# Mounts handler for processing RESTful API calls
|
||||
def self.mount_handler(beef_server)
|
||||
beef_server.mount('/api/dns', BeEF::Extension::DNS::DNSRest.new)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -77,6 +77,34 @@ module DNS
|
||||
end
|
||||
end
|
||||
|
||||
# Returns an AoH representing the entire current DNS ruleset where each element is a
|
||||
# hash with the following keys:
|
||||
#
|
||||
# * <code>:id</code>
|
||||
# * <code>:pattern</code>
|
||||
# * <code>:type</code>
|
||||
# * <code>:block</code>
|
||||
#
|
||||
# @return [Array<Hash>] DNS ruleset (empty if no rules are currently loaded)
|
||||
def get_rules
|
||||
@lock.synchronize do
|
||||
result = []
|
||||
|
||||
BeEF::Core::Models::DNS::Rule.each do |rule|
|
||||
element = {}
|
||||
|
||||
element[:id] = rule.id
|
||||
element[:pattern] = rule.pattern
|
||||
element[:type] = rule.type
|
||||
element[:block] = rule.block
|
||||
|
||||
result << element
|
||||
end
|
||||
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -20,5 +20,6 @@ end
|
||||
|
||||
require 'extensions/dns/api'
|
||||
require 'extensions/dns/dns'
|
||||
require 'extensions/dns/ruby'
|
||||
require 'extensions/dns/model'
|
||||
require 'extensions/dns/rest/dns'
|
||||
require 'extensions/dns/ruby'
|
||||
|
||||
65
extensions/dns/rest/dns.rb
Normal file
65
extensions/dns/rest/dns.rb
Normal file
@@ -0,0 +1,65 @@
|
||||
#
|
||||
# Copyright (c) 2006-2013 Wade Alcorn - wade@bindshell.net
|
||||
# Browser Exploitation Framework (BeEF) - http://beefproject.com
|
||||
# See the file 'doc/COPYING' for copying permission
|
||||
#
|
||||
|
||||
# GET:
|
||||
# * Rule count
|
||||
# * List of rules
|
||||
|
||||
# POST:
|
||||
# * Add rule
|
||||
# * Remove rule
|
||||
|
||||
|
||||
# /api/dns/rules
|
||||
# {
|
||||
# "rules": [
|
||||
# {
|
||||
# "id": 1,
|
||||
# "pattern": "foobar.com",
|
||||
# "type": "Resolv::DNS::Resource::IN::A"
|
||||
# "block": "proc {|t| ...do shit... }"
|
||||
# },
|
||||
#
|
||||
# {
|
||||
# },
|
||||
#
|
||||
# {
|
||||
# },
|
||||
# ]
|
||||
# }
|
||||
|
||||
|
||||
|
||||
module BeEF
|
||||
module Extension
|
||||
module DNS
|
||||
|
||||
class DNSRest < BeEF::Core::Router::Router
|
||||
|
||||
before do
|
||||
config = BeEF::Core::Configuration.instance
|
||||
|
||||
error 401 unless params[:token] == config.get('beef.api_token')
|
||||
halt 401 unless BeEF::Core::Rest.permitted_source?(request.ip)
|
||||
|
||||
headers 'Content-Type' => 'application/json; charset=UTF-8',
|
||||
'Pragma' => 'no-cache',
|
||||
'Cache-Control' => 'no-cache',
|
||||
'Expires' => '0'
|
||||
end
|
||||
|
||||
# Returns the entire current DNS ruleset
|
||||
get '/rules' do
|
||||
result = {}
|
||||
result[:rules] = BeEF::Extension::DNS::DNS.instance.get_rules
|
||||
result.to_json
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user