Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f9c630b
Update .gitignore to include secrets for local GitHub Actions testing…
zinduolis Aug 25, 2025
e93dc28
Add disconnect_all_active_record! calls before forking in multiple sp…
zinduolis Aug 25, 2025
56b3464
Comment out SERVER_START_TIMEOUT definition in spec_helper.rb
zinduolis Aug 27, 2025
1a4127c
Update Gemfile.lock to bump dependencies and add platform support
zinduolis Aug 27, 2025
180c2f2
Troubleshooting discrepancy between local tests passing and remote not
zinduolis Aug 28, 2025
418dc22
Update github_actions.yml
zinduolis Aug 28, 2025
407535d
Merge branch 'red/dev' of https://github.com/beefproject/beef into re…
zinduolis Sep 1, 2025
e394f2e
Update checkout action
zinduolis Sep 1, 2025
2494443
Testing code running in github actions
zinduolis Sep 1, 2025
dbc9fed
Revert back to the original before troubleshooting sql forking issue
zinduolis Sep 2, 2025
eecc73b
Remove testing message and improve code formatting in spec files
zinduolis Sep 3, 2025
f42fa9f
Add connection pool cleanup after each example in RSpec
zinduolis Sep 3, 2025
6d0531f
Change connection pool cleanup to run before each example in RSpec
zinduolis Sep 3, 2025
e5c8a0c
Refactor server teardown to improve error handling and cleanup process
zinduolis Sep 3, 2025
15fd00a
Refactor server start-up process in AutoRunEngine and Websocket tests…
zinduolis Sep 5, 2025
81a4caa
Refactor server start-up process in BeEF debug modules for improved c…
zinduolis Sep 6, 2025
ac6dfe5
Refactor database reset and migration handling in BeEF debug modules …
zinduolis Sep 6, 2025
5a333d4
Remove unnecessary server preparation step and ensure ActiveRecord di…
zinduolis Sep 6, 2025
f3834f7
Remove unnecessary server preparation step and ensure ActiveRecord di…
zinduolis Sep 6, 2025
41b595a
Remove unnecessary server preparation step and ensure ActiveRecord di…
zinduolis Sep 6, 2025
3df5bcb
Refactor database migration handling in browser details and websocket…
zinduolis Sep 6, 2025
c91b74e
Refactor database reset handling in AutoRunEngine and Websocket hooke…
zinduolis Sep 6, 2025
e716de7
Merge branch 'master' into red/dev
zinduolis Sep 7, 2025
31decb8
Centralised the initiation of MUTEX
zinduolis Sep 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/github_actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ jobs:
- name: 'BrowserStackLocal Stop' # Terminating the BrowserStackLocal tunnel connection
uses: browserstack/github-actions/setup-local@master
with:
local-testing: stop
local-testing: stop
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,6 @@ node_modules/
# Generated files
out/
doc/rdoc/

# Secrets for testing github actions locally
.secrets
70 changes: 49 additions & 21 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ GEM
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
ansi (1.5.0)
archive-zip (0.12.0)
io-like (~> 0.3.0)
archive-zip (0.13.1)
io-like (~> 0.4.0)
ast (2.4.3)
async (1.32.1)
console (~> 1.10)
Expand All @@ -49,7 +49,7 @@ GEM
coderay (1.1.3)
concurrent-ruby (1.3.5)
connection_pool (2.5.3)
console (1.29.2)
console (1.33.0)
fiber-annotation
fiber-local (~> 1.1)
json
Expand All @@ -71,7 +71,7 @@ GEM
fiber-annotation (0.2.0)
fiber-local (1.1.0)
fiber-storage
fiber-storage (1.0.0)
fiber-storage (1.0.1)
geckodriver-helper (0.24.0)
archive-zip (~> 0.7)
http-accept (1.7.0)
Expand All @@ -80,9 +80,9 @@ GEM
http_parser.rb (0.8.0)
i18n (1.14.7)
concurrent-ruby (~> 1.0)
io-console (0.8.0)
io-endpoint (0.15.1)
io-like (0.3.1)
io-console (0.8.1)
io-endpoint (0.15.2)
io-like (0.4.0)
irb (1.15.2)
pp (>= 0.6.0)
rdoc (>= 4.0.0)
Expand All @@ -91,29 +91,43 @@ GEM
language_server-protocol (3.17.0.5)
lint_roller (1.1.0)
logger (1.7.0)
matrix (0.4.2)
matrix (0.4.3)
maxmind-db (1.3.2)
method_source (1.1.0)
mime-types (3.7.0)
logger
mime-types-data (~> 3.2025, >= 3.2025.0507)
mime-types-data (3.2025.0520)
mime-types-data (3.2025.0819)
mini_mime (1.1.5)
minitest (5.25.5)
mojo_magick (0.6.8)
msfrpc-client (1.1.2)
msgpack (~> 1)
msgpack (1.7.5)
mustermann (3.0.3)
msgpack (1.8.0)
mustermann (3.0.4)
ruby2_keywords (~> 0.0.1)
net-protocol (0.2.2)
timeout
net-smtp (0.5.1)
net-protocol
netrc (0.11.0)
nio4r (2.7.4)
nokogiri (1.18.9-aarch64-linux-gnu)
racc (~> 1.4)
nokogiri (1.18.9-aarch64-linux-musl)
racc (~> 1.4)
nokogiri (1.18.9-arm-linux-gnu)
racc (~> 1.4)
nokogiri (1.18.9-arm-linux-musl)
racc (~> 1.4)
nokogiri (1.18.9-arm64-darwin)
racc (~> 1.4)
nokogiri (1.18.9-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.18.9-x86_64-linux-gnu)
racc (~> 1.4)
nokogiri (1.18.9-x86_64-linux-musl)
racc (~> 1.4)
otr-activerecord (2.5.0)
activerecord (>= 6.0, < 8.1)
parallel (1.27.0)
Expand All @@ -135,7 +149,7 @@ GEM
psych (5.2.6)
date
stringio
public_suffix (6.0.1)
public_suffix (6.0.2)
qr4r (0.6.2)
mojo_magick (~> 0.6.5)
rqrcode_core (~> 1.0)
Expand All @@ -152,7 +166,7 @@ GEM
erb
psych (>= 4.0.0)
regexp_parser (2.11.2)
reline (0.6.0)
reline (0.6.2)
io-console (~> 0.5)
rest-client (2.1.0)
http-accept (>= 1.7.0, < 2.0)
Expand All @@ -161,20 +175,20 @@ GEM
netrc (~> 0.8)
rexml (3.4.1)
rqrcode_core (1.2.0)
rr (3.1.1)
rr (3.1.2)
rspec (3.13.1)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
rspec-mocks (~> 3.13.0)
rspec-core (3.13.4)
rspec-core (3.13.5)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.5)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.5)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.4)
rspec-support (3.13.5)
rubocop (1.80.0)
json (~> 2.3)
language_server-protocol (~> 3.17.0.2)
Expand Down Expand Up @@ -208,12 +222,19 @@ GEM
rack-protection (= 3.2.0)
tilt (~> 2.0)
slack-notifier (2.4.0)
sqlite3 (2.7.3-aarch64-linux-gnu)
sqlite3 (2.7.3-aarch64-linux-musl)
sqlite3 (2.7.3-arm-linux-gnu)
sqlite3 (2.7.3-arm-linux-musl)
sqlite3 (2.7.3-arm64-darwin)
sqlite3 (2.7.3-x86_64-darwin)
sqlite3 (2.7.3-x86_64-linux-gnu)
sqlite3 (2.7.3-x86_64-linux-musl)
stringio (3.1.7)
sync (0.5.0)
term-ansicolor (1.11.2)
tins (~> 1.0)
test-unit (3.6.7)
test-unit (3.7.0)
power_assert
test-unit-context (0.5.1)
test-unit (>= 2.4.0)
Expand All @@ -234,10 +255,10 @@ GEM
daemons (~> 1.0, >= 1.0.9)
eventmachine (~> 1.0, >= 1.0.4)
rack (>= 1, < 3)
tilt (2.5.0)
tilt (2.6.1)
timeout (0.4.3)
timers (4.4.0)
tins (1.37.1)
tins (1.42.0)
bigdecimal
sync
tzinfo (2.0.6)
Expand All @@ -258,7 +279,14 @@ GEM
nokogiri (~> 1.8)

PLATFORMS
x86_64-linux
aarch64-linux-gnu
aarch64-linux-musl
arm-linux-gnu
arm-linux-musl
arm64-darwin
x86_64-darwin
x86_64-linux-gnu
x86_64-linux-musl

DEPENDENCIES
activerecord (~> 7.2)
Expand Down Expand Up @@ -305,4 +333,4 @@ DEPENDENCIES
xmlrpc (~> 0.3.3)

BUNDLED WITH
2.4.10
2.5.18
25 changes: 17 additions & 8 deletions spec/beef/core/main/autorun_engine/autorun_engine_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
print_info 'Loading database'
db_file = @config.get('beef.database.file')
print_info 'Resetting the database for BeEF.'
File.delete(db_file) if File.exist?(db_file)

if ENV['RESET_DB']
File.delete(db_file) if File.exist?(db_file)
end

@config.set('beef.credentials.user', 'beef')
@config.set('beef.credentials.passwd', 'beef')
Expand Down Expand Up @@ -49,9 +52,13 @@
OTR::ActiveRecord.establish_connection!
end
ActiveRecord::Migrator.migrations_paths = [File.join('core', 'main', 'ar-migrations')]
context = ActiveRecord::MigrationContext.new(ActiveRecord::Migrator.migrations_paths)
ActiveRecord::Migrator.new(:up, context.migrations, context.schema_migration, context.internal_metadata).migrate if context.needs_migration?

MUTEX.synchronize do
context = ActiveRecord::MigrationContext.new(ActiveRecord::Migrator.migrations_paths)
if context.needs_migration?
ActiveRecord::Migrator.new(:up, context.migrations, context.schema_migration, context.internal_metadata).migrate
end
end

BeEF::Core::Migration.instance.update_db!

# add AutoRunEngine rule
Expand All @@ -63,16 +70,17 @@
# 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

# ***** IMPORTANT: close any and all AR/OTR connections before forking *****
disconnect_all_active_record!

# 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.prepare
BeEF::API::Registrar.instance.fire(BeEF::API::Server, 'pre_http_start', http_hook_server)
http_hook_server.start
end

Expand Down Expand Up @@ -101,6 +109,7 @@

after(:all) do
server_teardown(@driver, @pid, @pids)
disconnect_all_active_record!
end

it 'AutoRunEngine is working' do
Expand Down
25 changes: 17 additions & 8 deletions spec/beef/core/main/handlers/browser_details_handler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
@config = BeEF::Core::Configuration.instance
db_file = @config.get('beef.database.file')
print_info 'Resetting the database for BeEF.'
File.delete(db_file) if File.exist?(db_file)

if ENV['RESET_DB']
File.delete(db_file) if File.exist?(db_file)
end

@config.set('beef.credentials.user', 'beef')
@config.set('beef.credentials.passwd', 'beef')
@username = @config.get('beef.credentials.user')
Expand Down Expand Up @@ -50,24 +54,28 @@

# Migrate (if required)
ActiveRecord::Migrator.migrations_paths = [File.join('core', 'main', 'ar-migrations')]
context = ActiveRecord::MigrationContext.new(ActiveRecord::Migrator.migrations_paths)
ActiveRecord::Migrator.new(:up, context.migrations, context.schema_migration, context.internal_metadata).migrate if context.needs_migration?

MUTEX.synchronize do
context = ActiveRecord::MigrationContext.new(ActiveRecord::Migrator.migrations_paths)
if context.needs_migration?
ActiveRecord::Migrator.new(:up, context.migrations, context.schema_migration, context.internal_metadata).migrate
end
end
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

# ***** IMPORTANT: close any and all AR/OTR connections before forking *****
disconnect_all_active_record!

# 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.prepare
BeEF::API::Registrar.instance.fire(BeEF::API::Server, 'pre_http_start', http_hook_server)
http_hook_server.start
end

Expand Down Expand Up @@ -97,6 +105,7 @@

after(:all) do
server_teardown(@driver, @pid, @pids)
disconnect_all_active_record!
end

it 'can successfully hook a browser' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
@server = Thin::Server.new('127.0.0.1', @port.to_s, @rackApp)
trap("INT") { @server.stop }
trap("TERM") { @server.stop }

# ***** IMPORTANT: close any and all AR/OTR connections before forking *****
disconnect_all_active_record!

@pid = fork do
@server.start!
end
Expand Down
5 changes: 5 additions & 0 deletions spec/beef/core/main/network_stack/handlers/redirector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
@server = Thin::Server.new('127.0.0.1', @port.to_s, @rackApp)
trap("INT") { @server.stop }
trap("TERM") { @server.stop }


# ***** IMPORTANT: close any and all AR/OTR connections before forking *****
disconnect_all_active_record!

@pid = fork do
@server.start!
end
Expand Down
Loading
Loading