- Access exclusive content
- Connect with peers
- Share your expertise
- Find support resources
Our community just got stronger! Explore new identity security resources, connect with experts, and discover more ways to learn and collaborate.
11-06-2024 09:27 PM
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?
11-06-2024 11:45 PM
You can create an exception to the rule by editing the scope option
11-06-2024 11:49 PM
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.
11-07-2024 01:12 AM
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:
Here’s an example of how you can write this regular expression:
^/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.
11-07-2024 01:26 AM
Robert, is that what you meant?
I tried this it didn't work, maybe I misunderstood something.
11-07-2024 02:00 AM
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?
11-18-2024 06:52 AM
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.
11-18-2024 11:52 PM
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.
01-28-2025 04:33 PM
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 .
01-28-2025 04:44 PM
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.
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!

