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 2d9b4dd2a..a0a9b94c5 100644 --- a/spec/beef/core/main/autorun_engine/autorun_engine_spec.rb +++ b/spec/beef/core/main/autorun_engine/autorun_engine_spec.rb @@ -90,23 +90,25 @@ RSpec.describe 'AutoRunEngine Test', :run_on_browserstack => true do # Hook new victim print_info 'Hooking a new victim, waiting a few seconds...' - @driver.navigate.to "#{VICTIM_URL}" + wait = Selenium::WebDriver::Wait.new(:timeout => 30) # seconds - sleep 1 + sleep 1 until wait.until { @driver.navigate.to "#{VICTIM_URL}" } # Give time for browser hook to occur - wait = Selenium::WebDriver::Wait.new(:timeout => 30) # seconds sleep 1 until wait.until { @driver.execute_script("return window.beef.session.get_hook_session_id().length") > 0} - if RestClient.get("#{RESTAPI_HOOKS}?token=#{@token}").code != 200 - @session = @driver.execute_script("return window.beef.session.get_hook_session_id()") - else + begin @hooks = JSON.parse(RestClient.get "#{RESTAPI_HOOKS}?token=#{@token}") if @hooks['hooked-browsers']['online'].empty? + puts @hooks['hooked-browsers']['online'] @session = @hooks['hooked-browsers']['online']['0']['session'] else @session = @driver.execute_script("return window.beef.session.get_hook_session_id()") end + rescue => exception + print_info "Encountered Exception: #{exception}" + print_info "Continuing to grab Session ID from client" + @session = @driver.execute_script("return window.beef.session.get_hook_session_id()") end end 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 94ec1a4c1..aaedcea52 100644 --- a/spec/beef/core/main/handlers/browser_details_handler_spec.rb +++ b/spec/beef/core/main/handlers/browser_details_handler_spec.rb @@ -87,17 +87,14 @@ RSpec.describe 'Browser Details Handler', :run_on_browserstack => true do # Hook new victim print_info 'Hooking a new victim, waiting a few seconds...' - @driver.navigate.to "#{VICTIM_URL}" + wait = Selenium::WebDriver::Wait.new(:timeout => 30) # seconds - sleep 1 + sleep 1 until wait.until { @driver.navigate.to "#{VICTIM_URL}" } # Give time for browser hook to occur - wait = Selenium::WebDriver::Wait.new(:timeout => 30) # seconds sleep 1 until wait.until { @driver.execute_script("return window.beef.session.get_hook_session_id().length") > 0} - if RestClient.get("#{RESTAPI_HOOKS}?token=#{@token}").code != 200 - @session = @driver.execute_script("return window.beef.session.get_hook_session_id()") - else + begin @hooks = JSON.parse(RestClient.get "#{RESTAPI_HOOKS}?token=#{@token}") if @hooks['hooked-browsers']['online'].empty? puts @hooks['hooked-browsers']['online'] @@ -105,6 +102,10 @@ RSpec.describe 'Browser Details Handler', :run_on_browserstack => true do else @session = @driver.execute_script("return window.beef.session.get_hook_session_id()") end + rescue => exception + print_info "Encountered Exception: #{exception}" + print_info "Continuing to grab Session ID from client" + @session = @driver.execute_script("return window.beef.session.get_hook_session_id()") end end diff --git a/spec/beef/modules/debug/test_beef_debugs_spec.rb b/spec/beef/modules/debug/test_beef_debugs_spec.rb index 8d2151408..bea3a46f5 100644 --- a/spec/beef/modules/debug/test_beef_debugs_spec.rb +++ b/spec/beef/modules/debug/test_beef_debugs_spec.rb @@ -86,24 +86,26 @@ RSpec.describe 'BeEF Debug Command Modules:', :run_on_browserstack => true do # Hook new victim print_info 'Hooking a new victim, waiting a few seconds...' - @driver.navigate.to "#{VICTIM_URL}" + wait = Selenium::WebDriver::Wait.new(:timeout => 30) # seconds - sleep 1 + sleep 1 until wait.until { @driver.navigate.to "#{VICTIM_URL}" } # Give time for browser hook to occur - wait = Selenium::WebDriver::Wait.new(:timeout => 30) # seconds sleep 1 until wait.until { @driver.execute_script("return window.beef.session.get_hook_session_id().length") > 0} - if RestClient.get("#{RESTAPI_HOOKS}?token=#{@token}").code != 200 - @session = @driver.execute_script("return window.beef.session.get_hook_session_id()") - else - @hooks = JSON.parse(RestClient.get "#{RESTAPI_HOOKS}?token=#{@token}") - if @hooks['hooked-browsers']['online'].empty? - @session = @hooks['hooked-browsers']['online']['0']['session'] - else - @session = @driver.execute_script("return window.beef.session.get_hook_session_id()") - end - end + begin + @hooks = JSON.parse(RestClient.get "#{RESTAPI_HOOKS}?token=#{@token}") + if @hooks['hooked-browsers']['online'].empty? + puts @hooks['hooked-browsers']['online'] + @session = @hooks['hooked-browsers']['online']['0']['session'] + else + @session = @driver.execute_script("return window.beef.session.get_hook_session_id()") + end + rescue => exception + print_info "Encountered Exception: #{exception}" + print_info "Continuing to grab Session ID from client" + @session = @driver.execute_script("return window.beef.session.get_hook_session_id()") + end # Grab Command Module IDs as they can differ from machine to machine @debug_mod_ids = JSON.parse(RestClient.get "#{RESTAPI_MODULES}?token=#{@token}")