From ded3ff9c75cedb099f75a4c68a483f64a2457b41 Mon Sep 17 00:00:00 2001 From: James Lee Date: Thu, 17 Mar 2011 05:39:30 +0000 Subject: [PATCH] add support for actions in post modules. fixes #3965~ git-svn-id: file:///home/svn/framework3/trunk@12008 4d416f70-5f16-0410-b530-b9f4589650da --- lib/msf/core/auxiliary.rb | 49 ++------------------------- lib/msf/core/module.rb | 1 + lib/msf/core/module/has_actions.rb | 54 ++++++++++++++++++++++++++++++ lib/msf/core/post.rb | 7 ++++ 4 files changed, 65 insertions(+), 46 deletions(-) create mode 100644 lib/msf/core/module/has_actions.rb diff --git a/lib/msf/core/auxiliary.rb b/lib/msf/core/auxiliary.rb index e47493adf3..2b2791a2fe 100644 --- a/lib/msf/core/auxiliary.rb +++ b/lib/msf/core/auxiliary.rb @@ -14,6 +14,8 @@ class Auxiliary < Msf::Module require 'msf/core/auxiliary/mixins' + include HasActions + # # Returns MODULE_AUX to indicate that this is an auxiliary module. # @@ -37,16 +39,8 @@ class Auxiliary < Msf::Module # to the information hash. super(info) - self.actions = Rex::Transformer.transform( - info['Actions'], Array, - [ AuxiliaryAction ], 'AuxiliaryAction' - ) - - self.passive = (info['Passive'] and info['Passive'] == true) || false - self.default_action = info['DefaultAction'] self.sockets = Array.new self.queue = Array.new - self.passive_actions = info['PassiveActions'] || [] end # @@ -65,36 +59,6 @@ class Auxiliary < Msf::Module return { } end - def action - sa = datastore['ACTION'] - return find_action(default_action) if not sa - return find_action(sa) - end - - def find_action(name) - return nil if not name - actions.each do |a| - return a if a.name == name - end - return nil - end - - # - # Returns a boolean indicating whether this module should be run passively - # - def passive? - act = action() - return passive_action?(act.name) if act - return self.passive - end - - # - # Returns a boolean indicating whether this specific action should be run passively - # - def passive_action?(name) - passive_actions.include?(name) - end - # # Performs last-minute sanity checking of auxiliary parameters. This method # is called during automated exploitation attempts and allows an @@ -190,19 +154,12 @@ class Auxiliary < Msf::Module } end - # - # Allow access to the hash table of actions and the string containing - # the default action - # - attr_reader :actions, :default_action, :passive, :passive_actions attr_accessor :queue protected - attr_writer :actions, :default_action attr_accessor :sockets - attr_writer :passive, :passive_actions - + attr_writer :passive end diff --git a/lib/msf/core/module.rb b/lib/msf/core/module.rb index 2519d83927..486b4945a4 100644 --- a/lib/msf/core/module.rb +++ b/lib/msf/core/module.rb @@ -102,6 +102,7 @@ class Module require 'msf/core/module/reference' require 'msf/core/module/target' require 'msf/core/module/auxiliary_action' + require 'msf/core/module/has_actions' # # Creates an instance of an abstract module using the supplied information diff --git a/lib/msf/core/module/has_actions.rb b/lib/msf/core/module/has_actions.rb new file mode 100644 index 0000000000..6fda586005 --- /dev/null +++ b/lib/msf/core/module/has_actions.rb @@ -0,0 +1,54 @@ +require 'msf/core/module/auxiliary_action' + +module Msf::Module::HasActions + def initialize(info={}) + super + self.actions = Rex::Transformer.transform( + info['Actions'], Array, + [ Msf::Module::AuxiliaryAction ], 'AuxiliaryAction' + ) + + self.passive = (info['Passive'] and info['Passive'] == true) || false + self.default_action = info['DefaultAction'] + self.passive_actions = info['PassiveActions'] || [] + end + + def action + sa = datastore['ACTION'] + return find_action(default_action) if not sa + return find_action(sa) + end + + def find_action(name) + return nil if not name + actions.each do |a| + return a if a.name == name + end + return nil + end + + # + # Returns a boolean indicating whether this module should be run passively + # + def passive? + act = action() + return passive_action?(act.name) if act + return self.passive + end + + # + # Returns a boolean indicating whether this specific action should be run passively + # + def passive_action?(name) + passive_actions.include?(name) + end + + # + # Allow access to the hash table of actions and the string containing + # the default action + # + attr_reader :actions, :default_action, :passive, :passive_actions + +protected + attr_writer :actions, :default_action, :passive, :passive_actions +end diff --git a/lib/msf/core/post.rb b/lib/msf/core/post.rb index 718aa50e49..0b42572fde 100644 --- a/lib/msf/core/post.rb +++ b/lib/msf/core/post.rb @@ -6,6 +6,8 @@ class Post < Msf::Module include Msf::Auxiliary::Report + include Msf::Module::HasActions + def self.type MODULE_POST end @@ -153,8 +155,13 @@ class Post < Msf::Module return true end + # + # True when this module is passive, false when active + # attr_reader :passive + protected + attr_writer :passive def session_changed?