Splunk Search

How to lookup value with wildcard?

test_qweqwe
Builder

Hi.
for example, i have that log:
Apr 26 12:04:38 centos7LAB sudo: qweqwe : TTY=pts/4 ; PWD=/home/qweqwe ; USER=root ; COMMAND=/bin/chmod +x 436346
and i want to make filter by command by lookup
kinda sourcetype=sudo | stats count by host _time src_user src TTY PWD USER dest COMMAND action | lookup suspicious_commands COMMAND AS COMMAND OUTPUT COMMAND AS COMMAND | where COMMAND!="" | sort - _time

I used match_type = WILDCARD(COMMAND)

my lookup look like it:

COMMAND
*chmod*

Open my screenshot and instead of *chmod* I want see /bin/chmod +x 436346

Or what you know other solutions to make what I want?

0 Karma
1 Solution

janispelss
Path Finder

Is the lookup only used as a list of things to search for? If yes, you can try using a query like this instead
sourcetype=sudo [| inputlookup suspicious_commands ] | stats count by host _time src_user src TTY PWD USER dest COMMAND action | sort - _time

View solution in original post

janispelss
Path Finder

Is the lookup only used as a list of things to search for? If yes, you can try using a query like this instead
sourcetype=sudo [| inputlookup suspicious_commands ] | stats count by host _time src_user src TTY PWD USER dest COMMAND action | sort - _time

test_qweqwe
Builder

It works! Thank you!
Will be nice if you will explain a bit why it works, cause i have some triggers in my head.

0 Karma

janispelss
Path Finder

So when a subsearch is used in a search command (and the search command is by default the first command of a query), the subsearch expands it's results into additional search terms, where the fields of a row/event are combined with "AND" and multiple rows/events are combined with "OR".

So if you have a lookup like
COMMAND
*chmod*
*chown*

then [| inputlookup suspicious_commands] will expand into ( (COMMAND="*chmod*") OR (COMMAND="*chown*") ).

You can actually see what exactly something would expand to by using the format command, like | inputlookup suspicious_commands| format. And you can use pretty much anything for the subsearch, not just lookups.

0 Karma

starcher
Influencer

Do
lookup suspicious_commands COMMAND OUTPUT COMMAND AS cmd_match | where isnotnull(cmd_match) | fields - cmd_match

test_qweqwe
Builder

It works, too!
Explain me what you did.
I mean:
lookup suspicious_commands COMMAND OUTPUT COMMAND AS cmd_match

0 Karma

starcher
Influencer

If this isnt going to be a large lookup then yes the inputlookup pattern works. I tend to stick with the normal lookup pattern. Your original search stomped the original command field. This just outputs the field you matched on to it's own name then looks for where it is not null. AKA found a match.

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

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

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...