SpoofDPI/proxy/https.go

98 lines
2.6 KiB
Go
Raw Normal View History

2022-01-02 12:56:12 +00:00
package proxy
import (
"fmt"
2022-01-03 08:12:51 +00:00
"io"
2022-01-02 12:56:12 +00:00
"net"
// "time"
2022-01-03 08:12:51 +00:00
"github.com/xvzc/SpoofDPI/config"
2022-01-02 12:56:12 +00:00
"github.com/xvzc/SpoofDPI/util"
)
func HandleHttps(clientConn net.Conn, ip string) {
remoteConn, err := net.Dial("tcp", ip+":443") // create connection to server
if err != nil {
2022-01-03 07:24:39 +00:00
util.Debug(err)
2022-01-02 12:56:12 +00:00
return
}
2022-01-03 08:12:51 +00:00
defer clientConn.Close()
2022-01-02 15:24:59 +00:00
defer remoteConn.Close()
2022-01-03 07:24:39 +00:00
util.Debug("Connected to the server.")
2022-01-02 12:56:12 +00:00
go func() {
for {
buf, err := util.ReadMessage(remoteConn)
if err != nil {
2022-01-02 15:24:59 +00:00
if err != io.EOF {
2022-01-03 07:24:39 +00:00
util.Debug("Error reading from the server:", err)
2022-01-02 15:24:59 +00:00
} else {
2022-01-03 07:24:39 +00:00
util.Debug("Remote connection Closed: ", err)
2022-01-02 15:24:59 +00:00
}
2022-01-03 07:24:39 +00:00
util.Debug("Closing connection: ", remoteConn.RemoteAddr())
2022-01-02 12:56:12 +00:00
return
}
2022-01-03 08:12:51 +00:00
util.Debug(remoteConn.RemoteAddr(), "Server sent data", len(buf))
2022-01-02 15:24:59 +00:00
2022-01-02 12:56:12 +00:00
_, write_err := clientConn.Write(buf)
if write_err != nil {
2022-01-03 07:24:39 +00:00
util.Debug("Error writing to client:", write_err)
2022-01-02 12:56:12 +00:00
return
}
}
}()
2022-01-03 08:12:51 +00:00
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
}
}
2022-01-02 12:56:12 +00:00
for {
buf, err := util.ReadMessage(clientConn)
if err != nil {
2022-01-02 15:24:59 +00:00
if err != io.EOF {
2022-01-03 07:24:39 +00:00
util.Debug("Error reading from the client:", err)
2022-01-02 15:24:59 +00:00
} else {
2022-01-03 07:24:39 +00:00
util.Debug("Client connection Closed: ", err)
2022-01-02 15:24:59 +00:00
}
2022-01-03 07:24:39 +00:00
util.Debug("Closing connection: ", clientConn.RemoteAddr())
2022-01-02 12:56:12 +00:00
break
}
2022-01-03 08:12:51 +00:00
util.Debug(clientConn.RemoteAddr(), "Client sent data", len(buf))
2022-01-02 12:56:12 +00:00
_, write_err := remoteConn.Write(buf)
if write_err != nil {
2022-01-03 07:24:39 +00:00
util.Debug("Error writing to client:", write_err)
2022-01-02 12:56:12 +00:00
break
}
}
}