Decoupled the module's dependency on category names to find module files. Module configuration now stores path on load

git-svn-id: https://beef.googlecode.com/svn/trunk@1063 b87d56ec-f9c0-11de-8c8a-61c5e9addfc9
This commit is contained in:
passbe
2011-07-13 09:44:39 +00:00
parent 63eef3e97e
commit 6ca6f4981e
4 changed files with 28 additions and 24 deletions

View File

@@ -97,6 +97,7 @@ module Core
Dir.glob("#{$root_dir}/modules/**/*/config.yaml") do | cf |
y = self.load(cf)
if y != nil
y['beef']['module'][y['beef']['module'].keys.first]['path'] = cf.gsub(/config\.yaml/, '')
@config = y.recursive_merge(@config)
end
end

View File

@@ -32,10 +32,10 @@ module Module
end
# Loads module
def self.load(mod, cat)
cat = self.safe_category(cat)
if File.exists?('modules/'+cat+'/'+mod+'/module.rb')
require 'modules/'+cat+'/'+mod+'/module.rb'
def self.load(mod)
config = BeEF::Core::Configuration.instance
if File.exists?(config.get('beef.module.'+mod+'.path')+'/module.rb')
require config.get('beef.module.'+mod+'.path')+'/module.rb'
BeEF::Core::Configuration.instance.set('beef.module.'+mod+'.class', mod.capitalize)
if self.exists?(mod)
BeEF::Core::Configuration.instance.set('beef.module.'+mod+'.loaded', true)
@@ -46,7 +46,7 @@ module Module
print_debug "Unable to locate module class: BeEF::Core::Commands::#{mod.capitalize}"
end
else
print_debug "Unable to locate module file: modules/#{cat}/#{mod}/module.rb"
print_debug "Unable to locate module file: #{config.get('beef.module.'+mod+'.path')}module.rb"
end
print_error "Unable to load module '#{mod}'"
return false
@@ -58,11 +58,6 @@ module Module
return (ret.kind_of?(Array)) ? ret.first.first : ret.keys.first
end
# Returns category name in a system folder format
def self.safe_category(cat)
return cat.to_s.strip.downcase.sub(/\s/, '_')
end
#checks to see if module class exists
def self.exists?(mod)
begin

View File

@@ -26,6 +26,17 @@ module Modules
return BeEF::Core::Configuration.instance.get('beef.module').select {|k,v| v['loaded'] == true }
end
# Return an array of categories specified in module configuration files
def self.get_categories
categories = []
BeEF::Core::Configuration.instance.get('beef.module').each {|k,v|
if not categories.include?(v['category'])
categories << v['category']
end
}
return categories.sort
end
def self.get_stored_in_db
return BeEF::Core::Models::CommandModule.all(:order => [:id.asc])
end
@@ -33,7 +44,7 @@ module Modules
# Loads modules
def self.load
self.get_enabled.each { |k,v|
BeEF::Module.load(k, v['category'])
BeEF::Module.load(k)
}
end
end

View File

@@ -238,16 +238,7 @@ class Modules < BeEF::Extension::AdminUI::HttpController
command_module_status
end
def update_command_module_tree(tree, categories, cmd_category, cmd_icon_path, cmd_status, cmd_name, cmd_id)
# construct the category branch if it doesn't exist for the command module tree
if not categories.include? cmd_category
categories.push(cmd_category) # flag that the category has been added
tree.push({ # add the branch structure
'text' => cmd_category,
'cls' => 'folder',
'children' => []
})
end
def update_command_module_tree(tree, cmd_category, cmd_icon_path, cmd_status, cmd_name, cmd_id)
# construct leaf node for the command module tree
leaf_node = {
@@ -270,7 +261,13 @@ class Modules < BeEF::Extension::AdminUI::HttpController
# Returns the list of all command_modules for a TreePanel in the interface.
def select_command_modules_tree
tree = []
categories = []
BeEF::Modules.get_categories.each { |c|
tree.push({
'text' => c,
'cls' => 'folder',
'children' => []
})
}
BeEF::Modules.get_loaded.each{|k, mod|
# get the hooked browser session id and set it in the command module
@@ -284,7 +281,7 @@ class Modules < BeEF::Extension::AdminUI::HttpController
command_module_icon_path = set_command_module_icon(command_mod)
command_module_status = set_command_module_status(command_mod)
update_command_module_tree(tree, categories, mod['category'], command_module_icon_path, command_module_status, mod['name'],mod['db']['id'])
update_command_module_tree(tree, mod['category'], command_module_icon_path, command_module_status, mod['name'],mod['db']['id'])
}
# if dynamic modules are found in the DB, then we don't have yaml config for them
@@ -317,7 +314,7 @@ class Modules < BeEF::Extension::AdminUI::HttpController
command_module_icon_path = set_command_module_icon(command_mod)
command_module_status = set_command_module_status(command_mod)
update_command_module_tree(tree, categories, dyn_mod_category, command_module_icon_path, command_module_status, command_mod_name,dyn_mod.id)
update_command_module_tree(tree, dyn_mod_category, command_module_icon_path, command_module_status, command_mod_name,dyn_mod.id)
}
end