mirror of
https://github.com/xvzc/SpoofDPI.git
synced 2024-12-22 14:26:31 +00:00
update
This commit is contained in:
parent
f43fe9e156
commit
cfe7ca2118
@ -1,74 +0,0 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net"
|
||||
"SpoofDPI/util"
|
||||
|
||||
|
||||
"github.com/babolivier/go-doh-client"
|
||||
)
|
||||
|
||||
var resolver = doh.Resolver{
|
||||
Host: "8.8.8.8",
|
||||
Class: doh.IN,
|
||||
}
|
||||
|
||||
func HandleClientRequest(clientConn net.Conn) {
|
||||
defer clientConn.Close()
|
||||
|
||||
buf, err := util.ReadBytes(clientConn)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("\n##### 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(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 {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
defer remoteConn.Close()
|
||||
|
||||
DoMitm(clientConn, remoteConn, buf)
|
||||
}
|
||||
|
||||
func DoMitm(clientConn net.Conn, remoteConn net.Conn, data []byte) {
|
||||
_, write_err := remoteConn.Write(data)
|
||||
if write_err != nil {
|
||||
fmt.Println("failed:", write_err)
|
||||
return
|
||||
}
|
||||
defer remoteConn.(*net.TCPConn).CloseWrite()
|
||||
|
||||
buf, read_err := ioutil.ReadAll(remoteConn)
|
||||
if read_err != nil {
|
||||
fmt.Println("failed:", read_err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Println("\n##### Response from server: ")
|
||||
log.Println(string(buf))
|
||||
|
||||
_, write_err = clientConn.Write(buf)
|
||||
if write_err != nil {
|
||||
fmt.Println("failed:", write_err)
|
||||
return
|
||||
}
|
||||
defer clientConn.(*net.TCPConn).CloseWrite()
|
||||
}
|
38
mitm/mitm.go
Normal file
38
mitm/mitm.go
Normal file
@ -0,0 +1,38 @@
|
||||
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()
|
||||
}
|
60
spoof-dpi.go
60
spoof-dpi.go
@ -1,28 +1,72 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net"
|
||||
"log"
|
||||
"SpoofDPI/handler"
|
||||
"SpoofDPI/mitm"
|
||||
"SpoofDPI/util"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
)
|
||||
|
||||
const (
|
||||
CLI_PORT = "8080"
|
||||
DNS_ADDR = "1.1.1.1"
|
||||
)
|
||||
|
||||
type config struct {
|
||||
port string
|
||||
age int
|
||||
}
|
||||
|
||||
func main() {
|
||||
log.Println("##### Listening 8080..")
|
||||
|
||||
listener, err := net.Listen("tcp", ":8080")
|
||||
listener, err := net.Listen("tcp", ":" + CLI_PORT)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
for {
|
||||
connClient, err := listener.Accept()
|
||||
clientConn, err := listener.Accept()
|
||||
if err != nil {
|
||||
log.Println("error accepting connection", err)
|
||||
continue
|
||||
}
|
||||
|
||||
log.Println("##### New connection", connClient.RemoteAddr())
|
||||
log.Println("##### New connection", clientConn.RemoteAddr())
|
||||
|
||||
go handler.HandleClientRequest(connClient)
|
||||
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)
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,10 +41,10 @@ func ReadBytes(conn net.Conn)([]byte, error) {
|
||||
return buf, nil
|
||||
}
|
||||
|
||||
func DnsLookupOverHttps(domain string)(string, error) {
|
||||
func DnsLookupOverHttps(addr string, domain string)(string, error) {
|
||||
// Perform a A lookup on example.com
|
||||
resolver := doh.Resolver{
|
||||
Host: "8.8.8.8", // Change this with your favourite DoH-compliant resolver.
|
||||
Host: addr, // Change this with your favourite DoH-compliant resolver.
|
||||
Class: doh.IN,
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user