Splunk Search

Method to copy over the value

xnx_1012
Explorer

Hello,  is there any way for the ip address to be copied over to the top... The condition is whenever the root's command doesn't have an ip and is followed by a standard user command's , which is bash with an ip, that ip should be root's too

xnx_1012_0-1592643007010.png


SPL

 

 

 

index=* (source="/var/log/secure"  (TERM(sudo)  AND (TERM(adduser) OR TERM(chown) OR TERM(userdel) OR TERM(chmod) OR TERM(usermod) OR TERM(useradd)))
OR (TERM(sudo:) OR TERM(su:) AND("session opened for user root" OR COMMAND=/bin/bash))
OR (TERM(sshd) AND "Accepted password" 
[search index=* (source="/var/log/secure"  (TERM(sudo)  AND (TERM(adduser) OR TERM(chown) OR TERM(userdel) OR TERM(chmod) OR TERM(usermod) OR TERM(useradd)))) 
OR (source="/root/.bash_history" AND (TERM(adduser) OR TERM(chown) OR TERM(userdel) OR TERM(chmod) OR TERM(usermod) OR TERM(useradd)))
| regex _raw!= ".*user NOT in sudoers.*"
| stats earliest(_time) as E latest(_time) as latest
| eval earliest = relative_time(E, "-24h@s") 
| fields  earliest latest]))
OR (source="/root/.bash_history" AND (TERM(adduser) OR TERM(chown) OR TERM(userdel) OR TERM(chmod) OR TERM(usermod) OR TERM(useradd)))

| eval Date = strftime(_time, "%Y-%d-%m")
| eval Time = if(source=="/root/.bash_history",strftime(_time, "%Y-%d-%m %H:%M:%S"),
if(match(_raw,"(?<=sudo:)\s*[[:alnum:]]\S*[[:alnum:]]\s*(?=\:).*(?<=COMMAND\=)*") ,strftime(_time, "%Y-%d-%m %H:%M:%S"),null()))
| regex _raw!= ".*user NOT in sudoers.*"
| eval Users = "root"
| eval command = if(source=="/root/.bash_history",_raw,null())
| rex field=_raw "(?<=sudo:)\s*(?P<Users>[[:alnum:]]\S*[[:alnum:]])\s*(?=\:).*(?<=COMMAND\=)(?P<command>.*)"
| rex field=_raw "(?<=for)\s*(?P<Users>[[:alnum:]]\S*[[:alnum:]])\s*(?=from).*(?<=from)\s*(?P<ip>[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+)"
| eval "Command/Events" = replace(command,"^(\/bin\/|\/sbin\/)","")
| eval time_command = mvzip(Time,'Command/Events')
| stats values(time_command) as Time_Command latest(ip) as "IP Address" by Date Users index host
| mvexpand Time_Command
| makemv Time_Command delim=","
| eval Time=mvindex(Time_Command , 0)
| eval "Command/Events"=mvindex(Time_Command , 1)
| table Time  Command/Events host Users "IP Address"

 

 

 

Labels (2)
0 Karma

to4kawa
Ultra Champion
  1. reverse
  2. filldown your_field
  3. reverse
0 Karma

xnx_1012
Explorer

Hello thank you for your solution however is there a way not to include other users that is not root. I only want this for the root user to have a copied over IP

0 Karma

to4kawa
Ultra Champion

what's wrong my query? it looks like good.

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas     Cisco Live 2026 is almost here, and this ...

What Is the Name of the USB Key Inserted by Bob Smith? (BOTS Hint, Not the Answer)

Hello Splunkers,   So you searched, “what is the name of the usb key inserted by bob smith?”  Not gonna lie… ...

Automating Threat Operations and Threat Hunting with Recorded Future

    Automating Threat Operations and Threat Hunting with Recorded Future June 29, 2026 | Register   Is your ...