Merged Josh's fix for the websocket hook test.
This commit is contained in:
@@ -88,6 +88,6 @@ addons:
|
||||
- libcurl4-openssl-dev
|
||||
browserstack:
|
||||
username:
|
||||
secure: "ricyJO2L+faqddj2o3+j7NjYNFERxSD2xtc9Lo3GcuFhwpJHix2GcxvSrE9Agze2dUdkvUQAqh2wcbZu69Qlx8hKgr9Didg8AyxBV5IZYJwyqb6H+Z0MjIgMQmaLnvJosJGkT86yBLo0WVxJKFBxOkZfxk8ts0yReJEKDc61JmSAo2Bdl3W+imcYQL28sI3E8VK//ufhC3FiPPlgreKTSmksN7eqDcDTek0mGRlQjBsVn0y3NJIOLWlubKgWy67QIYD66R+uu2Oz+4TntMZ5UrsUlH5RJuNTgqv451HqVjkTrbFwt/2EKAdbDfRIq+zPRhRfLUan0XUSrAf+1WGTklE+c2LpeVR5UI8A4Y8HDN1KoVEZdpC1ItM0nLRk6vVbsJPLzW1mnhcQ7uMn7pHEK/xhHk6qf2sern/MGlX1YDased9RIacZOkBRKka/lPKa64hukvNvIHUCx5nnr67Usy3LR18i5anM2zzFdRLGdm4ABYThZuWRDTh2chyxuPBzLB3DcuN5sOCZLfbl1H9nR3w7QvbwZKV6O9oak+vIVQvb9qVssh0p0GaHc83Ruzx0HTUD6Pl5yDUjV3oK+iy36KYpUfJpQzkuqwyxxwuj8Np71V1AhOFwQr3jERjF7uOS4BGSsDfJj9BrtJVWXcPc20rbRab3GakZhkOI0pKQpAs="
|
||||
secure: "iAMhXloUy1qzn2mmUHWtbnuLQpoKL42VGpghC47Gu5gTpcfSeHGKKPE4y2ZWQ1piu3yzGeDhP8jaW03DPYye/bjaVbH60RHLAaoIAcFypX4ryPmr3Z5+wpky8RQQy34t4prFX1LURf7z2NQKmlkpT0Gvgus7sqLbuojWJeFyERQ1qJ5esbXEndDFYR7qbI/UKXyQAJ8uK62O44+GfHUXiKlcXJvI8VFUMWAmvoys4bu5y56K0dQbilUKwlSBebU28vjd7FZqzgz/xy0P1G3pwSJm2VTJlhQKggu3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+1r1S9gGvJfaNOvdACpalzb9XKv7rA="
|
||||
secure: "qoDu6CKFgiPY9jQXNQ/XJ30x9sX2vfZ+KPca76sH0ELrSPw/rQDtC7L7w/NjwLxtgcGjxhfRL3uSqN8CZjCrxDUV5GKu/hWf4LXqzJqctXO7WFpC+YW7oPDhpKueJ4unAlQ68JKOrouHOcL3ZHoDLhAdQLJCVrbyq7hG/syNlOFvEFCrBN3exd+/NuVWE8NmuKTaONqsnD48hujvrAeNNmedZ3XQ3Wq/a08B/qiCrhTnVqSc9U9xTFGmvPAPwTXydT19gbsVoXt6fQpoWwaOiMe7zfkgW6OkeOye1Fg92G2lWJurVkgqECvC0mx9Z06SdHs5488mtDh0qhVWaCZea22iTAW4iPtGJrdquShLZJIMeQw8LqZPZXYfETb67cNL255t9AiAdKfUvUSk2R+cGNzHJH5ZdhxOUzDTvJsy0NL198/VhlVX/itcojl0bAbynQlhr2EALfPvl0TCvffKDig0vRmbXgvRt5M2crSeIy5UoESOUDOG5FHWrHKoYErdi58fiVbf8Ad38C4f8vqwqFHSnHkSQq+oTp0IndCH0N73PrrvTNHcBzwPGJU7l+0mQqd4tGbaEFnzMT3zkaC5f1/oRqRrdbEpOlRVkbIeIM3BrRVnC7O7C8aDnrJ6rOfNYHst7gp9sfx4hYmJcmZm0RAYnP7ObpWYJUi5a2lYipU="
|
||||
@@ -22,13 +22,13 @@ RSpec.describe 'Browser Details Handler', :run_on_browserstack => true do
|
||||
# whether or not this test passes.
|
||||
print_info "Loading in BeEF::Extensions"
|
||||
BeEF::Extensions.load
|
||||
|
||||
sleep 2
|
||||
|
||||
# Check if modules already loaded. No need to reload.
|
||||
if @config.get('beef.module').nil?
|
||||
print_info "Loading in BeEF::Modules"
|
||||
BeEF::Modules.load
|
||||
|
||||
sleep 2
|
||||
else
|
||||
print_info "Modules already loaded"
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
|
||||
|
||||
#
|
||||
# Copyright (c) 2006-2020 Wade Alcorn - wade@bindshell.net
|
||||
# Browser Exploitation Framework (BeEF) - http://beefproject.com
|
||||
@@ -12,94 +14,115 @@ require_relative '../../support/beef_test'
|
||||
require 'core/main/network_stack/websocket/websocket'
|
||||
require 'websocket-client-simple'
|
||||
|
||||
RSpec.describe 'BeEF WebSockets: Browser Hooking', :run_on_browserstack => true do
|
||||
|
||||
before(:all) do
|
||||
@config = BeEF::Core::Configuration.instance
|
||||
@cert_key = @config.get('beef.http.https.key')
|
||||
@cert = @config.get('beef.http.https.cert')
|
||||
@port = @config.get('beef.http.websocket.port')
|
||||
@secure_port = @config.get('beef.http.websocket.secure_port')
|
||||
@config.set('beef.http.websocket.secure', true)
|
||||
RSpec.describe 'Browser hooking with Websockets', :run_on_browserstack => true do
|
||||
before(:all) do
|
||||
@config = BeEF::Core::Configuration.instance
|
||||
@config.set('beef.credentials.user', "beef")
|
||||
@config.set('beef.credentials.passwd', "beef")
|
||||
@config.set('beef.http.websocket.secure', false)
|
||||
@config.set('beef.http.websocket.enable', true)
|
||||
#set config parameters
|
||||
@config.set('beef.credentials.user', "beef")
|
||||
@config.set('beef.credentials.passwd', "beef")
|
||||
@username = @config.get('beef.credentials.user')
|
||||
@password = @config.get('beef.credentials.passwd')
|
||||
#load extensions, best practice is to reload as previous tests can potentially cause issues.
|
||||
print_info "Loading in BeEF::Extensions"
|
||||
BeEF::Extensions.load
|
||||
sleep 2
|
||||
if @config.get('beef.module').nil?
|
||||
puts "loading modules"
|
||||
BeEF::Modules.load
|
||||
sleep 2
|
||||
end
|
||||
#generate token for the api to use
|
||||
@token = BeEF::Core::Crypto::api_token
|
||||
# load up DB
|
||||
# Connect to DB
|
||||
ActiveRecord::Base.logger = nil
|
||||
OTR::ActiveRecord.migrations_paths = [File.join('core', 'main', 'ar-migrations')]
|
||||
OTR::ActiveRecord.configure_from_hash!(adapter:'sqlite3', database:'beef.db')
|
||||
|
||||
# Migrate (if required)
|
||||
context = ActiveRecord::Migration.new.migration_context
|
||||
if context.needs_migration?
|
||||
puts "migrating db"
|
||||
ActiveRecord::Migrator.new(:up, context.migrations, context.schema_migration).migrate
|
||||
end
|
||||
#start the hook server instance, for it out to track the pids for graceful closure
|
||||
http_hook_server = BeEF::Core::Server.instance
|
||||
http_hook_server.prepare
|
||||
@pids = fork do
|
||||
BeEF::API::Registrar.instance.fire(BeEF::API::Server, 'pre_http_start', http_hook_server)
|
||||
end
|
||||
@pid = fork do
|
||||
http_hook_server.start
|
||||
end
|
||||
# wait for server to start
|
||||
sleep 1
|
||||
@ws = BeEF::Core::Websocket::Websocket.instance
|
||||
@username = @config.get('beef.credentials.user')
|
||||
@password = @config.get('beef.credentials.passwd')
|
||||
# Load BeEF extensions and modules
|
||||
# Always load Extensions, as previous changes to the config from other tests may affect
|
||||
# whether or not this test passes.
|
||||
print_info "Loading in BeEF::Extensions"
|
||||
BeEF::Extensions.load
|
||||
sleep 2
|
||||
|
||||
# Check if modules already loaded. No need to reload.
|
||||
if @config.get('beef.module').nil?
|
||||
print_info "Loading in BeEF::Modules"
|
||||
BeEF::Modules.load
|
||||
sleep 2
|
||||
else
|
||||
print_info "Modules already loaded"
|
||||
end
|
||||
# Grab DB file and regenerate if requested
|
||||
print_info "Loading database"
|
||||
db_file = @config.get('beef.database.file')
|
||||
if BeEF::Core::Console::CommandLine.parse[:resetdb]
|
||||
print_info 'Resetting the database for BeEF.'
|
||||
File.delete(db_file) if File.exists?(db_file)
|
||||
end
|
||||
# Load up DB and migrate if necessary
|
||||
ActiveRecord::Base.logger = nil
|
||||
OTR::ActiveRecord.migrations_paths = [File.join('core', 'main', 'ar-migrations')]
|
||||
OTR::ActiveRecord.configure_from_hash!(adapter:'sqlite3', database: db_file)
|
||||
context = ActiveRecord::Migration.new.migration_context
|
||||
if context.needs_migration?
|
||||
ActiveRecord::Migrator.new(:up, context.migrations, context.schema_migration).migrate
|
||||
end
|
||||
sleep 2
|
||||
BeEF::Core::Migration.instance.update_db!
|
||||
# Spawn HTTP Server
|
||||
print_info "Starting HTTP Hook Server"
|
||||
http_hook_server = BeEF::Core::Server.instance
|
||||
http_hook_server.prepare
|
||||
# Generate a token for the server to respond with
|
||||
@token = BeEF::Core::Crypto::api_token
|
||||
# Initiate server start-up
|
||||
@pids = fork do
|
||||
BeEF::API::Registrar.instance.fire(BeEF::API::Server, 'pre_http_start', http_hook_server)
|
||||
end
|
||||
@pid = fork do
|
||||
http_hook_server.start
|
||||
end
|
||||
# Give the server time to start-up
|
||||
sleep 1
|
||||
@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["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...'
|
||||
@driver.navigate.to "#{VICTIM_URL}"
|
||||
puts @driver.current_url
|
||||
|
||||
# Give time for browser hook to occur
|
||||
sleep 3.5
|
||||
end
|
||||
sleep 3
|
||||
|
||||
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
|
||||
|
||||
after(:all) do
|
||||
after(:all) do
|
||||
@driver.quit
|
||||
|
||||
# cleanup: delete test browser entries and session
|
||||
# kill the server
|
||||
@config.set('beef.http.websocket.enable', false)
|
||||
Process.kill("KILL", @pid)
|
||||
Process.kill("KILL", @pids)
|
||||
puts "waiting for server to die.."
|
||||
print_info "Shutting down server"
|
||||
Process.kill("KILL",@pid)
|
||||
Process.kill("KILL",@pids)
|
||||
end
|
||||
|
||||
it 'confirms a websocket server has been started' do
|
||||
expect(@ws).to be_a_kind_of(BeEF::Core::Websocket::Websocket)
|
||||
end
|
||||
|
||||
xit 'can hook a browser with websockets' do
|
||||
#prepare for the HTTP model
|
||||
https = BeEF::Core::Models::Http
|
||||
|
||||
@hooks = JSON.parse(RestClient.get "#{RESTAPI_HOOKS}?token=#{@token}")
|
||||
@session = @hooks['hooked-browsers']['online']
|
||||
|
||||
expect(@session).not_to be_empty
|
||||
|
||||
https.where(:hooked_browser_id => @session['0']['session']).delete_all
|
||||
it 'confirms a secure websocket server has been started' do
|
||||
@config.set('beef.http.websocket.secure', true)
|
||||
wss = BeEF::Core::Websocket::Websocket.instance
|
||||
expect(wss).to be_a_kind_of(BeEF::Core::Websocket::Websocket)
|
||||
end
|
||||
|
||||
it 'can successfully hook a browser' do
|
||||
if @hooks['hooked-browsers']['online'].empty?
|
||||
expect(BeEF::Filters.is_valid_hook_session_id?(@driver.execute_script("return window.beef.session.get_hook_session_id()"))).to eq true
|
||||
else
|
||||
expect(@hooks['hooked-browsers']['online']).not_to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user