Skip to content

Protocols ​

Every port has a protocol. New ports start as tcp or udp; set http, ftp or dns yourself for protocol-aware rules. A wrong guess would break the service, which is why vulnboxd does not guess.

yaml
ports:
  "8080":
    protocol: http

tcp ​

Each direction of a connection is one continuous stream. contains and regex find a pattern wherever it lands in it, even split across reads or megabytes apart, in constant memory.

  • Block closes the connection.
  • larger_than counts everything one side has sent over the connection.
  • replace rewrites the stream as it passes.
yaml
"1337":
  protocol: tcp
  rules:
    - name: shell payloads
      match: { regex: '/bin/(ba)?sh|/etc/passwd' }
    - name: oversized upload
      match: { larger_than: 64K }

http ​

Requests and responses are parsed, so rules can use method, path, headers, headers_opt, body and status, on top of contains and regex over the whole message.

A few things vulnboxd does on every http port:

  • Accept-Encoding is removed from requests, so responses come back uncompressed and body rules can read them.
  • A body sent with Content-Encoding (gzip, deflate, br, zstd, also stacked), which most frameworks undo before the service sees it, is read whole when a rule looks at the body and judged by what it says. The service gets the bytes as they were sent, unless a rule rewrote the body; then it gets the rewritten body uncompressed. A body that does not decompress, or is too large to hold, is one the rules cannot decide on.
  • Hop-by-hop headers (Connection, Keep-Alive, Upgrade and the like) are not forwarded, as a proxy should not; WebSocket upgrades are the exception.
  • Connections to the service are kept and reused for the next client, which saves a TCP handshake per request. If a service cannot cope with that, set pool_upstream: false for the service or the port.
  • A request whose headers take longer than timeouts.http_request (30 s) to arrive, or whose body does, gets a 408.

h2c ​

An http port serves whichever version the client speaks. A connection that opens with the http/2 preface is served as cleartext http/2 (h2c), anything else as http/1.1. vulnboxd then talks the same version to the service, since a service reached over h2c generally speaks nothing else. Rules see the same requests and responses either way.

gRPC and Connect ​

gRPC services are http ports too: put protocol: http on the port. vulnboxd passes trailers through (where gRPC's status is) and keeps TE: trailers, which gRPC clients send and some servers require. Rules can match calls by method, message fields and status, and a blocked call gets a proper gRPC error. Streaming calls, bidirectional ones included, are read one message at a time, so a rule never holds up a stream waiting for its end.

  • gRPC, gRPC-Web (binary and text) and Connect streaming are read as messages. A request is read so only when it is a POST whose body starts with envelopes; anything else with a call's content type (a GET, or {"cmd": ...} sent as application/grpc) is a plain request, its body read whole where a rule needs it so, since services read it whatever the content type says. Over HTTP/2 the start of the body is waited for 250 ms at most, since a streaming client may send nothing until the service answers; such a call is read as envelopes. A response is read as messages only when its own content-type says it is a call's; a request that merely claims to be a call gets its plain answer checked as a plain body.
  • Every byte of a call's body also goes through contains and regex as sent, so a frame that does not parse or a message too large to hold cannot take those rules away. Such bytes also go through replace, and count as undecidable.
  • A compressed message is read decompressed, within one budget per call and direction: limits.buffered_body decompressed in all, so many small envelopes that each expand to the limit cannot add up to gigabytes. What a message decompresses to counts against the memory budget while the rules look at it. Past either budget a compressed message is undecidable (budget_full). Only half the cores decompress at any moment, across every port, so the other workers stay free for the rest of the traffic.
  • One a replace rule rewrote goes on uncompressed (the message's flag says so, which every gRPC and Connect client accepts). On a port with a rule that rewrites answers, grpc-accept-encoding and connect-accept-encoding are taken out of requests, so services do not compress in the first place.
  • gRPC-Web text goes on exactly as sent unless a rule rewrote a message; from then on the call's messages are written as base64 again, each chunk padded on its own.

WebSockets ​

WebSocket connections on http ports are proxied too. The upgrade request and response go through the http rules as usual. After that, each message is matched like an http message with:

  • method set to WEBSOCKET,
  • path set to the path of the upgrade request,
  • the message's payload as body, and for contains and regex.
yaml
- name: no shell commands over the socket
  match: { method: WEBSOCKET, path: '^/ws', body: '(?i)\b(bash|sh|nc)\b' }

Blocking closes the connection. Compression (permessage-deflate) is not negotiated, so payloads stay readable. A message sent in several frames is put together first, and nothing of it goes on until it is judged; control frames in between go on at once. A message a rule rewrote goes on as one frame, otherwise its frames go on as they came. A message larger than limits.buffered_body cannot be held: it is undecidable, and its frames are then checked one at a time; a frame that does not fit itself (or the memory budget) goes on as it arrives, seen only by contains and regex. A frame's payload is held as it arrives, not by the length its head claims. Every frame's payload also goes through contains and regex as one stream per direction, so a pattern split across frames or messages is found either way.

ftp ​

Each line of the control connection is matched on its own, in both directions: commands going in, replies coming out. All lines of a direction also go through contains and regex as one stream, so a pattern across lines is found too. A line longer than 64 KiB reaches the line rules in pieces and is undecidable.

  • Block on a command answers it with 550 and the session carries on. Blocking a reply closes the session.
  • Data connections use ports of their own, which are handled like any other port: plain tcp unless you say otherwise.
yaml
"2121":
  protocol: ftp
  rules:
    - name: no site commands
      match: { regex: '(?i)^SITE ' }

udp ​

Each datagram is matched on its own.

  • Block drops the datagram.
  • larger_than counts each datagram.

dns ​

Datagrams are parsed as DNS, so rules can also use qname, a regex over the lower-cased query name, and qtype, such as A, TXT or ANY. Every question of a message counts, names written with compression pointers included: a rule matches when one question fits its qname and qtype together. A datagram that does not parse as a whole (a name running off the end, a pointer loop, more than 32 questions) is one the rules cannot decide on.

  • Block answers the query with REFUSED.
yaml
"53/udp":
  protocol: dns
  rules:
    - name: data exfiltration over txt records
      match: { qtype: TXT }
    - name: only our own zone
      not: { qname: '(^|\.)example\.ctf$' }

Timeouts ​

tcp, ftp, http and WebSocket connections that see no traffic for timeouts.idle (2 minutes) are closed. An HTTP/2 connection is also closed after timeouts.idle without a request in progress, however many PINGs or window updates it sends. A connection held by a stall is closed when the stall runs out, on HTTP/2 as well, where the stall is on one stream.

The limits are per connection or per port, never per address: in many games all traffic arrives through one NATed address, so a cap per address would hit the checker too.

  • limits.connections (4096) caps the client connections one tcp port carries at once. A WebSocket counts as a connection of its own from its upgrade on; past the limit an upgrade is answered 503.
  • An answer held whole for the rules (limits.buffered_body) that the client does not take within timeouts.http_request gets its connection closed, so a client that never reads cannot keep its share of the memory budget.
  • See the limits for the memory budgets.