From a618c5556ed1b16b55af5b686ea28f0dbbdf4a35 Mon Sep 17 00:00:00 2001 From: ginuerzh Date: Sun, 15 Sep 2024 21:12:10 +0800 Subject: [PATCH] fix tls host for handler recorder --- handler/redirect/tcp/handler.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/handler/redirect/tcp/handler.go b/handler/redirect/tcp/handler.go index 47b8cd01..64b4eeb5 100644 --- a/handler/redirect/tcp/handler.go +++ b/handler/redirect/tcp/handler.go @@ -142,7 +142,7 @@ func (h *redirectHandler) Handle(ctx context.Context, conn net.Conn, opts ...han if err == nil && hdr[0] == dissector.Handshake && (tlsVersion >= tls.VersionTLS10 && tlsVersion <= tls.VersionTLS13) { - return h.handleHTTPS(ctx, rw, conn.RemoteAddr(), dstAddr, log) + return h.handleHTTPS(ctx, rw, conn.RemoteAddr(), dstAddr, ro, log) } // try to sniff HTTP traffic @@ -272,7 +272,7 @@ func (h *redirectHandler) handleHTTP(ctx context.Context, rw io.ReadWriter, radd return nil } -func (h *redirectHandler) handleHTTPS(ctx context.Context, rw io.ReadWriter, raddr, dstAddr net.Addr, log logger.Logger) error { +func (h *redirectHandler) handleHTTPS(ctx context.Context, rw io.ReadWriter, raddr, dstAddr net.Addr, ro *xrecorder.HandlerRecorderObject, log logger.Logger) error { buf := new(bytes.Buffer) host, err := h.getServerName(ctx, io.TeeReader(rw, buf)) if err != nil { @@ -293,10 +293,11 @@ func (h *redirectHandler) handleHTTPS(ctx context.Context, rw io.ReadWriter, rad log = log.WithFields(map[string]any{ "host": host, }) + ro.Host = host if h.options.Bypass != nil && h.options.Bypass.Contains(ctx, "tcp", host) { log.Debug("bypass: ", host) - return nil + return xbypass.ErrBypass } cc, err = h.options.Router.Dial(ctx, "tcp", host)