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