Splunk Enterprise Security

How to filter query results by a lookuptable containing regex's?

mertox
Explorer

I am trying to filter query results based on regex. They are stored within a lookuptable like this:

path
/etc/group
/etc/passwd
/etc/rc0.d/*
/etc/rc1.d/*
the first step would be to replace all "/" with "\/" to get a valid regex and concat them using "|" later on. The query I would like to use would look like:

| from datamodel:"Change_Analysis"."Filesystem_Changes"
| eval path = file_path + file_name
| eval path_regex = [| inputlookup security_related_paths | eval path = replace(path, "/", "\/") | stats delim="|" values(path) as paths | mvcombine paths | return $paths]
| regex path=path_regex
I'm guessing there is a quite simple solution for this use case...

Thank you in advance!

1 Solution

VatsalJagani
SplunkTrust
SplunkTrust

Hi @mertox,

| from datamodel:"Change_Analysis"."Filesystem_Changes"
| eval path = file_path.file_name
| regex path = [| inputlookup security_related_paths | stats values(path) as paths | eval path_regex=mvjoin(paths, "|")  | eval path_regex = "\"".path_regex."\"" | return $path_regex]

map command can also help here, would you mind trying this query as well?

| inputlookup security_related_paths 
| eval path = replace(path, "/", "\/") 
| stats values(path) as paths 
| eval path_regex=mvjoin(paths, "|") 
| map search="| from datamodel:\"Change_Analysis\".\"Filesystem_Changes\" | eval path = file_path.file_name | regex path=$path_regex$"

Try the above two queries selext the one which gives better performance. Hope this helps!!!

View solution in original post

0 Karma

VatsalJagani
SplunkTrust
SplunkTrust

Hi @mertox,

| from datamodel:"Change_Analysis"."Filesystem_Changes"
| eval path = file_path.file_name
| regex path = [| inputlookup security_related_paths | stats values(path) as paths | eval path_regex=mvjoin(paths, "|")  | eval path_regex = "\"".path_regex."\"" | return $path_regex]

map command can also help here, would you mind trying this query as well?

| inputlookup security_related_paths 
| eval path = replace(path, "/", "\/") 
| stats values(path) as paths 
| eval path_regex=mvjoin(paths, "|") 
| map search="| from datamodel:\"Change_Analysis\".\"Filesystem_Changes\" | eval path = file_path.file_name | regex path=$path_regex$"

Try the above two queries selext the one which gives better performance. Hope this helps!!!

0 Karma

mertox
Explorer

The first option fails with:

Error in 'SearchParser': Missing a search command before '\'. Error at position '10284' of search query 'litsearch ((index=* OR index=_*) index=auditd_file...{snipped} {errorcontext = tc\/group|\/etc\/gsha}'.
0 Karma

VatsalJagani
SplunkTrust
SplunkTrust

Hi @mertox, I've removed | eval path = replace(path, "/", "\/") from the query because I think it should work even without that in regex. Can you please try?

0 Karma

mertox
Explorer

never the less. The map query takes around 2 seconds, the direct one doubles to execution time to around 4.

0 Karma

VatsalJagani
SplunkTrust
SplunkTrust

Awesome, map does great job then.

0 Karma

mertox
Explorer

Hi @VatsalJagani, seems like this does not solve the issue:

Error in 'SearchParser': Missing a search command before '/'. Error at position '10283' of search query 'litsearch ((index=* OR index=_*) index=auditd_file...{snipped} {errorcontext = etc/group|/etc/gshado}'

but I found the our pitfall. This works quite good:

| from datamodel:"Change_Analysis"."Filesystem_Changes"
 | eval path = file_path.file_name
 | regex path=[| inputlookup security_related_paths | stats values(path) as paths | eval path_regex=mvjoin(paths, "|") | eval path_regex = "\"".path_regex."\"" | return $path_regex]
0 Karma

VatsalJagani
SplunkTrust
SplunkTrust

Thanks @mertox for finding this solution, I've edited query in my answer so other can get help from that.

0 Karma

mertox
Explorer

works like a charm! Thank you a lot!

0 Karma

VatsalJagani
SplunkTrust
SplunkTrust

Glad to here that. I've added another query try that one as well let me know if that works and which gives you better performance.

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

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...