mirror of
https://github.com/xvzc/SpoofDPI.git
synced 2024-12-22 22:36:53 +00:00
update
This commit is contained in:
parent
45fcca92e0
commit
efbfddebc2
34
net/conn.go
34
net/conn.go
@ -13,11 +13,15 @@ import (
|
|||||||
const BUF_SIZE = 1024
|
const BUF_SIZE = 1024
|
||||||
|
|
||||||
type Conn struct {
|
type Conn struct {
|
||||||
conn net.Conn
|
conn *net.TCPConn
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Conn) CloseWrite() {
|
func (c *Conn) CloseWrite() {
|
||||||
c.conn.(*net.TCPConn).CloseWrite()
|
c.conn.CloseWrite()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Conn) CloseRead() {
|
||||||
|
c.conn.CloseRead()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Conn) Close() {
|
func (c *Conn) Close() {
|
||||||
@ -51,7 +55,7 @@ func (c *Conn) SetDeadLine(t time.Time) (error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Conn) SetKeepAlive(b bool) (error) {
|
func (c *Conn) SetKeepAlive(b bool) (error) {
|
||||||
c.conn.(*net.TCPConn).SetKeepAlive(b)
|
c.conn.SetKeepAlive(b)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,6 +99,8 @@ func (conn *Conn) ReadBytes() ([]byte, error) {
|
|||||||
|
|
||||||
func (lConn *Conn) HandleHttp(p *packet.HttpPacket) {
|
func (lConn *Conn) HandleHttp(p *packet.HttpPacket) {
|
||||||
defer func() {
|
defer func() {
|
||||||
|
lConn.CloseRead()
|
||||||
|
lConn.CloseWrite()
|
||||||
lConn.Close()
|
lConn.Close()
|
||||||
log.Debug("[HTTP] Closing client Connection.. ", lConn.RemoteAddr())
|
log.Debug("[HTTP] Closing client Connection.. ", lConn.RemoteAddr())
|
||||||
}()
|
}()
|
||||||
@ -111,19 +117,21 @@ func (lConn *Conn) HandleHttp(p *packet.HttpPacket) {
|
|||||||
log.Debug("[DOH] Found ", ip, " with ", p.Domain())
|
log.Debug("[DOH] Found ", ip, " with ", p.Domain())
|
||||||
|
|
||||||
// Create connection to server
|
// Create connection to server
|
||||||
var port = ":80"
|
var port = "80"
|
||||||
if p.Port() != "" {
|
if p.Port() != "" {
|
||||||
port = ":" + p.Port()
|
port = p.Port()
|
||||||
}
|
}
|
||||||
|
|
||||||
rConn, err := Dial("tcp", ip + port)
|
rConn, err := DialTCP("tcp", ip, port)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("[HTTP] ", err)
|
log.Debug("[HTTP] ", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
defer rConn.Close()
|
rConn.CloseRead()
|
||||||
|
rConn.CloseWrite()
|
||||||
|
rConn.Close()
|
||||||
log.Debug("[HTTP] Closing server Connection.. ", p.Domain(), " ", rConn.LocalAddr())
|
log.Debug("[HTTP] Closing server Connection.. ", p.Domain(), " ", rConn.LocalAddr())
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -144,6 +152,8 @@ func (lConn *Conn) HandleHttp(p *packet.HttpPacket) {
|
|||||||
|
|
||||||
func (lConn *Conn) HandleHttps(p *packet.HttpPacket) {
|
func (lConn *Conn) HandleHttps(p *packet.HttpPacket) {
|
||||||
defer func() {
|
defer func() {
|
||||||
|
lConn.CloseRead()
|
||||||
|
lConn.CloseWrite()
|
||||||
lConn.Close()
|
lConn.Close()
|
||||||
log.Debug("[HTTPS] Closing client Connection.. ", lConn.RemoteAddr())
|
log.Debug("[HTTPS] Closing client Connection.. ", lConn.RemoteAddr())
|
||||||
}()
|
}()
|
||||||
@ -158,19 +168,21 @@ func (lConn *Conn) HandleHttps(p *packet.HttpPacket) {
|
|||||||
log.Debug("[DOH] Found ", ip, " with ", p.Domain())
|
log.Debug("[DOH] Found ", ip, " with ", p.Domain())
|
||||||
|
|
||||||
// Create a connection to the requested server
|
// Create a connection to the requested server
|
||||||
var port = ":443"
|
var port = "443"
|
||||||
if p.Port() != "" {
|
if p.Port() != "" {
|
||||||
port = ":" + p.Port()
|
port = p.Port()
|
||||||
}
|
}
|
||||||
|
|
||||||
rConn, err := Dial("tcp", ip + port)
|
rConn, err := DialTCP("tcp4", ip, port)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("[HTTPS] ", err)
|
log.Debug("[HTTPS] ", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
defer rConn.Close()
|
rConn.CloseRead()
|
||||||
|
rConn.CloseWrite()
|
||||||
|
rConn.Close()
|
||||||
log.Debug("[HTTPS] Closing server Connection.. ", p.Domain(), " ", rConn.LocalAddr())
|
log.Debug("[HTTPS] Closing server Connection.. ", p.Domain(), " ", rConn.LocalAddr())
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
16
net/dial.go
16
net/dial.go
@ -2,10 +2,11 @@ package net
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Listen(network, address string) (Listener, error) {
|
func ListenTCP(network string, addr *TCPAddr) (Listener, error) {
|
||||||
l, err := net.Listen(network, address)
|
l, err := net.ListenTCP(network, addr.Addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Listener{}, err
|
return Listener{}, err
|
||||||
}
|
}
|
||||||
@ -13,8 +14,15 @@ func Listen(network, address string) (Listener, error) {
|
|||||||
return Listener{listener: l}, nil
|
return Listener{listener: l}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Dial(network, address string) (*Conn, error) {
|
func DialTCP(network string, ip string, port string) (*Conn, error) {
|
||||||
conn, err := net.Dial(network, address)
|
p, _ := strconv.Atoi(port)
|
||||||
|
|
||||||
|
addr := &net.TCPAddr{
|
||||||
|
IP: net.ParseIP(ip),
|
||||||
|
Port: p,
|
||||||
|
}
|
||||||
|
|
||||||
|
conn, err := net.DialTCP(network, nil, addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &Conn{}, err
|
return &Conn{}, err
|
||||||
}
|
}
|
||||||
|
@ -5,14 +5,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Listener struct {
|
type Listener struct {
|
||||||
listener net.Listener
|
listener *net.TCPListener
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Listener) Accept() (Conn, error) {
|
func (l *Listener) Accept() (*Conn, error) {
|
||||||
conn, err := l.listener.Accept()
|
conn, err := l.listener.AcceptTCP()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Conn{}, err
|
return &Conn{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return Conn{conn: conn}, nil
|
return &Conn{conn: conn}, nil
|
||||||
}
|
}
|
||||||
|
21
net/tcp.go
Normal file
21
net/tcp.go
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package net
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net"
|
||||||
|
)
|
||||||
|
|
||||||
|
type TCPAddr struct {
|
||||||
|
Addr *net.TCPAddr
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func TcpAddr(ip string, port int) (*TCPAddr) {
|
||||||
|
addr := &net.TCPAddr {
|
||||||
|
IP: net.ParseIP(ip),
|
||||||
|
Port: port,
|
||||||
|
}
|
||||||
|
|
||||||
|
return &TCPAddr{
|
||||||
|
Addr: addr,
|
||||||
|
}
|
||||||
|
}
|
@ -9,27 +9,27 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Proxy struct {
|
type Proxy struct {
|
||||||
port string
|
|
||||||
addr string
|
addr string
|
||||||
|
port int
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(addr string, port string) *Proxy {
|
func New(addr string, port int) *Proxy {
|
||||||
return &Proxy{
|
return &Proxy{
|
||||||
addr: addr,
|
addr: addr,
|
||||||
port: port,
|
port: port,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Proxy) TcpAddr() string {
|
func (p *Proxy) TcpAddr() *net.TCPAddr {
|
||||||
return p.addr + ":" + p.port
|
return net.TcpAddr(p.addr, p.port)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Proxy) Port() string {
|
func (p *Proxy) Port() int {
|
||||||
return p.port
|
return p.port
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Proxy) Start() {
|
func (p *Proxy) Start() {
|
||||||
l, err := net.Listen("tcp", p.TcpAddr())
|
l, err := net.ListenTCP("tcp4", p.TcpAddr())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error creating listener: ", err)
|
log.Fatal("Error creating listener: ", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
package util
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func SetOsProxy(port string) error {
|
func SetOsProxy(port int) error {
|
||||||
if runtime.GOOS != "darwin" {
|
if runtime.GOOS != "darwin" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -17,12 +18,12 @@ func SetOsProxy(port string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = exec.Command("sh", "-c", "networksetup -setwebproxy "+ "'" +strings.TrimSpace(string(network)) + "'" + " 127.0.0.1 "+port).Output()
|
_, err = exec.Command("sh", "-c", "networksetup -setwebproxy "+ "'" +strings.TrimSpace(string(network)) + "'" + " 127.0.0.1 "+ fmt.Sprint(port)).Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = exec.Command("sh", "-c", "networksetup -setsecurewebproxy " + "'" + strings.TrimSpace(string(network))+"'" + " 127.0.0.1 "+port).Output()
|
_, err = exec.Command("sh", "-c", "networksetup -setsecurewebproxy " + "'" + strings.TrimSpace(string(network))+"'" + " 127.0.0.1 "+ fmt.Sprint(port)).Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -7,9 +7,9 @@ import (
|
|||||||
"github.com/pterm/pterm"
|
"github.com/pterm/pterm"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ParseArgs() (string,string, string, bool) {
|
func ParseArgs() (string, int, string, bool) {
|
||||||
addr := flag.String("addr", "127.0.0.1", "Listen addr")
|
addr := flag.String("addr", "127.0.0.1", "Listen addr")
|
||||||
port := flag.String("port", "8080", "port")
|
port := flag.Int("port", 8080, "port")
|
||||||
dns := flag.String("dns", "8.8.8.8", "DNS server")
|
dns := flag.String("dns", "8.8.8.8", "DNS server")
|
||||||
debug := flag.Bool("debug", false, "true | false")
|
debug := flag.Bool("debug", false, "true | false")
|
||||||
|
|
||||||
@ -18,14 +18,14 @@ func ParseArgs() (string,string, string, bool) {
|
|||||||
return *addr, *port, *dns, *debug
|
return *addr, *port, *dns, *debug
|
||||||
}
|
}
|
||||||
|
|
||||||
func PrintWelcome(addr, port string, dns string, debug bool) {
|
func PrintWelcome(addr string, port int, dns string, debug bool) {
|
||||||
cyan := pterm.NewLettersFromStringWithStyle("Spoof", pterm.NewStyle(pterm.FgCyan))
|
cyan := pterm.NewLettersFromStringWithStyle("Spoof", pterm.NewStyle(pterm.FgCyan))
|
||||||
purple := pterm.NewLettersFromStringWithStyle("DPI", pterm.NewStyle(pterm.FgLightMagenta))
|
purple := pterm.NewLettersFromStringWithStyle("DPI", pterm.NewStyle(pterm.FgLightMagenta))
|
||||||
pterm.DefaultBigText.WithLetters(cyan, purple).Render()
|
pterm.DefaultBigText.WithLetters(cyan, purple).Render()
|
||||||
|
|
||||||
pterm.DefaultBulletList.WithItems([]pterm.BulletListItem{
|
pterm.DefaultBulletList.WithItems([]pterm.BulletListItem{
|
||||||
{Level: 0, Text: "ADDR : " + addr},
|
{Level: 0, Text: "ADDR : " + addr},
|
||||||
{Level: 0, Text: "PORT : " + port},
|
{Level: 0, Text: "PORT : " + fmt.Sprint(port)},
|
||||||
{Level: 0, Text: "DNS : " + dns},
|
{Level: 0, Text: "DNS : " + dns},
|
||||||
{Level: 0, Text: "DEBUG : " + fmt.Sprint(debug)},
|
{Level: 0, Text: "DEBUG : " + fmt.Sprint(debug)},
|
||||||
}).Render()
|
}).Render()
|
||||||
|
Loading…
Reference in New Issue
Block a user