1

OS is Debian. I have set up auditd to try and determine what is rebooting a system.

I have the following rule:

-a exit,always -F arch=b64 -S execve -F path=/bin/systemctl -k debug_test

Creating a rule for /usr/sbin/reboot doesn't work, since it's a symlink to /bin/systemctl, but this rule works perfectly, it captures every time a reboot command is executed. I can then search for these reboots with command: ausearch -k debug_test | grep reboot. (Note the rule key doesn't contain the string "reboot", since that is what I need to grep for)

However, this just prints the ppid of the process responsible, I am looking for the process name of the ppid. Is it possible to configure auditd to log this? Or would I have to write some kind of daemon that logs all pids + process names every 15 seconds or so?

1 Answer 1

2

I've been going over the auditing documentation some.

Auditd doesn't use placeholders like %{process.value}. Based on the list of values:

uid,  auid,  gid, pid, subj_user, subj_role, subj_type, subj_sen, subj_clr, msgtype,  and  executable  name.

I don't believe logging the parent process name directly in the rule key is possible. I think using "executable name" IS the problem you have with systemctl & reboot.

"You can find the parent process name by using the parent process id (ppid) printed in the audit log." ( which was essentially my first answer, terdon ;-) )

I've discovered you can use ausearch with your original ppid's to find the event where this process was created. It will be logged in the execve system call. That means the PID's are not long gone!

On the same log line as the PPID's, look for type=EXECVE and a list of arguments (a0, a1...) which "make" the command used:

type=EXECVE msg=audit(1622816736.650:123456): argc=3 a0="sh" a1="-c" a2="reboot"

This shows the parent process was a shell (sh), using argument -c running the command (reboot). Now, ausearch and my first suggestion can have a wedding.

#!/bin/bash

# Assuming ausearch command outputs lines with the format id=VAL
for ppid_line in $(your_actual_ausearch_command_here); do
    ppid_to_match=$(echo "$ppid_line" | grep -Eo 'id=[0-9]{1,}')

    # Extract the process information and commands
    process_info=$(sudo cat /var/log/audit/audit.log | grep -i "$ppid_to_match" | grep -Ei 'a0=.*')

    echo "$ppid_to_match is: $process_info"
done

exit 0

Your ausearch command retrieves the PPID in the form of id=VAL, isolate id=, then extract the corresponding information which starts with a0=, that lead to the actual command.

10
  • Since OP is tracking reboots, by the time the system has finished rebooting and OP checks the logs to get the process information, the PID isn't going to be relevant to whatever is currently running.
    – muru
    Commented Jan 13 at 1:40
  • If they got the number, capture it immediately. capture=$(commands the number comes out of); ps -p $capture -o comm= >> capture_file; printf " $capture" >> capture_file Output: process_name id_num on each line.
    – JayCravens
    Commented Jan 13 at 2:14
  • When I try this, I just get key=debug_test/%{parent.name} in the output of ausearch
    – cat pants
    Commented Jan 16 at 21:56
  • @catpants I modified it, it needed .exe.
    – JayCravens
    Commented Jan 16 at 22:10
  • Thank you. Unfortunately same issue: key=debug_test/%{parent.exe}
    – cat pants
    Commented Jan 17 at 1:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .