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!

Observability Highlights | January 2023 Newsletter

 January 2023New Product Releases Splunk Network Explorer for Infrastructure MonitoringSplunk unveils Network ...

Security Highlights | January 2023 Newsletter

January 2023 Splunk Security Essentials (SSE) 3.7.0 ReleaseThe free Splunk Security Essentials (SSE) 3.7.0 app ...

Platform Highlights | January 2023 Newsletter

 January 2023Peace on Earth and Peace of Mind With Business ResilienceAll organizations can start the new year ...