SpoofDPI/proxy/proxy.go

59 lines
1.3 KiB
Go
Raw Normal View History

2021-12-29 17:08:30 +00:00
package proxy
import (
"log"
"net"
"os"
2022-01-03 07:24:39 +00:00
"github.com/xvzc/SpoofDPI/util"
"github.com/xvzc/SpoofDPI/config"
2021-12-29 17:08:30 +00:00
)
func Start() {
2022-01-03 07:24:39 +00:00
listener, err := net.Listen("tcp", ":" + config.GetConfig().SrcPort)
2021-12-29 17:08:30 +00:00
if err != nil {
log.Fatal("Error creating listener: ", err)
os.Exit(1)
}
log.Println("Created a listener")
for {
clientConn, err := listener.Accept()
if err != nil {
log.Fatal("Error accepting connection: ", err)
continue
}
log.Println("Accepted a new connection.", clientConn.RemoteAddr())
2022-01-02 15:24:59 +00:00
go func() {
2021-12-29 17:08:30 +00:00
defer clientConn.Close()
message , err := util.ReadMessage(clientConn)
if err != nil {
return
}
2022-01-03 07:24:39 +00:00
log.Println("Client sent data: ", len(message))
2021-12-29 17:08:30 +00:00
domain := util.ExtractDomain(&message)
2022-01-03 07:24:39 +00:00
ip, err := util.DnsLookupOverHttps(config.GetConfig().DNS, domain) // Dns lookup over https
2021-12-29 17:08:30 +00:00
if err != nil {
return
}
log.Println("ip: "+ ip)
if util.ExtractMethod(&message) == "CONNECT" {
2022-01-03 07:24:39 +00:00
util.Debug("HTTPS Requested")
2022-01-02 12:56:12 +00:00
HandleHttps(clientConn, ip)
2021-12-29 17:08:30 +00:00
}else {
2022-01-02 12:56:12 +00:00
log.Println("HTTP Requested.")
2021-12-29 17:08:30 +00:00
HandleHttp(clientConn, ip, message)
}
}()
}
}