Splunk Search

I need help with my search query

jcorkey
Explorer

I have the follow search query:

sourcetype=linux_secure source="/var/log/*" "su: ("  | eval Date=strftime(_time, "%Y/%m/%d") | rex ".*:\d{2}\s(?<hostname>\S+)" | rex "su:\s\Sto\sroot\S\s(?<SU>\S+)"  | stats  count by Date, hostname, SU  | rename  count as "Occurrences"  | rename  SU as "Account with Escalated Privileges" | sort - Date

The regex seems wrong. I got the search from gosplunk.com and it's supposed to help detect who escalated privileges on any host in a given time range. I'm not good with regex and can't tell if this is wrong and why it's not working.

0 Karma
1 Solution

cpetterborg
SplunkTrust
SplunkTrust

My linux_secure data looks different in the format. This worked for my data:

sourcetype=linux_secure  "su:" | eval Date=strftime(_time, "%Y/%m/%d") | rex ".:\d{2}\s(?<hostname>\S+)" | rex "by (?<SU>[^(]+)"  | stats count by Date, hostname, SU | rename count as "Occurrences" | rename SU as "Account with Escalated Privileges" | sort - Date

View solution in original post

sbbadri
Motivator

@jcorkey

index=nix source=/var/log/*  "su: (" | eval Date=strftime(_time,"%Y/%m/%d") | rex field=_raw ".*:\d{2}\s(?P&lt;hostname&gt;\S+)" | rex field=_raw "su\:\s+\(\S+\s\S+\)\sroot\s\S+\s(?P&lt;SU&gt;\S+)" | stats count by Date, hostname, SU | rename count as "Occurrences" | rename SU as "Account with Escalated Privileges" | sort - Date
0 Karma

DalJeanis
Legend

marked as code for you

0 Karma

cpetterborg
SplunkTrust
SplunkTrust

My linux_secure data looks different in the format. This worked for my data:

sourcetype=linux_secure  "su:" | eval Date=strftime(_time, "%Y/%m/%d") | rex ".:\d{2}\s(?<hostname>\S+)" | rex "by (?<SU>[^(]+)"  | stats count by Date, hostname, SU | rename count as "Occurrences" | rename SU as "Account with Escalated Privileges" | sort - Date

jcorkey
Explorer

This seems to be working. Thanks!

0 Karma

cpetterborg
SplunkTrust
SplunkTrust

If this works for you, please accept it as the answer for the question so that others can know what answer worked for you and that the question does have an answer.

Thanks!!

0 Karma

sbbadri
Motivator

Can you paste sample event/data.

0 Karma

richgalloway
SplunkTrust
SplunkTrust

I edited the query to include the rex field names.
What makes you think the regex is wrong? If you run the base search by itself do you get events?

---
If this reply helps you, Karma would be appreciated.
0 Karma
Get Updates on the Splunk Community!

.conf25 Registration is OPEN!

Ready. Set. Splunk! Your favorite Splunk user event is back and better than ever. Get ready for more technical ...

Detecting Cross-Channel Fraud with Splunk

This article is the final installment in our three-part series exploring fraud detection techniques using ...

Splunk at Cisco Live 2025: Learning, Innovation, and a Little Bit of Mr. Brightside

Pack your bags (and maybe your dancing shoes)—Cisco Live is heading to San Diego, June 8–12, 2025, and Splunk ...