Skip to content

Commit f6dcabd

Browse files
mantvydasbgitbook-bot
authored andcommitted
GitBook: [#1860] No subject
1 parent 090aed8 commit f6dcabd

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

offensive-security/code-execution/powershell-constrained-language-mode-bypass.md

+14-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ For fun - creating another powershell instance inside powershell without actuall
1414

1515
## Constrained Language Mode
1616

17-
Enabling constrained language mode, that does not allow powershell execute complex attacks \(i.e. mimikatz\):
17+
Enabling constrained language mode, that does not allow powershell execute complex attacks (i.e. mimikatz):
1818

1919
```csharp
2020
[Environment]::SetEnvironmentVariable(‘__PSLockdownPolicy‘, ‘4’, ‘Machine‘)
@@ -41,6 +41,19 @@ If you have the ability to downgrade to Powershell 2.0, this can allow you to by
4141

4242
![](../../.gitbook/assets/ps-downgrade.png)
4343

44+
## System32 Bypass
45+
46+
[Carrie Roberts](https://twitter.com/OrOneEqualsOne) discovered and wrote in her post [https://www.blackhillsinfosec.com/constrained-language-mode-bypass-when-pslockdownpolicy-is-used/](https://www.blackhillsinfosec.com/constrained-language-mode-bypass-when-pslockdownpolicy-is-used/) that there's another way to bypass the contrained language mode and it's super easy - the path from where your script is being executed, needs to contain the string `system32`, meaning even if you rename the script to `system32.ps1`, it should work, so let's try it and confirm it works:
47+
48+
```
49+
PS>.\test.ps1; mv .\test.ps1 system32.ps1; .\system32.ps1
50+
ConstrainedLanguage
51+
FullLanguage
52+
53+
PS>cat .\system32.ps1
54+
$ExecutionContext.SessionState.LanguageMode
55+
```
56+
4457
## References
4558

4659
{% embed url="https://blogs.msdn.microsoft.com/powershell/2017/11/02/powershell-constrained-language-mode/" %}
@@ -50,4 +63,3 @@ If you have the ability to downgrade to Powershell 2.0, this can allow you to by
5063
{% embed url="https://adsecurity.org/?p=2604" %}
5164

5265
{% embed url="https://pentestn00b.wordpress.com/2017/03/20/simple-bypass-for-powershell-constrained-language-mode/" %}
53-

0 commit comments

Comments
 (0)