SpoofDPI/proxy/https.go

50 lines
1.3 KiB
Go
Raw Normal View History

2022-01-02 12:56:12 +00:00
package proxy
import (
"fmt"
"net"
"github.com/xvzc/SpoofDPI/util"
)
func HandleHttps(clientConn net.Conn, ip string) {
2022-01-03 15:13:42 +00:00
// Create a connection to the requested server
remoteConn, err := net.Dial("tcp", ip+":443")
2022-01-02 12:56:12 +00:00
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-02 15:24:59 +00:00
defer remoteConn.Close()
2022-01-03 15:13:42 +00:00
util.Debug("[HTTPS] Connected to the server.")
2022-01-02 12:56:12 +00:00
2022-01-03 15:13:42 +00:00
// Send self generated response for connect request
2022-01-03 08:12:51 +00:00
fmt.Fprintf(clientConn, "HTTP/1.1 200 Connection Established\r\n\r\n")
2022-01-03 15:13:42 +00:00
util.Debug("[HTTPS] Sent 200 Connection Estabalished")
2022-01-03 08:12:51 +00:00
2022-01-03 15:13:42 +00:00
// Read client hello
clientHello, err := ReadBytes(clientConn)
2022-01-03 08:12:51 +00:00
if err != nil {
2022-01-03 15:13:42 +00:00
util.Debug("[HTTPS] Error reading client hello: ", err)
util.Debug("Closing connection ", clientConn.RemoteAddr())
2022-01-03 08:12:51 +00:00
}
2022-01-03 08:31:39 +00:00
2022-01-03 15:13:42 +00:00
util.Debug(clientConn.RemoteAddr(), "[HTTPS] Client sent hello", len(clientHello))
2022-01-03 08:12:51 +00:00
2022-01-03 15:13:42 +00:00
// Generate a go routine that reads from the server
go Serve(remoteConn, clientConn, "HTTPS")
2022-01-03 08:12:51 +00:00
2022-01-03 15:13:42 +00:00
// Send chunked request
chunks := util.BytesToChunks(clientHello)
2022-01-03 08:12:51 +00:00
for i := 0; i < len(chunks); i++ {
_, write_err := remoteConn.Write(chunks[i])
if write_err != nil {
2022-01-03 15:13:42 +00:00
util.Debug("[HTTPS] Error writing to the client:", write_err)
2022-01-03 08:12:51 +00:00
break
}
}
2022-01-03 15:13:42 +00:00
// Read from the client
Serve(clientConn, remoteConn, "HTTPS")
2022-01-02 12:56:12 +00:00
}