Matching
A rule fires when all of its match conditions hold, unless all of its not conditions hold too. A rule without match always fires.
Conditions
| condition | protocols | holds when |
|---|---|---|
contains | all | the payload contains this exact text |
regex | all | the payload matches this regex |
method | http | the method matches (a regex over the whole method) |
path | http | the path and query match |
headers | http | each named header is present and matches |
headers_opt | http | each named header is missing, or matches |
headers_absent | http | none of the named headers is sent |
header_order | http | the header names, in the order sent, fit a list |
body | http | the body alone matches |
status | http | the response has this status code |
qname | dns | the query name (lower-cased) matches |
qtype | dns | the query type is this, e.g. TXT |
larger_than | all | the message is bigger than this size |
distinct | all | a pattern has produced more than over different values on this connection |
anomalies | http | the decoder finds an anomaly: something deliberate about how the message is encoded or framed, such as signs of request smuggling |
grpc_method | http | the gRPC or Connect call's method fits a glob, such as /notes.Notes/Get* |
grpc_status | http | the call ended with one of these statuses |
grpc_field | http | a field of one of the call's messages matches |
grpc_messages | http | the call has carried more than this many messages |
grpc_larger_than | http | one of the call's messages is larger than this |
contains, regex, path, header values and body can also match what the message decodes to, with decoded.
What "the payload" is depends on the protocol:
| protocol | payload for contains and regex |
|---|---|
| tcp | the whole stream of that direction, matched as it flows by |
| http | the whole message: request or status line, headers and body |
| ftp | each control line |
| udp, dns | each datagram |
On tcp and http, patterns are found wherever they land, even split across packets or megabytes apart. See Streaming and performance.
contains
Plain text, matched anywhere in the payload, with no pattern syntax to get wrong:
- name: reverse shells
match: { contains: '/bin/sh' }
action: blockIt is the cheapest condition there is — no regex engine, just a substring search — so where plain text will do, prefer it to regex. It takes no {flag}, since that is a pattern; use regex for anything that is not a literal.
Regex syntax
Patterns use Rust's regex syntax. The things to know:
- Matching is case-sensitive. Add
(?i)at the start for case-insensitive. - A pattern matches anywhere in the value; anchor with
^and$when you mean the whole value. - There are no backreferences and no lookaround (
\1,(?=...),(?!...)). That is what makes streaming matching in constant memory possible. For "does not match", usenot. - In YAML, single-quoted strings keep backslashes as they are:
'\.\./'. In double quotes you have to double them:"\\.\\./". \b, character classes and Unicode all work. A match that depends on what follows it (\b,$at its end) counts once the next byte is there, or the stream ends: the end of one read is not the end of the stream, so\bsh\bdoes not fire on/shwithowin the next packet.
The game's flags
{flag} in a pattern stands for the game's flag format, which a game mode knows, or which the config sets as flag. Rules then say what they mean, and work unchanged from one game to the next:
- name: flag leak outside the notes route
dir: out
match: { regex: '{flag}' }
not: { path: '^/notes/' }It can go anywhere a regex does: regex, path, body, header values, distinct patterns, grpc_field regexes and the patterns of replace. contains takes plain text, so it cannot use it: a contains with {flag} in it is refused when the rules load, with a hint to use regex. A rules file that uses {flag} without a flag format set does not load, and says why.
Used as a replace pattern for encryption, {flag} encrypts the part of the flag that varies, with the characters the game uses, and stores it behind an ENCRYPTED_FLAG_ marker, so what the service holds says what it is and cannot be handed in as a flag.
HTTP conditions
path
path sees the path and the query string together, as sent: /search?q=test. It is a regex, so anchor it:
- match: { path: '^/admin' } # also matches /administrator
- match: { path: '^/admin(/|\?|$)' } # just /admin and below
- match: { path: '[?&]debug=' } # a query parameter, wherever it appearsFor responses, path is the path of the request being answered, so dir: out rules can be scoped to a route.
headers and headers_opt
Header names are case-insensitive; values are regexes. If a header is sent more than once, it is enough for one of its values to match.
headers requires the header to be present. headers_opt checks a header only if it is sent: it holds when the header is missing, or one of its values matches. match has no "or", so this is the way to say "missing, or matching":
- name: odd content types on the api
match: { path: '^/api/' }
not: { headers_opt: { content-type: '^application/json' } }
set_status: 415This catches a request with another content type and leaves alone one without any (a GET, say). With headers in its place, it would block every request without the header too.
WebSocket messages have no headers, so a headers_opt condition always holds for them.
headers_absent
headers_absent lists header names, and holds when the request carries none of them, whatever their values. Names are case-insensitive. Browsers and real clients send headers that exploit scripts rarely bother with:
- name: no browser would send this
match: { path: '^/notes/', headers_absent: [accept-language, accept] }
action: logIt sees the headers the client sent, before the proxy removes any (such as Accept-Encoding and Connection), so a rule about those still works. WebSocket messages have no headers, so it always holds for them.
header_order
header_order looks at the header names in the order the client sent them. Every HTTP library sends its headers in an order of its own, which tells an exploit script apart from the checker even when it copies the checker's User-Agent. It takes one of three lists:
| key | holds when |
|---|---|
exact | the names are exactly these, in this order, with nothing else |
in_order | these names appear one right after the other, anywhere |
starts_with | the request begins with these names |
- name: python requests
match: { header_order: { starts_with: [Host, User-Agent, Accept-Encoding, Accept, Connection] } }
action: logA header sent twice appears twice in the list, as it was sent: exact: [Host, Cookie, Cookie] holds only for a request with two Cookie headers. Names are compared case-insensitively; add case_sensitive: true to tell user-agent from User-Agent, which clients also differ on:
- name: only the checker's client
match: { path: '^/api/' }
not: { header_order: { in_order: [Host, User-Agent], case_sensitive: true } }
set_status: 403The order and capitalisation come from the raw request, on HTTP/1. vulnboxd only reads requests this closely on ports with a header_order rule. On HTTP/2, which has no order of its own to keep, and for a request head over 64 KiB, the names stand in as vulnboxd parsed them: lower-cased, with a header sent twice listed twice side by side. For responses, header_order sees the response's headers that way too.
body
body matches the body alone, without the head. It needs the whole message at once, so the body is buffered up to limits.buffered_body (8 MiB). Scope body rules with a path so that other routes still stream. For patterns that may appear anywhere, contains and regex stream instead.
not
not takes the same conditions as match, and the rule is skipped when all of them hold. It is how a rule allows only what it names, such as the routes the service really has:
- name: unknown routes
match: { method: 'GET|POST' }
not: { path: '^/(|login|register|notes(/[0-9a-f-]+)?)(\?.*)?$' }
set_status: 404This answers every request for a path that is not on the list with a 404, which shuts out endpoints the service hides from its own frontend.
With several conditions, not is "not all of these": the rule is skipped only when every one of them holds, and fires as soon as one does not. not: { path: '^/a', method: GET } skips GET /a and still fires for POST /a. There is no way to say "skip if any of these holds" within one rule.
not can only use conditions known from the head: method, path, headers, headers_opt, headers_absent, header_order, status, qname, qtype, and an anomalies condition that does not look at the body. contains, regex, body, larger_than and distinct are rejected, because they are only known once the payload has arrived.
larger_than
A size in bytes, with optional K, M or G (powers of 1024): 4096, 64K, 1M.
| protocol | what is counted |
|---|---|
| http | the body |
| tcp | everything one side has sent over the connection |
| udp, dns | each datagram |
| ftp | each line |
| websocket | each message |
On http, if the length is known from the head (Content-Length, or a message without a body), the rule is decided before the body is read, and an oversized upload is refused without reading it. Otherwise the body is counted as it streams by.
- name: request too large
match: { larger_than: 1M }
set_status: 413Put size limits first
A request blocked from its head alone is refused without its body being read. Putting a size limit before any rule that would need the body spares the proxy from reading an oversized upload at all.
distinct
distinct counts how many different values a pattern produces over one connection, and holds once that count passes over. It tells a client walking through every record apart from one reading its own:
- name: mass flag extraction
dir: out
match: { distinct: { pattern: '{flag}', over: 3 } }
set_status: 403- The same value seen twice counts once.
- The count carries across every message on the connection, so once a client is over the limit, the rest of its connection is blocked too.
- A new connection starts from zero.
- At most 4096 values are remembered per rule and connection.
A brake, not a wall
distinct only sees what one connection carries. It catches exploit scripts that reuse a connection, such as those built on requests.Session, httpx.Client or aiohttp, and anything that pulls many records in one response. A script that opens a new connection per request, as plain requests.get does, gets around it.
Set over well above what a legitimate client reads in one connection, and run the rule as action: log for a few ticks to check that it does not fire on the checker.
Decoded data
An exploit rarely sends cat /flag as it is when a rule might be looking for it. It writes {"cmd":"cat /flag"}, percent-encodes it twice, wraps it in base64, or spells it in fullwidth letters, and the service decodes it all the same. decoded makes a condition look through that:
- name: reading the flag file, however it is written
match: { contains: 'cat /flag', decoded: true }With decoded, a condition holds when the message as sent or as decoded matches. The raw form still counts, so leaving the payload plain gets nothing past either. It applies to contains, regex, path, header values (headers, headers_opt) and body; nothing else has a value to decode. Set it for a whole block, or for one condition by writing the condition as { value: <pattern>, decoded: ... }, which also overrides the block:
- name: admin, also as %61dmin
match:
decoded: true
path: '^/admin(/|\?|$)'
headers: { x-role: { value: '^admin$', decoded: false } } # this one raw onlydecoded: true undoes every layer. A list undoes only those:
| layer | undoes |
|---|---|
url | percent-encoding, %uXXXX and + in forms, the URL's own included |
json | JSON, parsed, with its string escapes read; strings holding JSON are parsed in turn |
html | HTML entities, named, decimal and hex |
unicode | \uXXXX and \xXX escapes outside JSON, and Unicode folding: fullwidth and other compatibility letters become ASCII, zero-width and bidi characters go |
utf7 | UTF-7 runs (+ADw-) |
base64 | base64 or base64url of a whole value, JWTs, and multipart parts sent as base64 |
hex | hex of a whole value |
charset | a body or part in another charset (UTF-16, Latin-1, …, by BOM or charset), and quoted-printable parts |
- name: shell commands in base64
match: { regex: '\b(sh|bash|nc|curl)\b', decoded: [base64] }Layers apply in any order and repeatedly, up to six deep: base64 of JSON with an escape in a percent-encoded query parameter decodes all the way. Base64 and hex are only undone when the whole value decodes to readable text, so ids and tokens are left alone. Rules also read base64 the way lenient decoders do, since that is what a service may run: Python's b64decode, PHP's base64_decode and Node's Buffer.from(s, 'base64') skip characters outside the alphabet, take both alphabets mixed and padding anywhere, so Y2F0!IC9m.bGFn is cat /flag to them and to the rules. Such a value, or one whose decoded text is padded with control or non-ASCII bytes, counts when it holds a run of at least eight readable characters. The full rules are in the anomalies reference, which describes the same decoder the hub uses.
What the decoded form is
| condition | matched against, as well as the raw form |
|---|---|
path | the decoded path, then ?name=value&... with each query value decoded |
headers, headers_opt | each decoded value of that request header; for Cookie, each name=value; for Authorization, the decoded credentials |
body | the decoded body, one line per value as key=value (cmd=cat /flag, user.name=x for nested JSON, a form's fields, multipart parts by name) |
contains, regex | each of those: the decoded target, each decoded request header as name: value, and the decoded body |
A part that decoding does not change has no decoded form of its own: the raw form covers it. Write patterns that find the payload rather than the layout around it: body: 'cat\s+/flag' matches both {"cmd":"cat /flag"} raw and cmd=cat /flag decoded; body: '"cmd":\s*"cat' only matches the raw JSON. Request headers are decoded as the client sent them; response headers have no decoded form.
not, case and order
- Negated. In
not, a condition withdecodedholds when the raw or the decoded form matches, so the rule is skipped only when neither does:not: { path: { value: '^/admin', decoded: true } }fires for/notes, and for neither/adminnor/%61dmin. - Case. Decoding never changes case. A pattern is as case-sensitive on the decoded form as on the raw one: add
(?i)to a regex for both. FullwidthCATfolds toCAT, not tocat.header_order'scase_sensitiveis about header names, which are never decoded. - Cost. A message is only decoded when some rule of its port uses
decodedoranomalies, only the part a condition needs (target, headers, body), only once the raw form has not matched, and at most once per message for all the rules that ask. Ports without such rules pay nothing.
Bodies too large to buffer
Decoding needs the whole body. A body is held up to limits.buffered_body (8 MiB) for rules that read it; one larger than that streams through the rules and is not decoded. Then contains and regex match the raw stream only, as they would without decoded; a body rule answers 413 as always; an anomalies condition is decided on the anomalies of the head. vulnboxd counts each such body in vulnboxd_proxy_decode_skipped_total. The decoder itself stops after 64 KiB of decoded text or 512 values per part (vulnboxd_proxy_decode_truncated_total); what lies beyond is matched raw only. Padding a request with hundreds of dummy parameters is how a payload is pushed past that, so a cut is the anomaly decode.truncated, of severity warning, and a message the rules cannot decide on for it: with on_undecidable: block it is refused.
What is decoded is only ever looked at. The service gets the request, and the client the response, exactly as they were sent; logs and the hub show them as sent too. Should the decoder fail on a message, it counts as decoding to nothing, the message goes on, and vulnboxd_proxy_decode_failures_total says so. WebSocket messages are not decoded.
anomalies
anomalies holds when the decoder finds something about the message that a well-behaved client would not do: an anomaly of one of the anomaly rules. Name what to look for by group, by rule id, or by id prefix ending in *, alone or in a list:
- name: request smuggling
match: { anomalies: request_smuggling }
- name: obfuscated or path tricks
action: log
match: { anomalies: [obfuscation, path_tricks] }The groups are request_smuggling, obfuscation, path_tricks, parser_confusion, malformed and wrapped; the reference lists their rules. Group names never contain a dot, ids always do (http.cl_te_both).
Or pick by severity, and where in the message, in any combination; an anomaly has to fit all that is given:
- name: deliberately odd urls
action: log
match: { anomalies: { ids: [path_tricks, 'url.*'], min_severity: warning, in: [target] } }| key | |
|---|---|
ids | groups, rule ids, or id prefixes like url.*; "*" for any. A name that does not exist is an error that names the closest group or id |
min_severity | info, notice, warning or high |
in | target (path and query), headers, body; all three by default |
Severities mean: info worth knowing and usually legitimate; notice unusual, but real software does it; warning hardly ever legitimate; high a known filter-bypass or request-smuggling technique. anomalies: { min_severity: high } is a reasonable thing to block outright; run anything wider as action: log first and look at what it finds.
Anomalies are found with every layer, whatever decoded says. http.* anomalies are about the head as the client sent it: vulnboxd's HTTP parser keeps only one of Content-Length and Transfer-Encoding, but the rules see both. http.obs_fold and http.chunk_extension are only ever found in raw bytes, which no rule sees (vulnboxd refuses folded headers outright), so naming them is an error; the request_smuggling group leaves them out. For responses, there is no target, and only the headers' framing is checked.
An anomalies condition that does not look at the body — in without body, or only rules that are never about the body (request_smuggling, http.*, content_encoding.stacked and path.*) — is decided from the head, before the body is read. It can go in not, and in a route or mirror rule. Any other needs the body, which is buffered for it like for contains; on a body too large to buffer, it sees the head's anomalies only.
- name: odd encoding in json bodies
action: log
match: { path: '^/api/', anomalies: { ids: ['json.*', 'unicode.*'], in: [body] } }
- name: smuggling attempts on /admin go to the patched copy
match: { path: '^/admin', anomalies: request_smuggling }
route: 9001Messages the rules cannot decide on
Some messages cannot be judged as a rule would need: a body larger than limits.buffered_body that a rule needs whole or decoded, a body that arrives while every connection's held bodies take limits.buffered_total, decoding cut short at its limits, a call's body that does not frame as its head says, a dns datagram that does not parse (a name running off the end, a compression pointer loop, more than 32 questions), an ftp line longer than the proxy reads at once, a websocket message larger than it holds, a body or call message whose compression does not undo (Content-Encoding, or a message's grpc-encoding). Only a message some rule of the port would have needed it for counts, and a port without rules has nothing to decide. vulnboxd_proxy_undecidable_total counts them by reason.
By default such a message is stopped, as a block rule would stop it: every difference between vulnboxd's parser and the service's would otherwise be a silent way past the rules, and a body that does not decompress is never benign in a CTF. A body whose compression fails part way is first matched (contains and regex) on what it came to up to there. on_undecidable, for the whole service or one port, says otherwise:
on_undecidable: log # let it through, and report it
ports:
"8080":
protocol: http
on_undecidable: block # fail closed on this port (the default)block stops the message; log lets it through, judged on its bytes as sent. Both report it as a hit of a rule named on_undecidable, in the logs (at warn level) and the metrics. If the checker's legitimate traffic goes past the limits (large uploads, say), raise the limits or set log on that port. vulnboxd reads what legitimate clients send: zero bytes after a gzip body (as Node writes them), a UTF-16 label on a UTF-8 body, and a call content type on a body that is no call.
gRPC and Connect
On an http port, a request that is a gRPC call (application/grpc, over h2c), a gRPC-Web call (application/grpc-web, also over HTTP/1.1) or a ConnectRPC call (unary application/proto or application/json with Connect-Protocol-Version, the GET form, or streaming application/connect+proto) can be matched as the call it is: its method, its messages and their fields, and the status it ends with.
- name: no more listing
match: { grpc_method: /notes.Notes/List }
- name: flags only for the checker's ids
dir: out
match: { grpc_method: '/notes.Notes/Get*', grpc_field: { path: '3', regex: '{flag}' } }
not: { headers: { user-agent: '^grpc-go/' } }
grpc_error: { status: not_found, message: note not found }| condition | holds when |
|---|---|
grpc_method | the method, /package.Service/Method, fits a glob: * for any run of characters, ? for one; the leading / may be left out. A list fits if one of its globs does. Decided from the head, so it can go in not, route and mirror rules |
grpc_status | the call ended with one of these statuses: names in gRPC's or Connect's spelling (NOT_FOUND, not_found, permission_denied) or numbers; one or a list. For dir: out rules: it is known at the end of the response |
grpc_field | a field of one message has a value that contains, equals or matches the regex: { path: '1.3', contains: x }. A list of them must all hold in the same message |
grpc_messages | { over: n }: the call has carried more than n messages in the rule's direction |
grpc_larger_than | a message, decompressed, is larger than this size (64K, as larger_than) |
Field paths. path is field numbers, from the top of the message: 1.3 is field 3 of the message in field 1. With the service's schema, path (or name) can be field names instead: note.body. Names need the schema on the vulnbox: list its .proto files or descriptor sets (protoc --include_imports -o) under grpc_schema at the top of the rules file, relative to it:
grpc_schema: [proto/notes.proto]
ports:
"50051":
protocol: http
rules:
- name: no shell in titles
match: { grpc_field: { name: note.title, regex: '[;|`$]' } }A rules file that uses names without grpc_schema does not load. Field numbers need nothing. A field's value is what a client would read: a string's or bytes' exact bytes; a number as decimal text (equals: '42'), signed when the schema says so, or for a varint without one when its top bit is set; an enum by its name with the schema. A repeated field holds when one of its values does.
One message at a time. A gRPC, gRPC-Web or Connect streaming call's body is read one message at a time, as each completes: rules decide on each message without waiting for the end of a stream, which for a bidirectional call might never come. On these calls contains, regex and body also look at one message at a time (decompressed), and larger_than at one message's size; contains and regex also see the body's bytes as sent, across messages. A message is held until it is whole, up to limits.buffered_body; a larger one, or a frame that does not parse, is only seen as bytes (by contains, regex and replace) and is undecidable. A response is read as messages only when its own content-type says it carries them. A Connect unary call's body is its one message (its Content-Encoding undone), and a GET's message comes from its query.
Answers. A blocked call is answered in its own protocol, so clients see a clean failure instead of a broken connection: a gRPC or gRPC-Web call with grpc-status 7 (PERMISSION_DENIED) and the message blocked (in the trailers, or a trailers-only answer when the response has not begun), a Connect call with its JSON error and the matching HTTP status. grpc_error picks another status and message. A rule that sets set_status or set_body without grpc_error answers with those instead, as for any http request.
The hub reads calls the same way, and its rule preview evaluates gRPC rules on stored calls with the same code.