Module: Msf::Simple::Post
- Includes:
- Module
- Defined in:
- lib/msf/base/simple/post.rb
Overview
A simplified post-exploitation module wrapper.
Class Method Summary collapse
-
.job_cleanup_proc(ctx) ⇒ Object
protected
Clean up the module after the job completes.
-
.job_run_proc(ctx) ⇒ Object
protected
Job run proc, sets up the module and kicks it off.
-
.run_simple(omod, opts = {}) {|mod| ... } ⇒ Object
Wraps the post-exploitation module running process in a simple single method.
Instance Method Summary collapse
-
#run_simple(opts = {}, &block) ⇒ Object
Calls the class method.
Methods included from Module
#_import_extra_options, #init_simplified, #inspect, #load_config, #save_config
Class Method Details
.job_cleanup_proc(ctx) ⇒ Object (protected)
Clean up the module after the job completes.
Copy/pasted from simple/auxiliary.rb
177 178 179 180 181 182 |
# File 'lib/msf/base/simple/post.rb', line 177 def self.job_cleanup_proc(ctx) mod = ctx[0] mod.framework.events.on_module_complete(mod) # Allow the exploit to cleanup after itself, that messy bugger. mod.cleanup end |
.job_run_proc(ctx) ⇒ Object (protected)
Job run proc, sets up the module and kicks it off.
XXX: Mostly Copy/pasted from simple/auxiliary.rb
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/msf/base/simple/post.rb', line 106 def self.job_run_proc(ctx) mod, run_uuid, job_listener = ctx begin job_listener.start run_uuid mod.setup mod.framework.events.on_module_run(mod) # Grab the session object since we need to fire an event for not # only the normal module_run event that all module types have to # report, but a specific event for sessions as well. s = mod.framework.sessions.get(mod.datastore["SESSION"]) if s mod.framework.events.on_session_module_run(s, mod) result = mod.run job_listener.completed(run_uuid, result, mod) return result else mod.print_error("Session not found") job_listener.failed(run_uuid, 'Session not found', mod) mod.cleanup return end rescue Msf::Post::Complete job_listener.completed(run_uuid, nil, mod) mod.cleanup return rescue Msf::Post::Failed => e mod.error = e mod.print_error("Post aborted due to failure: #{e.}") job_listener.failed(run_uuid, e, mod) mod.cleanup return rescue ::Timeout::Error => e mod.error = e mod.print_error("Post triggered a timeout exception") job_listener.failed(run_uuid, e, mod) mod.cleanup return rescue ::Interrupt => e mod.error = e mod.print_error("Post interrupted by the console user") job_listener.failed(run_uuid, e, mod) mod.cleanup return rescue ::Msf::OptionValidateError => e mod.error = e ::Msf::Ui::Formatter::OptionValidateError.print_error(mod, e) job_listener.failed(run_uuid, e, mod) rescue ::Exception => e mod.error = e mod.print_error("Post failed: #{e.class} #{e}") if(e.class.to_s != 'Msf::OptionValidateError') mod.print_error("Call stack:") e.backtrace.each do |line| break if line =~ /lib.msf.base.simple.post.rb/ mod.print_error(" #{line}") end end elog('Post failed', error: e) job_listener.failed(run_uuid, e, mod) mod.cleanup return end end |
.run_simple(omod, opts = {}) {|mod| ... } ⇒ Object
Wraps the post-exploitation module running process in a simple single method. The options hash can have the following values passed in it:
OptionStr
A string of comma separated option values that should be imported into the datastore.
Options
A hash of values to be imported directly into the datastore.
LocalInput
The local input handle that data can be read in from.
LocalOutput
The local output through which data can be displayed.
RunAsJob
Whether or not the module should be run in the context of a background job.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/msf/base/simple/post.rb', line 40 def self.run_simple(omod, opts = {}, &block) job_listener = opts.delete('JobListener') || Msf::Simple::NoopJobListener.instance # Clone the module to prevent changes to the original instance mod = omod.replicant Msf::Simple::Framework.simplify_module(mod) yield(mod) if block_given? # Import options from the OptionStr or Option hash. mod.(opts) mod.datastore['ACTION'] = opts['Action'] if opts['Action'] # Verify the ACTION if (mod.actions.length > 0 and not mod.action) raise MissingActionError, "Please use: #{mod.actions.collect {|e| e.name} * ", "}" end # Verify the options mod.validate # Initialize user interaction if ! opts['Quiet'] mod.init_ui(opts['LocalInput'] || mod.user_input, opts['LocalOutput'] || mod.user_output) else mod.init_ui(nil, nil) end run_uuid = Rex::Text.rand_text_alphanumeric(24) mod.run_uuid = run_uuid omod.run_uuid = run_uuid job_listener.waiting run_uuid ctx = [mod, run_uuid, job_listener] # # Disable this until we can test background stuff a little better # if(mod.passive? or opts['RunAsJob']) mod.job_id = mod.framework.jobs.start_bg_job( "Post: #{mod.refname}", ctx, Proc.new { |ctx_| self.job_run_proc(ctx_) }, Proc.new { |ctx_| self.job_cleanup_proc(ctx_) } ) # Propagate this back to the caller for console mgmt omod.job_id = mod.job_id else self.job_run_proc(ctx) self.job_cleanup_proc(ctx) end end |
Instance Method Details
#run_simple(opts = {}, &block) ⇒ Object
Calls the class method.
95 96 97 |
# File 'lib/msf/base/simple/post.rb', line 95 def run_simple(opts = {}, &block) Msf::Simple::Post.run_simple(self, opts, &block) end |