Using Regular Expressions in Tanium Index, to Search for Multiple Files Containing Spaces in the File Name
In this article, one of our TAMs shares a resolution for a customer who is having difficulty using Index to search for multiple files, including those with filenames containing spaces. The customer is leveraging regular expressions, and the questions the customer has been trying to use are yielding inconsistent results. Depending on the data being gathered, for a professional this can result in frustration in the best case, to a false sense of security in the more severe.
In this scenario, the reference example is:
Get Index Query File Path Using Name[1,"(?i).*(FileName01.ext1| FileName02.ext2|File Name With Spaces.ext3)$"] from all machines with OS Platform contains Windows
Resolution
Regular Expressions can be like a smooth canoe ride that turns into a Level 4 Whitewater Adventure if you take the wrong fork. In this scenario, the frustrated customer is getting inconsistent results because of the following errors in Regular Expression syntax:
-
File extensions should be properly escaped by using the \ character
Corrected To: \ext1
-
There was an additional whitespace after the first or condition fileName01\ext1|**_**FileName02
Corrected To: FileName01\ext1|FileName02\ext2
-
Whenever the Use Regular Expression checkbox is selected and the file name has spaces, be sure to use the proper syntax \s to escape those. Otherwise, the RegEx will not be evaluated as expected.
Corrected To: File\sName\sWith\sSpaces\ext3
With the previously listed corrections applied the resulting question is:
Get Index Query File Path Using Name[1,(FileName01\ext1|FileName02\ext2|File\sName\sWith\sSpaces\ext3)] from all machines with OS Platform contains "Windows"
It is worth mentioning that once the query is selected the Question Bar reformats it by adding double quotes surrounding the parentheses, as this is the properly formatted question that will be executed on the endpoint:
Get Index Query File Path Using Name[1,"(FileName01\ext1|FileName02\ext2|File\sName\sWith\sSpaces\ext3)"] from all machines with OS Platform contains Windows
This example should help clear up any confusion for customers searching for multiple files. Happy RegEx-ing!
Additional Information
-
Tanium Incident Response 5.0 User Guide – Indexing File Systems
-
Related articleCreating and Testing Regular Expressions for Tuning Index Exclusions
-
Related articleRegular Expression (Regex) Basics and Best Practices
-
Video tutorial on using Tanium Index to find which computer names are hosting a specified filename