OnCallReadyStart learning

execsnoop-bpfcc: Trace exec() syscalls

execsnoop-bpfcc [-h] [-T] [-t] [-x] [--cgroupmap CGROUPMAP] [--mntnsmap MNTNSMAP] [-u USER] [-q] [-n NAME] [-l LINE] [-U] [-C] [-M] [--max-args MAX_ARGS] [-P PPID]

What it does

Trace exec() syscalls. Part of the bcc tools (bpfcc-tools 0.35.0 on Ubuntu, installed as /usr/sbin/execsnoop-bpfcc; upstream and other distributions call it execsnoop). It loads an eBPF program, so it needs root.

Options you will use

-T, --time
include time column on output (HH:MM:SS)
-t, --timestamp
include timestamp on output
-x, --fails
include failed exec()s
--cgroupmap CGROUPMAP
trace cgroups in this BPF map only
--mntnsmap MNTNSMAP
trace mount namespaces in this BPF map only
-u, --uid USER
trace this UID only
-q, --quote
Add quotemarks (") around arguments.
-n, --name NAME
only print commands matching this name (regex), any arg
-l, --line LINE
only print commands where arg contains this line (regex)
-U, --print-uid
print UID column
-C, --print-cpu
print CPU column
-M, --print-pcomm
print parent command
--max-args MAX_ARGS
maximum number of arguments parsed and displayed, defaults to 20
-P, --ppid PPID
trace this parent PID only

Examples

$ sudo execsnoop-bpfcc

trace all exec() syscalls

$ sudo execsnoop-bpfcc -x

include failed exec()s

$ sudo execsnoop-bpfcc -T

include time (HH:MM:SS)

$ sudo execsnoop-bpfcc -P 181

only trace new processes whose parent PID is 181

$ sudo execsnoop-bpfcc -U

include UID

$ sudo execsnoop-bpfcc -C

include CPU

$ sudo execsnoop-bpfcc -M

include PCOMM

$ sudo execsnoop-bpfcc -u 1000

only trace UID 1000

Gotchas

Taught in

On the blog

Try execsnoop-bpfcc in a real terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.