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
This commit is contained in:
passbe
2011-08-11 05:59:30 +00:00
parent 3167722af2
commit 887d93697f
20 changed files with 125 additions and 24 deletions

View File

@@ -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'

View File

@@ -36,4 +36,4 @@ module API
end
end
end
end

30
core/api/extensions.rb Normal file
View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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"

View File

@@ -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)
}

View File

@@ -16,6 +16,7 @@
beef:
extension:
admin_ui:
name: 'Admin UI'
enable: true
username: "beef"
password: "beef"

View File

@@ -17,4 +17,5 @@ beef:
extension:
autoloader:
enable: true
name: 'Autoloader'

View File

@@ -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

View File

@@ -17,4 +17,5 @@ beef:
extension:
console:
enable: true
name: 'Console'

View File

@@ -17,4 +17,5 @@ beef:
extension:
demos:
enable: true
name: 'Demos'

View File

@@ -17,4 +17,5 @@ beef:
extension:
events:
enable: true
name: 'Events'

View File

@@ -17,4 +17,5 @@ beef:
extension:
initialization:
enable: true
name: 'Initialization'

View File

@@ -22,6 +22,7 @@
beef:
extension:
metasploit:
name: 'Metasploit'
enable: true
host: "127.0.0.1"
url-path: "/RPC2"

View File

@@ -16,6 +16,7 @@
beef:
extension:
proxy:
name: 'Proxy'
enable: true
address: "127.0.0.1"
port: 6789

View File

@@ -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><|\"\\[\\]\\\'`"

View File

@@ -17,6 +17,7 @@ beef:
extension:
xssrays:
enable: true
name: 'XSSRays'
authors: ["antisnatchor"]
clean_timeout: 5000
cross_domain: false