Skip to main content

A very simple NIO TCP proxy server

Project description

simple-proxy :rocket:

A very simple TCP proxy tool empowered by nio tcp framework py-netty

Traffic control is negociated between 2 segments of TCP connection:

USER <---------> simple-proxy <---------> REAL SERVER
          |                         |
          |---- traffic control ----|

Installation

pip install simple-proxy

Usage

Usage: simple-proxy [OPTIONS]

Options:
  -l, --local-server TEXT         Local server address  [default: localhost]
  -lp, --local-port INTEGER       Local port  [default: 8080]
  -r, --remote-server TEXT        Remote server address  [default: localhost]
  -rp, --remote-port INTEGER      Remote port  [default: 80]
  -g, --global                    Listen on 0.0.0.0
  --workers INTEGER               Number of worker threads  [default: 1]
  --proxy-workers INTEGER         Number of proxy threads  [default: 1]
  -c, --tcp-flow                  Dump tcp flow on to console
  -f, --save-tcp-flow             Save tcp flow to file
  -s, --tls                       Denote remote server listening on secure port
  -ss                             Denote local sever listening on secure port
  -kf, --key-file PATH            Key file for local server
  -cf, --cert-file PATH           Certificate file for local server
  -sm, --speed-monitor            Print speed info to console for established connection
  -smi, --speed-monitor-interval INTEGER
                                  Speed monitor interval  [default: 3]
  -dti, --disguise-tls-ip TEXT    Disguise TLS IP
  -dtp, --disguise-tls-port INTEGER
                                  Disguise TLS port  [default: 443]
  -wl, --white-list TEXT          IP White list for incoming connections (comma separated)
  --run-mock-tls-server           Run mock TLS server
  --shadow                        Disguise if incoming connection is TLS client request
  --alpn                          Set ALPN protocol as [h2, http/1.1]
  --http-proxy                    HTTP proxy mode
  --shell-proxy                   Shell proxy mode
  -v, --verbose
  --read-delay-millis INTEGER     Read delay in milliseconds (only apply to TCP proxy mode)  [default: 0]
  --write-delay-millis INTEGER    Write delay in milliseconds (only apply to TCP proxy mode)  [default: 0]
  -h, --help                      Show this message and exit.

Features

Basic proxy (TLS termination)

> simple-proxy --tls -r www.google.com -rp 443 -lp 8080
Proxy server started listening: localhost:8080 => www.google.com:443(TLS) ...
console:False, file:False, disguise:n/a, whitelist:*
> curl -I -H 'Host: www.google.com'  http://localhost:8080
HTTP/1.1 200 OK
...
> simple-proxy -r www.google.com -rp 80 -lp 8443 -ss
Proxy server started listening: localhost:8443(TLS) => www.google.com:80 ...
console:False, file:False, disguise:n/a, whitelist:*
> curl -I -H 'Host: www.google.com' -k https://localhost:8443
HTTP/1.1 200 OK
...

Dump TCP flow

TCP flow can be dumped into console or files (under directory tcpflow)

> simple-proxy -r www.google.com -rp 443 -lp 8443 -ss -s -c -f
Proxy server started listening: localhost:8443(TLS) => www.google.com:443(TLS) ...
console:True, file:True, disguise:n/a, whitelist:*
> curl -k -I -H 'Host: www.google.com'  https://localhost:8443

tcpflow

Connection status monitor

> $ simple-proxy -r echo-server.proxy.com -rp 8080 -lp 48080 --speed-monitor
Proxy server started listening: localhost:48080 => echo-server.proxy.com:8080 ...
console:False, file:False, disguise:n/a, whitelist:*
Connection opened: ('127.0.0.1', 60937)
Connection opened: ('127.0.0.1', 60938)
Connection opened: ('127.0.0.1', 60939)
Connection opened: ('127.0.0.1', 60940)
Connection opened: ('127.0.0.1', 60941)
Connection opened: ('127.0.0.1', 60942)
Connection opened: ('127.0.0.1', 60943)
Connection opened: ('127.0.0.1', 60944)
---------------------------2024-02-12 17:43:02.337268 (total:8, rounds:1)---------------------------
[  1] | 127.0.0.1:60937       | Speed Rx:32.00 K/s  Tx:32.00 K/s  | Total Rx:235.00 K   Tx:235.00 K   | duration: 7s
[  2] | 127.0.0.1:60938       | Speed Rx:32.00 K/s  Tx:32.00 K/s  | Total Rx:235.00 K   Tx:234.00 K   | duration: 7s
[  3] | 127.0.0.1:60939       | Speed Rx:32.00 K/s  Tx:32.00 K/s  | Total Rx:235.00 K   Tx:234.00 K   | duration: 7s
[  4] | 127.0.0.1:60940       | Speed Rx:32.00 K/s  Tx:32.00 K/s  | Total Rx:235.00 K   Tx:234.00 K   | duration: 7s
[  5] | 127.0.0.1:60941       | Speed Rx:32.00 K/s  Tx:32.00 K/s  | Total Rx:235.00 K   Tx:234.00 K   | duration: 7s
[  6] | 127.0.0.1:60942       | Speed Rx:32.00 K/s  Tx:32.00 K/s  | Total Rx:234.00 K   Tx:234.00 K   | duration: 7s
[  7] | 127.0.0.1:60943       | Speed Rx:32.00 K/s  Tx:32.00 K/s  | Total Rx:234.00 K   Tx:234.00 K   | duration: 7s
[  8] | 127.0.0.1:60944       | Speed Rx:32.00 K/s  Tx:32.00 K/s  | Total Rx:234.00 K   Tx:234.00 K   | duration: 7s
Average Read Speed:  32765.0 bytes/s, Average Write Speed: 32752.88 bytes/s

HTTP Proxy

You can set global envs https_proxy or https_proxy after http proxy server startd.

> simple-proxy --http-proxy

Shell Proxy

Make shell accessible through TCP. Please run this mode with caution.

:warning: Stop the server as soon as you finish your work.

> simple-proxy --shell-proxy

# How to connect:
# socat file:`tty`,raw,echo=0 tcp:<server-ip>:<server-port> # for Bash proxy in Linux
# socat - tcp:<server-ip>:<server-port> # for cmd.exe proxy in Windows

Disguise as HTTPS server with whitelist

Any connection beyond whitelist will be served by a mock https server. Real service can thus be hided.

For example, you can protect your Scurrying Squirrel against attack from Grim Foolish Weasel.

> simple-proxy -rp 8388 -lp 443 -g  --run-mock-tls-server -wl=<your ip>,<your wife's ip>,<your friend's wife's ip> 

joey

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simple-proxy-0.0.20.tar.gz (16.4 kB view details)

Uploaded Source

Built Distribution

simple_proxy-0.0.20-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

Details for the file simple-proxy-0.0.20.tar.gz.

File metadata

  • Download URL: simple-proxy-0.0.20.tar.gz
  • Upload date:
  • Size: 16.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.13

File hashes

Hashes for simple-proxy-0.0.20.tar.gz
Algorithm Hash digest
SHA256 72d0b0e66d5d7391937d2cc3d94c06c46981d5d62bc8f6851a37c45fb26d7a01
MD5 df2d3cc005abada79eadb9fea4f75e44
BLAKE2b-256 6aa9e8fedb0b5edd6f7861e37d120f6896c0c75cfea58ffafafb789db59bd4de

See more details on using hashes here.

File details

Details for the file simple_proxy-0.0.20-py3-none-any.whl.

File metadata

File hashes

Hashes for simple_proxy-0.0.20-py3-none-any.whl
Algorithm Hash digest
SHA256 ddc2bbdc7ec89df859f3d3c12182483cb096da3d726c7ee0701621b5ca6dfc8d
MD5 9e7179564c67e5c6d1d311efc7428c3a
BLAKE2b-256 d04d24e0a47e97c911c6d65d2fde4f6a6821e91da56473500ec46eeac0aa1318

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page