From b41c6e855976ac9bf460b23e2e01256595a406e5 Mon Sep 17 00:00:00 2001 From: antisnatchor Date: Wed, 18 Apr 2012 16:56:43 +0100 Subject: [PATCH] Catched JSON::ParserError exception when a client abruptly disconnects (i.e.: closing the browser manually, or the hooked tab) --- .../main/network_stack/websocket/websocket.rb | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/core/main/network_stack/websocket/websocket.rb b/core/main/network_stack/websocket/websocket.rb index a9a625d8c..4716d75ba 100644 --- a/core/main/network_stack/websocket/websocket.rb +++ b/core/main/network_stack/websocket/websocket.rb @@ -38,27 +38,30 @@ module BeEF Thread.new { server.run() do |ws| - print_debug("Path requested #{ws.path} Origins #{ws.origin}") - if ws.path == "/" - ws.handshake() #accept and connect - - while true - #command interpretation - message=ws.receive() - messageHash= JSON.parse("#{message}") - #@note messageHash[result] is Base64 encoded - if (messageHash["cookie"]!= nil) - print_info("Browser #{ws.origin} says helo! WebSocket is running") - #insert new connection in activesocket - @@activeSocket["#{messageHash["cookie"]}"] = ws - print_debug("In activesocket we have #{@@activeSocket}") - else - #json recv is a cmd response decode and send all to - #we have to call dynamicreconstructor handler camp must be websocket - print_debug("Received from WebSocket #{messageHash}") - execute(messageHash) + begin + print_debug("Path requested #{ws.path} Origins #{ws.origin}") + if ws.path == "/" + ws.handshake() #accept and connect + while true + #command interpretation + message=ws.receive() + messageHash= JSON.parse("#{message}") + #@note messageHash[result] is Base64 encoded + if (messageHash["cookie"]!= nil) + print_info("Browser #{ws.origin} says helo! WebSocket is running") + #insert new connection in activesocket + @@activeSocket["#{messageHash["cookie"]}"] = ws + print_debug("In activesocket we have #{@@activeSocket}") + else + #json recv is a cmd response decode and send all to + #we have to call dynamicreconstructor handler camp must be websocket + print_debug("Received from WebSocket #{messageHash}") + execute(messageHash) + end + end end - end + rescue Exception => e + print_error "Hooked browser from origin #{ws.origin} abruptly disconnected." end end }