From 7186b75aade994f8ebb1d83036407c5a0db54bee Mon Sep 17 00:00:00 2001 From: passbe Date: Thu, 1 Sep 2011 06:45:49 +0000 Subject: [PATCH] Added API BeEF::Module.get_options() override. Added API.matched?() method to determine if a conditional API register is met. API methods can now return data to the core git-svn-id: https://beef.googlecode.com/svn/trunk@1248 b87d56ec-f9c0-11de-8c8a-61c5e9addfc9 --- core/api.rb | 20 ++++++++++++++++++-- core/api/module.rb | 5 ++++- core/module.rb | 15 +++++++++++++-- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/core/api.rb b/core/api.rb index ee14cd40a..7a061e97d 100644 --- a/core/api.rb +++ b/core/api.rb @@ -59,6 +59,16 @@ module API return false end + # match is used to determine if a fire() method should continue, matchs a registered API hook without the owner + def matched?(c, method, params = []) + @registry.each{|r| + if r['class'] == c and r['method'] == method and params == r['params'] + return true + end + } + return false + end + # unregister API call from owner, class and method def unregister(id) @registry.delete_if{|r| @@ -72,7 +82,7 @@ module API @registry.each{|r| if r['class'] == c and r['method'] == method if r['params'].length == 0 or r['params'] == params - owners << r['owner'] + owners << { :owner => r['owner'], :id => r['id']} end end } @@ -95,13 +105,17 @@ module API def fire(c, m, *args) mods = self.get_owners(c, m, args) if mods.length > 0 + data = [] 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} fired #{method}" - mod.send method, *args + result = mod[:owner].method(method).call(*args) + if not result == nil + data << {:api_id => mod[:id], :data => result} + end rescue Exception => e print_error "API Fire Error: #{e.message} in #{mod.to_s}.#{method.to_s}()" end @@ -109,7 +123,9 @@ module API else print_error "API Path not defined for Class: "+c.to_s+" Method: "+m.to_s end + return data end + return nil end end diff --git a/core/api/module.rb b/core/api/module.rb index d1d7acf3e..e6c595905 100644 --- a/core/api/module.rb +++ b/core/api/module.rb @@ -25,7 +25,8 @@ module API 'pre_soft_load' => :pre_soft_load, 'post_soft_load' => :post_soft_load, 'pre_hard_load' => :pre_hard_load, - 'post_hard_load' => :post_hard_load + 'post_hard_load' => :post_hard_load, + 'get_options' => :get_options } def pre_soft_load(mod); end @@ -36,6 +37,8 @@ module API def post_hard_load(mod); end + def get_options; end + end end diff --git a/core/module.rb b/core/module.rb index e3a219e00..ec8bd8708 100644 --- a/core/module.rb +++ b/core/module.rb @@ -38,14 +38,25 @@ module Module # Gets all module options def self.get_options(mod) + if BeEF::API::Registra.instance.matched?(BeEF::API::Module, 'get_options', [mod]) + options = BeEF::API::Registra.instance.fire(BeEF::API::Module, 'get_options', mod) + mo = [] + options.each{|o| + if o[:data].kind_of?(Array) + mo += o[:data] + else + print_debug "API Warning: return result for BeEF::Module.get_options() was not an array." + end + } + return mo + end if self.check_hard_load(mod) class_name = BeEF::Core::Configuration.instance.get("beef.module.#{mod}.class") class_symbol = BeEF::Core::Command.const_get(class_name) if class_symbol and class_symbol.respond_to?(:options) return class_symbol.options else - #makes too much noise as many modules dont have options defined - #print_debug "Module '#{mod}', no options method defined" + print_debug "Module '#{mod}', no options method defined" end end return []