Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
beefproject
GitHub Repository: beefproject/beef
Path: blob/master/core/modules.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 Modules
8
# Return configuration hashes of all modules that are enabled
9
# @return [Array] configuration hashes of all enabled modules
10
def self.get_enabled
11
BeEF::Core::Configuration.instance.get('beef.module').select do |_k, v|
12
v['enable'] == true && !v['category'].nil?
13
end
14
end
15
16
# Return configuration hashes of all modules that are loaded
17
# @return [Array] configuration hashes of all loaded modules
18
def self.get_loaded
19
BeEF::Core::Configuration.instance.get('beef.module').select do |_k, v|
20
v['loaded'] == true
21
end
22
end
23
24
# Return an array of categories specified in module configuration files
25
# @return [Array] all available module categories sorted alphabetically
26
def self.get_categories
27
categories = []
28
BeEF::Core::Configuration.instance.get('beef.module').each_value do |v|
29
flatcategory = ''
30
if v['category'].is_a?(Array)
31
# Therefore this module has nested categories (sub-folders),
32
# munge them together into a string with '/' characters, like a folder.
33
v['category'].each do |cat|
34
flatcategory << "#{cat}/"
35
end
36
else
37
flatcategory = v['category']
38
end
39
categories << flatcategory unless categories.include? flatcategory
40
end
41
42
# This is now uniqued, because otherwise the recursive function to build
43
# the json tree breaks if there are duplicates.
44
categories.sort.uniq
45
end
46
47
# Get all modules currently stored in the database
48
# @return [Array] DataMapper array of all BeEF::Core::Models::CommandModule's in the database
49
def self.get_stored_in_db
50
BeEF::Core::Models::CommandModule.all.order(:id)
51
end
52
53
# Loads all enabled modules
54
# @note API Fire: post_soft_load
55
def self.load
56
BeEF::Core::Configuration.instance.load_modules_config
57
get_enabled.each_key do |k|
58
BeEF::Module.soft_load k
59
end
60
BeEF::API::Registrar.instance.fire BeEF::API::Modules, 'post_soft_load'
61
end
62
end
63
end
64
65