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
Get Updates on the Splunk Community!

Index This | Why did the turkey cross the road?

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

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  &#x1f680; Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Feel the Splunk Love: Real Stories from Real Customers

Hello Splunk Community,    What’s the best part of hearing how our customers use Splunk? Easy: the positive ...