Splunk Search

Extracting Linux permissions using rex

izyknows
Path Finder

Hi all!

I'm looking to extract certain values from a Linux command line. Take the following example

 

| makeresults
| eval sampleCLI="find / -perm -664 -type d 2>/dev/null"
| eval sampleCLI2="find . -perm -2 -type d 2>/dev/null"
| eval sampleCLI3="find . \( -perm -o rwx \) -type d 2>/dev/null"
| eval sampleCLI4="find / -perm -o+w"

 

What I want is to extract the permissions and run some checks on it. For example, 664, 2, rwx and +w respectively in the above example. I'm having a hard type writing the regex query for this. I'm new to this and was trying to keep it simple and just get the value using negative matching like so

 

| rex field=sampleCLI* “find * -perm (?<permval>\S+)” 

 


However the rex command doesn't even run. Throws up the following error: Error in 'rex' command: The regex '“find' does not extract anything. It should specify at least one named group. Format: (?<name>...). 

Could someone please explain where I'm going wrong? Thanks very much!

Labels (3)
0 Karma
1 Solution

thambisetty
SplunkTrust
SplunkTrust

| rex field=yourfield "-perm(\s-o)?\s?(-|\+)?(?<permission>[^\s]+)"

————————————
If this helps, give a like below.

View solution in original post

thambisetty
SplunkTrust
SplunkTrust

you can't use wildcard (*) in rex field attribute.

 

| rex field=sampleCLI "-perm\s+-(-0)?(?<permission>[^\s]+)"
| rex field=sampleCLI2 "-perm\s+-(-0)?(?<permission>[^\s]+)"

 

 

————————————
If this helps, give a like below.

izyknows
Path Finder

Thank you, this is great. However, it does not match for commands like

 

find / -perm -o+w
find . \( -perm -o rwx \) -type d 2>/dev/null

 

 Is it possible for the same regex expression to have this?

0 Karma

thambisetty
SplunkTrust
SplunkTrust

| rex field=yourfield "-perm(\s-o)?\s?(-|\+)?(?<permission>[^\s]+)"

————————————
If this helps, give a like below.
Get Updates on the Splunk Community!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...