|
| 1 | +python-proxy |
| 2 | +=========== |
| 3 | + |
| 4 | +HTTP/Socks5/Shadowsocks Asynchronous Tunnel Proxy implemented in Python 3.6 asyncio. |
| 5 | + |
| 6 | +Python 3.6 |
| 7 | +----------- |
| 8 | + |
| 9 | +*Python 3.5* added new syntax *async def* and *await* to make asyncio programming easier. *Python 3.6* added new syntax *formatted string literals*. This utility is to demonstrate these new syntax and is also fully ready for production usage. |
| 10 | + |
| 11 | +Features |
| 12 | +----------- |
| 13 | + |
| 14 | +- Automatically detect incoming protocol: HTTP/Socks5/Shadowsocks. |
| 15 | +- Specify remote servers for outcoming protocol. |
| 16 | +- Unix path support for communicating locally. |
| 17 | +- Basic authentication method for HTTP/Socks5/Shadowsocks. |
| 18 | +- Regex pattern file support for redirecting/blocking by hostname. |
| 19 | +- SSL connection support to prevent Man-In-The-Middle attack. |
| 20 | +- Many ciphers support to keep communication securely. (chacha20, salsa20, aes-256-cfb, etc) |
| 21 | +- Basic statistics for bandwidth and total traffic by client/hostname. |
| 22 | +- PAC support for automatically javascript configuration. |
| 23 | + |
| 24 | +Usage |
| 25 | +----------- |
| 26 | + |
| 27 | + $ pproxy -h |
| 28 | + usage: pproxy [-h] [-i LISTEN] [-r RSERVER] [-b BLOCK] [-v] |
| 29 | + [--ssl SSLFILE] [--pac PAC] [--version] |
| 30 | + |
| 31 | + Proxy server that can tunnel among remote servers by regex rules. Supported |
| 32 | + protocols: http,socks,shadowsocks |
| 33 | + |
| 34 | + optional arguments: |
| 35 | + -h, --help show this help message and exit |
| 36 | + -i LISTEN proxy server setting uri (default: http+socks://:8080/) |
| 37 | + -r RSERVER remote server setting uri (default: direct) |
| 38 | + -b BLOCK block regex rules |
| 39 | + -v print verbose output |
| 40 | + --ssl SSLFILE certfile[,keyfile] if server listen in ssl mode |
| 41 | + --pac PAC http pac file path |
| 42 | + --version show program's version number and exit |
| 43 | + |
| 44 | + Online help: <https://github.com/qwj/python-proxy> |
| 45 | + |
| 46 | +Uri Syntax |
| 47 | +----------- |
| 48 | + |
| 49 | +{scheme}://[{cipher}@]{netloc}[?{rules}][#{auth}] |
| 50 | + |
| 51 | +- scheme |
| 52 | + Currently supported scheme: http, socks, ss, ssl, secure. You can use + to add multiple protocols together. |
| 53 | + http - http protocol |
| 54 | + socks - socks5 protocol |
| 55 | + ss - shadowsocks protocol |
| 56 | + ssl - communicate in (unsecured) ssl |
| 57 | + secure - comnunicate in (secured) ssl |
| 58 | + Valid schemes are: http://, http+socks://, http+ssl://, ss+secure:// |
| 59 | + Invalid schemes are: ssl://, secure:// |
| 60 | +- cipher |
| 61 | + Cipher is consisted by cipher name, colon ':' and cipher key. |
| 62 | + Full cipher list: table, rc4, rc4-md5, chacha20, salsa20, aes-128-cfb, aes-192-cfb, aes-256-cfb, bf-cfb, cast5-fb, des-cfb |
| 63 | +- netloc |
| 64 | + It can be "hostname:port" or "/unix_path". If the hostname is empty, server will listen on all interfaces. |
| 65 | +- rules |
| 66 | + The filename that contains regex rules |
| 67 | +- auth |
| 68 | + The username, colon ':', and the password |
| 69 | + |
| 70 | +Examples |
| 71 | +----------- |
| 72 | + |
| 73 | +We can define file "rules" as follow: |
| 74 | + |
| 75 | + #google domains |
| 76 | + (?:.+\.)?google.*\.com |
| 77 | + (?:.+\.)?gstatic\.com |
| 78 | + (?:.+\.)?gmail\.com |
| 79 | + (?:.+\.)?ntp\.org |
| 80 | + (?:.+\.)?glpals\.com |
| 81 | + (?:.+\.)?akamai.*\.net |
| 82 | + (?:.+\.)?ggpht\.com |
| 83 | + (?:.+\.)?android\.com |
| 84 | + (?:.+\.)?gvt1\.com |
| 85 | + (?:.+\.)?youtube.*\.com |
| 86 | + (?:.+\.)?ytimg\.com |
| 87 | + (?:.+\.)?goo\.gl |
| 88 | + (?:.+\.)?youtu\.be |
| 89 | + (?:.+\.)?google\..+ |
| 90 | + |
| 91 | +Then start the pproxy |
| 92 | + |
| 93 | + pproxy -i http+socks://:8080 -r http://aa.bb.cc.dd:8080?rules -v |
| 94 | + |
| 95 | +With these parameters, this utility will serve incoming traffic by either http/socks5 protocol, redirect all google traffic to http proxy aa.bb.cc.dd:8080, and visit all other traffic locally. |
| 96 | + |
| 97 | +To bridge two servers, add cipher key to ensure data can't be intercepted. First, run pproxy locally |
| 98 | + |
| 99 | + pproxy -i ss://:8888 -r ss://chacha20:cipher_key@aa.bb.cc.dd:12345 -v |
| 100 | + |
| 101 | +Next, run pproxy.py remotely on server "aa.bb.cc.dd" |
| 102 | + |
| 103 | + pproxy -i ss://chacha20:cipher_key@:12345 |
| 104 | + |
| 105 | +By doing this, the traffic between local and aa.bb.cc.dd is encrypted by stream cipher Chacha20 with key "This is a cipher key". If target hostname is not in "rules", traffic will go through locally. Otherwise, traffic will go through the remote server by encryption. |
| 106 | + |
0 commit comments