diff --git a/README.md b/README.md deleted file mode 100644 index cf0db9b..0000000 --- a/README.md +++ /dev/null @@ -1 +0,0 @@ -# SpoofDPI \ No newline at end of file diff --git a/cmd/spoof-dpi/main.go b/cmd/spoof-dpi/main.go new file mode 100644 index 0000000..5dc991b --- /dev/null +++ b/cmd/spoof-dpi/main.go @@ -0,0 +1,9 @@ +package main + +import ( + "fmt" +) + +func main() { + fmt.Println("Hello, world!") +} diff --git a/go.mod b/go.mod deleted file mode 100644 index 7c01ac4..0000000 --- a/go.mod +++ /dev/null @@ -1,5 +0,0 @@ -module SpoofDPI - -go 1.17 - -require github.com/babolivier/go-doh-client v0.0.0-20201028162107-a76cff4cb8b6 diff --git a/go.sum b/go.sum deleted file mode 100644 index 94a486b..0000000 --- a/go.sum +++ /dev/null @@ -1,2 +0,0 @@ -github.com/babolivier/go-doh-client v0.0.0-20201028162107-a76cff4cb8b6 h1:4NNbNM2Iq/k57qEu7WfL67UrbPq1uFWxW4qODCohi+0= -github.com/babolivier/go-doh-client v0.0.0-20201028162107-a76cff4cb8b6/go.mod h1:J29hk+f9lJrblVIfiJOtTFk+OblBawmib4uz/VdKzlg= diff --git a/handler/handler.go b/handler/handler.go deleted file mode 100644 index e69de29..0000000 diff --git a/mitm/mitm.go b/mitm/mitm.go deleted file mode 100644 index 7377386..0000000 --- a/mitm/mitm.go +++ /dev/null @@ -1,38 +0,0 @@ -package mitm - -import ( - "net" - "log" - "io/ioutil" - "fmt" -) - -func GoGoSing(clientConn net.Conn, remoteConn net.Conn, data []byte) { - _, write_err := remoteConn.Write(data) - if write_err != nil { - log.Fatal("failed:", write_err) - return - } - defer remoteConn.(*net.TCPConn).CloseWrite() - - // Read from the server - buf, read_err := ioutil.ReadAll(remoteConn) - if read_err != nil { - log.Fatal("failed:", read_err) - return - } - - fmt.Println() - log.Println() - fmt.Println("##### Response from the server: ") - fmt.Println(string(buf)) - - - // Write to client - _, write_err = clientConn.Write(buf) - if write_err != nil { - log.Fatal("failed:", write_err) - return - } - defer clientConn.(*net.TCPConn).CloseWrite() -} diff --git a/spoof-dpi.go b/spoof-dpi.go deleted file mode 100644 index f091bea..0000000 --- a/spoof-dpi.go +++ /dev/null @@ -1,67 +0,0 @@ -package main - -import ( - "SpoofDPI/mitm" - "SpoofDPI/util" - "fmt" - "log" - "net" -) - -const ( - CLI_PORT = "8080" - DNS_ADDR = "1.1.1.1" -) - -func main() { - log.Println("##### Listening 8080..") - - listener, err := net.Listen("tcp", ":" + CLI_PORT) - if err != nil { - panic(err) - } - - for { - clientConn, err := listener.Accept() - if err != nil { - log.Println("error accepting connection", err) - continue - } - - log.Println("##### New connection", clientConn.RemoteAddr()) - - go func() { - defer clientConn.Close() - - buf, err := util.ReadBytes(clientConn) - if err != nil { - return - } - - fmt.Println() - log.Println() - fmt.Println("##### Request from client : ") - fmt.Println(string(buf)) - - domain, port := util.ExtractDomainAndPort(string(buf)) - - log.Println("domain: "+ domain) - log.Println("port: " + port) - - ip, err := util.DnsLookupOverHttps(DNS_ADDR, domain) // Dns lookup over https - if err != nil { - log.Fatal(err) - return - } - - remoteConn, err := net.Dial("tcp", ip+":"+port) // create connection to server - if err != nil { - log.Fatal(err) - return - } - defer remoteConn.Close() - - mitm.GoGoSing(clientConn, remoteConn, buf) - }() - } -} diff --git a/util/util.go b/util/util.go deleted file mode 100644 index 10b4c2b..0000000 --- a/util/util.go +++ /dev/null @@ -1,59 +0,0 @@ -package util - -import ( - "log" - "net" - "strings" - "io" - "github.com/babolivier/go-doh-client" -) - -func ExtractDomainAndPort(s string) (string, string) { - lines := strings.Split(s, "\n") - hostPart := strings.Split(lines[1], " ")[1] - tokens := strings.Split(hostPart, ":") - if len(tokens) == 1 { - return strings.TrimSpace(string(tokens[0])), "80" - } - - return string(tokens[0]), string(tokens[1]) -} - -func ReadBytes(conn net.Conn)([]byte, error) { - buf := make([]byte, 0, 4096) // big buffer - tmp := make([]byte, 1024) // using small tmo buffer for demonstrating - for { - n, err := conn.Read(tmp) - if err != nil { - if err != io.EOF { - log.Fatal("ReadRequest error:", err) - } - return nil, err - } - log.Println("##### got", n, "bytes.") - buf = append(buf, tmp[:n]...) - - if n < 1024 { - break - } - } - - return buf, nil -} - -func DnsLookupOverHttps(addr string, domain string)(string, error) { - // Perform a A lookup on example.com - resolver := doh.Resolver{ - Host: addr, // Change this with your favourite DoH-compliant resolver. - Class: doh.IN, - } - - a, _, err := resolver.LookupA(domain) - if err != nil { - return "", err - } - - ip := a[0].IP4 - - return ip, nil -}