Splunk Search

How to use mvfilter with multiple regexes?

pdoconnell
Path Finder

I am building an alert based on file accesses to certain files. This is what I have so far:

index=wineventlog sourcetype=WinEventLog:Security EventCode=560 OR EventCode=4663 OR EventCode=5145 NOT user=*$
| lookup lookup_wild_folder folder_lookup AS folder_name, server AS host OUTPUT group_lookup user_lookup file_exceptions 
| eval user=if(isnull(Object_Name),null,user)
| eval user=if(match(Object_Name,folder_lookup),null,user)
| eval user=if(match(user_lookup,user),null,user)
| eval user=mvfilter(match(Object_Name,file_exceptions))
| table user host folder_lookup folder_name Object_Name Message group_lookup
| ldapfilter domain=default search="(sAMAccountName=$user$)" attrs="memberOf"
| rex field=memberOf "^CN=(?<group_name>[^,]+)"
| eval user=mvfilter(match(group_name,group_lookup))
| search user!=null
| table user host folder_lookup folder_name Object_Name Message group_lookup group_name

My problems are in the mvfilter lines. What I want is to check if the user is a member of an Active Directory group that is in the list of owners for the files (e.g. is user foo in group bar or baz), and is the file something we care about (e.g. does Object_Name contain one of the various file names from the lookup). The mvfilter command LOOKS similar to what I want, but in reverse (the mv variables are the regexes, of which any match is a reason to exit the search). Do I need to create a junk variable to do this?

0 Karma

woodcock
Esteemed Legend

If you make sure that your lookup values have known delimiters, then you can do it like this. Let's assume you are using a pair of colons ( :: ) to make your list and your input files look something like this (notice the delimiter on both ends of the strings, too):

lookup_wild_folder

folder_lookup,server,group_lookup,user_lookup,file_exceptions
some_folder,some_server,::group_A::group_B::group_C::,some_user,::exceptions_A::exceptions_B::exceptions_C::

Then you can do your search like this (untested but should work):

index=wineventlog sourcetype=WinEventLog:Security EventCode=560 OR EventCode=4663 OR EventCode=5145 NOT user=*$ | lookup lookup_wild_folder folder_lookup AS folder_name, server AS host OUTPUT group_lookup user_lookup file_exceptions | eval user=if(isnull(Object_Name),null,user) | eval user=if(match(Object_Name,folder_lookup),null,user) | eval user=if(match(user_lookup,user),null,user) | eval user=mvfilter(if(mvindex(split($file_exceptions$, "::" . $Object_Name$ . "::"), 0)) != $file_exceptions$)) | table user host folder_lookup folder_name Object_Name Message group_lookup | ldapfilter domain=default search="(sAMAccountName=$user$)" attrs="memberOf" | rex field=memberOf "^CN=(?<group_name>[^,]+)" | eval user=mvfilter(if(mvindex(split($group_lookup$, "::" . $group_name$ . "::"), 0)) != $group_lookup$)) | search user!=null | table user host folder_lookup folder_name Object_Name Message group_lookup group_name
0 Karma
Get Updates on the Splunk Community!

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...