2015-05-21 00:32:31 -04:00
|
|
|
##
|
2017-07-24 06:26:21 -07:00
|
|
|
# This module requires Metasploit: https://metasploit.com/download
|
2015-05-21 00:32:31 -04:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
2015-05-20 18:09:28 -04:00
|
|
|
##
|
|
|
|
|
|
2016-03-08 14:02:44 +01:00
|
|
|
class MetasploitModule < Msf::Post
|
2015-05-20 19:08:50 -04:00
|
|
|
include Msf::Post::Windows::Powershell
|
2015-05-20 18:09:28 -04:00
|
|
|
|
2023-02-08 13:47:34 +00:00
|
|
|
def initialize(info = {})
|
|
|
|
|
super(
|
|
|
|
|
update_info(
|
|
|
|
|
info,
|
2025-05-09 10:51:17 +10:00
|
|
|
'Name' => 'Windows PowerShell Execution Post Module',
|
2023-02-08 13:47:34 +00:00
|
|
|
'Description' => %q{
|
2025-05-09 10:51:17 +10:00
|
|
|
This module will execute a PowerShell script in a meterpreter session.
|
2023-02-08 13:47:34 +00:00
|
|
|
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 <rageltman[at]sempervictus>' # post module and libs
|
2025-05-09 10:51:17 +10:00
|
|
|
],
|
|
|
|
|
'Notes' => {
|
|
|
|
|
'Stability' => [CRASH_SAFE],
|
|
|
|
|
'SideEffects' => [],
|
|
|
|
|
'Reliability' => []
|
|
|
|
|
}
|
2023-02-08 13:47:34 +00:00
|
|
|
)
|
|
|
|
|
)
|
2015-05-20 18:09:28 -04:00
|
|
|
|
2015-05-20 19:08:50 -04:00
|
|
|
register_options(
|
|
|
|
|
[
|
2023-02-08 13:47:34 +00:00
|
|
|
OptString.new('SCRIPT', [true, 'Path to the local PS script or command string to execute']),
|
|
|
|
|
]
|
|
|
|
|
)
|
2015-05-20 18:09:28 -04:00
|
|
|
|
2015-05-20 19:08:50 -04:00
|
|
|
register_advanced_options(
|
|
|
|
|
[
|
2015-10-20 13:09:17 -05:00
|
|
|
OptString.new('SUBSTITUTIONS', [false, 'Script subs in gsub format - original,sub;original,sub']),
|
2023-02-08 13:47:34 +00:00
|
|
|
]
|
|
|
|
|
)
|
2015-05-20 19:08:50 -04:00
|
|
|
end
|
2015-05-20 18:09:28 -04:00
|
|
|
|
2015-05-20 19:08:50 -04:00
|
|
|
def run
|
2025-05-09 10:51:17 +10:00
|
|
|
fail_with(Failure::BadConfig, 'PowerShell is not available') unless have_powershell?
|
2015-05-20 18:09:28 -04:00
|
|
|
|
2015-08-16 10:47:20 +01:00
|
|
|
# Preprocess the Powershell::Script object with substitions from Exploit::Powershell
|
2015-10-20 13:09:17 -05:00
|
|
|
script = make_subs(read_script(datastore['SCRIPT']), process_subs(datastore['SUBSTITUTIONS']))
|
2015-05-20 18:09:28 -04:00
|
|
|
|
2015-08-16 10:47:20 +01:00
|
|
|
# Execute in session
|
2015-05-20 19:08:50 -04:00
|
|
|
print_status psh_exec(script)
|
2015-10-20 13:09:17 -05:00
|
|
|
print_good 'Finished!'
|
2015-05-20 19:08:50 -04:00
|
|
|
end
|
2015-05-20 18:09:28 -04:00
|
|
|
end
|