Coder Social home page Coder Social logo

phantomsocks's Introduction

phantomsocks

A cross-platform proxy client/server for Linux/Windows/macOS with Pcap/RawSocket/WinDivert

Usage

./phantomsocks -h
Usage of ./phantomsocks:
  -log int
    	LogLevel
  -maxprocs int
    	MaxProcesses
  -install
    	Install service (Windows)
  -remove
    	Remove service (Windows)
  -start
    	Start service (Windows)
  -stop
    	Stop service (Windows)

Configure

config.json:

{
    "vaddrprefix": 6,
    "proxy": "socks://address:port",
    "profiles": ["1.conf", "2.conf", "3.conf"],
    "services": [
        {
            "name": "dns",
            "protocol": "dns",
            "address": "127.0.0.1:5353"
        },
        {
            "name": "socks",
            "protocol": "socks",
            "address": "127.0.0.1:1081"
        },
        {
            "name": "redirect",
            "protocol": "redirect",
            "address": "0.0.0.0:6"
        },
        {
            "name": "tproxy",
            "protocol": "tproxy",
            "address": "0.0.0.0:6"
        }
    ],
    "interfaces": [
        {
            "name": "default",
            "dns": "udp://8.8.8.8:53"
        },
        {
            "name": "https",
            "dns": "udp://8.8.8.8:53",
            "device": "eth0",
            "hint": "https"
        },
        {
            "name": "doh",
            "dns": "https://cloudflare-dns.com/dns-query"
        },
        {
            "name": "dot",
            "dns": "tls://8.8.8.8:853"
        },
        {
            "name": "ecs",
            "dns": "udp://8.8.8.8:53/?ecs=35.190.247.1"
        },
        {
            "name": "socks5",
            "protocol": "socks5",
            "address": "127.0.0.1:1080"
        },
        {
            "name": "socks4",
            "dns": "udp://8.8.8.8:53",
            "protocol": "socks4",
            "address": "127.0.0.1:1080"
        }
    ]
}

Socks:

Windows:
config.json:
    "proxy" :"socks://127.0.0.1:1080/?dns=127.0.0.1",
    "services": [
        {
            "name": "DNS",
            "protocol": "dns",
            "address": "127.0.0.1:53"
        },
        {
            "name": "Socks",
            "protocol": "socks",
            "address": "127.0.0.1:1080"
        }
    ]

macOS:
config.json:
    "proxy": "socks://127.0.0.1:1080",
    "services": [
        {
            "name": "Socks",
            "protocol": "socks",
            "address": "127.0.0.1:1080"
        }
    ]

Redirect:

Linux:
iptables -t nat -A OUTPUT -d 6.0.0.0/8 -p tcp -j REDIRECT --to-port 6
config.json:
    "vaddrprefix": 6,
    "services": [
        {
            "name": "DNS",
            "protocol": "dns",
            "address": "127.0.0.1:53"
        },
        {
            "name": "Redirect",
            "protocol": "redirect",
            "address": "0.0.0.0:6"
        }
    ]

Windows(windivert):
config.json:
    "vaddrprefix": 6,
    "proxy": "redirect://0.0.0.0:6",
    "services": [
        {
            "name": "Redirect",
            "protocol": "redirect",
            "address": "0.0.0.0:6"
        }
    ]

Rules

  [default]         #domains below will use the config of this interface
  domain=ip,ip,...  #this domain will use these IPs
  domain            #this domain will be resolved by DNS
  domain=[domain]   #this domain will use the config of this domain
  domain=domain     #this domain will use the addresses of this domain
  
  [dot]             #domains below will use the config of dot
  domain
  [socks5]          #domains below will use the config of socks5
  domain

Installation

go get github.com/macronut/phantomsocks

Compile

cd $GOPATH/src/github.com/macronut/phantomsocks/

go build

pcap version

static linking for pcap

sudo apt-get install -y libpcap-dev
go build -tags pcap -ldflags '-extldflags "-static"'

raw socket version

raw socket is Linux only

go build -tags rawsocket

windivert version

windivert is Windows only

env GOOS=windows GOARCH=amd64 go build -tags windivert

cross & static compile pcap version on Ubuntu 18.04

Install dependencies

apt-get install git autoconf automake bison build-essential flex gawk gettext gperf libtool pkg-config libpcap-dev

Download & uncompress tool-chain

cd ~/Downloads
wget https://downloads.openwrt.org/releases/19.07.2/targets/ramips/mt7621/openwrt-sdk-19.07.2-ramips-mt7621_gcc-7.5.0_musl.Linux-x86_64.tar.xz
tar -xJvf openwrt-sdk-19.07.2-ramips-mt7621_gcc-7.5.0_musl.Linux-x86_64.tar.xz

Set environment variable

export PATH=$PATH:~/Downloads/openwrt-sdk-19.07.2-ramips-mt7621_gcc-7.5.0_musl.Linux-x86_64/staging_dir/toolchain-mipsel_24kc_gcc-7.5.0_musl/bin: && export STAGING_DIR=~/Downloads/openwrt-sdk-19.07.2-ramips-mt7621_gcc-7.5.0_musl.Linux-x86_64/staging_dir/toolchain-mipsel_24kc_gcc-7.5.0_musl

Download & uncompress libpcap

wget https://www.tcpdump.org/release/libpcap-1.9.1.tar.gz
tar -xzvf libpcap-1.9.1.tar.gz

Build libpcap

cd libpcap-1.9.1
./configure --host=mipsel-openwrt-linux-musl --prefix='~/Downloads/openwrt-sdk-19.07.2-ramips-mt7621_gcc-7.5.0_musl.Linux-x86_64/staging_dir/toolchain-mipsel_24kc_gcc-7.5.0_musl'
make && make install 

Build phantomsocks

cd ~/go/src/github.com/Macronut/phantomsocks
env GOOS=linux GOARCH=mipsle CGO_ENABLED=1 CC='~/Downloads/openwrt-sdk-19.07.2-ramips-mt7621_gcc-7.5.0_musl.Linux-x86_64/staging_dir/toolchain-mipsel_24kc_gcc-7.5.0_musl/bin/mipsel-openwrt-linux-gcc'  go build  -ldflags '-extldflags "-static"'

phantomsocks's People

Contributors

macronut avatar lifegpc avatar detiam avatar bluemap1e avatar wuyu8512 avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.