Introduction: The Dual Nature of eBPF
Over the past few years, Extended Berkeley Packet Filter (eBPF) has revolutionized network monitoring, observability, and security. By allowing developers to run sandboxed code directly inside the Linux kernel without changing kernel source code or loading external modules, eBPF has unlocked unprecedented performance and deep system visibility. Solutions like Cilium, Falco, and Pixie rely heavily on this technology to provide real-time cloud-native security.
However, the very features that make eBPF a dream for system administrators make it an incredibly potent weapon for advanced adversaries. Today, we are seeing a rise in sophisticated, kernel-level user-space bypasses. Malicious actors are utilizing eBPF to construct highly stealthy rootkits, establish covert communication channels, and intercept sensitive cryptographic payloads before they are even encrypted. For digital forensics investigators and systems security engineers, understanding how to hunt, analyze, and mitigate these kernel-space threats is no longer optional—it is a critical capability.
The Adversarial Playground: How eBPF Rootkits Operate
Traditional Linux rootkits typically relied on malicious Kernel Loadable Modules (LKM). Loading an LKM is a highly privileged, noisy event that modern Endpoint Detection and Response (EDR) agents and kernel integrity mechanisms (such as Kernel Lockdown mode and UEFI Secure Boot) easily flag. eBPF bypasses many of these traditional barriers because it does not modify the running kernel’s binary image on disk; instead, it injects safe, verified bytecode directly into the kernel runtime.
An attacker who has achieved root privileges (via local privilege escalation or misconfigured container runtimes) can load an eBPF program to hook various kernel functions. The most common hooks exploited by adversaries include:
- kprobes (Kernel Probes): Allows attaching to virtually any kernel instruction. Attackers use these to intercept system calls (like
sys_enter_writeorsys_enter_execve) to hide files, processes, and network connections. - uprobes (User Probes): Enables tracing of user-space executable binaries and shared libraries. This hook is particularly dangerous because it allows attackers to intercept functions within SSL/TLS libraries (such as OpenSSL's
SSL_writeorSSL_read), effectively capturing plaintext data before encryption or after decryption. - Tracepoints: Static hooks pre-compiled into the kernel. These can be used to silently log system events without altering performance, giving attackers a silent window into administrative activities.
- XDP (eXpress Data Path): Runs at the earliest point of the network driver, before the packet reaches the TCP/IP stack. Adversaries use XDP to parse incoming packets, identify custom "magic packets" to trigger reverse shells, and filter outbound malicious traffic from local logging utilities.
“Because eBPF operates below the standard user-space boundary, traditional auditing tools like
auditdor standard syslog setups are often completely blind to its activities. If your monitoring tools rely on user-space telemetry, they are effectively looking at a simulated reality created by the rootkit.”
The OpenSSL Hook: Stealing Decrypted Data
To illustrate the gravity of this threat, consider a real-world scenario where an attacker targets a high-value database server. By deploying an eBPF program containing a uprobe targeting libssl.so, the attacker can silently extract database queries, credentials, and session keys. Because the hook is placed inside the user-space memory of the target application, the data is captured in plaintext before the TLS library wraps it in cryptography. No network-level decryption proxy or certificate manipulation is required; the data is exfiltrated directly from memory to a shared eBPF map accessible by the attacker's user-space stager.
Forensic Analysis: Hunting for Rogue eBPF Programs
If an attacker has successfully deployed an eBPF-based rootkit, how do digital forensics and incident response (DFIR) teams detect it? Because standard process listings (ps aux) and network connection utilities (netstat, ss) can be manipulated by the rootkit itself, investigators must query the kernel directly using specialized tools.
Step 1: Auditing Loaded Programs with bpftool
The primary utility for interacting with and inspecting the eBPF subsystem is bpftool. This tool allows investigators to query the kernel to list all currently loaded eBPF programs and maps. To get a comprehensive view of all running eBPF programs, execute the following command:
sudo bpftool prog show
This command outputs a list of loaded programs, their types (e.g., kprobe, tracepoint, sched_cls), their unique IDs, and the helper functions they call. When reviewing this list, look for anomalies such as:
- Programs with suspicious names or no name at all.
- Programs loaded from unexpected directories or associated with unusual user-space processes (listed under the
pidsfield). - Unexpected program types (e.g., an XDP or socket filter program on a server that shouldn't be doing low-level packet manipulation).
Step 2: Inspecting eBPF Maps
eBPF programs use key-value stores called "maps" to share data between the kernel and user-space. Attackers use these maps to store exfiltrated credentials, configuration settings, or command-and-control (C2) instructions. To view all active maps, run:
sudo bpftool map show
Once you identify a suspicious map, you can dump its contents to analyze what data is being shared or collected:
sudo bpftool map dump id <map_id>
Analyzing these dumps can yield critical indicators of compromise (IoCs), such as hardcoded IP addresses, exfiltrated session cookies, or targeted file paths.
Step 3: Checking Sysctl Parameters
By default, many modern Linux distributions allow unprivileged users to load eBPF programs, though this is increasingly being locked down. You can check the configuration status of unprivileged eBPF by querying the kernel parameters:
sysctl kernel.unprivileged_bpf_disabled
If this parameter is set to 0, any user on the system can load eBPF programs, vastly increasing the attack surface. A value of 1 or 2 restricts loading to processes with explicit privileges (like CAP_BPF or CAP_SYS_ADMIN).
Ethical Hacking: Simulating and Verifying Detections
For penetration testers and security engineers, simulating eBPF-based attacks is essential to verify that detection pipelines are functioning correctly. Frameworks like BadBBPF or open-source proof-of-concepts (PoCs) like ebpfkit can be used in controlled lab environments to simulate process hiding and network packet manipulation.
When simulating these attacks, ethical hackers should verify whether their Security Information and Event Management (SIEM) systems capture the loading event. Modern security platforms monitor the bpf() system call. If an alert is not generated when a new eBPF program of type BPF_PROG_TYPE_KPROBE is loaded, the defensive infrastructure is blind to kernel-level tampering.
Hardening the Fortress: Actionable Mitigation Strategies
Defending against eBPF threats requires a defense-in-depth approach that focuses on prevention, restriction, and robust runtime monitoring.
- Disable Unprivileged eBPF: This is the most effective administrative control. Ensure that unprivileged eBPF is completely disabled on all production servers by adding the following line to
/etc/sysctl.conf:kernel.unprivileged_bpf_disabled=1 - Restrict Linux Capabilities: Implement strict principle of least privilege. Do not run containers with
--privilegedflags, and explicitly drop theCAP_BPF,CAP_SYS_ADMIN, andCAP_NET_ADMINcapabilities unless absolutely necessary for the application's runtime. - Enable Kernel Lockdown Mode: Configuring the Linux kernel in Integrity or Confidentiality lockdown mode limits the ability of user-space processes to modify or read running kernel memory, significantly hindering the execution of arbitrary kprobes and uprobes.
- Deploy eBPF-Aware Security Monitoring: Irony is the best defense here. Use eBPF-based security monitoring tools like Cilium Tetragon or Falco to monitor the eBPF subsystem itself. These tools run at the kernel level and can be configured to alert on, or even block, unauthorized
sys_bpfcalls and suspicious probe attachments.
Conclusion: The Future of Kernel-Level Security
As operating system security matures, the battleground between security researchers and adversaries has inevitably moved deeper into the kernel. eBPF is an incredibly powerful technology that has enabled a new generation of high-performance observability and security tools. However, in the hands of a skilled attacker, it becomes an invisible cloaking device.
By understanding the mechanisms of eBPF rootkits, utilizing bpftool for proactive threat hunting, and hardening systems through strict sysctl configurations and modern runtime security engines, practitioners can ensure that this revolutionary technology remains an asset to defenders rather than an open door for adversaries.
