From 852b789ac3f5b52288a2136102dea6408e2a55b7 Mon Sep 17 00:00:00 2001 From: LiquidTheDangerous Date: Sun, 11 Aug 2024 18:54:06 +0500 Subject: [PATCH] fix: client hello --- proxy/client_hello.go | 48 +++++++++++++++++++++++++++++++++++++++++++ proxy/https.go | 4 ++-- 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 proxy/client_hello.go diff --git a/proxy/client_hello.go b/proxy/client_hello.go new file mode 100644 index 0000000..102b7c8 --- /dev/null +++ b/proxy/client_hello.go @@ -0,0 +1,48 @@ +package proxy + +import ( + "encoding/binary" + "io" +) + +const headerLen = 5 + +type ClientHello struct { + Header ClientHelloHeader + Raw []byte //Header + Payload + RawHeader []byte + RawPayload []byte +} + +type ClientHelloHeader struct { + Type byte + ProtoVersion uint16 + PayloadLen uint16 +} + +func ReadClientHello(r io.Reader) (*ClientHello, error) { + var rawHeader [5]byte + _, err := io.ReadFull(r, rawHeader[:]) + if err != nil { + return nil, err + } + + header := ClientHelloHeader{ + Type: rawHeader[0], + ProtoVersion: binary.BigEndian.Uint16(rawHeader[1:3]), + PayloadLen: binary.BigEndian.Uint16(rawHeader[3:5]), + } + raw := make([]byte, header.PayloadLen+headerLen) + copy(raw[0:headerLen], rawHeader[:]) + _, err = io.ReadFull(r, raw[headerLen:]) + if err != nil { + return nil, err + } + hello := &ClientHello{ + Header: header, + Raw: raw, + } + hello.RawHeader = hello.Raw[:headerLen] + hello.RawPayload = hello.Raw[headerLen:] + return hello, nil +} diff --git a/proxy/https.go b/proxy/https.go index 359336c..1ef49f8 100644 --- a/proxy/https.go +++ b/proxy/https.go @@ -45,12 +45,12 @@ func (pxy *Proxy) handleHttps(lConn *net.TCPConn, exploit bool, initPkt *packet. log.Debug("[HTTPS] Sent 200 Connection Estabalished to ", lConn.RemoteAddr()) // Read client hello - tmpBuffer := make([]byte, 4096) - clientHello, err := ReadBytes(lConn, tmpBuffer) + hello, err := ReadClientHello(lConn) if err != nil { log.Debug("[HTTPS] Error reading client hello from the client", err) return } + clientHello := hello.Raw log.Debug("[HTTPS] Client sent hello ", len(clientHello), "bytes")