Skip to content

Instantly share code, notes, and snippets.

@aserper
Created March 19, 2024 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aserper/d495b119395bf8352558d4b824f46f93 to your computer and use it in GitHub Desktop.
Save aserper/d495b119395bf8352558d4b824f46f93 to your computer and use it in GitHub Desktop.
from bcc import BPF
# eBPF program
prog = """
#include <uapi/linux/ptrace.h>
// Instrument the chdir syscall entry
TRACEPOINT_PROBE(syscalls, sys_enter_chdir) {
// args is a built-in structure provided by the tracepoint
// It contains all the arguments of the syscall being traced
const char *pathname = (const char *)args->filename;
// Log the pathname
bpf_trace_printk("chdir called with pathname %s\\n", pathname);
return 0;
}
"""
# Load eBPF program
b = BPF(text=prog)
# Print the output of bpf_trace_printk
print("Tracing chdir syscalls... Hit Ctrl-C to end.")
while True:
try:
(task, pid, cpu, flags, ts, msg) = b.trace_fields()
print("%-18.9f %-16s %-6d %s" % (ts, task, pid, msg))
except KeyboardInterrupt:
exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment