From 887d93697fc280ae8b21c2db3130e1f179581dfb Mon Sep 17 00:00:00 2001 From: passbe Date: Thu, 11 Aug 2011 05:59:30 +0000 Subject: [PATCH] Added basic timed API calls including: pre/post soft/hard module load (+config load). post extension load. Added name tag to all extension config files git-svn-id: https://beef.googlecode.com/svn/trunk@1181 b87d56ec-f9c0-11de-8c8a-61c5e9addfc9 --- core/api.rb | 32 +++++++++++++++------------ core/api/extension.rb | 2 +- core/api/extensions.rb | 30 +++++++++++++++++++++++++ core/api/main/configuration.rb | 29 ++++++++++++++++++++++++ core/api/module.rb | 16 ++++++++++++++ core/extensions.rb | 3 +++ core/main/configuration.rb | 6 +++-- core/module.rb | 8 +++++++ core/modules.rb | 1 + extensions/admin_ui/config.yaml | 1 + extensions/autoloader/config.yaml | 1 + extensions/console/banners.rb | 12 +++++----- extensions/console/config.yaml | 1 + extensions/demos/config.yaml | 1 + extensions/events/config.yaml | 1 + extensions/initialization/config.yaml | 1 + extensions/metasploit/config.yaml | 1 + extensions/proxy/config.yaml | 1 + extensions/requester/config.yaml | 1 + extensions/xssrays/config.yaml | 1 + 20 files changed, 125 insertions(+), 24 deletions(-) create mode 100644 core/api/extensions.rb create mode 100644 core/api/main/configuration.rb diff --git a/core/api.rb b/core/api.rb index b4bbfb77a..35660ee02 100644 --- a/core/api.rb +++ b/core/api.rb @@ -13,11 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # -=begin - - -=end module BeEF module API @@ -25,17 +21,22 @@ module API # Calls a API fire against a certain class / module (c) method (m) with n parameters (*args) # def self.fire(c, m, *args) - if self.verify_api_path(c, m) and c.ancestors[0].to_s > "BeEF::API" - method = self.get_api_path(c, m) - c.extended_in_modules.each do |mod| - begin - mod.send method, *args - rescue Exception => e - print_error e.message - end + mods = c.extended_in_modules + if mods.length > 0 + if self.verify_api_path(c, m) and c.ancestors[0].to_s > "BeEF::API" + method = self.get_api_path(c, m) + mods.each do |mod| + begin + #Only used for API Development + #print_info "API: #{mod} called #{method}" + mod.send method, *args + rescue Exception => e + print_error "API Fire Error: #{e.message} in #{mod.to_s}.#{method.to_s}()" + end + end + else + print_error "API Path not defined for Class: "+c.to_s+" Method: "+m.to_s end - else - print_error "API Path not defined for Class: "+c.to_s+" Method: "+m.to_s end end @@ -54,6 +55,9 @@ end require 'core/api/module' require 'core/api/extension' +require 'core/api/extensions' require 'core/api/main/migration' require 'core/api/main/server/handler' require 'core/api/main/server/hook' +require 'core/api/main/configuration' + diff --git a/core/api/extension.rb b/core/api/extension.rb index 2b65ea08d..c82bc186d 100644 --- a/core/api/extension.rb +++ b/core/api/extension.rb @@ -36,4 +36,4 @@ module API end end -end \ No newline at end of file +end diff --git a/core/api/extensions.rb b/core/api/extensions.rb new file mode 100644 index 000000000..8560dce3a --- /dev/null +++ b/core/api/extensions.rb @@ -0,0 +1,30 @@ +# +# Copyright 2011 Wade Alcorn wade@bindshell.net +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +module BeEF +module API +module Extensions + + API_PATHS = { + 'post_load' => :post_load + } + + def post_load; end + + + +end +end +end diff --git a/core/api/main/configuration.rb b/core/api/main/configuration.rb new file mode 100644 index 000000000..3e40eca70 --- /dev/null +++ b/core/api/main/configuration.rb @@ -0,0 +1,29 @@ +# +# Copyright 2011 Wade Alcorn wade@bindshell.net +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +module BeEF +module API + module Configuration + + API_PATHS = { + 'module_configuration_load' => :module_configuration_load + } + + def module_configuration_load(mod); end + + end + +end +end diff --git a/core/api/module.rb b/core/api/module.rb index b25ef0e5d..d1d7acf3e 100644 --- a/core/api/module.rb +++ b/core/api/module.rb @@ -20,6 +20,22 @@ module API end module Module + + API_PATHS = { + 'pre_soft_load' => :pre_soft_load, + 'post_soft_load' => :post_soft_load, + 'pre_hard_load' => :pre_hard_load, + 'post_hard_load' => :post_hard_load + } + + def pre_soft_load(mod); end + + def post_soft_load(mod); end + + def pre_hard_load(mod); end + + def post_hard_load(mod); end + end end diff --git a/core/extensions.rb b/core/extensions.rb index d4a4fd2a0..a7fad2438 100644 --- a/core/extensions.rb +++ b/core/extensions.rb @@ -28,9 +28,12 @@ module Extensions # Loads all enabled extensions def self.load + BeEF::Core::Configuration.instance.load_extensions_config self.get_enabled.each { |k,v| BeEF::Extension.load(k) } + # API post extension load + BeEF::API.fire(BeEF::API::Extensions, 'post_load') end end diff --git a/core/main/configuration.rb b/core/main/configuration.rb index be77d4a4b..46600b9d7 100644 --- a/core/main/configuration.rb +++ b/core/main/configuration.rb @@ -39,8 +39,6 @@ module Core @config = self.load(configuration_file) # set default value if key? does not exist @config.default = nil - load_extensions_config - load_modules_config end # @@ -96,6 +94,7 @@ module Core # load extensions configurations # def load_extensions_config + self.set('beef.extension', {}) Dir.glob("#{$root_dir}/extensions/*/config.yaml") do | cf | y = self.load(cf) if y != nil @@ -109,11 +108,14 @@ module Core # Load module configurations # def load_modules_config + self.set('beef.module', {}) 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.deep_merge(@config) + # API call for post module config load + BeEF::API.fire(BeEF::API::Configuration, 'module_configuration_load', y['beef']['module'].keys.first) end end end diff --git a/core/module.rb b/core/module.rb index d54394d2b..52847be79 100644 --- a/core/module.rb +++ b/core/module.rb @@ -48,12 +48,16 @@ module Module # Soft Load, loads the module without requiring the module.rb file def self.soft_load(mod) + # API call for pre-soft-load module + BeEF::API.fire(BeEF::API::Module, 'pre_soft_load', mod) config = BeEF::Core::Configuration.instance if not config.get("beef.module.#{mod}.loaded") if File.exists?(config.get('beef.module.'+mod+'.path')+'/module.rb') BeEF::Core::Configuration.instance.set('beef.module.'+mod+'.class', mod.capitalize) self.parse_targets(mod) print_debug "Soft Load module: '#{mod}'" + # API call for post-soft-load module + BeEF::API.fire(BeEF::API::Module, 'post_soft_load', mod) return true else print_debug "Unable to locate module file: #{config.get('beef.module.'+mod+'.path')}module.rb" @@ -65,6 +69,8 @@ module Module # Hard Load, loads a pre-soft-loaded module by requiring the module.rb def self.hard_load(mod) + # API call for pre-hard-load module + BeEF::API.fire(BeEF::API::Module, 'pre_hard_load', mod) config = BeEF::Core::Configuration.instance if self.is_enabled(mod) begin @@ -75,6 +81,8 @@ module Module BeEF::Core::Configuration.instance.set("beef.module.#{mod}.mount", "/command/#{mod}.js") BeEF::Core::Configuration.instance.set('beef.module.'+mod+'.loaded', true) print_debug "Hard Load module: '#{mod.to_s}'" + # API call for post-hard-load module + BeEF::API.fire(BeEF::API::Module, 'post_hard_load', mod) return true else print_error "Hard loaded module '#{mod.to_s}' but the class BeEF::Core::Commands::#{mod.capitalize} does not exist" diff --git a/core/modules.rb b/core/modules.rb index 839d371a0..911a32636 100644 --- a/core/modules.rb +++ b/core/modules.rb @@ -43,6 +43,7 @@ module Modules # Loads modules def self.load + BeEF::Core::Configuration.instance.load_modules_config self.get_enabled.each { |k,v| BeEF::Module.soft_load(k) } diff --git a/extensions/admin_ui/config.yaml b/extensions/admin_ui/config.yaml index 7ce6daa09..e16701ab4 100644 --- a/extensions/admin_ui/config.yaml +++ b/extensions/admin_ui/config.yaml @@ -16,6 +16,7 @@ beef: extension: admin_ui: + name: 'Admin UI' enable: true username: "beef" password: "beef" diff --git a/extensions/autoloader/config.yaml b/extensions/autoloader/config.yaml index 141683380..2dd15a525 100644 --- a/extensions/autoloader/config.yaml +++ b/extensions/autoloader/config.yaml @@ -17,4 +17,5 @@ beef: extension: autoloader: enable: true + name: 'Autoloader' diff --git a/extensions/console/banners.rb b/extensions/console/banners.rb index e82b22fee..985ad7831 100644 --- a/extensions/console/banners.rb +++ b/extensions/console/banners.rb @@ -99,14 +99,13 @@ module Banners # Print loaded extensions # def print_loaded_extensions - extensions = BeEF::API::Extension.extended_in_modules + extensions = BeEF::Extensions.get_loaded print_info "#{extensions.size} extensions loaded:" output = '' - extensions.each do |extension| - if extension.full_name - output += "#{extension.full_name}\n" - end + + extensions.each do |key,ext| + output += "#{ext['name']}\n" end print_more output @@ -115,8 +114,7 @@ module Banners # # Print loaded modules def print_loaded_modules - puts BeEF::API::Module.extended_in_modules - print_info "#{BeEF::Modules::get_enabled.count} modules loaded." + print_info "#{BeEF::Modules::get_enabled.count} modules enabled." end end end diff --git a/extensions/console/config.yaml b/extensions/console/config.yaml index 1cf8c03a0..3e1268b07 100644 --- a/extensions/console/config.yaml +++ b/extensions/console/config.yaml @@ -17,4 +17,5 @@ beef: extension: console: enable: true + name: 'Console' diff --git a/extensions/demos/config.yaml b/extensions/demos/config.yaml index 0d619a5bf..27a935cd5 100644 --- a/extensions/demos/config.yaml +++ b/extensions/demos/config.yaml @@ -17,4 +17,5 @@ beef: extension: demos: enable: true + name: 'Demos' diff --git a/extensions/events/config.yaml b/extensions/events/config.yaml index 7ccf428c5..4011cf77a 100644 --- a/extensions/events/config.yaml +++ b/extensions/events/config.yaml @@ -17,4 +17,5 @@ beef: extension: events: enable: true + name: 'Events' diff --git a/extensions/initialization/config.yaml b/extensions/initialization/config.yaml index 0c5fee8ab..5857c91f4 100644 --- a/extensions/initialization/config.yaml +++ b/extensions/initialization/config.yaml @@ -17,4 +17,5 @@ beef: extension: initialization: enable: true + name: 'Initialization' diff --git a/extensions/metasploit/config.yaml b/extensions/metasploit/config.yaml index 205f5f428..e246c8e36 100644 --- a/extensions/metasploit/config.yaml +++ b/extensions/metasploit/config.yaml @@ -22,6 +22,7 @@ beef: extension: metasploit: + name: 'Metasploit' enable: true host: "127.0.0.1" url-path: "/RPC2" diff --git a/extensions/proxy/config.yaml b/extensions/proxy/config.yaml index a2380c183..3f75cadff 100644 --- a/extensions/proxy/config.yaml +++ b/extensions/proxy/config.yaml @@ -16,6 +16,7 @@ beef: extension: proxy: + name: 'Proxy' enable: true address: "127.0.0.1" port: 6789 diff --git a/extensions/requester/config.yaml b/extensions/requester/config.yaml index e706db8d4..54a63ccbc 100644 --- a/extensions/requester/config.yaml +++ b/extensions/requester/config.yaml @@ -16,6 +16,7 @@ beef: extension: requester: + name: 'Requester' enable: true # used to overwrite the Uri parser regex when sending attack vectors. This prevents Bad URI errors. uri_unreserved_chars: "-_.!~*'()a-zA-Z\\d><|\"\\[\\]\\\'`" diff --git a/extensions/xssrays/config.yaml b/extensions/xssrays/config.yaml index 14e18a950..b46b847d5 100644 --- a/extensions/xssrays/config.yaml +++ b/extensions/xssrays/config.yaml @@ -17,6 +17,7 @@ beef: extension: xssrays: enable: true + name: 'XSSRays' authors: ["antisnatchor"] clean_timeout: 5000 cross_domain: false