Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
beefproject
GitHub Repository: beefproject/beef
Path: blob/master/core/extension.rb
1146 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
module BeEF
7
module Extension
8
# Checks to see if extension is set inside the configuration
9
# @param [String] ext the extension key
10
# @return [Boolean] whether or not the extension exists in BeEF's configuration
11
def self.is_present(ext)
12
BeEF::Core::Configuration.instance.get('beef.extension').key? ext.to_s
13
end
14
15
# Checks to see if extension is enabled in configuration
16
# @param [String] ext the extension key
17
# @return [Boolean] whether or not the extension is enabled
18
def self.is_enabled(ext)
19
return false unless is_present(ext)
20
21
BeEF::Core::Configuration.instance.get("beef.extension.#{ext}.enable") == true
22
end
23
24
# Checks to see if extension has been loaded
25
# @param [String] ext the extension key
26
# @return [Boolean] whether or not the extension is loaded
27
def self.is_loaded(ext)
28
return false unless is_enabled(ext)
29
30
BeEF::Core::Configuration.instance.get("beef.extension.#{ext}.loaded") == true
31
end
32
33
# Loads an extension
34
# @param [String] ext the extension key
35
# @return [Boolean] whether or not the extension loaded successfully
36
def self.load(ext)
37
if File.exist? "#{$root_dir}/extensions/#{ext}/extension.rb"
38
require "#{$root_dir}/extensions/#{ext}/extension.rb"
39
print_debug "Loaded extension: '#{ext}'"
40
BeEF::Core::Configuration.instance.set "beef.extension.#{ext}.loaded", true
41
return true
42
end
43
print_error "Unable to load extension '#{ext}'"
44
false
45
rescue StandardError => e
46
print_error "Unable to load extension '#{ext}':"
47
print_more e.message
48
end
49
end
50
end
51
52