SpoofDPI/proxy/https.go

68 lines
1.6 KiB
Go
Raw Normal View History

2022-01-02 12:56:12 +00:00
package proxy
import (
"fmt"
2022-01-11 15:05:16 +00:00
log "github.com/sirupsen/logrus"
"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) {
2022-01-11 15:05:16 +00:00
// Create connection to server
remoteConn, err := net.Dial("tcp", ip+":80")
if err != nil {
2022-01-11 15:05:16 +00:00
log.Debug(err)
return
}
defer remoteConn.Close()
2022-01-11 15:05:16 +00:00
log.Debug("[HTTP] Connected to the server.")
go remoteConn.Serve(clientConn, "HTTP")
2022-01-11 15:05:16 +00:00
log.Debug("[HTTP] Sending request to the server")
2022-01-10 19:27:12 +00:00
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-11 15:05:16 +00:00
log.Debug(err)
2022-01-07 14:04:09 +00:00
return
}
defer remoteConn.Close()
2022-01-11 15:05:16 +00:00
log.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-11 15:05:16 +00:00
log.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-11 15:05:16 +00:00
log.Debug("[HTTPS] Error reading client hello: ", err)
log.Debug("Closing connection: ", clientConn.RemoteAddr())
2022-01-07 14:04:09 +00:00
}
2022-01-11 15:05:16 +00:00
log.Debug(clientConn.RemoteAddr(), "[HTTPS] Client sent hello: ", len(clientHello), "bytes")
2022-01-07 14:04:09 +00:00
// Generate a go routine that reads from the server
go remoteConn.Serve(clientConn, "HTTPS")
2022-01-10 19:27:12 +00:00
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
}