24 lines
984 B
Bash
Executable File
24 lines
984 B
Bash
Executable File
#!/bin/bash
|
|
# Log every execve/execveat attempt, failed ones included, with the path and argv[0..5].
|
|
# Uses tracefs event probes, so nothing is attached to the traced processes.
|
|
# Usage (root): exec-snoop [seconds] > log
|
|
set -eu
|
|
secs=${1:-600}
|
|
T=/sys/kernel/tracing
|
|
I=$T/instances/exec-snoop
|
|
A='a0=+0(+u0($argv)):ustring a1=+0(+u8($argv)):ustring a2=+0(+u16($argv)):ustring'
|
|
A+=' a3=+0(+u24($argv)):ustring a4=+0(+u32($argv)):ustring a5=+0(+u40($argv)):ustring'
|
|
|
|
cleanup() {
|
|
[[ -d $I ]] && { echo 0 > "$I/events/exec_snoop/enable"; rmdir "$I"; }
|
|
for e in execve execveat; do echo "-:exec_snoop/$e" >> $T/dynamic_events 2>/dev/null || true; done
|
|
}
|
|
cleanup
|
|
trap cleanup EXIT
|
|
|
|
echo "e:exec_snoop/execve syscalls.sys_enter_execve file=+0(\$filename):ustring $A" >> $T/dynamic_events
|
|
echo "e:exec_snoop/execveat syscalls.sys_enter_execveat file=+0(\$filename):ustring $A" >> $T/dynamic_events
|
|
mkdir "$I"
|
|
echo 1 > "$I/events/exec_snoop/enable"
|
|
timeout "$secs" cat "$I/trace_pipe" || true
|