diff --git a/lib/msf/base/simple/auxiliary.rb b/lib/msf/base/simple/auxiliary.rb index 0afcf86ece..a6a6c44dab 100644 --- a/lib/msf/base/simple/auxiliary.rb +++ b/lib/msf/base/simple/auxiliary.rb @@ -119,6 +119,7 @@ protected # Clean up the module after the job completes. # def self.job_cleanup_proc(mod) + mod.framework.events.on_module_complete(mod) # Allow the exploit to cleanup after itself, that messy bugger. mod.cleanup end diff --git a/lib/msf/core/event_dispatcher.rb b/lib/msf/core/event_dispatcher.rb index 2d39b17220..c50cb9e7f1 100644 --- a/lib/msf/core/event_dispatcher.rb +++ b/lib/msf/core/event_dispatcher.rb @@ -27,6 +27,18 @@ module GeneralEventSubscriber def on_module_run(instance) end + # + # Called when a module finishes + # + def on_module_complete(instance) + end + + # + # Called when a module raises an exception + # + def on_module_error(instance, exception) + end + end ### diff --git a/lib/msf/core/exploit_driver.rb b/lib/msf/core/exploit_driver.rb index 61ec9ed04c..12b38d077b 100644 --- a/lib/msf/core/exploit_driver.rb +++ b/lib/msf/core/exploit_driver.rb @@ -185,6 +185,7 @@ protected end rescue ::Exception + exploit.framework.events.on_module_error(exploit, $!) exploit.print_error("Exploit failed: #{$!}") elog("Exploit failed (#{exploit.refname}): #{$!}", 'core', LEV_0) dlog("Call stack:\n#{$@.join("\n")}", 'core', LEV_3) @@ -204,6 +205,8 @@ protected # Ensure that, no matter what, clean up of the handler occurs payload.stop_handler + exploit.framework.events.on_module_complete(exploit) + # Allow the exploit to cleanup after itself, that messy bugger. exploit.cleanup end diff --git a/lib/msf/core/framework.rb b/lib/msf/core/framework.rb index e2924cdd07..e6f4552acb 100644 --- a/lib/msf/core/framework.rb +++ b/lib/msf/core/framework.rb @@ -201,19 +201,35 @@ class FrameworkEventSubscriber end include GeneralEventSubscriber - def on_module_run(instance) + + # + # Generic handler for module events + # + def module_event(name, instance, opts={}) if framework.db.active event = { :workspace => framework.db.find_workspace(instance.workspace), - :name => "module_run", + :name => name, :info => { :module_name => instance.fullname, - :datastore => instance.datastore.to_h - } + }.merge(opts) } + report_event(event) end end + def on_module_run(instance) + opts = { :datastore => instance.datastore.to_h } + module_event('module_run', instance, opts) + end + + def on_module_complete(instance) + module_event('module_complete', instance) + end + + def on_module_error(instance, exception=nil) + module_event('module_error', instance, :exception => exception.to_s) + end include ::Msf::UiEventSubscriber def on_ui_command(command) @@ -238,6 +254,9 @@ class FrameworkEventSubscriber #report_event(:name => "ui_start", :info => info) end + # + # Generic handler for session events + # def session_event(name, session, opts={}) address = session.tunnel_peer[0, session.tunnel_peer.rindex(":") || session.tunnel_peer.length ]