From 236c8a81b6f32b73a69385ee3170cf2c76903adf Mon Sep 17 00:00:00 2001 From: antisnatchor Date: Sat, 7 Apr 2012 12:31:37 +0100 Subject: [PATCH] Fixed issue with lib loading and WebSocket server initalization --- beef | 3 +- core/bootstrap.rb | 3 +- .../websocket/handlers/module.rb | 55 ------------------- .../main/network_stack/websocket/websocket.rb | 51 +++++++++++++++++ 4 files changed, 55 insertions(+), 57 deletions(-) delete mode 100644 core/main/network_stack/websocket/handlers/module.rb create mode 100644 core/main/network_stack/websocket/websocket.rb diff --git a/beef b/beef index cb1bc8ca1..c37e7b50e 100755 --- a/beef +++ b/beef @@ -112,7 +112,8 @@ BeEF::Core::Console::Banners.print_network_interfaces_routes #@note Prints the API key needed to use the RESTful API print_info "RESTful API key: #{BeEF::Core::Crypto::api_token}" -BeEF::Core::Websocket.initialize +#@note Starts the WebSocket server +BeEF::Core::Websocket::Websocket.new diff --git a/core/bootstrap.rb b/core/bootstrap.rb index b070cf051..821df91ec 100644 --- a/core/bootstrap.rb +++ b/core/bootstrap.rb @@ -48,4 +48,5 @@ require 'core/main/rest/handlers/logs' require 'core/main/rest/api' ## @note Include Websocket -require 'core/main/network_stack/websocket/handlers/module' +require 'core/main/network_stack/websocket/lib/web_socket' +require 'core/main/network_stack/websocket/websocket' diff --git a/core/main/network_stack/websocket/handlers/module.rb b/core/main/network_stack/websocket/handlers/module.rb deleted file mode 100644 index b7cf8087f..000000000 --- a/core/main/network_stack/websocket/handlers/module.rb +++ /dev/null @@ -1,55 +0,0 @@ -# -# Copyright 2012 Wade Alcorn wade@bindshell.net -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -module BeEF - module Core - module Websocket - - - def initialize - - - print_info("Inside") - #load the library - $LOAD_PATH << File.dirname(__FILE__) + "../lib" - require "web_socket" - server = WebSocketServer.new("localhost", 6666) #we get host and port how - server.run() do |ws| - #@TODO debug print the path and who request for hooked browser mapping - print_info("Path requested #{ws.path} Originis #{ws.origin}") - if ws.path == "/" - ws.handshake() #accept and connect - - while true - #command interpretation - message=ws.receve() - - if (message!="helo") - #module return value case - else - print_info("Browser #{ws.origin} says helo! ws is running") - end - - end - end - - - end - - - end - end - end -end diff --git a/core/main/network_stack/websocket/websocket.rb b/core/main/network_stack/websocket/websocket.rb new file mode 100644 index 000000000..159234655 --- /dev/null +++ b/core/main/network_stack/websocket/websocket.rb @@ -0,0 +1,51 @@ +# +# Copyright 2012 Wade Alcorn wade@bindshell.net +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +module BeEF + module Core + module Websocket + class Websocket + + + def initialize + print_info("Starting WebSockets") + + #todo antisnatchor: add config file options for IP/port/enable websocket + + server = WebSocketServer.new(:accepted_domains => "0.0.0.0",:port => 6666) #we get host and port + server.run() do |ws| + #@TODO debug print the path and who request for hooked browser mapping + print_info("Path requested #{ws.path} Origins #{ws.origin}") + if ws.path == "/" + ws.handshake() #accept and connect + + while true + #command interpretation + message=ws.receve() + + if (message!="helo") + #module return value case + else + print_info("Browser #{ws.origin} says helo! ws is running") + end + + end + end + end + end + end + end + end + end