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 16:54:36 +00:00
listener, err := net.Listen("tcp", ":" + config.GetConfig().Port)
2021-12-29 17:08:30 +00:00
if err != nil {
log.Fatal("Error creating listener: ", err)
os.Exit(1)
}
2022-01-03 15:13:42 +00:00
util.Debug("Created a listener")
2021-12-29 17:08:30 +00:00
for {
clientConn, err := listener.Accept()
if err != nil {
log.Fatal("Error accepting connection: ", err)
continue
}
2022-01-03 15:13:42 +00:00
util.Debug("Accepted a new connection.", clientConn.RemoteAddr())
2021-12-29 17:08:30 +00:00
2022-01-02 15:24:59 +00:00
go func() {
2021-12-29 17:08:30 +00:00
defer clientConn.Close()
2022-01-03 15:13:42 +00:00
message , err := ReadBytes(clientConn)
2021-12-29 17:08:30 +00:00
if err != nil {
return
}
2022-01-03 15:13:42 +00:00
util.Debug("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
}
2022-01-03 15:13:42 +00:00
util.Debug("ip: "+ ip)
2021-12-29 17:08:30 +00:00
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-03 15:13:42 +00:00
util.Debug("HTTP Requested.")
2021-12-29 17:08:30 +00:00
HandleHttp(clientConn, ip, message)
}
}()
}
}