• Blog
  • Contact
  • About
Menu

The PowerShell Bear

I'm here to help you!
  • Blog
  • Contact
  • About

Execution Policy is not a security countermeasure (Part 2: Group Policy)

July 10, 2016

In my last post, I wrote about how setting the Execution Policy is not a viable security countermeasure, and is very easy to bypass by malicious actors.  The examples provided work when the Execution Policy is set by running "Set-ExecutionPolicy"; however, it does not bypass an Execution Policy set by Group Policy.

This post will demonstrate a way to get around that as well.

Again, create 2 files under "C:\temp\" called "EP-Demo.ps1" and "EP-Demo.bat" and paste the following lines in them:

REM Put this in EP-Demo.bat
powershell.exe -Command "$script = Get-Content C:\temp\EP-Demo.ps1 -Raw; . ([ScriptBlock]::Create($script))"
pause
# Put this in EP-Demo.ps1
Write-Host "The Execution Policy is set to: $(Get-ExecutionPolicy)"

Go ahead and double-click on EP-Demo.bat to test that it works as-is.

For the next part, assuming you don't already have a Group Policy in place to disable scripts, let's go ahead and set that in Local Group Policy:

  1. Open the Run dialog and type "gpedit.msc" to open the Local Group Policy Editor
  2. Navigate to Computer Configuration > Administrative Templates > Windows Components > Windows PowerShell
  3. Double click on "Turn on Script Execution"
  4. Change the setting from "Not Configured" to "Disabled"

Once that's changed, double click on EP-Demo.bat again, and watch it still execute the script (showing the Execution Policy as "Restricted" this time).

Note: to change your Execution Policy back, simply change the setting back to "Not Configured" and your system will revert to the settings it had previously.

So, setting up code signing or disabling scripts entirely will not stop malicious actors from leveraging PowerShell.  Although it does have some benefit in certain applications (such as automated scripting), it is not a real security countermeasure.  If you are concerned with malicious actors leveraging PowerShell, much more effective countermeasures would be to ensure your machines are fully patched, and making sure you're following solid best practices such as disabling Office macros (one common attack vector).

In Code Snippets, Just a Blog, Tips and Tricks Tags Security, Execution Policy, Best Practices, Demonstration, Group Policy
← The (very basic) Anatomy of an ObjectExecution Policy is not a security countermeasure →

Latest Posts

Blog
Using Visual Studio Code Syntax highlighting to make PowerShell better
about 3 years ago
"PoshMailKit" Release version 1.1.0 published to Gallery
about 3 years ago
"PoshMailKit" version 0.9.1-beta2 published to Gallery
about 3 years ago
New project announcement: "PoshMailKit"
about 3 years ago
Change Report: 2021
about 4 years ago

Fresh Tweets

Whatever it is, the way you tell your story online can make all the difference.
  • #PowerShell #PoshMailKit, based on #MailKit, version 1.1.1 published to the #PowerShellGallery:… https://t.co/hj3WHKq5A9
    Jun 29, 2022, 1:54 PM
  • Using Visual Studio Code Syntax highlighting to make PowerShell better https://t.co/XoFrFonUQ9 #PowerShell #VSCode #SyntaxHighlighting
    Apr 26, 2022, 4:45 PM
  • "PoshMailKit" Release version 1.1.0 published to Gallery https://t.co/MNbDLtu8VG #PowerShell #SendMailMessage #MailKit #PoshMailKit
    Apr 20, 2022, 12:59 PM
  • "PoshMailKit" version 0.9.1-beta2 published to Gallery https://t.co/BUBdaYn86a #PowerShell #SendMailMessage #MailKit #PoshMailKit
    Mar 14, 2022, 10:55 AM
  • New project announcement: "PSMailKit" https://t.co/o3kme1upaE #PowerShell #SmtpClient #Send-MailMessage #MailKit
    Mar 8, 2022, 6:54 PM

Powered by Squarespace