
Pqsniff 发布:可查看网络中哪些连接使用后量子密钥交换
来源标题:Show HN: Pqsniff – See which connections on your network are post-quantum
Pqsniff 是一款用于 Linux 路由器的被动握手日志工具,能识别 TLS 和 QUIC 连接是否使用后量子密钥交换。它读取握手明文部分,每连接输出一行 JSON,记录客户端提供的密钥交换组、服务器选择结果以及是否采用 X25519MLKEM768 等后量子混合方案。该工具为约 470 KB 的静态二进制文件,无需 libpcap 或 tcpdump,在家用路由器上仅占用单核 0.15% CPU 和约 0.5 MB 内存。
以下正文同步自 Hacker News 最新,版权归原站所有,已转换为易读排版。
See which TLS and QUIC connections on your network use post-quantum key exchange.
pqsniff is a small passive handshake logger for Linux routers (OpenWrt included) and any Linux box that can see your traffic. It reads the parts of every TLS and QUIC handshake that are still sent in the clear and writes one JSON line per connection: which key-exchange groups the device offered, which one the server picked, and whether that connection is protected by a post-quantum hybrid like X25519MLKEM768.
One static binary, about 470 KB, no libpcap, no tcpdump. On a home router it used 0.15% of one CPU core and about 0.5 MB of memory.
{ "t": 1796354566.106, "proto": "quic", "mac": "02:00:00:00:00:0a", "client": "192.0.2.10", "server": "198.51.100.20", "port": 443, "sni": "www.example.com", "ja4": "q13d0311h3_55b375c5d22e_f2a83c8e78ae", "offered": ["X25519MLKEM768", "x25519", "secp256r1", "secp384r1", "secp521r1"], "key_share": ["X25519MLKEM768", "x25519"], "client_pq": true, "alpn": ["h3"], "tls": "1.3", "cipher": "0x1302", "chosen": "X25519MLKEM768", "pq": true, "risks": [] }
(Pretty-printed here; the real output is one object per line.)
"Harvest now, decrypt later" means today's recorded traffic matters once large quantum computers exist. Browsers, Apple and Google platforms, and big CDNs already negotiate hybrid ML-KEM key exchange, but older stacks, IoT gadgets and plenty of servers don't. Server scanners tell you what a site supports. pqsniff tells you what your devices actually negotiated, connection by connection, including QUIC/HTTP/3, which is often a large share of home traffic and invisible to most flow tools.
Field Meaning
proto tcp or quic
client, server, port, mac endpoints; mac is the client's Ethernet address
sni, alpn, ech hostname asked for, application protocols, Encrypted Client Hello used
ja4 JA4 client fingerprint
offered groups the client supports, in its order of preference (GREASE removed)
key_share groups it actually sent keys for
client_pq the client offered a post-quantum group
chosen group the server picked (null: RSA key exchange or resumed TLS 1.2 session)
pq this connection uses post-quantum key exchange
tls, cipher negotiated version and cipher suite
hrr the server asked the client to retry with a different group (HelloRetryRequest)
issuer_dn, subject_dn, server_cn, fingerprint, not_before, not_after server certificate (TLS 1.2 and older only; TLS 1.3 encrypts it)
risks numbered like nDPI/netifyd: 29 certificate expires within 30 days, 30 expired, 31 hostname mismatch, 32 validity over 398 days, 35 no SNI, 36 TLS older than 1.2, 37 self-signed, 41 weak cipher (no forward secrecy, RC4, 3DES)
server_hello: false the server never answered
Post-quantum groups recognised: X25519MLKEM768 (0x11EC), SecP256r1MLKEM768, SecP384r1MLKEM1024, pure MLKEM512/768/1024, and the pre-standard X25519Kyber768Draft00 (0x6399, still seen on older stacks; named separately).
- Get the binary
With Rust installed (any Linux, or macOS for reading pcap files):
cargo install pqsniff
Or a prebuilt static binary, the easy route on routers and Raspberry Pis. Pick the build for your CPU (uname -m):
T=aarch64-unknown-linux-musl curl -LO https://github.com/xydac/pqsniff/releases/latest/download/pqsniff-$T curl -LO https://github.com/xydac/pqsniff/releases/latest/download/SHA256SUMS sha256sum -c --ignore-missing SHA256SUMS && chmod +x pqsniff-$T && mv pqsniff-$T pqsniff
They are static binaries: no libraries to install. Routers without curl or HTTPS tools: download on your computer and copy it over (scp -O pqsniff root@router:/usr/bin/).
Use the interface that carries your LAN traffic, usually the one holding your LAN address (ip -br addr):
It has to sit where the traffic passes. A laptop on Wi-Fi only sees its own connections. pqsniff puts the interface into promiscuous mode for its own socket (undone when it exits), so a mirror port works without extra setup. On a router, which already sees what it forwards, --no-promisc skips that (the OpenWrt service does).
Run it for a minute and watch the handshakes go by. The raw output is JSON; this one command adds a small jq program that prints each connection as one colored line (needs jq: apt install jq, or opkg install jq / apk add jq on OpenWrt, where you'd also use -i br-lan and no sudo):
sudo ./pqsniff -i eth0 -s 60 | jq -r --unbuffered ' def pad(n): tostring | if length < n then . + (" " * (n - length)) else .[:n-2] + "… " end; def c(x): "\u001b[" + x + "m"; (if .pq then c("1;30;42") + " PQ " else c("1;30;43") + " -- " end) + c("0") + " "
- (if .proto == "quic" then c("36") else c("90") end) + (.proto | pad(5)) + c("0")
- (.client | pad(15)) + ((.sni // .server) | pad(30))
- (if .pq then c("32") else c("33") end) + ((.chosen // "-") | pad(15)) + c("0")
- (if .hrr then c("90") + " hrr" + c("0") else "" end)
- (if (.risks | index(30)) then c("31") + " cert expired" + c("0") elif (.risks | index(29)) then c("31") + " cert expiring" + c("0") elif .tls == "1.2" then c("31") + " TLS 1.2" + c("0") else "" end)'
Open a few websites on another device. Within seconds you should see something like:
PQ quic 192.0.2.15 www.example.com X25519MLKEM768 PQ tcp 192.0.2.15 api.example.com X25519MLKEM768 -- tcp 192.0.2.12 mail.example.org secp384r1 hrr PQ quic 192.0.2.23 video.example.net X25519MLKEM768 -- tcp 192.0.2.31 cloud.camera.example secp256r1 cert expiring -- tcp 192.0.2.40 telemetry.example.net x25519 -- tcp 192.0.2.44 plug.iot.example secp256r1 TLS 1.2
Green PQ = post-quantum key exchange, amber -- = not; the notes flag a retry (hrr), a bad certificate or TLS 1.2. Nothing at all means the wrong interface, or this machine doesn't see the traffic. Without jq, drop the pipe and you get the JSON lines.
Happy with what you see? Then make it permanent:
OpenWrt (procd; hourly files in /tmp/pqsniff, i.e. RAM, nothing written to flash):
scp -O pqsniff root@192.168.1.1:/usr/bin/pqsniff scp -O contrib/openwrt/pqsniff.init root@192.168.1.1:/etc/init.d/pqsniff scp -O contrib/openwrt/cleanup.sh root@192.168.1.1:/usr/bin/pqsniff-cleanup.sh ssh root@192.168.1.1 ' chmod +x /usr/bin/pqsniff /usr/bin/pqsniff-cleanup.sh /etc/init.d/pqsniff echo "7 * * * * /usr/bin/pqsniff-cleanup.sh" >> /etc/crontabs/root && /etc/init.d/cron restart /etc/init.d/pqsniff enable && /etc/init.d/pqsniff start'
The init script watches br-lan; change IFACE at its top for anything else. A firmware upgrade wipes /usr/bin and /etc/init.d, so repeat this after upgrading.
systemd (runs as an unprivileged user with only CAP_NET_RAW; files in /var/log/pqsniff):
sudo install -m 755 pqsniff /usr/local/bin/ sudo install -m 644 contrib/systemd/pqsniff.service /etc/systemd/system/ sudo sed -i 's/-i eth0/-i YOUR_INTERFACE/' /etc/systemd/system/pqsniff.service # if not eth0 sudo systemctl daemon-reload && sudo systemctl enable --now pqsniff
Raspberry Pi (Raspberry Pi OS uses systemd, so it's the steps above with the right binary):
A Pi only sees your traffic in one of these setups:
uname -m # pick the file from the table T=aarch64-unknown-linux-musl curl -LO https://github.com/xydac/pqsniff/releases/latest/download/pqsniff-$T curl -LO https://github.com/xydac/pqsniff/releases/latest/download/SHA256SUMS sha256sum -c --ignore-missing SHA256SUMS && chmod +x pqsniff-$T && mv pqsniff-$T pqsniff sudo ./pqsniff -i eth0 -s 30 # browse on another device; lines should appear sudo install -m 755 pqsniff /usr/local/bin/ curl -LO https://raw.githubusercontent.com/xydac/pqsniff/main/contrib/systemd/pqsniff.service sudo install -m 644 pqsniff.service /etc/systemd/system/ sudo systemctl daemon-reload && sudo systemctl enable --now pqsniff
Even a Pi Zero keeps up: only handshake packets reach pqsniff, not the traffic itself.
pqsniff -r capture.pcap > handshakes.jsonl
Classic pcap with Ethernet framing (tcpdump -w writes it). Wireshark's pcapng: editcap -F pcap in.pcapng out.pcap first.
-i, --interface <name> interface to watch (Linux, root or CAP_NET_RAW) -r, --read <file> read a pcap file instead -o, --output <file> append JSON lines to <file> (default: standard output) -d, --dir <dir> write <dir>/tls-YYYYmmdd-HH.jsonl, one file per local hour (TZ from the environment) -s, --seconds <n> stop after <n> seconds -P, --no-promisc leave promiscuous mode off (routers) -v, --verbose packet and handshake counters on stderr every minute
Questions jq can answer
The output is plain JSON lines, so jq does the rest (it's opkg install jq / apk add jq on OpenWrt). Point L at your logs, e.g. L=/tmp/pqsniff/.jsonl on OpenWrt or L=/var/log/pqsniff/.jsonl with systemd.
jq -s 'map(select(.tls)) | {connections: length, post_quantum: (map(select(.pq)) | length)} | .percent = (100 * .post_quantum / .connections | round)' $L
{ "connections": 855, "post_quantum": 667, "percent": 78 }
HTTP/3 or plain TCP?
jq -rs 'map(select(.tls)) | group_by(.proto)[] | "(.[0].proto)\t(length) connections\t(100 * (map(select(.pq)) | length) / length | round)% post-quantum"' $L
quic 367 connections 95% post-quantum tcp 488 connections 65% post-quantum
Which devices are behind? (connections, % post-quantum, whether it ever offers it)
jq -rs 'group_by(.mac)[] | [length, (100 * (map(select(.pq)) | length) / length | round | tostring + "%"), (if any(.[]; .client_pq) then "offers PQ" else "never offers PQ" end), .[0].client, .[0].mac] | @tsv' $L | sort -rn
389 82% offers PQ 192.0.2.15 02:00:00:00:00:15 50 42% offers PQ 192.0.2.12 02:00:00:00:00:12 12 0% never offers PQ 192.0.2.31 02:00:00:00:00:31
Which servers turn down a post-quantum offer?
jq -r 'select(.client_pq and .tls == "1.3" and (.pq | not)) | "(.sni // .server)\t(.chosen)"' $L | sort | uniq -c | sort -rn
3 mail.example.com secp384r1 2 telemetry.example.net x25519
What gets negotiated?
jq -r '.chosen // "none"' $L | sort | uniq -c | sort -rn
667 X25519MLKEM768 151 x25519 18 secp256r1 10 secp384r1 8 none
Any certificate problems? (TLS 1.2 and older only)
jq -r 'select(.risks | any(. == 29 or . == 30 or . == 31 or . == 32 or . == 37)) | [(.sni // .server), (.risks | map({"29":"expiring","30":"expired","31":"wrong-host","32":"too-long","37":"self-signed"}[tostring] // empty) | join(",")), .issuer_dn] | @tsv' $L | sort -u
198.51.100.9 expiring,wrong-host C=CN, O=Example CA Limited, CN=Example RSA OV SSL CA 2
(That one is a real pattern: a security camera calling its vendor's cloud by bare IP.)
jq -r 'select(.risks | any(. == 36 or . == 41)) | [.client, (.sni // .server), .tls, .cipher] | @tsv' $L | sort | uniq -c
Watch live: the jq program from Try it works on stored logs too: put the log files after it in place of the pipe.
cargo test cargo build --release --target aarch64-unknown-linux-musl # also armv7-/arm-unknown-linux-musleabihf, x86_64-unknown-linux-musl
Static musl binaries link with the bundled rust-lld (.cargo/config.toml), so no cross C toolchain is needed: rustup target add <target> is enough. MIPS routers: Rust's MIPS targets are tier 3, so build with nightly and -Zbuild-std.
Capture: a Linux AF_PACKET socket with a classic BPF filter in the kernel. It passes TCP on common TLS ports (443, 853, 993, 995, 465, 5223, 8443, 8883, 9443, 4433, 10443, 5061, 6443), the first segment of a TLS handshake on any other port, and only QUIC long-header packets on UDP 443. Video streams and other bulk data never reach userspace.
TCP: each direction is reassembled from the first handshake record (a post-quantum ClientHello is about 1.8 KB, so it spans two segments). The record layer is stripped; parsing stops at the first encrypted record.
QUIC: Initial packets are protected with keys derived from the client's first connection ID and a public salt (RFC 9001 §5.2), so they can be decrypted by anyone on the path. pqsniff removes header protection, decrypts with AES-128-GCM and reassembles CRYPTO frames by offset (browsers deliberately send them out of order). QUIC v1 and v2; Retry handled
正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。
