From bdd39209da49e38fc325a074831fccea5aa15d2c Mon Sep 17 00:00:00 2001 From: passbe Date: Tue, 10 May 2011 22:26:09 +0000 Subject: [PATCH] Added sanity check to module loading + additional print_debug's for futher information if something breaks in the loading process (Fixes issue 334) git-svn-id: https://beef.googlecode.com/svn/trunk@962 b87d56ec-f9c0-11de-8c8a-61c5e9addfc9 --- core/module.rb | 27 ++++++++++++++++++++++----- core/modules.rb | 1 - modules/recon/collect_links/module.rb | 2 +- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/core/module.rb b/core/module.rb index 2c16980e4..781117860 100644 --- a/core/module.rb +++ b/core/module.rb @@ -18,14 +18,21 @@ module Module # Loads module def self.load(mod, cat) - cat = BeEF::Module.safe_category(cat) + cat = self.safe_category(cat) if File.exists?('modules/'+cat+'/'+mod+'/module.rb') require 'modules/'+cat+'/'+mod+'/module.rb' - BeEF::Core::Configuration.instance.set('beef.module.'+mod+'.loaded', true) BeEF::Core::Configuration.instance.set('beef.module.'+mod+'.class', mod.capitalize) - print_debug "Loaded module: '#{mod}'" - return true - end + if self.exists?(mod) + BeEF::Core::Configuration.instance.set('beef.module.'+mod+'.loaded', true) + print_debug "Loaded module: '#{mod}'" + return true + else + BeEF::Core::Configuration.instance.set('beef.module.'+mod+'.loaded', false) + 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" + end print_error "Unable to load module '#{mod}'" return false end @@ -40,6 +47,16 @@ module Module 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 + kclass = BeEF::Core::Command.const_get(mod.capitalize) + return kclass.is_a?(Class) + rescue NameError + return false + end + end end end diff --git a/core/modules.rb b/core/modules.rb index 47da1bc55..2cad7fe1b 100644 --- a/core/modules.rb +++ b/core/modules.rb @@ -15,7 +15,6 @@ module Modules return BeEF::Core::Models::CommandModule.all(:order => [:id.asc]) end - # Loads modules def self.load self.get_enabled.each { |k,v| diff --git a/modules/recon/collect_links/module.rb b/modules/recon/collect_links/module.rb index b63cbe379..3e73199e7 100644 --- a/modules/recon/collect_links/module.rb +++ b/modules/recon/collect_links/module.rb @@ -27,4 +27,4 @@ class Collect_links < BeEF::Core::Command save content end -end \ No newline at end of file +end