SpoofDPI/proxy/https.go

74 lines
1.7 KiB
Go
Raw Normal View History

2022-01-02 12:56:12 +00:00
package proxy
import (
"fmt"
"log"
"net"
2022-01-02 15:24:59 +00:00
"io"
2022-01-02 12:56:12 +00:00
// "time"
"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 {
log.Fatal(err)
return
}
2022-01-02 15:24:59 +00:00
defer remoteConn.Close()
2022-01-02 12:56:12 +00:00
log.Println("Connected to the server.")
// established := []byte("HTTP/1.1 204 No Content\n\n")
2022-01-02 15:24:59 +00:00
log.Println("Sending 200 Connection Estabalished")
2022-01-02 12:56:12 +00:00
2022-01-02 15:24:59 +00:00
fmt.Fprintf(clientConn, "HTTP/1.1 200 Connection Established\r\n\r\n")
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 {
log.Println("Error reading from the server:", err)
} else {
log.Println("Remote connection Closed: ", err)
}
2022-01-02 12:56:12 +00:00
return
}
2022-01-02 15:24:59 +00:00
log.Println("Server Sent Data", len(buf))
2022-01-02 12:56:12 +00:00
_, write_err := clientConn.Write(buf)
if write_err != nil {
log.Println("Error writing to client:", write_err)
return
}
}
}()
for {
defer clientConn.Close()
buf, err := util.ReadMessage(clientConn)
if err != nil {
2022-01-02 15:24:59 +00:00
if err != io.EOF {
log.Println("Error reading from the client:", err)
} else {
log.Println("Client connection Closed: ", err)
}
2022-01-02 12:56:12 +00:00
break
}
2022-01-02 15:24:59 +00:00
log.Println("Client Sent Data", len(buf))
2022-01-02 12:56:12 +00:00
_, write_err := remoteConn.Write(buf)
if write_err != nil {
log.Println("Error writing to client:", write_err)
break
}
}
}