Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
beefproject
GitHub Repository: beefproject/beef
Path: blob/master/spec/features/debug_modules_spec.rb
1154 views
1
#
2
# Copyright (c) 2006-2025 Wade Alcorn - [email protected]
3
# Browser Exploitation Framework (BeEF) - https://beefproject.com
4
# See the file 'doc/COPYING' for copying permission
5
#
6
require 'rspec'
7
require 'rest-client'
8
require 'spec/support/constants.rb'
9
require 'spec/support/ui_support.rb'
10
11
RSpec.describe 'Debug Modules Integration', run_on_long_tests: true do
12
before(:each) do
13
@pid, @beef_session, @hooked_browser = start_beef_and_hook_browser
14
end
15
16
after(:each) do
17
stop_beef_and_unhook_browser(@pid, @beef_session, @hooked_browser)
18
end
19
20
it 'Test beef.debug module' do
21
click_on_module(@beef_session, 'Debug', 'Test beef.debug')
22
expect(@beef_session).to have_content('Execute', wait: PAGE_LOAD_TIMEOUT)
23
expect(@beef_session).to have_content('244', wait: PAGE_LOAD_TIMEOUT) # Module ID
24
expect(@beef_session).to have_content('Debug Message:', wait: PAGE_LOAD_TIMEOUT)
25
end
26
27
it "Load all debug modules" do
28
Dir.glob("modules/debug/**/config.yaml").each do |file|
29
module_yaml_data = YAML.load_file(file)
30
31
module_yaml_data['beef']['module'].each do |module_key, module_value|
32
module_category = module_value['category']
33
module_name = module_value['name']
34
# some descriptions are too long and include html tags
35
module_description_sub = module_value['description'][0, 20]
36
37
expect(@beef_session).to have_content(module_category, wait: PAGE_LOAD_TIMEOUT)
38
expect(module_category).not_to be_nil
39
expect(module_category).to be_a(String)
40
expect(module_name).not_to be_nil
41
expect(module_name).to be_a(String)
42
expect(module_description_sub).not_to be_nil
43
expect(module_description_sub).to be_a(String)
44
45
click_on_module(@beef_session, 'Debug', module_name)
46
47
expect(@beef_session).to have_content(module_description_sub, wait: PAGE_LOAD_TIMEOUT)
48
expect(@beef_session).to have_content('Execute', wait: PAGE_LOAD_TIMEOUT)
49
50
# execute the module
51
@beef_session.click_on('Execute')
52
53
# expect the module to make command output visible
54
expect(@beef_session).to have_content('command 1', wait: PAGE_LOAD_TIMEOUT)
55
56
# click on the command section to display the output
57
@beef_session.all('div.x-grid3-cell-inner').each do |div|
58
if div.text == 'command 1'
59
div.click
60
break
61
end
62
end
63
64
if module_name == 'Return Image' # this module returns an image not a string
65
image_selector = "img[src^='data:image/png;base64,iVBORw0KGgo']"
66
expect(@beef_session).to have_css(image_selector, wait: PAGE_LOAD_TIMEOUT)
67
else
68
expect(@beef_session).to have_content('data: ', wait: PAGE_LOAD_TIMEOUT)
69
end
70
end
71
end
72
end
73
74
end
75