Created API override_execute() for modules. Re-wrote is_matched_params? to fix bug and for better parameter matching

git-svn-id: https://beef.googlecode.com/svn/trunk@1257 b87d56ec-f9c0-11de-8c8a-61c5e9addfc9
This commit is contained in:
passbe
2011-09-02 23:56:52 +00:00
parent 687e058c88
commit 0403ea0853
3 changed files with 30 additions and 4 deletions

View File

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

View File

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

View File

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