Fixed extensions loading issue causing tests to run with previously loaded config.
This commit is contained in:
@@ -7,28 +7,87 @@
|
||||
RSpec.describe 'BeEF API Rate Limit' do
|
||||
|
||||
before(:all) do
|
||||
# Note: rake spec passes --patterns which causes BeEF to pickup this argument via optparse. I can't see a better way at the moment to filter this out. Therefore ARGV=[] for this test.
|
||||
ARGV = []
|
||||
@config = BeEF::Core::Configuration.instance
|
||||
@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 BeEF extensions and modules
|
||||
# Always load Extensions, as previous changes to the config from other tests may affect
|
||||
# whether or not this test passes.
|
||||
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!
|
||||
|
||||
# add AutoRunEngine rule
|
||||
test_rule = {"name"=>"Display an alert", "author"=>"mgeeky", "browser"=>"ALL", "browser_version"=>"ALL", "os"=>"ALL", "os_version"=>"ALL", "modules"=>[{"name"=>"alert_dialog", "condition"=>nil, "options"=>{"text"=>"You've been BeEFed ;>"}}], "execution_order"=>[0], "execution_delay"=>[0], "chain_mode"=>"sequential"}
|
||||
|
||||
BeEF::Core::AutorunEngine::RuleLoader.instance.load_directory
|
||||
# are_engine.R
|
||||
|
||||
# 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
|
||||
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
|
||||
# wait for server to start
|
||||
|
||||
# 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']
|
||||
end
|
||||
|
||||
after(:all) do
|
||||
print_info "Shutting down server"
|
||||
Process.kill("KILL",@pid)
|
||||
Process.kill("KILL",@pids)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
it 'adheres to auth rate limits' do
|
||||
passwds = (1..9).map { |i| "broken_pass"}
|
||||
passwds.push BEEF_PASSWD
|
||||
|
||||
@@ -12,7 +12,6 @@ require_relative '../../../../support/beef_test'
|
||||
RSpec.describe 'AutoRunEngine test' do
|
||||
|
||||
before(:all) do
|
||||
# Note: rake spec passes --patterns which causes BeEF to pickup this argument via optparse. I can't see a better way at the moment to filter this out. Therefore ARGV=[] for this test.
|
||||
@config = BeEF::Core::Configuration.instance
|
||||
@config.set('beef.credentials.user', "beef")
|
||||
@config.set('beef.credentials.passwd', "beef")
|
||||
@@ -20,15 +19,12 @@ RSpec.describe 'AutoRunEngine test' do
|
||||
@password = @config.get('beef.credentials.passwd')
|
||||
|
||||
# Load BeEF extensions and modules
|
||||
if @config.get('beef.extension').keys.length == 10
|
||||
print_info "Loading in BeEF::Extensions"
|
||||
BeEF::Extensions.load
|
||||
|
||||
sleep 2
|
||||
else
|
||||
print_info "Extensions already loaded"
|
||||
end
|
||||
# Always load Extensions, as previous changes to the config from other tests may affect
|
||||
# whether or not this test passes.
|
||||
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
|
||||
|
||||
@@ -18,15 +18,12 @@ RSpec.describe 'Browser details handler' do
|
||||
@password = @config.get('beef.credentials.passwd')
|
||||
|
||||
# Load BeEF extensions and modules
|
||||
if @config.get('beef.extension').keys.length == 10
|
||||
print_info "Loading in BeEF::Extensions"
|
||||
BeEF::Extensions.load
|
||||
|
||||
sleep 2
|
||||
else
|
||||
print_info "Extensions already loaded"
|
||||
end
|
||||
# Always load Extensions, as previous changes to the config from other tests may affect
|
||||
# whether or not this test passes.
|
||||
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
|
||||
|
||||
@@ -17,25 +17,21 @@ RSpec.describe 'BeEF Debug Command Modules:' do
|
||||
@username = @config.get('beef.credentials.user')
|
||||
@password = @config.get('beef.credentials.passwd')
|
||||
|
||||
# Load BeEF extensions and modules
|
||||
if @config.get('beef.extension').keys.length == 10
|
||||
print_info "Loading in BeEF::Extensions"
|
||||
BeEF::Extensions.load
|
||||
# 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.
|
||||
BeEF::Extensions.load
|
||||
sleep 2
|
||||
|
||||
sleep 2
|
||||
else
|
||||
print_info "Extensions already loaded"
|
||||
end
|
||||
# Check if modules already loaded. No need to reload.
|
||||
if @config.get('beef.module').nil?
|
||||
print_info "Loading in BeEF::Modules"
|
||||
BeEF::Modules.load
|
||||
|
||||
|
||||
if @config.get('beef.module').nil?
|
||||
BeEF::Modules.load
|
||||
print_info "Loading in BeEF::Modules"
|
||||
|
||||
sleep 2
|
||||
else
|
||||
print_info "Modules already loaded"
|
||||
end
|
||||
sleep 2
|
||||
else
|
||||
print_info "Modules already loaded"
|
||||
end
|
||||
|
||||
# Grab DB file and regenerate if requested
|
||||
print_info "Loading database"
|
||||
|
||||
Reference in New Issue
Block a user