From f33dc7aec0bcf076fc68ea2fdf57fac96cc179e5 Mon Sep 17 00:00:00 2001 From: Jack Walker Date: Wed, 27 May 2020 20:07:07 +1000 Subject: [PATCH] Forced session identification to be performed client side. Server-side response too flakey atm. Cleaned up code. --- .../autorun_engine/autorun_engine_spec.rb | 39 +++++++++---------- .../handlers/browser_details_handler_spec.rb | 6 +-- .../websocket_hooked_browser_spec.rb | 37 +++++++++--------- .../modules/debug/test_beef_debugs_spec.rb | 20 +++++----- spec/spec_helper.rb | 1 + 5 files changed, 51 insertions(+), 52 deletions(-) diff --git a/spec/beef/core/main/autorun_engine/autorun_engine_spec.rb b/spec/beef/core/main/autorun_engine/autorun_engine_spec.rb index f67e74928..a110cca17 100644 --- a/spec/beef/core/main/autorun_engine/autorun_engine_spec.rb +++ b/spec/beef/core/main/autorun_engine/autorun_engine_spec.rb @@ -81,39 +81,38 @@ RSpec.describe 'AutoRunEngine Test', run_on_browserstack: true do sleep 1 begin - @caps = CONFIG['common_caps'].merge(CONFIG['browser_caps'][TASK_ID]) - @caps['name'] = self.class.description || ENV['name'] || 'no-name' - @caps['browserstack.local'] = true - @caps['browserstack.localIdentifier'] = ENV['BROWSERSTACK_LOCAL_IDENTIFIER'] + @caps = CONFIG['common_caps'].merge(CONFIG['browser_caps'][TASK_ID]) + @caps['name'] = self.class.description || ENV['name'] || 'no-name' + @caps['browserstack.local'] = true + @caps['browserstack.localIdentifier'] = ENV['BROWSERSTACK_LOCAL_IDENTIFIER'] - @driver = Selenium::WebDriver.for(:remote, - url: "http://#{CONFIG['user']}:#{CONFIG['key']}@#{CONFIG['server']}/wd/hub", - desired_capabilities: @caps) - # Hook new victim - print_info 'Hooking a new victim, waiting a few seconds...' - wait = Selenium::WebDriver::Wait.new(timeout: 30) # seconds + @driver = Selenium::WebDriver.for(:remote, + url: "http://#{CONFIG['user']}:#{CONFIG['key']}@#{CONFIG['server']}/wd/hub", + desired_capabilities: @caps) + # Hook new victim + print_info 'Hooking a new victim, waiting a few seconds...' + wait = Selenium::WebDriver::Wait.new(timeout: 30) # seconds - @driver.navigate.to VICTIM_URL.to_s + @driver.navigate.to VICTIM_URL.to_s - # Give time for browser hook to occur - sleep 3 + # Give time for browser hook to occur + sleep 3 - sleep 1 until wait.until { @driver.execute_script('return window.beef.session.get_hook_session_id().length') > 0 } + sleep 1 until wait.until { @driver.execute_script('return window.beef.session.get_hook_session_id().length') > 0 } - @hook_request = RestClient.get "#{RESTAPI_HOOKS}?token=#{@token}" - @hooks = JSON.parse(@hook_request) + @session = @driver.execute_script('return window.beef.session.get_hook_session_id()') rescue StandardError => e print_info "Exception: #{e}" print_info "Exception Class: #{e.class}" print_info "Exception Message: #{e.message}" - print_info "Exception Stack Trace: #{e.stacktrace}" + print_info "Exception Stack Trace: #{e.backtrace}" if @driver.execute_script('return window.beef.session.get_hook_session_id().length').nil? && e.class == NoMethodError exit 1 else exit 0 end - end + end end after(:all) do @@ -121,12 +120,12 @@ RSpec.describe 'AutoRunEngine Test', run_on_browserstack: true do end it 'AutoRunEngine is working' do - expect(@hooks['hooked-browsers']['online']).not_to be_empty + expect(@session).not_to be_nil rescue StandardError => e print_info "Exception: #{e}" print_info "Exception Class: #{e.class}" print_info "Exception Message: #{e.message}" - print_info "Exception Stack Trace: #{e.stacktrace}" + print_info "Exception Stack Trace: #{e.backtrace}" if @driver.execute_script('return window.beef.session.get_hook_session_id().length').nil? && e.class == NoMethodError exit 1 diff --git a/spec/beef/core/main/handlers/browser_details_handler_spec.rb b/spec/beef/core/main/handlers/browser_details_handler_spec.rb index d58dc1f69..7c28334ac 100644 --- a/spec/beef/core/main/handlers/browser_details_handler_spec.rb +++ b/spec/beef/core/main/handlers/browser_details_handler_spec.rb @@ -114,12 +114,12 @@ RSpec.describe 'Browser Details Handler', run_on_browserstack: true do end it 'can successfully hook a browser' do - expect(@hooks['hooked-browsers']['online']).not_to be_empty + expect(@session).not_to be_nil rescue StandardError => e print_info "Exception: #{e}" print_info "Exception Class: #{e.class}" print_info "Exception Message: #{e.message}" - print_info "Exception Stack Trace: #{e.stacktrace}" + print_info "Exception Stack Trace: #{e.backtrace}" if @driver.execute_script('return window.beef.session.get_hook_session_id().length').nil? && e.class == NoMethodError exit 1 @@ -144,7 +144,7 @@ RSpec.describe 'Browser Details Handler', run_on_browserstack: true do print_info "Exception: #{e}" print_info "Exception Class: #{e.class}" print_info "Exception Message: #{e.message}" - print_info "Exception Stack Trace: #{e.stacktrace}" + print_info "Exception Stack Trace: #{e.backtrace}" exit 0 end end diff --git a/spec/beef/extensions/websocket_hooked_browser_spec.rb b/spec/beef/extensions/websocket_hooked_browser_spec.rb index 210579356..28bf2dbf8 100644 --- a/spec/beef/extensions/websocket_hooked_browser_spec.rb +++ b/spec/beef/extensions/websocket_hooked_browser_spec.rb @@ -68,39 +68,38 @@ RSpec.describe 'Browser hooking with Websockets', run_on_browserstack: true do # Give the server time to start-up sleep 1 begin - @caps = CONFIG['common_caps'].merge(CONFIG['browser_caps'][TASK_ID]) - @caps['name'] = self.class.description || ENV['name'] || 'no-name' - @caps['browserstack.local'] = true - @caps['browserstack.localIdentifier'] = ENV['BROWSERSTACK_LOCAL_IDENTIFIER'] + @caps = CONFIG['common_caps'].merge(CONFIG['browser_caps'][TASK_ID]) + @caps['name'] = self.class.description || ENV['name'] || 'no-name' + @caps['browserstack.local'] = true + @caps['browserstack.localIdentifier'] = ENV['BROWSERSTACK_LOCAL_IDENTIFIER'] - @driver = Selenium::WebDriver.for(:remote, - url: "http://#{CONFIG['user']}:#{CONFIG['key']}@#{CONFIG['server']}/wd/hub", - desired_capabilities: @caps) - # Hook new victim - print_info 'Hooking a new victim, waiting a few seconds...' - wait = Selenium::WebDriver::Wait.new(timeout: 30) # seconds + @driver = Selenium::WebDriver.for(:remote, + url: "http://#{CONFIG['user']}:#{CONFIG['key']}@#{CONFIG['server']}/wd/hub", + desired_capabilities: @caps) + # Hook new victim + print_info 'Hooking a new victim, waiting a few seconds...' + wait = Selenium::WebDriver::Wait.new(timeout: 30) # seconds - @driver.navigate.to VICTIM_URL.to_s + @driver.navigate.to VICTIM_URL.to_s - # Give time for browser hook to occur - sleep 3 + # Give time for browser hook to occur + sleep 3 - sleep 1 until wait.until { @driver.execute_script('return window.beef.session.get_hook_session_id().length') > 0 } + sleep 1 until wait.until { @driver.execute_script('return window.beef.session.get_hook_session_id().length') > 0 } - @hook_request = RestClient.get "#{RESTAPI_HOOKS}?token=#{@token}" - @hooks = JSON.parse(@hook_request) + @session = @driver.execute_script('return window.beef.session.get_hook_session_id().length') rescue StandardError => e print_info "Exception: #{e}" print_info "Exception Class: #{e.class}" print_info "Exception Message: #{e.message}" - print_info "Exception Stack Trace: #{e.stacktrace}" + print_info "Exception Stack Trace: #{e.backtrace}" if @driver.execute_script('return window.beef.session.get_hook_session_id().length').nil? && e.class == NoMethodError exit 1 else exit 0 end - end + end end after(:all) do @@ -118,7 +117,7 @@ RSpec.describe 'Browser hooking with Websockets', run_on_browserstack: true do end it 'can successfully hook a browser' do - expect(@hooks['hooked-browsers']['online']).not_to be_empty + expect(@session).not_to be_nil rescue StandardError => e print_info "Exception: #{e}" print_info "Exception Class: #{e.class}" diff --git a/spec/beef/modules/debug/test_beef_debugs_spec.rb b/spec/beef/modules/debug/test_beef_debugs_spec.rb index b950e72a7..6577325e9 100644 --- a/spec/beef/modules/debug/test_beef_debugs_spec.rb +++ b/spec/beef/modules/debug/test_beef_debugs_spec.rb @@ -107,7 +107,7 @@ RSpec.describe 'BeEF Debug Command Modules:', run_on_browserstack: true do print_info "Exception: #{e}" print_info "Exception Class: #{e.class}" print_info "Exception Message: #{e.message}" - print_info "Exception Stack Trace: #{e.stacktrace}" + print_info "Exception Stack Trace: #{e.backtrace}" if @driver.execute_script('return window.beef.session.get_hook_session_id().length').nil? && e.class == NoMethodError exit 1 @@ -132,7 +132,7 @@ RSpec.describe 'BeEF Debug Command Modules:', run_on_browserstack: true do print_info "Exception: #{e}" print_info "Exception Class: #{e.class}" print_info "Exception Message: #{e.message}" - print_info "Exception Stack Trace: #{e.stacktrace}" + print_info "Exception Stack Trace: #{e.backtrace}" if @driver.execute_script('return window.beef.session.get_hook_session_id().length').nil? && e.class == NoMethodError exit 1 @@ -152,7 +152,7 @@ RSpec.describe 'BeEF Debug Command Modules:', run_on_browserstack: true do print_info "Exception: #{e}" print_info "Exception Class: #{e.class}" print_info "Exception Message: #{e.message}" - print_info "Exception Stack Trace: #{e.stacktrace}" + print_info "Exception Stack Trace: #{e.backtrace}" if @driver.execute_script('return window.beef.session.get_hook_session_id().length').nil? && e.class == NoMethodError exit 1 @@ -172,7 +172,7 @@ RSpec.describe 'BeEF Debug Command Modules:', run_on_browserstack: true do print_info "Exception: #{e}" print_info "Exception Class: #{e.class}" print_info "Exception Message: #{e.message}" - print_info "Exception Stack Trace: #{e.stacktrace}" + print_info "Exception Stack Trace: #{e.backtrace}" if @driver.execute_script('return window.beef.session.get_hook_session_id().length').nil? && e.class == NoMethodError exit 1 @@ -192,7 +192,7 @@ RSpec.describe 'BeEF Debug Command Modules:', run_on_browserstack: true do print_info "Exception: #{e}" print_info "Exception Class: #{e.class}" print_info "Exception Message: #{e.message}" - print_info "Exception Stack Trace: #{e.stacktrace}" + print_info "Exception Stack Trace: #{e.backtrace}" if @driver.execute_script('return window.beef.session.get_hook_session_id().length').nil? && e.class == NoMethodError exit 1 @@ -213,8 +213,8 @@ RSpec.describe 'BeEF Debug Command Modules:', run_on_browserstack: true do print_info "Exception: #{e}" print_info "Exception Class: #{e.class}" print_info "Exception Message: #{e.message}" - print_info "Exception Stack Trace: #{e.stacktrace}" - print_info "Exception Message: #{e.stacktrace}" + print_info "Exception Stack Trace: #{e.backtrace}" + print_info "Exception Message: #{e.backtrace}" if @driver.execute_script('return window.beef.session.get_hook_session_id().length').nil? && e.class == NoMethodError exit 1 @@ -242,7 +242,7 @@ RSpec.describe 'BeEF Debug Command Modules:', run_on_browserstack: true do print_info "Exception: #{e}" print_info "Exception Class: #{e.class}" print_info "Exception Message: #{e.message}" - print_info "Exception Stack Trace: #{e.stacktrace}" + print_info "Exception Stack Trace: #{e.backtrace}" if @driver.execute_script('return window.beef.session.get_hook_session_id().length').nil? && e.class == NoMethodError exit 1 @@ -263,7 +263,7 @@ RSpec.describe 'BeEF Debug Command Modules:', run_on_browserstack: true do print_info "Exception: #{e}" print_info "Exception Class: #{e.class}" print_info "Exception Message: #{e.message}" - print_info "Exception Stack Trace: #{e.stacktrace}" + print_info "Exception Stack Trace: #{e.backtrace}" if @driver.execute_script('return window.beef.session.get_hook_session_id().length').nil? && e.class == NoMethodError exit 1 @@ -287,7 +287,7 @@ RSpec.describe 'BeEF Debug Command Modules:', run_on_browserstack: true do print_info "Exception: #{e}" print_info "Exception Class: #{e.class}" print_info "Exception Message: #{e.message}" - print_info "Exception Stack Trace: #{e.stacktrace}" + print_info "Exception Stack Trace: #{e.backtrace}" if @driver.execute_script('return window.beef.session.get_hook_session_id().length').nil? && e.class == NoMethodError exit 1 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 988ccd3dd..78c374796 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -76,6 +76,7 @@ RSpec.configure do |config| print_info "Exception: #{exception}" print_info "Exception Class: #{exception.class}" print_info "Exception Message: #{exception.message}" + print_info "Exception Stack Trace: #{exception.backtrace}" exit 0 ensure print_info "Shutting down server"