From 5717f52246ccdd2a3cf3f3d3c237a082bb000ecc Mon Sep 17 00:00:00 2001 From: James Lee Date: Thu, 17 May 2012 16:13:25 -0600 Subject: [PATCH] Make the Exploit::Local class useful This commit is the main infrastructure needed to run exploits in a local context, gluing the Exploit and Post module classes together. --- lib/msf/core/exploit.rb | 2 ++ lib/msf/core/post.rb | 70 ++++++++++++++++++++++++++--------------- 2 files changed, 46 insertions(+), 26 deletions(-) diff --git a/lib/msf/core/exploit.rb b/lib/msf/core/exploit.rb index 39409c2b95..afeaa39d11 100644 --- a/lib/msf/core/exploit.rb +++ b/lib/msf/core/exploit.rb @@ -1,5 +1,6 @@ require 'msf/core' require 'msf/core/module' +require 'msf/core/post' module Msf @@ -137,6 +138,7 @@ class Exploit < Msf::Module # ### class Local < Exploit + include PostMixin # # Returns the fact that this exploit is a local exploit. diff --git a/lib/msf/core/post.rb b/lib/msf/core/post.rb index 774c11f2b6..f913a448c1 100644 --- a/lib/msf/core/post.rb +++ b/lib/msf/core/post.rb @@ -2,19 +2,16 @@ require 'msf/core' require 'msf/core/module' module Msf -class Post < Msf::Module + +# +# A mixin used for providing Modules with post-exploitation options and helper methods +# +module PostMixin include Msf::Auxiliary::Report include Msf::Module::HasActions - def self.type - MODULE_POST - end - def type - MODULE_POST - end - def initialize(info={}) super @@ -31,13 +28,16 @@ class Post < Msf::Module # if one doesn't exist. Initializes user input and output on the session. # def setup - @sysinfo = nil if not session raise Msf::OptionValidateError.new(["SESSION"]) end + + super + check_for_session_readiness() if session.type == "meterpreter" @session.init_ui(self.user_input, self.user_output) + @sysinfo = nil end # Meterpreter sometimes needs a little bit of extra time to @@ -114,23 +114,6 @@ class Post < Msf::Module sessions end - # - # Create an anonymous module not tied to a file. Only useful for IRB. - # - def self.create(session) - mod = new - mod.instance_variable_set(:@session, session) - # Have to override inspect because for whatever reason, +type+ is coming - # from the wrong scope and i can't figure out how to fix it. - mod.instance_eval do - def inspect - "#" - end - end - mod.class.refname = "anonymous" - - mod - end # # Return false if the given session is not compatible with this module @@ -219,5 +202,40 @@ protected end end end + +# +# A Post-exploitation module +# +# +class Post < Msf::Module + include PostMixin + + def type + MODULE_POST + end + + def self.type + MODULE_POST + end + + # + # Create an anonymous module not tied to a file. Only useful for IRB. + # + def self.create(session) + mod = new + mod.instance_variable_set(:@session, session) + # Have to override inspect because for whatever reason, +type+ is coming + # from the wrong scope and i can't figure out how to fix it. + mod.instance_eval do + def inspect + "#" + end + end + mod.class.refname = "anonymous" + + mod + end +end + end