December 1, 2026

eBPF security tools like bpftrace and BCC are production-ready for detecting container escapes, privilege escalation, and fileless malware — without loading kernel modules or modifying the kernel.

What eBPF actually is for security monitoring

eBPF (extended Berkeley Packet Filter) lets you run sandboxed programs in the Linux kernel triggered by events — system calls, tracepoints, kprobes, uprobes, network events. For security monitoring, this means you can observe process execution, file access, network connections, and capability usage at the kernel level without the overhead and risk of traditional kernel modules.

The key distinction from auditd or sysdig: eBPF programs are verified by the kernel before loading. They cannot crash the kernel, cannot loop infinitely, and cannot access arbitrary memory. The verifier rejects programs that violate safety rules. This is why eBPF has replaced kernel modules for observability in production environments at Netflix, Meta, Google, and Cloudflare.

Why security teams are adopting eBPF now

Three things changed between 2020 and 2024:

  • Kernel support matured. Linux 5.10+ (Ubuntu 22.04, 24.04, RHEL 9) includes BTF (BPF Type Format), CO-RE (Compile Once Run Everywhere), and stable helper APIs. You no longer need kernel headers on the target machine to compile tools.
  • Tooling became usable. bpftrace (high-level tracing language), BCC (Python/C++ libraries), and Tetragon (Cilium’s security daemon) abstract away the complexity. You write a 10-line bpftrace script instead of 500 lines of C.
  • Container runtimes expose eBPF. containerd, CRI-O, and Docker now integrate with eBPF for runtime security. Falco, Tetragon, and Tracee all use eBPF as their primary data source.

If you are running Ubuntu 24.04 or RHEL 9 on kernel 6.x, the infrastructure is already there. You just need to write the detection logic.

What you can detect with eBPF that you couldn’t before

Container escapes via syscall monitoring

Traditional container security relies on seccomp profiles that block dangerous syscalls. eBPF lets you observe every syscall with full context — arguments, return values, PID, container ID, user namespace — and alert on anomalies without blocking legitimate workloads.

Example: detecting ptrace or process_vm_readv from a container process targeting a host process.

# bpftrace -e 'tracepoint:syscalls:sys_enter_ptrace /comm == "containerd-shim"/ { printf("%s[%d] ptrace -> %d\n", comm, pid, args->request); }'

This catches a compromised container trying to attach to a host process — something seccomp might allow but eBPF surfaces with full context.

Privilege escalation via capability usage

Capabilities like CAP_SYS_ADMIN, CAP_SYS_PTRACE, CAP_DAC_OVERRIDE are the building blocks of privilege escalation. eBPF can trace cap_capable LSM hooks to log every capability check with the requesting process, the capability, and whether it was granted.

# bpftrace -e 'kprobe:cap_capable { printf("%s[%d] capable(%d) = %d\n", comm, pid, arg1, retval); }'

Run this during a suspected escalation and you see exactly which capability was checked, by which process, and the result. No auditd rule captures this level of detail with this low overhead.

Fileless malware via memory execution detection

Fileless malware executes code from memory without touching disk — memfd_create + execveat, or mmap with PROT_EXEC on anonymous memory. eBPF traces these syscalls and correlates them with process ancestry.

# bpftrace -e '
tracepoint:syscalls:sys_enter_memfd_create { @create[pid] = comm; }
tracepoint:syscalls:sys_enter_execveat /@create[pid]/ {
    printf("memfd_exec: %s[%d] fd=%d\n", @create[pid], pid, args->fd);
    delete(@create[pid]);
}
'

This detects the memfd_create → execveat pattern used by fileless loaders. Auditd sees the syscalls but cannot correlate them across the time gap.

Network-level C2 detection

eBPF attaches to socket operations (connect, sendmsg, recvmsg) and TCP retransmission tracepoints. You can detect beaconing behavior — regular outbound connections to rare destinations — without a separate network tap.

# bpftrace -e 'tracepoint:syscalls:sys_enter_connect { printf("%s[%d] connect -> %s:%d\n", comm, pid, ntop(args->addr->sin_addr.s_addr), args->addr->sin_port); }'

The tooling landscape: what to use when

Tool Best for Learning curve Production readiness
bpftrace Ad-hoc investigation, one-liners, rapid prototyping Low (awk-like syntax) High — single binary, no deps
BCC (Python) Complex logic, data aggregation, integration with Python stack Medium (Python + BPF C) High — used at Netflix, Facebook
Tetragon (Cilium) Kubernetes runtime security, policy enforcement, alerting Low (YAML policies) High — CNCF graduated project
Falco Rule-based runtime security, CNCF graduated, large rule library Low (YAML rules) High — default in many distros
Tracee Container forensics, 300+ built-in signatures, eBPF + LSM Low (CLI + signatures) Medium — Aqua Security project

Start with bpftrace. It is a single binary (apt install bpftrace on Ubuntu 24.04), the syntax is readable, and you can test detection logic in minutes. Graduate to BCC when you need stateful aggregation across events. Deploy Tetragon or Falco when you need cluster-wide policy enforcement with alerting.

A practical detection workflow

Step 1: Establish baseline

Run bpftrace on a healthy workload for 30 minutes. Capture the syscall frequency, capability checks, and network connections.

# Baseline syscall frequency per process
bpftrace -e 'tracepoint:raw_syscalls:sys_enter { @[comm] = count(); } interval:s:30 { exit(); }'

Step 2: Write a detection script

Target a specific threat. Example: detect CAP_SYS_ADMIN usage in containers (often indicates a misconfigured or compromised container).

# cap_sys_admin.bt
kprobe:cap_capable
/arg1 == 21/  // CAP_SYS_ADMIN = 21
{
    printf("%-16s %-6d CAP_SYS_ADMIN granted=%d cgroup=%s\n",
           comm, pid, retval, cgrouppath);
}
bpftrace cap_sys_admin.bt

Step 3: Validate against false positives

Run the detection on staging workloads. Legitimate uses of CAP_SYS_ADMIN include container runtimes, backup agents, and monitoring daemons. Document these as allowed exceptions.

Step 4: Deploy with Tetragon/Falco for alerting

Translate the bpftrace logic into a Tetragon TracingPolicy or Falco rule for continuous monitoring.

# Tetragon TracingPolicy example
apiVersion: cilium.io/v1alpha1
kind: TracingPolicy
metadata:
  name: detect-cap-sys-admin
spec:
  kprobes:
  - call: "cap_capable"
    syscall: false
    args:
    - index: 1
      type: "int"
      value: "21"  # CAP_SYS_ADMIN
    returnArg:
      index: 0
      type: "int"
    selectors:
    - matchPids:
      - operator: "NotIn"
        followForks: true
        isNamespacePid: true
        values: ["containerd", "kubelet", "backup-agent"]

Performance reality check

eBPF overhead is not zero. A typical bpftrace script tracing 10 syscalls on a busy web server adds 1-3% CPU overhead. BCC tools with aggregation add 2-5%. Tetragon/Falco in production clusters typically consume 2-4% CPU per node.

The overhead scales with event frequency, not data volume. Tracing open on a file server is expensive. Tracing execve on the same server is cheap.

Rule of thumb: if your baseline syscall rate exceeds 50,000/sec per core, sample or filter in the eBPF program rather than userspace.

What eBPF does not solve

  • Encrypted traffic inspection. eBPF sees syscall arguments, not TLS payloads. For C2 over HTTPS, you need TLS termination or eBPF uprobes on OpenSSL/BoringSSL (fragile across versions).
  • Kernel exploits before detection. If an attacker exploits a kernel vulnerability to disable eBPF or hide from tracepoints, eBPF cannot detect it. Defense in depth still requires kernel hardening (lockdown mode, signed modules).
  • Persistent storage of events. eBPF ring buffers are in-memory. You need a userspace collector (Tetragon, Falco, custom) to persist alerts.
  • Cross-host correlation. eBPF is per-node. Correlating a container escape on node A with lateral movement on node B requires a centralized SIEM.

Getting started today

  1. Install bpftrace: sudo apt update && sudo apt install -y bpftrace (Ubuntu 24.04) or sudo dnf install -y bpftrace (RHEL 9/Fedora)
  2. Verify kernel support: bpftrace -e 'BEGIN { printf("OK\n"); }' — should print OK
  3. Run your first trace: sudo bpftrace -e 'tracepoint:syscalls:sys_enter_execve { printf("%s[%d] execve: %s\n", comm, pid, str(args->filename)); }'
  4. Explore the BCC tools: apt install bpfcc-tools — includes opensnoop, execsnoop, tcplife, capable
  5. Deploy Tetragon on Kubernetes: helm install tetragon cilium/tetragon --namespace kube-system

Useful DevStackIO Tools

Validate configurations and analyze traces with our free tools:

Related Reading

References

Leave a Reply

Your email address will not be published. Required fields are marked *