Windows Manage PowerShell Download and/or Execute - Metasploit
This page contains detailed information about how to use the post/windows/manage/powershell/exec_powershell metasploit module. For list of all metasploit modules, visit the Metasploit Module Library.
Module Overview
Name: Windows Manage PowerShell Download and/or Execute
Module: post/windows/manage/powershell/exec_powershell
Source code: modules/post/windows/manage/powershell/exec_powershell.rb
Disclosure date: -
Last modification time: 2021-10-06 13:43:31 +0000
Supported architecture(s): -
Supported platform(s): Windows
Target service / protocol: -
Target network port(s): -
List of CVEs: -
This module will download and execute a PowerShell script over 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.
Module Ranking and Traits
Module Ranking:
- normal: The exploit is otherwise reliable, but depends on a specific version and can't (or doesn't) reliably autodetect. More information about ranking can be found here.
Basic Usage
There are two ways to execute this post module.
From the Meterpreter prompt
The first is by using the "run" command at the Meterpreter prompt. It allows you to run the post module against that specific session:
meterpreter > run post/windows/manage/powershell/exec_powershell
From the msf prompt
The second is by using the "use" command at the msf prompt. You will have to figure out which session ID to set manually. To list all session IDs, you can use the "sessions" command.
msf > use post/windows/manage/powershell/exec_powershell
msf post(exec_powershell) > show options
... show and set options ...
msf post(exec_powershell) > set SESSION session-id
msf post(exec_powershell) > exploit
If you wish to run the post against all sessions from framework, here is how:
1 - Create the following resource script:
framework.sessions.each_pair do |sid, session|
run_single("use post/windows/manage/powershell/exec_powershell")
run_single("set SESSION #{sid}")
run_single("run")
end
2 - At the msf prompt, execute the above resource script:
msf > resource path-to-resource-script
Required Options
- SESSION: The session to run this module on.
Go back to menu.
Msfconsole Usage
Here is how the windows/manage/powershell/exec_powershell post exploitation module looks in the msfconsole:
msf6 > use post/windows/manage/powershell/exec_powershell
msf6 post(windows/manage/powershell/exec_powershell) > show info
Name: Windows Manage PowerShell Download and/or Execute
Module: post/windows/manage/powershell/exec_powershell
Platform: Windows
Arch:
Rank: Normal
Provided by:
Nicholas Nam (nick <Nicholas Nam ([email protected])>
RageLtMan <rageltman@sempervictus>
Compatible session types:
Meterpreter
Basic options:
Name Current Setting Required Description
---- --------------- -------- -----------
SCRIPT /opt/metasploit-framework/embedded/framework/scripts/ps/msflag.ps1 yes Path to the local PS script
SESSION yes The session to run this module on.
Description:
This module will download and execute a PowerShell script over 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.
Module Options
This is a complete list of options available in the windows/manage/powershell/exec_powershell post exploitation module:
msf6 post(windows/manage/powershell/exec_powershell) > show options
Module options (post/windows/manage/powershell/exec_powershell):
Name Current Setting Required Description
---- --------------- -------- -----------
SCRIPT /opt/metasploit-framework/embedded/framework/scripts/ps/msflag.ps1 yes Path to the local PS script
SESSION yes The session to run this module on.
Advanced Options
Here is a complete list of advanced options supported by the windows/manage/powershell/exec_powershell post exploitation module:
msf6 post(windows/manage/powershell/exec_powershell) > show advanced
Module advanced options (post/windows/manage/powershell/exec_powershell):
Name Current Setting Required Description
---- --------------- -------- -----------
DELETE false no Delete file after execution
DRY_RUN false no Only show what would be done
Powershell::Post::dry_run false yes Return encoded output to caller
Powershell::Post::force_wow64 false yes Force WOW64 execution
Powershell::Post::log_output false yes Write output to log file
Powershell::Post::timeout 15 yes Powershell execution timeout, set < 0 to run async without termination
Powershell::encode_final_payload false yes Encode final payload for -EncodedCommand
Powershell::encode_inner_payload false yes Encode inner payload for -EncodedCommand
Powershell::exec_in_place false yes Produce PSH without executable wrapper
Powershell::exec_rc4 false yes Encrypt PSH with RC4
Powershell::method reflection yes Payload delivery method (Accepted: net, reflection, old, msil)
Powershell::no_equals false yes Pad base64 until no "=" remains
Powershell::noninteractive true yes Execute powershell without interaction
Powershell::persist false yes Run the payload in a loop
Powershell::prepend_protections_bypass true yes Prepend AMSI/SBL bypass
Powershell::prepend_sleep no Prepend seconds of sleep
Powershell::remove_comspec false yes Produce script calling powershell directly
Powershell::strip_comments true yes Strip comments
Powershell::strip_whitespace false yes Strip whitespace
Powershell::sub_funcs false yes Substitute function names
Powershell::sub_vars true yes Substitute variable names
Powershell::wrap_double_quotes true yes Wraps the -Command argument in single quotes
SUBSTITUTIONS no Script subs in gsub format - original,sub;original,sub
TIMEOUT 15 no Execution timeout
VERBOSE false no Enable detailed status messages
WORKSPACE no Specify the workspace for this module
Post Actions
This is a list of all post exploitation actions which the windows/manage/powershell/exec_powershell module can do:
msf6 post(windows/manage/powershell/exec_powershell) > show actions
Post actions:
Name Description
---- -----------
Evasion Options
Here is the full list of possible evasion options supported by the windows/manage/powershell/exec_powershell post exploitation module in order to evade defenses (e.g. Antivirus, EDR, Firewall, NIDS etc.):
msf6 post(windows/manage/powershell/exec_powershell) > show evasion
Module evasion options:
Name Current Setting Required Description
---- --------------- -------- -----------
Go back to menu.
Error Messages
This module may fail with the following error messages:
Check for the possible causes from the code snippets below found in the module source code. This can often times help in identifying the root cause of the problem.
Compressed size: <COMPRESSED_SCRIPT.SIZE>
Here is a relevant code snippet related to the "Compressed size: <COMPRESSED_SCRIPT.SIZE>" error message:
91: return
92: end
93:
94: # If the compressed size is > 8100 bytes, launch stager
95: if (compressed_script.size > 8100)
96: print_error("Compressed size: #{compressed_script.size}")
97: error_msg = "Compressed size may cause command to exceed "
98: error_msg += "cmd.exe's 8kB character limit."
99: print_error(error_msg)
100: print_status('Launching stager:')
101: script = stage_to_env(compressed_script, env_suffix)
Compressed size may cause command to exceed
Here is a relevant code snippet related to the "Compressed size may cause command to exceed" error message:
92: end
93:
94: # If the compressed size is > 8100 bytes, launch stager
95: if (compressed_script.size > 8100)
96: print_error("Compressed size: #{compressed_script.size}")
97: error_msg = "Compressed size may cause command to exceed "
98: error_msg += "cmd.exe's 8kB character limit."
99: print_error(error_msg)
100: print_status('Launching stager:')
101: script = stage_to_env(compressed_script, env_suffix)
102: print_good("Payload successfully staged.")
cmd.exe's 8kB character limit.
Here is a relevant code snippet related to the "cmd.exe's 8kB character limit." error message:
93:
94: # If the compressed size is > 8100 bytes, launch stager
95: if (compressed_script.size > 8100)
96: print_error("Compressed size: #{compressed_script.size}")
97: error_msg = "Compressed size may cause command to exceed "
98: error_msg += "cmd.exe's 8kB character limit."
99: print_error(error_msg)
100: print_status('Launching stager:')
101: script = stage_to_env(compressed_script, env_suffix)
102: print_good("Payload successfully staged.")
103: else
Go back to menu.
Related Pull Requests
- #12002 Merged Pull Request: Feature/reverse ssh
- #8716 Merged Pull Request: Print_Status -> Print_Good (And OCD bits 'n bobs)
- #8338 Merged Pull Request: Fix msf/core and self.class msftidy warnings
- #6655 Merged Pull Request: use MetasploitModule as a class name
- #6648 Merged Pull Request: Change metasploit class names
- #5379 Merged Pull Request: New post module to Load Powershell scripts into Powershell Session
- #2525 Merged Pull Request: Change module boilerplate
- #2304 Merged Pull Request: Fix load order in posts, hopefully forever
- #1241 Merged Pull Request: Removed all $Id$ and $Revision$ occurences
- #958 Merged Pull Request: Msftidy 2
Go back to menu.
See Also
Check also the following modules related to this module:
Authors
- Nicholas Nam (nick[at]executionflow.org)
- RageLtMan <rageltman[at]sempervictus>
Version
This page has been produced using Metasploit Framework version 6.1.24-dev. For more modules, visit the Metasploit Module Library.
Go back to menu.