Forums
New posts
Search forums
News
Security News
Technology News
Giveaways
Giveaways, Promotions and Contests
Discounts & Deals
Reviews
Users Reviews
Video Reviews
Support
Windows Malware Removal Help & Support
Mac Malware Removal Help & Support
Mobile Malware Removal Help & Support
Blog
Log in
Register
What's new
Search
Search titles only
By:
Search titles only
By:
Reply to thread
Menu
Install the app
Install
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Forums
Security
Guides - Privacy & Security Tips
How do you secure PowerShell?
Message
<blockquote data-quote="Andy Ful" data-source="post: 623535" data-attributes="member: 32260"><p>I noticed that many users are interested in securing Windows Home from PowerShell attacks. There are a few ways to do it, using GPO, reg tweaks or SRP.</p><p></p><p><strong>A. Disabling PowerShell script execution by reg tweak (Windows 7+):</strong></p><p>[HKEY_LOCAL_MACHINE \Software\Policies\Microsoft\Windows\PowerShell]</p><p>"EnableScripts"=dword:00000000</p><p>The above reg tweak can stop known PowerShell bypass (paths omitted for simplicity):</p><p>powershell.exe "-Command" "if((Get-ExecutionPolicy ) -ne 'AllSigned') { Set-ExecutionPolicy -Scope Process Bypass }; & 'malware.ps1'"</p><p>etc.</p><p>The user can still run scripts from PowerShell console, for example (paths omitted for simplicity):</p><p>Get-Content helloworld.ps1 | PowerShell.exe -noprofile -</p><p></p><p><strong>B. Restricting PowerShell by reg tweak to Constrained Language mode (PowerShell v.3.0 or later).</strong></p><p>Constrained language mode locks down PowerShell to the core elements (no access to: direct .NET scripting, invocation of Win32 APIs via the Add-Type cmdlet, and interaction with COM objects).</p><p>[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment]</p><p>"__PSLockDownPolicy"="4"</p><p></p><p><strong>C. Using Default Deny Software Restriction Policies</strong> with Enforcement setting 'All software files' or 'All software files except libraries (such as Dlls)'. Scripts can be run with Administrative Rights when SRP are applied to 'All users except local administrators'.</p><ol> <li data-xf-list-type="ol">Adding PowerShell extensions to 'Designated File Types' list.<br /> This can disable script execution when using Windows Explorer or Internet Explorer, by clicking PowerShell script or choosing 'Run with PowerShell' from the right click context menu.<br /> The script can still be executed when using commands with sponsors (PowerShell.exe, PowerShell_ise.exe):<br /> <em>powershell.exe "-Command" "if((Get-ExecutionPolicy ) -ne 'AllSigned') { Set-ExecutionPolicy -Scope Process Bypass }; & 'malware.ps1'"</em><br /> etc.</li> <li data-xf-list-type="ol">Adding Disallowed rule '*.PS1' (or similar rules for other extensions). This can stop all examples of script execution from C.1. - PowerShell console is accessible as standard user. PowerShell still exists in the System.Management.Automation.dll (System.Management.Automation.ni.dll) and can be executed through a memory exploit to run scripts with nonstandard extensions.</li> <li data-xf-list-type="ol">Applying Disallowed rules to powershell.exe and powershell_ise.exe . This can stop all examples of script execution from C.1. - PowerShell console is not accessible as standard user. PowerShell still exists in the System.Management.Automation.dll (System.Management.Automation.ni.dll) and can be executed through a memory exploit.</li> <li data-xf-list-type="ol">When SRP Default Security Level: 'Disallowed' or 'Basic User' is applied and the enforcement is set to apply to ‘All users except local administrators’, then PowerShell (as standard user) is set to Constrained Language Mode (in Windows 7+ with installed PowerShell 5+). This can stop many malware scripts and exploit tools. In Windows 7, one should have .NET Framework 4.5.2 installed, and then install WMF 5.1: <em><a href="https://msdn.microsoft.com/en-us/powershell/wmf/5.1/install-configure" target="_blank">Install and configure WMF 5.1</a></em> . Whitelisted locations in SRP, do not change Constrained Language Mode setting. When PowerShell is run as administrator the Language mode is set to FullLanguage.</li> </ol><p>.</p><p>Post edited to add System.Management.Automation.ni.dll .</p><p>There is a way to bypass<strong> __PSLockDownPolicy</strong>, but this can be prevented when using it with <strong>Disabling PowerShell script execution </strong>reg tweak.</p></blockquote><p></p>
[QUOTE="Andy Ful, post: 623535, member: 32260"] I noticed that many users are interested in securing Windows Home from PowerShell attacks. There are a few ways to do it, using GPO, reg tweaks or SRP. [B]A. Disabling PowerShell script execution by reg tweak (Windows 7+):[/B] [HKEY_LOCAL_MACHINE \Software\Policies\Microsoft\Windows\PowerShell] "EnableScripts"=dword:00000000 The above reg tweak can stop known PowerShell bypass (paths omitted for simplicity): powershell.exe "-Command" "if((Get-ExecutionPolicy ) -ne 'AllSigned') { Set-ExecutionPolicy -Scope Process Bypass }; & 'malware.ps1'" etc. The user can still run scripts from PowerShell console, for example (paths omitted for simplicity): Get-Content helloworld.ps1 | PowerShell.exe -noprofile - [B]B. Restricting PowerShell by reg tweak to Constrained Language mode (PowerShell v.3.0 or later).[/B] Constrained language mode locks down PowerShell to the core elements (no access to: direct .NET scripting, invocation of Win32 APIs via the Add-Type cmdlet, and interaction with COM objects). [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment] "__PSLockDownPolicy"="4" [B]C. Using Default Deny Software Restriction Policies[/B] with Enforcement setting 'All software files' or 'All software files except libraries (such as Dlls)'. Scripts can be run with Administrative Rights when SRP are applied to 'All users except local administrators'. [LIST=1] [*]Adding PowerShell extensions to 'Designated File Types' list. This can disable script execution when using Windows Explorer or Internet Explorer, by clicking PowerShell script or choosing 'Run with PowerShell' from the right click context menu. The script can still be executed when using commands with sponsors (PowerShell.exe, PowerShell_ise.exe): [I]powershell.exe "-Command" "if((Get-ExecutionPolicy ) -ne 'AllSigned') { Set-ExecutionPolicy -Scope Process Bypass }; & 'malware.ps1'"[/I] etc. [*]Adding Disallowed rule '*.PS1' (or similar rules for other extensions). This can stop all examples of script execution from C.1. - PowerShell console is accessible as standard user. PowerShell still exists in the System.Management.Automation.dll (System.Management.Automation.ni.dll) and can be executed through a memory exploit to run scripts with nonstandard extensions. [*]Applying Disallowed rules to powershell.exe and powershell_ise.exe . This can stop all examples of script execution from C.1. - PowerShell console is not accessible as standard user. PowerShell still exists in the System.Management.Automation.dll (System.Management.Automation.ni.dll) and can be executed through a memory exploit. [*]When SRP Default Security Level: 'Disallowed' or 'Basic User' is applied and the enforcement is set to apply to ‘All users except local administrators’, then PowerShell (as standard user) is set to Constrained Language Mode (in Windows 7+ with installed PowerShell 5+). This can stop many malware scripts and exploit tools. In Windows 7, one should have .NET Framework 4.5.2 installed, and then install WMF 5.1: [I][URL='https://msdn.microsoft.com/en-us/powershell/wmf/5.1/install-configure']Install and configure WMF 5.1[/URL][/I] . Whitelisted locations in SRP, do not change Constrained Language Mode setting. When PowerShell is run as administrator the Language mode is set to FullLanguage. [/LIST] . Post edited to add System.Management.Automation.ni.dll . There is a way to bypass[B] __PSLockDownPolicy[/B], but this can be prevented when using it with [B]Disabling PowerShell script execution [/B]reg tweak. [/QUOTE]
Insert quotes…
Verification
Post reply
Top