diff --git a/core/module.rb b/core/module.rb index b8f111f76..516fd6d81 100644 --- a/core/module.rb +++ b/core/module.rb @@ -434,22 +434,22 @@ module BeEF # @param [String] mod module key # @param [String] hbsession hooked browser session # @param [Array] opts array of module execute options (see #get_options) - # @return [Boolean] whether or not the BeEF system executed the module + # @return [Fixnum] the command_id associated to the module execution when info is persisted. nil if there are errors. # @note The return value of this function does not specify if the module was successful, only that it was executed within the framework def self.execute(mod, hbsession, opts=[]) if not (self.is_present(mod) and self.is_enabled(mod)) print_error "Module not found '#{mod}'. Failed to execute module." - return false + return nil end if BeEF::API::Registrar.instance.matched?(BeEF::API::Module, 'override_execute', [mod, nil,nil]) BeEF::API::Registrar.instance.fire(BeEF::API::Module, 'override_execute', mod, hbsession,opts) - # @note We return true by default as we cannot determine the correct status if multiple API hooks have been called - return true + # @note We return not_nil by default as we cannot determine the correct status if multiple API hooks have been called + return 'override_execute' end hb = BeEF::HBManager.get_by_session(hbsession) if not hb print_error "Could not find hooked browser when attempting to execute module '#{mod}'" - return false + return nil end self.check_hard_load(mod) command_module = self.get_definition(mod).new(mod) @@ -457,12 +457,12 @@ module BeEF command_module.pre_execute end h = self.merge_options(mod, []) - c = BeEF::Core::Models::Command.new(:data => self.merge_options(mod, opts).to_json, + c = BeEF::Core::Models::Command.create(:data => self.merge_options(mod, opts).to_json, :hooked_browser_id => hb.id, :command_module_id => BeEF::Core::Configuration.instance.get("beef.module.#{mod}.db.id"), :creationdate => Time.new.to_i - ).save - return true + ) + return c.id end # Merges default module options with array of custom options diff --git a/extensions/admin_ui/controllers/modules/modules.rb b/extensions/admin_ui/controllers/modules/modules.rb index 86300c74a..ca9a7a22b 100644 --- a/extensions/admin_ui/controllers/modules/modules.rb +++ b/extensions/admin_ui/controllers/modules/modules.rb @@ -636,7 +636,8 @@ class Modules < BeEF::Extension::AdminUI::HttpController def2.push({'name' => k, 'value' => v}) } # End hack - @body = (BeEF::Module.execute(mod_key, zombie_session, def2)) ? '{success: true}' : '{success: false}' + exec_results = BeEF::Module.execute(mod_key, zombie_session, def2) + @body = (exec_results != nil) ? '{success: true}' : '{success: false}' end # Re-execute an command_module to a zombie. diff --git a/extensions/console/lib/shellinterface.rb b/extensions/console/lib/shellinterface.rb index 1f65112cb..712276123 100644 --- a/extensions/console/lib/shellinterface.rb +++ b/extensions/console/lib/shellinterface.rb @@ -195,7 +195,7 @@ class ShellInterface def2.push({'name' => k, 'value' => v}) } # End hack - if BeEF::Module.execute(mod_key, self.targetsession.to_s, def2) == true + if BeEF::Module.execute(mod_key, self.targetsession.to_s, def2) != nil return true else return false