SpoofDPI/proxy/https.go

66 lines
1.6 KiB
Go
Raw Normal View History

2022-01-02 12:56:12 +00:00
package proxy
import (
"fmt"
"github.com/xvzc/SpoofDPI/net"
2022-01-08 06:35:32 +00:00
"github.com/xvzc/SpoofDPI/packet"
2022-01-02 12:56:12 +00:00
)
func HandleHttp(clientConn net.Conn, ip string, p *packet.HttpPacket) {
remoteConn, err := net.Dial("tcp", ip+":80") // create connection to server
if err != nil {
// util.Debug(err)
return
}
defer remoteConn.Close()
// util.Debug("[HTTP] Connected to the server.")
go remoteConn.Serve(clientConn, "HTTP")
// util.Debug("[HTTP] Sending request to the server")
fmt.Fprintf(remoteConn.Conn, string(*p.Raw))
go clientConn.Serve(remoteConn, "HTTP")
}
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.Conn, "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 := clientConn.ReadBytes()
2022-01-07 14:04:09 +00:00
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 remoteConn.Serve(clientConn, "HTTPS")
pkt := packet.NewHttpsPacket(&clientHello)
chunks := pkt.SplitInChunks()
if _, err := remoteConn.WriteChunks(chunks); err != nil {
return
2022-01-07 14:04:09 +00:00
}
// Read from the client
clientConn.Serve(remoteConn, "HTTPS")
2022-01-02 12:56:12 +00:00
}