Skip to content

ours-sniff ​

libs/sniff — a connection's protocol and the domain it is for, from the first bytes.

Why it repeats sing-box, quirks included ​

Every sniffer repeats sing-box 1.14.4 (common/sniff): rules written for sing-box compare what it reports. The sniffers fill in Sniffed the same way sing-box fills in the connection metadata: one may write a field and still return an error (QUIC, when the ClientHello spans several packets).

API ​

  • Sniffer — Tls, Http, StreamDns, BitTorrent, Ssh, Rdp, Dns, Quic, Stun, Utp, UdpTracker, Dtls, Ntp.
  • STREAM_DEFAULT, PACKET_DEFAULT — the default sets; AVAILABLE — the names in this build.
  • by_names — the stream and packet sniffers named by the sniff action, as in sing-box: dns — StreamDns and Dns (TCP and UDP), quic — only Quic.
  • skip(port) — server-first protocols on their usual ports: the client is silent, there is nothing to sniff.
  • stream(data, sniffers, &mut Sniffed) — tries the sniffers in order on everything the stream has sent; the first that recognizes it ends the search. Error distinguishes "more data needed" and "not this".
  • packet(packet, sniffers, &mut PacketState, &mut Sniffed) — the same for a packet of a UDP flow.

Modules: tls.rs (the record layer and Go's clientHelloMsg), http.rs (http.ReadRequest), dns.rs (miekg/dns structure checks, record data are skipped by length), quic.rs (Initial: keys from the DCID, CRYPTO frames, assembly from several packets), ja3.rs (the common/ja3 ClientHello parser — kept as is), simple.rs (SSH, RDP, BitTorrent, STUN, DTLS, NTP — by a fixed header).

Features ​

default = ["all"]; all — all of them: tls, http, dns, bittorrent, ssh, rdp, quic, stun, dtls, ntp. quic requires ring (decrypting Initial) and dns. The binary enables them with the sniff feature (all) or sniff-<name> one at a time.

Who uses it ​

ours-mod-dispatch (the sniff action), ours-mod-router, the binary and the allocs tool.

Tests ​

Unit tests in src/; libs/sniff/tests/sing_box.rs — sing-box's own sniffer tests: the packets and expectations are copied from common/sniff/*_test.go of 1.14.4. Fuzz targets stream and packet are in fuzz/.

GPL-3.0-or-later