mirror of
https://github.com/xvzc/SpoofDPI.git
synced 2025-01-03 04:50:11 +00:00
update
This commit is contained in:
parent
76da7260d0
commit
95c4199025
@ -5,6 +5,7 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/xvzc/SpoofDPI/proxy"
|
||||
"github.com/xvzc/SpoofDPI/config"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -13,7 +14,7 @@ func main() {
|
||||
debug := flag.Bool("debug", false, "true | false")
|
||||
mtu := flag.Int("mtu", 100, "int")
|
||||
|
||||
err := proxy.InitConfig(*src, *dns, *mtu, *debug)
|
||||
err := config.InitConfig(*src, *dns, *mtu, *debug)
|
||||
if err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package proxy
|
||||
package config
|
||||
|
||||
import (
|
||||
"errors"
|
||||
@ -64,6 +64,6 @@ func InitConfig(srcAddress string, dns string, mtu int, debug bool) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func getConfig() (*Config) {
|
||||
func GetConfig() (*Config) {
|
||||
return config
|
||||
}
|
@ -2,7 +2,6 @@ package proxy
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
|
||||
"github.com/xvzc/SpoofDPI/util"
|
||||
@ -11,33 +10,33 @@ import (
|
||||
func HandleHttp(clientConn net.Conn, ip string, message []byte) {
|
||||
remoteConn, err := net.Dial("tcp", ip+":80") // create connection to server
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
util.Debug(err)
|
||||
return
|
||||
}
|
||||
defer remoteConn.Close()
|
||||
|
||||
_, write_err := remoteConn.Write(message)
|
||||
if write_err != nil {
|
||||
log.Fatal("failed:", write_err)
|
||||
util.Debug("failed:", write_err)
|
||||
return
|
||||
}
|
||||
defer remoteConn.(*net.TCPConn).CloseWrite()
|
||||
|
||||
buf, err := util.ReadMessage(remoteConn)
|
||||
if err != nil {
|
||||
log.Fatal("failed:", err)
|
||||
util.Debug("failed:", err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println()
|
||||
log.Println()
|
||||
util.Debug()
|
||||
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)
|
||||
util.Debug("failed:", write_err)
|
||||
return
|
||||
}
|
||||
defer clientConn.(*net.TCPConn).CloseWrite()
|
||||
|
@ -2,7 +2,6 @@ package proxy
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"io"
|
||||
|
||||
@ -14,16 +13,14 @@ import (
|
||||
func HandleHttps(clientConn net.Conn, ip string) {
|
||||
remoteConn, err := net.Dial("tcp", ip+":443") // create connection to server
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
util.Debug(err)
|
||||
return
|
||||
}
|
||||
defer remoteConn.Close()
|
||||
|
||||
log.Println("Connected to the server.")
|
||||
util.Debug("Connected to the server.")
|
||||
|
||||
// established := []byte("HTTP/1.1 204 No Content\n\n")
|
||||
|
||||
log.Println("Sending 200 Connection Estabalished")
|
||||
util.Debug("Sending 200 Connection Estabalished")
|
||||
|
||||
fmt.Fprintf(clientConn, "HTTP/1.1 200 Connection Established\r\n\r\n")
|
||||
|
||||
@ -33,18 +30,20 @@ func HandleHttps(clientConn net.Conn, ip string) {
|
||||
buf, err := util.ReadMessage(remoteConn)
|
||||
if err != nil {
|
||||
if err != io.EOF {
|
||||
log.Println("Error reading from the server:", err)
|
||||
util.Debug("Error reading from the server:", err)
|
||||
} else {
|
||||
log.Println("Remote connection Closed: ", err)
|
||||
util.Debug("Remote connection Closed: ", err)
|
||||
}
|
||||
|
||||
util.Debug("Closing connection: ", remoteConn.RemoteAddr())
|
||||
return
|
||||
}
|
||||
|
||||
log.Println("Server Sent Data", len(buf))
|
||||
util.Debug(remoteConn.RemoteAddr(), "Server Sent Data", len(buf))
|
||||
|
||||
_, write_err := clientConn.Write(buf)
|
||||
if write_err != nil {
|
||||
log.Println("Error writing to client:", write_err)
|
||||
util.Debug("Error writing to client:", write_err)
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -55,19 +54,20 @@ func HandleHttps(clientConn net.Conn, ip string) {
|
||||
buf, err := util.ReadMessage(clientConn)
|
||||
if err != nil {
|
||||
if err != io.EOF {
|
||||
log.Println("Error reading from the client:", err)
|
||||
util.Debug("Error reading from the client:", err)
|
||||
} else {
|
||||
log.Println("Client connection Closed: ", err)
|
||||
util.Debug("Client connection Closed: ", err)
|
||||
}
|
||||
|
||||
util.Debug("Closing connection: ", clientConn.RemoteAddr())
|
||||
break
|
||||
}
|
||||
log.Println("Client Sent Data", len(buf))
|
||||
util.Debug(clientConn.RemoteAddr(), "Client Sent Data", len(buf))
|
||||
|
||||
_, write_err := remoteConn.Write(buf)
|
||||
if write_err != nil {
|
||||
log.Println("Error writing to client:", write_err)
|
||||
util.Debug("Error writing to client:", write_err)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,14 +2,15 @@ package proxy
|
||||
|
||||
import (
|
||||
"log"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"github.com/xvzc/SpoofDPI/util"
|
||||
|
||||
"github.com/xvzc/SpoofDPI/util"
|
||||
"github.com/xvzc/SpoofDPI/config"
|
||||
)
|
||||
|
||||
func Start() {
|
||||
listener, err := net.Listen("tcp", ":" + config.SrcPort)
|
||||
listener, err := net.Listen("tcp", ":" + config.GetConfig().SrcPort)
|
||||
if err != nil {
|
||||
log.Fatal("Error creating listener: ", err)
|
||||
os.Exit(1)
|
||||
@ -34,14 +35,11 @@ func Start() {
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println()
|
||||
log.Println()
|
||||
fmt.Println("##### Request from client : ")
|
||||
fmt.Println(string(message))
|
||||
log.Println("Client sent data: ", len(message))
|
||||
|
||||
domain := util.ExtractDomain(&message)
|
||||
|
||||
ip, err := util.DnsLookupOverHttps(getConfig().DNS, domain) // Dns lookup over https
|
||||
ip, err := util.DnsLookupOverHttps(config.GetConfig().DNS, domain) // Dns lookup over https
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -49,7 +47,7 @@ func Start() {
|
||||
log.Println("ip: "+ ip)
|
||||
|
||||
if util.ExtractMethod(&message) == "CONNECT" {
|
||||
log.Println("HTTPS Requested.")
|
||||
util.Debug("HTTPS Requested")
|
||||
HandleHttps(clientConn, ip)
|
||||
}else {
|
||||
log.Println("HTTP Requested.")
|
||||
|
27
util/util.go
27
util/util.go
@ -1,12 +1,16 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"net"
|
||||
"log"
|
||||
"strings"
|
||||
"github.com/babolivier/go-doh-client"
|
||||
"log"
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
"github.com/babolivier/go-doh-client"
|
||||
"github.com/xvzc/SpoofDPI/config"
|
||||
)
|
||||
|
||||
const BUF_SIZE = 1024
|
||||
|
||||
func WriteAndRead(conn net.Conn, message []byte) ([]byte, error){
|
||||
_, err := conn.Write(message)
|
||||
if err != nil {
|
||||
@ -25,8 +29,9 @@ func WriteAndRead(conn net.Conn, message []byte) ([]byte, error){
|
||||
}
|
||||
|
||||
func ReadMessage(conn net.Conn)([]byte, error) {
|
||||
buf := make([]byte, 0, 4096) // big buffer
|
||||
tmp := make([]byte, 1024) // using small tmo buffer for demonstrating
|
||||
buf := make([]byte, 0) // big buffer
|
||||
tmp := make([]byte, BUF_SIZE) // using small tmo buffer for demonstrating
|
||||
|
||||
for {
|
||||
n, err := conn.Read(tmp)
|
||||
if err != nil {
|
||||
@ -34,7 +39,7 @@ func ReadMessage(conn net.Conn)([]byte, error) {
|
||||
}
|
||||
buf = append(buf, tmp[:n]...)
|
||||
|
||||
if n < 1024 {
|
||||
if n < BUF_SIZE {
|
||||
break
|
||||
}
|
||||
}
|
||||
@ -102,3 +107,11 @@ func ExtractMethod(message *[]byte) (string) {
|
||||
|
||||
return strings.ToUpper(method)
|
||||
}
|
||||
|
||||
func Debug(v ...interface{}) {
|
||||
if config.GetConfig().Debug == false {
|
||||
return
|
||||
}
|
||||
|
||||
log.Println(v...)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user