Splunk Search

Need help to identify user field in my current search string

jcorkey
Explorer

Below is my search string:

index=* host=* sourcetype="*" "usermod" "add" "to shadow group" | rex "^(?:[^'\n]*'){3}(?P<addedToGroup>\w+)" | rex "^[^'\n]*'(?P<userInGroup>\w+)"

This search shows me which user was added to which group but I really need it to show WHO added the user to the group. I can't figure out how to find the actual user who ran the usermod command. What do I need to do to get that field?

0 Karma

DalJeanis
Legend

That's looking like unix log records. Your best bet is to take all the events from about 30 seconds before to ten seconds after and look at each one.

Here's a set of log records I stole for reference off of stackexchange ...

$ cat /var/log/auth.log | grep -i xyz
Dec 18 18:54:51 pandya-desktop sudo:   pandya : TTY=pts/2 ; PWD=/home/pandya ; USER=root ; COMMAND=/usr/sbin/useradd xyz
Dec 18 18:54:51 pandya-desktop useradd[7763]: new group: name=xyz, GID=1002
Dec 18 18:54:51 pandya-desktop useradd[7763]: new user: name=xyz, UID=1002, GID=1002, home=/home/xyz, shell=
Dec 18 18:55:51 pandya-desktop sudo:   pandya : TTY=pts/2 ; PWD=/home/pandya ; USER=root ; COMMAND=/usr/sbin/usermod -a -G group xyz
Dec 18 18:55:57 pandya-desktop sudo:   pandya : TTY=pts/2 ; PWD=/home/pandya ; USER=root ; COMMAND=/usr/sbin/usermod -a -G sudo xyz
Dec 18 18:55:57 pandya-desktop usermod[7872]: add 'xyz' to group 'sudo'
Dec 18 18:55:57 pandya-desktop usermod[7872]: add 'xyz' to shadow group 'sudo'

Your search is keying off the last record.

The immediately prior set of records indicate that the user involved in altering user xyz was USER=root. (Really helpful, right?)

The one other thing I noticed, poking around a bit, is that sometimes there will be a logoff right after the person does this. You might see something like "connection closed by 1.2.3.4" . So, that could be a clue too.

0 Karma

somesoni2
Revered Legend

Can you share a sample event? Do you know if the raw data contains who ran the command?

Get Updates on the Splunk Community!

Index This | What is broken 80% of the time by February?

December 2025 Edition   Hayyy Splunk Education Enthusiasts and the Eternally Curious!    We’re back with this ...

Unlock Faster Time-to-Value on Edge and Ingest Processor with New SPL2 Pipeline ...

Hello Splunk Community,   We're thrilled to share an exciting update that will help you manage your data more ...

Splunk MCP & Agentic AI: Machine Data Without Limits

Discover how the Splunk Model Context Protocol (MCP) Server can revolutionize the way your organization uses ...