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:
wade@bindshell.net
2011-01-03 05:01:07 +00:00
parent c4e07ff66d
commit cdbde91bb9
3 changed files with 53 additions and 0 deletions

View File

@@ -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'

View 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

View File

@@ -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/"