Skip to content

Capturing traffic ​

vulnboxd can capture every packet the box sees and serve it over PCAP-over-IP, so the tools that pick attacks and flags out of traffic read it live over a socket instead of scraping files off the box.

yaml
pcap:
  enabled: true
  listen: 127.0.0.1:4242
  interface: any
  ports: 9000-9999
  # Your own ssh into the box (10.60.13.2 is the box's address), and nothing else.
  filter: not (src host 10.60.13.2 and tcp src port 22) and not (dst host 10.60.13.2 and tcp dst port 22)

vulnboxctl setup-interactive asks for this, and vulnboxctl install writes the service when it is on.

Turning it on later ​

The unit is written when pcap.enabled is set at install time, so a team that decides a day into the game needs one more step:

sh
sudo vulnboxctl install          # writes the unit; keeps the existing config
sudo systemctl enable --now vulnboxd-pcap

vulnboxctl install is safe to run again: it keeps your config and only puts what is missing in place.

Reading the stream ​

Anything that speaks PCAP-over-IP works:

sh
# Locally on the box, or through ssh from your laptop.
nc 127.0.0.1 4242 | tcpdump -r - -nn
ssh vulnbox 'nc 127.0.0.1 4242' | tshark -r -

The header is always written little-endian, with microsecond timestamps and a snapshot length of 65535, whatever the capture produced; the link type is the capture's own. That is pcap-broker's normalisation, so every consumer sees one format. A capture with nanosecond timestamps is rewritten to microseconds, losing the last three digits — the only thing that is not passed through untouched.

Nothing is written to disk. With no reader connected the packets are read and dropped, so leaving capture on all game costs no space; it also means you only have what someone was listening for.

The tools' own configuration ​

Separately from the broker, vulnboxctl init writes the files tulip and shovel want, so captured traffic is filed under a service name rather than a port number: one entry per public port, named after the service, at the address in init.vulnbox_ip.

text
<init.capture_dir>/tulip.json
<init.capture_dir>/shovel.yaml

init.capture_dir defaults to the working directory. They are rewritten whenever the setup runs, so a service added later ends up in them. They describe your services, not the broker, so where to read the traffic from is still yours to point the tool at.

What ends up in the capture ​

interface, ports and filter build a tcpdump command, plus one term that is always added. With the config at the top of this page:

sh
tcpdump -i any -n --immediate-mode -s 65535 -U -w - \
  '(not (src host 10.60.13.2 and tcp src port 22) and not (dst host 10.60.13.2 and tcp dst port 22)) and portrange 9000-9999 and not (src host 127.0.0.1 and tcp src port 4242) and not (dst host 127.0.0.1 and tcp dst port 4242)'

Three parts, ANDed, so each only narrows what is kept: your filter, your ports, and the broker's own connections, which are always left out.

Leave out by direction, never by port alone ​

Whatever is left out of the capture is invisible to everyone reading it, and an attacker picks their own source port. not port 22 drops every packet with 22 on either side, so an exploit sent from source port 22 to one of your services — and the flag going back to it — never shows up. The same goes for any not port N.

Name the box's own side instead. For your own ssh into the box, that is packets from the box's port 22 and packets to it:

yaml
pcap:
  filter: not (src host 10.60.13.2 and tcp src port 22) and not (dst host 10.60.13.2 and tcp dst port 22)

An exploit from source port 22 has the attacker's address as its source, and your service's port as its destination, so it is kept; so is ssh the box makes to somewhere else. vulnboxctl setup-interactive fills this in with your box's address when you turn the capture on, and refuses a filter that leaves a port out in both directions. The broker warns about one in its log as well.

ports keeps the game in and the box out. A vulnbox talks to itself constantly — containers to their databases, the proxy to its backends, the daemon to GitHub or GitLab — and none of that is what you want to look through afterwards. Game modes that know where their services are fill this in: ECSC_2026 gives 9000-9999, because during the ECSC everything else is internal traffic. Setting it yourself wins over the game's, and an empty value captures every port.

Single ports and ranges mix freely, for a game that does not keep its services together:

yaml
pcap:
  ports: 9000,9100-9200,8000

That becomes (port 9000 or portrange 9100-9200 or port 8000). Each part covers tcp and udp, and a bad one — a range that ends before it starts, a port of 0 — is refused when the config is read rather than when the capture fails to start.

The broker's own traffic is always excluded. Serving a packet is itself traffic, so a capture that saw its own PCAP-over-IP connections would serve those too, and serving those would make more again. vulnboxd knows its listen address and leaves out exactly the broker's side of its connections: packets from listen's address and port, and packets to them. A client that sends from port 4242 to a service is still captured.

If you bind to every address

With listen: 0.0.0.0:4242 the broker serves every packet the box sees to anyone who can reach port 4242 on any of its addresses, and the broker warns about it when it starts. The exclusion then names every address the box has (and loopback) as the broker's side, as they were when the capture started; a reader that connects through an address the box gained later is turned away, because serving it would put the broker's own traffic in the capture. Restart vulnboxd-pcap after an address change, or better, bind it to one address.

With the proxy in the path ​

Every intercepted service is reached through the proxy, so on the wire each exchange exists twice: the client to the public port, and vulnboxd to the container on a loopback port from backend_port_base (20000 and up).

The default ports narrowing keeps the second one out, which is what you want: tulip and shovel see one flow per exchange, from the real client address to the real service port. If you widen ports or clear it, expect every intercepted request to appear twice, the inner copy from 127.0.0.1.

Internal traffic ​

What happens behind the proxy — the service talking to its database, one container to another, a container calling out — never crosses the public interface. To keep it too, name the interfaces to capture instead of one:

yaml
pcap:
  interfaces: [eth0, lo, bridges]
  • eth0 (any interface named outright) is captured as before, narrowed to pcap.ports.
  • lo is narrowed to the backend ports (backend_port_base and up): the proxy's connections to the services and nothing else of the box's own loopback traffic.
  • bridges is every docker bridge of a managed service's network, from the inventory, on every port — the game's port range says nothing about which port a database listens on. A bridge that appears with a new service's first deploy is picked up within seconds; one that goes away is let go of. The others carry on undisturbed.

Each interface gets a tcpdump of its own, and the broker merges them into one stream of link type LINUX_SLL2, whose header carries the index of the interface every packet was seen on (and whether the box sent it, received it, or saw it pass between two containers). The inventory lists the interfaces by that index, so a reader — the hub, or Wireshark's "interface index" column — can tell the external hop from the internal ones. Readers that only take ethernet captures need the single interface instead.

Why a capture per bridge, and no veths ​

tcpdump -i any would be one process, but a capture on any never puts an interface in promiscuous mode, and a Linux bridge only shows its own device the frames it forwards between two containers when that device is promiscuous. Capturing any would miss container-to-container traffic entirely — or, with the veths, see every such packet twice. A capture on the bridge itself puts it in promiscuous mode for as long as it runs and sees every frame exactly once, whichever containers it passes between.

That is the rule that keeps a connection from being counted twice: bridges are captured, veths never are, and loopback only on the backend ports. The proxy's backend connection shows on lo; docker's own connection into the container shows on the bridge; they are two different connections, which the request log links.

How a request is followed inside ​

The proxy keeps its connections to the services open and hands them from one client to the next, so the capture alone cannot say which client request became which request to the service. The request log can: each line names the client's connection and the request's place on it, and the backend connection — the proxy's own source port towards the service — and the request's place on that.

From there into the container depends on how docker forwards the published loopback port:

  • docker-proxy (docker's default, "userland-proxy": true): docker's userland proxy accepts the proxy's connection on loopback and opens a new one to the container from the bridge's gateway address. Nothing the kernel shows ties the two together exactly, so vulnboxd does not guess; the inventory marks these ports docker-proxy, and the host sensor is what will link them.
  • DNAT ("userland-proxy": false in /etc/docker/daemon.json): the connection itself is rewritten on its way in. vulnboxd asks conntrack for it (off the traffic path) and writes how the bridge sees it into the request log line (nat): an exact link all the way into the container.

For exact links from the client to the container today, turn the userland proxy off (restart docker afterwards; vulnboxd republishes the ports at the next deploy):

json
{ "userland-proxy": false }

vulnboxctl inventory shows which applies to each port.

Settings ​

settingdefault
pcap.enabledfalserun it at all. The setup turns it on and installs the service
pcap.listen127.0.0.1:4242where readers connect. pcap-broker's own port
pcap.interfaceanywhich interface to capture, or any for all of them
pcap.interfaces[]several interfaces as one stream that says where each packet was seen; see internal traffic
pcap.portsthe game'sonly capture these ports: single ports and ranges in any mix, 9000,9100-9200. Empty captures every port
pcap.filtera pcap filter for what to leave out. Name the box's own side, as in leave out by direction; never not port 22
pcap.commandthe whole capture command, for when the above is not enough
pcap.buffer_mb64how far behind one reader may fall before it is disconnected

Keep it off the public internet

The stream is every packet the box sees: your flags, your traffic and your patches going past. Leave listen on loopback and read it over your team's vpn or an ssh tunnel, or bind it to the vpn address. Nothing about PCAP-over-IP asks who is connecting.

Where all of this is not enough, command replaces it entirely — and then what it captures is your affair, including keeping its own traffic out. It has to write classic pcap to its output, as tcpdump -w - does:

yaml
pcap:
  command: dumpcap -i eth0 -w - -P

A pcapng stream is refused with a message saying so rather than read as nonsense. See vulnboxd-pcap for the command-line and environment overrides.

Its own service ​

The broker is a separate binary and a separate service, vulnboxd-pcap, tied to nothing of the daemon's:

sh
systemctl status vulnboxd-pcap
journalctl -fu vulnboxd-pcap

A gap in the capture is a gap in what the team can look at afterwards, so upgrading vulnboxd leaves it running, and restarting it does not touch the proxy. If its capture command dies it alerts and systemd tries three times before leaving the unit failed, so a capture that cannot work is visible rather than looping in silence.

Slow readers cannot stall the capture ​

Each reader gets its own buffer, pcap.buffer_mb (64 MB). One that stops reading — a laptop that went to sleep, an analysis tool that fell over — fills its own buffer and is then disconnected with a log line. The capture and every other reader carry on.

A plain list of the services ​

Set init.services_file and the setup also writes every service listener as a name, an address and a port — for the tools that want to be told where the services are rather than work it out from a compose file:

yaml
# Written by vulnboxctl: one entry per service listener.
services:
  notes-notes:
    host: "10.60.13.2"
    port: 9100

Readers across a network ​

Each consumer's socket has Nagle off (TCP_NODELAY), and that is not a detail. A pcap record is a hundred-odd bytes; with Nagle on, a reader on another box gets one segment per delayed acknowledgement — a few hundred packets a second — while a reader on the box itself sees everything, because there a round trip costs nothing. Two readers, one stream, one of them quietly starved: an assembler on another machine was getting a fraction of what Suricata beside the capture got, with no packet lost anywhere and nothing in any log to say so.

Whatever is already queued for a consumer goes out in one write, so a busy capture does not become one small segment per packet either.

Compared with pcap-broker ​

It is a reimplementation of fox-it's pcap-broker and sends the same bytes, so anything already pointed at one works unchanged: a client connects, is sent a pcap file header, and then every packet as it is captured. PCAP_COMMAND and LISTEN_ADDRESS work too, as do --cmd and --listen. Its sockets are set up the same way, Nagle included — Go turns that off for every connection it makes, so pcap-broker never had to think about it. It is built in so there is nothing extra to install and it is configured from the same file as the rest.

One behaviour is deliberately not copied: pcap-broker writes to its clients inside the packet loop, so one stalled reader backs the capture up for everyone. That loss would be silent and global.

Writing your own reader ​

The repository has a Rust library for tools of your own, pcap-broker-client in crates/pcap-broker-client. It is the same code the broker uses to read the capture and write what it serves, so the two cannot disagree about the format. It reads a broker, a pcap file or tcpdump -w - packet by packet, and decodes each frame into addresses, ports, TCP flags and payload:

rust
use pcap_broker_client::{connect, decode::{decode, Transport}};

let mut capture = connect("127.0.0.1:4242").await?;
let linktype = capture.header().linktype;
while let Some(packet) = capture.next_packet().await? {
    let Ok(ip) = decode(linktype, &packet.data) else { continue };
    if let Transport::Tcp(tcp) = ip.transport {
        println!("{}:{} -> {}:{}, {} bytes", ip.src, tcp.src_port, ip.dst, tcp.dst_port, ip.payload.len());
    }
}

The decoder reads the link layers a capture on Linux produces (ethernet with VLAN tags, the Linux cooked capture that -i any writes, raw IP and loopback), IPv4 and IPv6 with their extension headers, and TCP and UDP. Each packet also gives its flow(), a key that is the same in both directions, for grouping a connection's packets. Nothing is reassembled: a TCP payload is that one segment's.

For a tool that runs all game, Reconnecting stays subscribed across broker restarts. It connects again after a lost connection, waiting longer after each failure, and says when it is connected, since a new capture can have a different link type.