Splunk Enterprise Security

Splunk Query

rupeshn
Explorer

Hi,

After Extracting a field using regex. I now need to compare whether that particular field contains any command . Could you please help how to proceed further using eval,match or any other way?

0 Karma

sanjeev543
Communicator

Hi,

You could write the regex to match the field values to capture the commands in your newly extracted field. See below,

| makeresults 
| eval commands="vi,cd,hello,world"
| makemv delim="," commands
| mvexpand commands
| rex field=commands "(?<abc>.*)"
| eval contains_command=if(match(abc,"vi|cd"),"Yes","No")

Here I have extracted field abc from field commands and then I used eval and simple regex using match function to identify the commands in field abc
If it's there then I will see result as yes and no respectively.

0 Karma

493669
Super Champion

Hi @rupeshn,
Try below-

...| eval matches = if(match(fieldname,"command Line"), 1, 0)

If it find command line in fieldname then it will return 1 else 0

0 Karma

rupeshn
Explorer

That can be any command. Can i write a regex for command in place of "command line". If yes, Could you please suggest.

0 Karma

493669
Super Champion

Please provide more details on sample data and what output are you expecting

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.


Introducing Unified TDIR with the New Enterprise Security 8.2

Read the blog
Get Updates on the Splunk Community!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...