From 3d2678212549a5d056290c79e0bde43e7c1c556e Mon Sep 17 00:00:00 2001 From: Nikolaos Anastopoulos Date: Fri, 23 Mar 2012 15:09:46 +0200 Subject: [PATCH 1/2] Added public port setting to server configuration --- config.yaml | 1 + core/main/handlers/modules/beefjs.rb | 6 ++++++ core/main/server.rb | 5 ++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/config.yaml b/config.yaml index 679d183f6..d01fd3649 100644 --- a/config.yaml +++ b/config.yaml @@ -32,6 +32,7 @@ beef: port: "3000" # if running behind a nat set the public ip address here #public: "" + #public_port: "" dns: "localhost" panel_path: "/ui/panel" hook_file: "/hook.js" diff --git a/core/main/handlers/modules/beefjs.rb b/core/main/handlers/modules/beefjs.rb index a43fc5674..054a047e1 100644 --- a/core/main/handlers/modules/beefjs.rb +++ b/core/main/handlers/modules/beefjs.rb @@ -48,6 +48,12 @@ module Modules hook_session_config['beef_url'].sub!(/0\.0\.0\.0/, req_host) end + # @note if http_port <> public_port in config ini, use the public_port + if hook_session_config['beef_port'] != hook_session_config['beef_public_port'] + hook_session_config['beef_port'] = hook_session_config['beef_public_port'] + hook_session_config['beef_url'].sub!(/#{hook_session_config['beef_port']}/, hook_session_config['beef_public_port']) + end + # @note populate place holders in the beefjs string and set the response body eruby = Erubis::FastEruby.new(beefjs) @body << eruby.evaluate(hook_session_config) diff --git a/core/main/server.rb b/core/main/server.rb index e47eb1fd1..b29a78665 100644 --- a/core/main/server.rb +++ b/core/main/server.rb @@ -29,7 +29,8 @@ module BeEF def initialize @configuration = BeEF::Core::Configuration.instance beef_host = @configuration.get("beef.http.public") || @configuration.get("beef.http.host") - @url = "http://#{beef_host}:#{@configuration.get("beef.http.port")}" + beef_port = @configuration.get("beef.http.public_port") || @configuration.get("beef.http.port") + @url = "http://#{beef_host}:#{beef_port}" @root_dir = File.expand_path('../../../', __FILE__) @command_urls = {} @mounts = {} @@ -44,6 +45,8 @@ module BeEF 'beef_root_dir' => @root_dir, 'beef_host' => @configuration.get('beef.http.host'), 'beef_port' => @configuration.get('beef.http.port'), + 'beef_public' => @configuration.get('beef.http.public'), + 'beef_public_port' => @configuration.get('beef.http.public_port'), 'beef_dns' => @configuration.get('beef.http.dns'), 'beef_hook' => @configuration.get('beef.http.hook_file') } From e4d4edba7524e96d3f5ed0acf4431cc00b281b7b Mon Sep 17 00:00:00 2001 From: Nikolaos Anastopoulos Date: Fri, 23 Mar 2012 20:42:12 +0200 Subject: [PATCH 2/2] Public port setting affects URI scheme --- config.yaml | 2 +- core/main/client/net.js | 2 +- core/main/handlers/modules/beefjs.rb | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/config.yaml b/config.yaml index d01fd3649..21f5acc9e 100644 --- a/config.yaml +++ b/config.yaml @@ -32,7 +32,7 @@ beef: port: "3000" # if running behind a nat set the public ip address here #public: "" - #public_port: "" + #public_port: "" dns: "localhost" panel_path: "/ui/panel" hook_file: "/hook.js" diff --git a/core/main/client/net.js b/core/main/client/net.js index b5340d472..0d1e97f45 100644 --- a/core/main/client/net.js +++ b/core/main/client/net.js @@ -124,7 +124,7 @@ beef.net = { push: function(stream) { //need to implement wait feature here eventually for (var i = 0; i < stream.pc; i++) { - this.request('http', 'GET', this.host, this.port, this.handler, null, stream.get_packet_data(), 10, 'text', null); + this.request(this.port == '443' ? 'https' : 'http', 'GET', this.host, this.port, this.handler, null, stream.get_packet_data(), 10, 'text', null); } }, diff --git a/core/main/handlers/modules/beefjs.rb b/core/main/handlers/modules/beefjs.rb index 054a047e1..0d9572a99 100644 --- a/core/main/handlers/modules/beefjs.rb +++ b/core/main/handlers/modules/beefjs.rb @@ -51,7 +51,10 @@ module Modules # @note if http_port <> public_port in config ini, use the public_port if hook_session_config['beef_port'] != hook_session_config['beef_public_port'] hook_session_config['beef_port'] = hook_session_config['beef_public_port'] - hook_session_config['beef_url'].sub!(/#{hook_session_config['beef_port']}/, hook_session_config['beef_public_port']) + hook_session_config['beef_url'].sub!(/#{hook_session_config['beef_port']}/, hook_session_config['beef_public_port']) + if hook_session_config['beef_public_port'] == '443' + hook_session_config['beef_url'].sub!(/http:/, 'https:') + end end # @note populate place holders in the beefjs string and set the response body