Splunk Search

Regex for looking at executables in a specific folder

tbradsher86
Engager

Hi All,

I am trying to create a search that will parse our endpoint logs for any executable that have been run from the Desktop or Downloads folders and any sub folders. Most searches I try return a large number of false positives (product names or folders have desktop or downloads in the name, but they aren't specifically in that folder. So to combat this I'm trying to rex the specific folder. Using the regex I have below on regex101 it works exactly how I expect. However in splunk I get, first a missing parenthesis error, and if I arbitrarily add another close parenthesis I get "look back is not a fixed length" error. Thoughts?

sourcetype=endpointsource AND event_name=process_ran
| rex field=CommandLine "(?<=\\Desktop|Downloads\\)(?<EXE_RAN>.*\.exe)"
| table _time ComputerName TargetFileName EXE_RAN user

Example of it working on regex101: https://regex101.com/r/24uxEB/1

Thanks!

0 Karma
1 Solution

jpolvino
Builder

Here is one way:

| rex field=CommandLine ".*(Desktop|Downloads)\\\(?<EXE_RAN>.*\.exe)"

https://regex101.com/r/24uxEB/2

View solution in original post

mayurr98
Super Champion

Try this:

| rex field=CommandLine "(?<=\\\Desktop|Downloads\\\)(?<EXE_RAN>.*\.exe)"

Also try run anywhere search

| makeresults 
| eval data="C:\users\user1\Downloads\blah.exe,C:\Users\user234\Downloads\sqldeveloper-17.4.0.355.2349-x64\sqldeveloper\sqldeveloper\bin\sqldeveloper64W.exe,C:\Users\user9823\AppData\Local\iManage\Installer\Updates\iManage Work Desktop for Windows x86.exe,C:\Users\johnsmith\Desktop\dataloader-44.0.0.exe" 
| makemv data delim="," 
| mvexpand data 
| table data 
| rex field=data "(?<=\\\Desktop|Downloads\\\)(?<EXE_RAN>.*\.exe)"
0 Karma

jpolvino
Builder

Here is one way:

| rex field=CommandLine ".*(Desktop|Downloads)\\\(?<EXE_RAN>.*\.exe)"

https://regex101.com/r/24uxEB/2

tbradsher86
Engager

This worked perfectly, that extra escape character really got me. Thank you!

0 Karma

tbradsher86
Engager

This gets me the following error still:

Error in 'rex' command: Encountered the following error while compiling the regex '.(Desktop|Downloads)(?..exe)': Regex: unmatched closing parenthesis.

0 Karma

jpolvino
Builder

Sorry, forgot Splunk needed another escape character. Fixed above!

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Persistent Queue at TcpOut — One of Splunk's Most Practical Features

Splunk introduced persistent queueing at the tcpout layer as one of the most practical resilience features in ...

Skip the Awkward Silence: Have a .conf-ersation at .conf26

Picture this. You arrive at .conf26 already having your socializing and networking plans mapped out. No ...

Rethinking Zero Trust: From Product Purchases to Logical Control Evidence

Implementing Zero Trust (ZT) across complex environments often falters at the very beginning due to a ...