Forced session identification to be performed client side. Server-side response too flakey atm. Cleaned up code.

This commit is contained in:
Jack Walker
2020-05-27 20:07:07 +10:00
parent f7e46c5994
commit f33dc7aec0
5 changed files with 51 additions and 52 deletions

View File

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

View File

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

View File

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

View File

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

View File

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