mirror of
https://github.com/xvzc/SpoofDPI.git
synced 2025-01-03 04:50:11 +00:00
add client hello chunks
This commit is contained in:
parent
b54d28c5a7
commit
b58ec8d6c4
@ -2,11 +2,12 @@ package proxy
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"io"
|
|
||||||
|
|
||||||
// "time"
|
// "time"
|
||||||
|
|
||||||
|
"github.com/xvzc/SpoofDPI/config"
|
||||||
"github.com/xvzc/SpoofDPI/util"
|
"github.com/xvzc/SpoofDPI/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -16,15 +17,11 @@ func HandleHttps(clientConn net.Conn, ip string) {
|
|||||||
util.Debug(err)
|
util.Debug(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
defer clientConn.Close()
|
||||||
defer remoteConn.Close()
|
defer remoteConn.Close()
|
||||||
|
|
||||||
util.Debug("Connected to the server.")
|
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() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
buf, err := util.ReadMessage(remoteConn)
|
buf, err := util.ReadMessage(remoteConn)
|
||||||
@ -39,7 +36,7 @@ func HandleHttps(clientConn net.Conn, ip string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
util.Debug(remoteConn.RemoteAddr(), "Server Sent Data", len(buf))
|
util.Debug(remoteConn.RemoteAddr(), "Server sent data", len(buf))
|
||||||
|
|
||||||
_, write_err := clientConn.Write(buf)
|
_, write_err := clientConn.Write(buf)
|
||||||
if write_err != nil {
|
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 {
|
for {
|
||||||
defer clientConn.Close()
|
|
||||||
buf, err := util.ReadMessage(clientConn)
|
buf, err := util.ReadMessage(clientConn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err != io.EOF {
|
if err != io.EOF {
|
||||||
@ -62,7 +86,7 @@ func HandleHttps(clientConn net.Conn, ip string) {
|
|||||||
util.Debug("Closing connection: ", clientConn.RemoteAddr())
|
util.Debug("Closing connection: ", clientConn.RemoteAddr())
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
util.Debug(clientConn.RemoteAddr(), "Client Sent Data", len(buf))
|
util.Debug(clientConn.RemoteAddr(), "Client sent data", len(buf))
|
||||||
|
|
||||||
_, write_err := remoteConn.Write(buf)
|
_, write_err := remoteConn.Write(buf)
|
||||||
if write_err != nil {
|
if write_err != nil {
|
||||||
|
14
util/util.go
14
util/util.go
@ -4,6 +4,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
|
"errors"
|
||||||
|
|
||||||
"github.com/babolivier/go-doh-client"
|
"github.com/babolivier/go-doh-client"
|
||||||
"github.com/xvzc/SpoofDPI/config"
|
"github.com/xvzc/SpoofDPI/config"
|
||||||
@ -108,6 +109,19 @@ func ExtractMethod(message *[]byte) (string) {
|
|||||||
return strings.ToUpper(method)
|
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{}) {
|
func Debug(v ...interface{}) {
|
||||||
if config.GetConfig().Debug == false {
|
if config.GetConfig().Debug == false {
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user