The Physics of Observability: Auditd, eBPF & Merkle Trees
Why standard logging is blind. The physics of Kernel Auditing, eBPF Tracing, and constructing tamper-proof log chains with Merkle Trees.
🎯 What You'll Learn
- Configure Linux Audit System (`auditd`) for Syscall tracing
- Trace hidden processes with eBPF (bypassing rootkits)
- Construct a Tamper-Proof Log Chain (Merkle DAG)
- Understand the Coordinated Omission problem in logging
- Detect Fileless Malware using Memory Scanning logic
📚 Prerequisites
Before this lesson, you should understand:
Introduction
“My logs show nothing suspicious.” That’s because your logs are lying. Standard Application Logs (STDOUT) only show what the developer chose to print. Rootkits and sophisticated malware operate in the kernel shadows, intercepting syscalls and modifying logs before they touch the disk.
This lesson explores Deep Observability: Tracing the actual physics of the Kernel and ensuring log integrity with Cryptography.
The Linux Audit System (Auditd)
auditd listens to the kernel’s internal event stream. It is not an application log; it is a Syscall Recorder.
The Physics of a Trace
When you run cat /etc/passwd:
- Syscall:
openat(AT_FDCWD, "/etc/passwd", O_RDONLY) - Kernel Hook: The Audit subsystem pauses the CPU thread.
- Filter: Checks rules. Does this match a monitored path?
- Record: Writes event to
audit.log(Binary format) before the file is even opened.
Code: Configuring Audit Checks
# /etc/audit/rules.d/audit.rules
# 1. Watch critical file writes (Permissions Physics)
-w /etc/passwd -p wa -k identity_theft
# 2. Watch execution of sensitive binaries
-a always,exit -F arch=b64 -S execve -k command_exec
# 3. Lock the configuration (Immutable Mode)
-e 2
Physics Note: Once -e 2 is set, auditd cannot be stopped or changed until Reboot. This prevents an attacker who gets Root from disabling auditing.
eBPF: The X-Ray Machine
Even auditd can be bypassed by advanced rootkits that modify the syscall table.
eBPF (Extended Berkeley Packet Filter) is the ultimate source of truth. It runs sandboxed code inside the kernel to observe functions as they execute.
Tracing a “Fileless” Attack
Malware often executes purely in memory (no disk file).
Traditional AV scanning files on disk sees nothing.
eBPF traces the mmap and mprotect syscalls used to create executable memory pages.
# Using bpftrace to watch for executable memory allocation
sudo bpftrace -e 'tracepoint:syscalls:sys_enter_mprotect /args->prot & PROT_EXEC/ { printf("Process %s is making memory executable!\n", comm); }'
Log Integrity: The Merkle Tree
Hackers delete logs. How do you prove a log entry wasn’t deleted? Merkle Chains.
The Physics: Log Entry N includes the Hash of Log Entry N-1.
If an attacker deletes Entry 50, the Hash of Entry 51 breaks. The chain snaps. To delete one log, they must recalculate the hashes of ALL subsequent logs. If you stream these hashes to a separate “Write-Only” server (or Blockchain), modification becomes mathematically impossible.
Practice Exercises
Exercise 1: auditd setup (Beginner)
Task: Install auditd. Watch /tmp/testfile.
Action: Modify the file.
Observation: Read /var/log/audit/audit.log and decode the hex-encoded typical output using ausearch.
Exercise 2: The Immutable Flag (Intermediate)
Task: TBD (Dangerous). Concept only: chattr +i vs auditd -e 2.
Constraint: Do not actually lock your production machine.
Exercise 3: eBPF Spy (Advanced)
Task: Use execsnoop (from bcc-tools).
Action: Run it in one terminal. Run ls in another.
Observation: See the ls execution even if you hide the process from ps.
Knowledge Check
- What is the difference between
syslogandauditd? - Why is
-e 2critical in audit rules? - How does eBPF bypass syscall hooking rootkits?
- What mathematical structure prevents log deletion?
- Does
auditdimpact system performance?
Answers
- Depth. Syslog is application-level text. Auditd is kernel-level syscall tracing.
- Immutability. It prevents changes until reboot.
- Internal Instrumentation. It hooks kernel functions directly (kprobes), not only the syscall table interface.
- Merkle Chain (Hash Chain).
- Yes. Inspecting every syscall adds context switch overhead. Use filters wisely.
Summary
- Auditd: The Kernel’s Flight Recorder.
- eBPF: The X-Ray for deeper visibility.
- Immutability:
-e 2locks the door. - Integrity: Hashing chains prevent history rewriting.
Pro Version: See the full research: Security Architecture for Trading Firms
Questions about this lesson? Working on related infrastructure?
Let's discuss