diff --git a/proxy/https.go b/proxy/https.go index a2be5c7..0f5b0fb 100644 --- a/proxy/https.go +++ b/proxy/https.go @@ -2,11 +2,12 @@ package proxy import ( "fmt" + "io" "net" - "io" // "time" + "github.com/xvzc/SpoofDPI/config" "github.com/xvzc/SpoofDPI/util" ) @@ -16,15 +17,11 @@ func HandleHttps(clientConn net.Conn, ip string) { util.Debug(err) return } + defer clientConn.Close() defer remoteConn.Close() util.Debug("Connected to the server.") - util.Debug("Sending 200 Connection Estabalished") - - fmt.Fprintf(clientConn, "HTTP/1.1 200 Connection Established\r\n\r\n") - - go func() { for { buf, err := util.ReadMessage(remoteConn) @@ -39,7 +36,7 @@ func HandleHttps(clientConn net.Conn, ip string) { return } - util.Debug(remoteConn.RemoteAddr(), "Server Sent Data", len(buf)) + util.Debug(remoteConn.RemoteAddr(), "Server sent data", len(buf)) _, write_err := clientConn.Write(buf) if write_err != nil { @@ -49,8 +46,35 @@ func HandleHttps(clientConn net.Conn, ip string) { } }() + util.Debug("Sending 200 Connection Estabalished") + fmt.Fprintf(clientConn, "HTTP/1.1 200 Connection Established\r\n\r\n") + + clientHello, err := util.ReadMessage(clientConn) + if err != nil { + if err != io.EOF { + util.Debug("Error reading from the client:", err) + } else { + util.Debug("Client connection Closed: ", err) + } + + util.Debug("Closing connection: ", clientConn.RemoteAddr()) + } + util.Debug(clientConn.RemoteAddr(), "Client sent hello", len(clientHello)) + + chunks, err := util.SplitSliceInChunks(clientHello, config.GetConfig().MTU) + if err != nil { + util.Debug("Error chunking client hello: ", err) + } + + for i := 0; i < len(chunks); i++ { + _, write_err := remoteConn.Write(chunks[i]) + if write_err != nil { + util.Debug("Error writing to client:", write_err) + break + } + } + for { - defer clientConn.Close() buf, err := util.ReadMessage(clientConn) if err != nil { if err != io.EOF { @@ -62,7 +86,7 @@ func HandleHttps(clientConn net.Conn, ip string) { util.Debug("Closing connection: ", clientConn.RemoteAddr()) break } - util.Debug(clientConn.RemoteAddr(), "Client Sent Data", len(buf)) + util.Debug(clientConn.RemoteAddr(), "Client sent data", len(buf)) _, write_err := remoteConn.Write(buf) if write_err != nil { diff --git a/util/util.go b/util/util.go index d79a735..693cf3a 100644 --- a/util/util.go +++ b/util/util.go @@ -4,6 +4,7 @@ import ( "log" "net" "strings" + "errors" "github.com/babolivier/go-doh-client" "github.com/xvzc/SpoofDPI/config" @@ -108,6 +109,19 @@ func ExtractMethod(message *[]byte) (string) { return strings.ToUpper(method) } +func SplitSliceInChunks(a []byte, size int) ([][]byte, error) { + if size < 1 { + return nil, errors.New("chuckSize must be greater than zero") + } + chunks := make([][]byte, 0, (len(a)+size-1)/size) + + for size < len(a) { + a, chunks = a[size:], append(chunks, a[0:size:size]) + } + chunks = append(chunks, a) + return chunks, nil +} + func Debug(v ...interface{}) { if config.GetConfig().Debug == false { return