diff --git a/core/api.rb b/core/api.rb index 7a061e97d..70fb483a1 100644 --- a/core/api.rb +++ b/core/api.rb @@ -26,7 +26,7 @@ module API @registry = [] @count = 1 end - + # Register owner, c, method and matching params def register(owner, c, method, params = []) if self.verify_api_path(c, method) @@ -62,7 +62,7 @@ module API # 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'] + if r['class'] == c and r['method'] == method and self.is_matched_params?(r, params) return true end } @@ -81,7 +81,7 @@ module API owners = [] @registry.each{|r| if r['class'] == c and r['method'] == method - if r['params'].length == 0 or r['params'] == params + if self.is_matched_params?(r, params) owners << { :owner => r['owner'], :id => r['id']} end end @@ -99,6 +99,24 @@ module API return (self.verify_api_path(c, m)) ? c.const_get('API_PATHS')[m] : nil; end + # Match stored API parameters to params, if array item is nil then skip this item + def is_matched_params?(reg, params) + stored = reg['params'] + if stored.length == params.length + matched = true + stored.each_index{|i| + next if stored[i] == nil + if not stored[i] == params[i] + matched = false + end + } + return false if not matched + end + # We return a match because the fire() method did not indicate any, or + # we return a match because there were no params defined for this register + return true + end + # # Calls a API fire against a certain class / module (c) method (m) with n parameters (*args) # diff --git a/core/api/module.rb b/core/api/module.rb index e6c595905..33ca5a2b2 100644 --- a/core/api/module.rb +++ b/core/api/module.rb @@ -26,7 +26,8 @@ module API 'post_soft_load' => :post_soft_load, 'pre_hard_load' => :pre_hard_load, 'post_hard_load' => :post_hard_load, - 'get_options' => :get_options + 'get_options' => :get_options, + 'override_execute' => :override_execute } def pre_soft_load(mod); end @@ -39,6 +40,8 @@ module API def get_options; end + def override_execute(mod, opts); end + end end diff --git a/core/module.rb b/core/module.rb index ec8bd8708..ae3863024 100644 --- a/core/module.rb +++ b/core/module.rb @@ -357,6 +357,11 @@ module Module print_error "Module not found '#{mod}'. Failed to execute module." return false end + if BeEF::API::Registra.instance.matched?(BeEF::API::Module, 'override_execute', [mod, nil]) + BeEF::API::Registra.instance.fire(BeEF::API::Module, 'override_execute', mod, opts) + #We return true by default as we cannot determine the correct status if multiple API hooks have been called + return true + end hb = BeEF::HBManager.get_by_session(hbsession) if not hb print_error "Could not find hooked browser when attempting to execute module '#{mod}'"