PTA rule creation with regular expression, how to write it?

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

PTA rule creation with regular expression, how to write it?

L4 Transporter

Hello, CyberArk community!

 

I want to test and create a rule in the PTA that would prevent users from executing the rm -rf command in the linux OS machine, but merely creating the rule (.*)rm -rf(.*) would trigger a lot of false positives when users would attempt to use this command for legitimate purpose.

 

Can someone please help, how do I need to write this regular expression to limit the blocking of this command when users are in, let's say, /etc folder, but in any other locations it it's going to be legitimate and will not get triggered?

9 REPLIES 9

L7 Applicator

You can create an exception to the rule by editing the scope option

Hello, Robert, thanks for the reply!

 

How exactly? from all I see, is that I can define a scope and put some specifications based on the vault users/accounts/target machines, but I don't see an option to specify the path, where I want this rule to be applied in.

L7 Applicator

Perhaps this may help

 

 

To create a regular expression that blocks a command only when users are in the 

/etc

 folder, you can use the following approach:

  1. Anchor the pattern to the start of the string to ensure it matches the beginning of the path.
  2. Specify the 
  3. /etc
  4.  directory.
  5. Use a wildcard to match any subdirectories or files within 
  6. /etc
  7. .

Here’s an example of how you can write this regular expression:

^/etc(/|$)

 

  • ^
  •  asserts the position at the start of the string.
  • /etc
  •  
  •  matches the 
  • /etc
  •  directory.
  • (/|$)
  •  
  •  ensures that the match is either followed by a 
  • /
  •  
  •  (indicating a subdirectory or file within 
  • /etc
  •  
  • ) or the end of the string (indicating exactly 
  • /etc
  • ).

This regex will match any path that starts with 

/etc

 

 or is exactly 

/etc

 

, effectively blocking the command in the 

/etc

 directory and its subdirectories, but allowing it elsewhere.

Robert, is that what you meant?

Field_Content_versions_oct20__068Ht00000VfefKIAR.png 

I tried this it didn't work, maybe I misunderstood something.

Hey, Robert.

 

I just checked if I can get the chatGPT to write the regular expression for me, and I was able to get one: .*\brm\s+-r\s+/etc(/.*)?\b.*

 

This one works for cases when the /etc folder is explicitely mentioned, but it doesn't if it's not. So if I am in the /etc folder and I run this prohibited command, it's not getting triggered.

 

I assume it will not be possible to create a regex that would allow to cover this aspect as well, right? From my understanding we only specify in the patterns whatever we are tracking in user's commands execution, but not which directory they are in at the moment, is that correct?

 

 

Hi @Almaz Akhmadullin​ 

 

As the community has not yet provided an answer to this question for some time, were you able to find a solution?

If so, we'd appreciate it if you could share it.

Your solution could help other community members who have similar questions.

 

Thanks, Liad.

Hello, LiadD,

 

Yes, I was able to get the regular expression that satisfied my requirement, it's: .*^\s*\brm\s+-r\s+(/etc\b|/etc/.*)\b\s*$

 

It does what I want, terminates the session if a user tries to execute rm -r /etc/

 

Only one downside, is that if a user is in the /etc folder and tries to run the command without /etc then it wouldn't work. I still don't know if it's possible to capture this case somehow.

Hi @Almaz Akhmadullin​ I think you are correct ,however I don't think Regex alone can fully solve this problem because it only matches command strings, not the directory context. What about this ,.. alog with pta , you can use Auditd (Linux auditing tool) to monitor and block rm commands executed within /etc/ directory .

Also, we could try writing a regex to block all methods that allow users to navigate to the /etc directory.

 

Example:

 

Ex-.*^\s*(\bcd\b|\bpushd\b|\balias\b\s*cd\s*=\s*(["'])?cd\s+/etc(/.*)?\b.*)$

 

However, it would be better to use the suspend action rather than terminate, so that a manager or authorized personnel can approve the action for legitimate use cases. Additionally, you can exclude specific users from this restriction if needed.

  • 275 Views
  • 9 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!