Added error handling to try/catch block.

This commit is contained in:
Jack Walker
2020-04-30 10:38:50 +10:00
parent 3f47d2f838
commit 5f8bf6b14a
3 changed files with 30 additions and 25 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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}")