sniff: Enhance BitTorrent detection with 11 protocol-aware sniffers#3801
Closed
spaiter wants to merge 1 commit intoSagerNet:dev-nextfrom
Closed
sniff: Enhance BitTorrent detection with 11 protocol-aware sniffers#3801spaiter wants to merge 1 commit intoSagerNet:dev-nextfrom
spaiter wants to merge 1 commit intoSagerNet:dev-nextfrom
Conversation
Replace the 3 basic BitTorrent sniffers with comprehensive detection covering encrypted streams (MSE/PE), DHT, LSD, FAST/Extended protocol, HTTP-based BT, and signature matching. Add robust false positive rejection for STUN, DHCP, DTLS, WireGuard, DNS, CAPWAP, AFS RX, SSH, and VoIP protocols. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
BitTorrent,UTP,UDPTracker) with comprehensive, hardened detection logic ported from a standalone DPI project with 99.5%+ accuracyBitTorrentMSE(encrypted streams),BitTorrentMessage(TCP message structure),BitTorrentFAST(BEP 6),BitTorrentExtended(BEP 10),BitTorrentHTTP(WebSeed/UA detection),BitTorrentSignature(pattern matching),BitTorrentDHTPacket(bencode DHT),BitTorrentLSD(Local Service Discovery)UTPandUDPTrackerbittorrent_signatures.gorule_action.go) and default sniffer lists (route.go)Details
Enhanced existing sniffers
UTP: Validates connection ID, window size, timestamp_diff; rejects DHCP (magic cookie), STUN (RFC 5389 + 3489), DTLS, WireGuard handshakes, VoIP/messaging protocols (Zoom, Telegram, WhatsApp patterns)UDPTracker: Validates connection_id non-zero/non-magic, peer ID prefixes, info_hash validity, trailing zero rejection; rejects DNS queries/responses, CAPWAP, DTLS, AFS RX protocolNew TCP stream sniffers
BitTorrentMSE: 4-phase detection of Message Stream Encryption — distinct-byte pre-check → Shannon entropy → Verification Constant scan → crypto field validationBitTorrentMessage: Validates BT message structure (length + ID) with per-type size validation; rejects SSH encrypted packets and MSDO control messagesBitTorrentFAST: BEP 6 message IDs 13-17 with exact length matchingBitTorrentExtended: BEP 10 message ID 20 with bencode dict detectionBitTorrentHTTP: WebSeed, Bitcomet, known User-Agent strings with Shareaza/Gnutella exclusionBitTorrentSignature: Fast pattern matching against 40+ known BT signaturesNew UDP packet sniffers
BitTorrentDHTPacket: Bencode dictionary validation with DHT method names, transaction IDs, node list structure (26/38 bytes per IPv4/IPv6 node)BitTorrentLSD: Multicast address detection (239.192.152.143:6771) and BT-SEARCH payload matchingBitTorrentSignaturePacket: Same signature database applied to UDP packetsTest plan
go vet ./common/sniff/— cleango test ./common/sniff/— 44 tests pass (22 new tests for false positive rejection + new detectors)go build -tags "with_gvisor,with_quic,with_wireguard,with_utls,with_acme,with_clash_api" ./cmd/sing-box— compilesgo test ./route/rule— no regressions🤖 Generated with Claude Code