#1# Copyright (c) 2006-2025 Wade Alcorn - [email protected]2# Browser Exploitation Framework (BeEF) - https://beefproject.com3# See the file 'doc/COPYING' for copying permission4#5module BeEF6module Modules7# Return configuration hashes of all modules that are enabled8# @return [Array] configuration hashes of all enabled modules9def self.get_enabled10BeEF::Core::Configuration.instance.get('beef.module').select do |_k, v|11v['enable'] == true && !v['category'].nil?12end13end1415# Return configuration hashes of all modules that are loaded16# @return [Array] configuration hashes of all loaded modules17def self.get_loaded18BeEF::Core::Configuration.instance.get('beef.module').select do |_k, v|19v['loaded'] == true20end21end2223# Return an array of categories specified in module configuration files24# @return [Array] all available module categories sorted alphabetically25def self.get_categories26categories = []27BeEF::Core::Configuration.instance.get('beef.module').each_value do |v|28flatcategory = ''29if v['category'].is_a?(Array)30# Therefore this module has nested categories (sub-folders),31# munge them together into a string with '/' characters, like a folder.32v['category'].each do |cat|33flatcategory << "#{cat}/"34end35else36flatcategory = v['category']37end38categories << flatcategory unless categories.include? flatcategory39end4041# This is now uniqued, because otherwise the recursive function to build42# the json tree breaks if there are duplicates.43categories.sort.uniq44end4546# Get all modules currently stored in the database47# @return [Array] DataMapper array of all BeEF::Core::Models::CommandModule's in the database48def self.get_stored_in_db49BeEF::Core::Models::CommandModule.all.order(:id)50end5152# Loads all enabled modules53# @note API Fire: post_soft_load54def self.load55BeEF::Core::Configuration.instance.load_modules_config56get_enabled.each_key do |k|57BeEF::Module.soft_load k58end59BeEF::API::Registrar.instance.fire BeEF::API::Modules, 'post_soft_load'60end61end62end636465