Conversation
Adds -fingerprint, which drives the outbound TLS handshake through uTLS so the ClientHello matches a browser profile. Off by default: with no flag the transport is untouched and every scanner keeps the existing behaviour. The seam is buildTransport, which is where the plan in vmfunc#435 pointed: one dialer, composed rather than replacing the proxy path. socks5 keeps working because the TLS layer wraps the proxy's dialer instead of racing it, and an http(s) proxy is refused when a fingerprint is set, since that proxy performs the origin handshake from tls.Config where DialTLSContext is never consulted - the flag would otherwise be a silent no-op. Known gap, documented in the flag, the doc page and the code: this is the hello only. net/http negotiates h2 only when it performs the handshake itself, so taking it over forces HTTP/1.1, and a full browser-coherent JA4 plus h2 (correct SETTINGS, WINDOW_UPDATE, priority frames) is deliberately out of scope. A target that fingerprints on h2 behaviour will still see a mismatch. uTLS was already an indirect dependency; this promotes it to direct, go mod tidy included. Behaviour is covered by four unit tests plus one real handshake against a TLS server, which fails if the uTLS dialer is disabled.
pr summary8 files changed (+368 -29)
|
There was a problem hiding this comment.
Thanks for this. It's scoped the way #435 asked: opt-in, off by default, one dialer seam in buildTransport, and the h2 gap is documented. The no-flag path looks unchanged to me, and refusing an http/https proxy combined with an unknown profile is a reasonable call.
CI / verification status
- On head
a62b21a, onlyci-summary,sizeandlabelhave run. The required workflows (lint,build-and-test,build (1.26)) haven't run, most likely because a maintainer still has to approve workflows for a fork/first-time contributor. That isn't a failure in the PR. - I couldn't run
go build ./...,go vet ./...orgo test ./...locally for this review because my sandbox has no Go 1.26 toolchain and can't download one. Everything below comes from reading the code, so please treat the uTLS ALPN point as something to confirm with the test I suggest.
Main concern (correctness): ALPN may still advertise h2
With a non-custom ClientHelloID such as HelloChrome_Auto, uTLS builds the hello from the preset spec. My understanding is that its ALPNExtension writes the spec's protocols (h2, http/1.1) into the config when the preset is applied, which would override cfg.NextProtos = []string{"http/1.1"}. If so, any h2-capable server (most CDNs) will pick h2. The transport would then send HTTP/1.1 on an h2 connection, because it only consults TLSNextProto for a *tls.Conn, and *utls.UConn isn't one. That would break most real HTTPS targets whenever -fingerprint is set.
The current handshake test can't catch this: httptest.NewTLSServer advertises only http/1.1 unless EnableHTTP2 is set. Please see the inline comments for a test that would fail, and for possible fixes.
Other items
HTTPS_PROXY/HTTP_PROXYfrom the environment get around the http-proxy refusal (inline comment).- The case-insensitivity test passes a lowercase value (inline comment).
- Minor: the copied
tls.Configonly carriesRootCAs,InsecureSkipVerify, Min/MaxVersion andCipherSuites. That's fine today because nothing else setsTLSClientConfig. If you keep it, a short comment saying the other fields are deliberately dropped would help.
Not merging. This needs the required CI to run and a maintainer approval.
| // Advertise http/1.1 only, matching the transport. Advertising h2 here | ||
| // without then sending h2 SETTINGS frames would make the handshake | ||
| // claim something the connection cannot do. | ||
| cfg.NextProtos = []string{"http/1.1"} |
There was a problem hiding this comment.
I suspect this has no effect for the *_Auto presets. When uTLS applies a preset, the spec's ALPNExtension (h2, http/1.1 for Chrome/Firefox/Edge/Safari) overwrites config.NextProtos, so the hello still offers h2. Two possible fixes:
- Build the spec yourself and rewrite ALPN before applying it:
spec, _ := utls.UTLSIdToSpec(id), find the*utls.ALPNExtension, setAlpnProtocols = []string{"http/1.1"}, thenutls.UClient(raw, cfg, utls.HelloCustom)andconn.ApplyPreset(&spec). This keeps the rest of the fingerprint and only changes ALPN, which a JA4 hash will show, so document it. - Keep the hello as it is, then after the handshake check
conn.ConnectionState().NegotiatedProtocol. If it'sh2, close the connection and return a clear error. Otherwise hand it to anhttp2.Transport(golang.org/x/net/http2is already a dependency) and drop the HTTP/1.1-only restriction.
At minimum, the dialer should refuse to return a connection where NegotiatedProtocol == "h2", because that connection will fail later with a confusing error.
| // and a completed uTLS handshake on the other end. If uTLS cannot drive the | ||
| // connection this fails rather than erroring somewhere quiet. | ||
| func TestFingerprintHandshakeReachesServer(t *testing.T) { | ||
| srv := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { |
There was a problem hiding this comment.
httptest.NewTLSServer only advertises http/1.1, so this test passes whatever the client offers in ALPN. Please add a variant that more closely matches real targets:
srv := httptest.NewUnstartedServer(handler)
srv.EnableHTTP2 = true
srv.StartTLS()and assert the request succeeds over HTTP/1.1. I expect it to fail with the current dialer, as described on fingerprint.go:99.
| } | ||
| } | ||
| if _, err := clientHelloID("chrome"); err != nil { | ||
| t.Errorf("matching should be case-insensitive: %v", err) |
There was a problem hiding this comment.
This passes "chrome" in lowercase, so it doesn't test case-insensitivity. It should be something like clientHelloID(" Chrome ") to cover both ToLower and TrimSpace.
| return nil, fmt.Errorf("unsupported proxy scheme %q (want http/https/socks5)", parsed.Scheme) | ||
| } | ||
|
|
||
| if fingerprint != "" { |
There was a problem hiding this comment.
When -proxy is empty, transport.Proxy is still http.ProxyFromEnvironment, inherited from the DefaultTransport clone. If HTTPS_PROXY is set, net/http dials the proxy, sends CONNECT and does the origin handshake itself from TLSClientConfig, skipping DialTLSContext. That's the same silent no-op this PR refuses for -proxy http://....
For consistency, either set transport.Proxy = nil when fingerprinting with no explicit proxy (and document that env proxies are ignored), or fail at startup when http.ProxyFromEnvironment would return a proxy for https. A unit test using t.Setenv("HTTPS_PROXY", ...) would pin down whichever you choose.
Closes #435, scoped to what you described: opt-in, off by default, ClientHello only via a pluggable dialer in
buildTransport, with the h2 mismatch as a documented gap.What it does.
-fingerprint chrome(or firefox, safari, edge, ios, android) drives the outbound TLS handshake through uTLS so the ClientHello matches the profile. With no flag,buildTransportis untouched and behaviour is identical for every scanner.Where the seam is. One dialer composed into
buildTransport, as mapped on the issue. The socks5 branch now feeds the same dial function the TLS layer wraps, so proxying and fingerprinting compose instead of competing.Two decisions I made rather than leaving implicit.
An
http/httpsproxy plus a fingerprint is refused at startup. That proxy performs the origin handshake itself fromtls.Config, whereDialTLSContextis never consulted, so the flag would be a silent no-op: the user would believe the hello changed when it did not.socks5is the supported combination.An unknown profile is a startup error, not a warning. Every other bad HTTP option warns and continues, which is right for a proxy that might be transient, but a mistyped profile would run a whole scan with Go's hello while the command line claimed otherwise.
The gap, stated plainly. net/http only negotiates h2 when it performs the handshake, so taking it over forces HTTP/1.1. A Chrome hello over HTTP/1.1 is a real match on the hello and a real mismatch on anything that fingerprints h2 behaviour (SETTINGS ordering, WINDOW_UPDATE, priority frames). That is written into the flag help,
docs/usage.md, and the comment onbuildTransportso nobody discovers it by surprise.Verification. Five unit tests in
internal/httpx/fingerprint_test.go: off-by-default leavesDialTLSContextnil and h2 attempted; a set fingerprint installs the dialer, clears both h2 switches andTLSNextProto; the http-proxy refusal names the working alternative; profile names resolve and unknown ones fail;Configurefails before installing a half-built transport. Plus one real handshake against anhttptestTLS server, which I confirmed bites by disabling the uTLS dialer and watching it fail.go build ./...,go vetand both affected packages are clean;go mod tidypromotes uTLS from indirect to direct.I could not exercise the CLI end to end here: the binary hangs without a TTY in my sandbox even with no flags, and the control run does the same, so it says nothing about this change. The flag parses,
-hlists it, and the wiring is three lines into the existingConfigurecall.Happy to drop the fingerprint-plus-proxy refusal if you would rather warn than fail.