How to block specific PowerShell Commands?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements

Welcome Idira to LIVEcommunity!

Our community just got stronger! Explore new identity security resources, connect with experts, and discover more ways to learn and collaborate.

Meet Idira

How to block specific PowerShell Commands?

L1 Bithead

Hello,

 

I was wondering if there may be a possibility to block specific power shell commands and how would this be done? For instance, we would like to block this command:

Add-LocalGroupMember -Group "Administrators" -Member "username" ?

1 accepted solution

Accepted Solutions

L5 Sessionator

iI was wondering if there may be a possibility to block specific power shell commands and how would this be done? For instance, we would like to block this command in cyberark epm - Add-LocalGroupMember -Group "Administrators" -Member "username" ?

Yes, you can block specific PowerShell commands like 

Add-LocalGroupMember

 using CyberArk Endpoint Privilege Manager (EPM). This is particularly useful for preventing users from adding themselves or others to the Administrators group.

Here's how you can implement this:

  1. Create an advanced policy to block the specific PowerShell command:
    • In the EPM management console, go to Policies
    • Click "Create advanced policy"
    • Select "Windows" as the platform and "Block" as the action
    • Give your policy a name like "Block Add-LocalGroupMember Command"
  1. Define the application scope:
    • Under Scope, click "Add definition"
    • Set Definition type to "Executable"
  • Add the following properties:
      • Original filename: "powershell.exe"
      • Parameters: contains "Add-LocalGroupMember" (make sure case sensitive is NOT selected)
    • You can also add additional parameters like "-Group "Administrators"" to be more specific
  1. Set the policy targets:
    • Under Targets, define which computers, users, and groups this policy will apply to
    • You can target all computers or specific AD computer groups

This approach aligns with CyberArk's security best practices for protecting against LOLBAS (Living Off The Land Binaries And Scripts) attacks, as described in the Secure endpoints with EPM policies documentation.

For additional protection, you might also want to consider:

  1. Implementing the "Remove local administrators" policy to enforce least privilege principles
  2. Using "Protect Administrative User Groups" setting to prevent elevated applications from modifying administrative user groups

This multi-layered approach will provide comprehensive protection against unauthorized privilege escalation attempts.

 

View solution in original post

5 REPLIES 5

L5 Sessionator

iI was wondering if there may be a possibility to block specific power shell commands and how would this be done? For instance, we would like to block this command in cyberark epm - Add-LocalGroupMember -Group "Administrators" -Member "username" ?

Yes, you can block specific PowerShell commands like 

Add-LocalGroupMember

 using CyberArk Endpoint Privilege Manager (EPM). This is particularly useful for preventing users from adding themselves or others to the Administrators group.

Here's how you can implement this:

  1. Create an advanced policy to block the specific PowerShell command:
    • In the EPM management console, go to Policies
    • Click "Create advanced policy"
    • Select "Windows" as the platform and "Block" as the action
    • Give your policy a name like "Block Add-LocalGroupMember Command"
  1. Define the application scope:
    • Under Scope, click "Add definition"
    • Set Definition type to "Executable"
  • Add the following properties:
      • Original filename: "powershell.exe"
      • Parameters: contains "Add-LocalGroupMember" (make sure case sensitive is NOT selected)
    • You can also add additional parameters like "-Group "Administrators"" to be more specific
  1. Set the policy targets:
    • Under Targets, define which computers, users, and groups this policy will apply to
    • You can target all computers or specific AD computer groups

This approach aligns with CyberArk's security best practices for protecting against LOLBAS (Living Off The Land Binaries And Scripts) attacks, as described in the Secure endpoints with EPM policies documentation.

For additional protection, you might also want to consider:

  1. Implementing the "Remove local administrators" policy to enforce least privilege principles
  2. Using "Protect Administrative User Groups" setting to prevent elevated applications from modifying administrative user groups

This multi-layered approach will provide comprehensive protection against unauthorized privilege escalation attempts.

 

L4 Transporter

iI was wondering if there may be a possibility to block specific power shell commands and how would this be done? For instance, we would like to block this command in cyberark epm - Add-LocalGroupMember -Group "Administrators" -Member "username" ?

Yes, you can block specific PowerShell commands like 

Add-LocalGroupMember

 using CyberArk Endpoint Privilege Manager (EPM). This is particularly useful for preventing users from adding themselves or others to the Administrators group.

Here's how you can implement this:

  1. Create an advanced policy to block the specific PowerShell command:
    • In the EPM management console, go to Policies
    • Click "Create advanced policy"
    • Select "Windows" as the platform and "Block" as the action
    • Give your policy a name like "Block Add-LocalGroupMember Command"
  1. Define the application scope:
    • Under Scope, click "Add definition"
    • Set Definition type to "Executable"
  • Add the following properties:
      • Original filename: "powershell.exe"
      • Parameters: contains "Add-LocalGroupMember" (make sure case sensitive is NOT selected)
    • You can also add additional parameters like "-Group "Administrators"" to be more specific
  1. Set the policy targets:
    • Under Targets, define which computers, users, and groups this policy will apply to
    • You can target all computers or specific AD computer groups

This approach aligns with CyberArk's security best practices for protecting against LOLBAS (Living Off The Land Binaries And Scripts) attacks, as described in the Secure endpoints with EPM policies documentation.

For additional protection, you might also want to consider:

  1. Implementing the "Remove local administrators" policy to enforce least privilege principles
  2. Using "Protect Administrative User Groups" setting to prevent elevated applications from modifying administrative user groups

This multi-layered approach will provide comprehensive protection against unauthorized privilege escalation attempts.

 

L0 Member

Hello @Touseef-ur rehman​ ,

We have tried the same approach, but in this case, the command is not being blocked as expected. We are using the following command:

net localgroup "Administrators" /add "AzureAD\username"

We have included the parameter that contains : net localgroup "Administrators"

 

Hmm I do recall might be related, that there is a registry key that needs to amending to do with the LSASS that then allows epm to inject and handle the admin group, maybe this is why users can add themselves to the group via powershell/cmd - fix mentioned here - https://community.cyberark.com/s/question/0D7Ht000008iEluKAE/remove-local-administrators-on-windows-not-working?fromEmail=1&s1oid=00D300000000HNg&s1nid=0DB50000000TRHA&s1uid=005Ht00000Ai0zl&s1ext=0&emkind=chatterBestAnswerNotification&emtm=1722338622637

Hmm I do recall might be related, that there is a registry key that needs to amending to do with the LSASS that then allows epm to inject and handle the admin group, maybe this is why users can add themselves to the group via powershell/cmd - fix mentioned here - https://community.cyberark.com/s/question/0D7Ht000008iEluKAE/remove-local-administrators-on-windows-not-working?fromEmail=1&s1oid=00D300000000HNg&s1nid=0DB50000000TRHA&s1uid=005Ht00000Ai0zl&s1ext=0&emkind=chatterBestAnswerNotification&emtm=1722338622637

  • 1 accepted solution
  • 828 Views
  • 5 replies
  • 0 Likes
Like what you see?

Show your appreciation!

Click Like if a post is helpful to you or if you just want to show your support.

Click Accept as Solution to acknowledge that the answer to your question has been provided.

The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!

These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the LIVEcommunity as a whole!

The LIVEcommunity thanks you for your participation!