From cdbde91bb9f42d428f8350155a9a033181aeb041 Mon Sep 17 00:00:00 2001 From: "wade@bindshell.net" Date: Mon, 3 Jan 2011 05:01:07 +0000 Subject: [PATCH] Adding the start of the eventhandler git-svn-id: https://beef.googlecode.com/svn/trunk@660 b87d56ec-f9c0-11de-8c8a-61c5e9addfc9 --- lib/loader.rb | 2 ++ lib/server/eventhandler.rb | 48 ++++++++++++++++++++++++++++++++++++ lib/server/httphookserver.rb | 3 +++ 3 files changed, 53 insertions(+) create mode 100644 lib/server/eventhandler.rb diff --git a/lib/loader.rb b/lib/loader.rb index 0757d7258..03d4842d5 100644 --- a/lib/loader.rb +++ b/lib/loader.rb @@ -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' diff --git a/lib/server/eventhandler.rb b/lib/server/eventhandler.rb new file mode 100644 index 000000000..746b44a77 --- /dev/null +++ b/lib/server/eventhandler.rb @@ -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 \ No newline at end of file diff --git a/lib/server/httphookserver.rb b/lib/server/httphookserver.rb index 0442ccc45..4ae8822d1 100644 --- a/lib/server/httphookserver.rb +++ b/lib/server/httphookserver.rb @@ -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/"