SpoofDPI/proxy/https.go

51 lines
1.3 KiB
Go
Raw Normal View History

2022-01-02 12:56:12 +00:00
package proxy
import (
"fmt"
"net"
2022-01-08 06:35:32 +00:00
"github.com/xvzc/SpoofDPI/packet"
2022-01-02 12:56:12 +00:00
"github.com/xvzc/SpoofDPI/util"
)
2022-01-08 15:09:01 +00:00
func HandleHttps(clientConn net.Conn, ip string, r *packet.HttpPacket) {
2022-01-07 14:04:09 +00:00
// Create a connection to the requested server
remoteConn, err := net.Dial("tcp", ip+":443")
if err != nil {
2022-01-08 15:48:19 +00:00
// util.Debug(err)
2022-01-07 14:04:09 +00:00
return
}
defer remoteConn.Close()
2022-01-08 15:48:19 +00:00
// util.Debug("[HTTPS] Connected to the server.")
2022-01-07 14:04:09 +00:00
// Send self generated response for connect request
fmt.Fprintf(clientConn, "HTTP/1.1 200 Connection Established\r\n\r\n")
2022-01-08 15:48:19 +00:00
// util.Debug("[HTTPS] Sent 200 Connection Estabalished")
2022-01-07 14:04:09 +00:00
// Read client hello
clientHello, err := ReadBytes(clientConn)
if err != nil {
2022-01-08 15:48:19 +00:00
// util.Debug("[HTTPS] Error reading client hello: ", err)
// util.Debug("Closing connection ", clientConn.RemoteAddr())
2022-01-07 14:04:09 +00:00
}
2022-01-08 15:48:19 +00:00
// util.Debug(clientConn.RemoteAddr(), "[HTTPS] Client sent hello", len(clientHello))
2022-01-07 14:04:09 +00:00
// Generate a go routine that reads from the server
go Serve(remoteConn, clientConn, "HTTPS")
// Send chunked request
chunks := util.BytesToChunks(clientHello)
for i := 0; i < len(chunks); i++ {
_, write_err := remoteConn.Write(chunks[i])
if write_err != nil {
2022-01-08 15:48:19 +00:00
// util.Debug("[HTTPS] Error writing to the client:", write_err)
2022-01-07 14:04:09 +00:00
break
}
}
// Read from the client
Serve(clientConn, remoteConn, "HTTPS")
2022-01-02 12:56:12 +00:00
}