mirror of
https://github.com/xvzc/SpoofDPI.git
synced 2025-01-03 04:50:11 +00:00
restart..
This commit is contained in:
parent
6a87cb8b23
commit
72af9ed7ad
9
cmd/spoof-dpi/main.go
Normal file
9
cmd/spoof-dpi/main.go
Normal file
@ -0,0 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println("Hello, world!")
|
||||
}
|
5
go.mod
5
go.mod
@ -1,5 +0,0 @@
|
||||
module SpoofDPI
|
||||
|
||||
go 1.17
|
||||
|
||||
require github.com/babolivier/go-doh-client v0.0.0-20201028162107-a76cff4cb8b6
|
2
go.sum
2
go.sum
@ -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=
|
38
mitm/mitm.go
38
mitm/mitm.go
@ -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()
|
||||
}
|
67
spoof-dpi.go
67
spoof-dpi.go
@ -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)
|
||||
}()
|
||||
}
|
||||
}
|
59
util/util.go
59
util/util.go
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user