Adding the start of the eventhandler
git-svn-id: https://beef.googlecode.com/svn/trunk@660 b87d56ec-f9c0-11de-8c8a-61c5e9addfc9
This commit is contained in:
@@ -63,10 +63,12 @@ require 'lib/server/commandhandler'
|
||||
require 'lib/server/publichandler'
|
||||
require 'lib/server/requesterhandler'
|
||||
require 'lib/server/inithandler'
|
||||
require 'lib/server/eventhandler'
|
||||
|
||||
require 'lib/logger'
|
||||
require 'lib/modules/command'
|
||||
require 'lib/modules/requester'
|
||||
|
||||
require 'lib/modules/msfclient'
|
||||
require 'lib/modules/msfcommand'
|
||||
|
||||
|
||||
48
lib/server/eventhandler.rb
Normal file
48
lib/server/eventhandler.rb
Normal file
@@ -0,0 +1,48 @@
|
||||
module BeEF
|
||||
|
||||
#
|
||||
# The http handler that manages the Events.
|
||||
#
|
||||
class EventHandler < WEBrick::HTTPServlet::AbstractServlet
|
||||
|
||||
attr_reader :guard
|
||||
|
||||
H = BeEF::Models::Http
|
||||
Z = BeEF::Models::Zombie
|
||||
|
||||
#
|
||||
# Class constructor
|
||||
#
|
||||
def initialize(config)
|
||||
# we set up a mutex
|
||||
@guard = Mutex.new
|
||||
end
|
||||
|
||||
#
|
||||
# This function receives any POST http requests. We only
|
||||
# allow the hooked browser to send back results using POST.
|
||||
#
|
||||
def do_POST(request, response)
|
||||
# validates the hook token
|
||||
beef_hook = request.query['BEEFHOOK'] || nil
|
||||
raise WEBrick::HTTPStatus::BadRequest, "beef_hook is null" if beef_hook.nil?
|
||||
|
||||
# validates that a hooked browser with the beef_hook token exists in the db
|
||||
zombie = Z.first(:session => beef_hook) || nil
|
||||
raise WEBrick::HTTPStatus::BadRequest, "Invalid beef hook id: the hooked browser cannot be found in the database" if zombie.nil?
|
||||
|
||||
event_string = request.query['event_string'] || nil
|
||||
raise WEBrick::HTTPStatus::BadRequest, "event_string is null" if event_string.nil?
|
||||
|
||||
BeEF::Logger.instance.register('Zombie', "#{zombie.ip}: #{event_string}", "#{zombie.id}")
|
||||
|
||||
response.set_no_cache()
|
||||
response.header['Content-Type'] = 'text/javascript'
|
||||
response.header['Access-Control-Allow-Origin'] = '*'
|
||||
response.header['Access-Control-Allow-Methods'] = 'POST'
|
||||
response.body = ''
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
@@ -88,6 +88,9 @@ module BeEF
|
||||
# registers the init page
|
||||
@http_server.mount '/init', BeEF::InitHandler
|
||||
|
||||
# registers the event handler
|
||||
@http_server.mount '/event', BeEF::EventHandler
|
||||
|
||||
@http_server.mount '/ui/public', BeEF::PublicHandler, "#{root_dir}/public"
|
||||
@http_server.mount '/favicon.ico', WEBrick::HTTPServlet::FileHandler, "#{root_dir}#{@configuration.get("favicon_dir")}/#{@configuration.get("favicon_file_name")}"
|
||||
@http_server.mount '/demos/', WEBrick::HTTPServlet::FileHandler, "#{root_dir}/demos/"
|
||||
|
||||
Reference in New Issue
Block a user