Usage of regex for an executable application definition's 'parameter' not working as expected

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

Usage of regex for an executable application definition's 'parameter' not working as expected

L2 Linker

We have CyberArk EPM SaaS version (25.10.0.5070)

I want to use below regular expression to block few powershell commands that fetch from the internet and pipe straight into Invoke-Expression. We drafted below regex, but when configured in the 'Parameter' property field's value, is not able to detect the sample commands listed. Has anyone experience this issue with using regex?

 

RegEx:

^.*(iwr|invoke-webrequest)[^|]*\|\s*(iex|invoke-expression).*

RegEx explanation:

(iwr|invoke-webrequest) -> matches 'iwr' or 'invoke-webrequest' commands to download from internet [^|]*\| -> eats everything from the end of iwr up to the first | \s*(iex|invoke-expression) -> confirms the next token is 'iex' or 'invoke-expression'

Sample lines of command the regular expression should be able to catch:

powershell.exe iwr https://google.com | iex powershell.exe iwr https://google.com | invoke-expression powershell.exe invoke-webrequest https://google.com | iex

 Field_Content_versions_oct20__068Vy00000uzKSzIAM.png

2 REPLIES 2

L2 Linker

CyberArk EPM uses the CAtlRegExp class; therefore, we must use the syntax and features supported by CAtlRegExp

 

Regular Expression Syntax

 

Below simple example match either "iwr" or "invoke-webrequest" match

.*((iwr)|(invoke-webrequest)).*

Field_Content_versions_oct20__068Vy00000v4OZEIA2.png 

L2 Linker

Thank you so much @Manikandan Krishnasamy​ for this sample regex. I was able to only match the command when there is no pipe (|) used at all in the command. For example this below regex,

.*((iwr)|(invoke-webrequest)).*((http)|(https)).*((iex)|(invoke-expression)).*

is able to match this command:

powershell.exe iwr https://google.com iex

but NOT able to match this command because there is a pipe:

powershell.exe iwr https://google.com | iex

Could someone from CyberArk EPM support/engineer confirm for sure if this truly a limitation?

  • 217 Views
  • 2 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!