simple-proxy


Namesimple-proxy JSON
Version 0.0.21 PyPI version JSON
download
home_pagehttps://github.com/ruanhao/simple-proxy
SummaryA very simple NIO TCP proxy server
upload_time2024-07-29 13:26:26
maintainerNone
docs_urlNone
authorHao Ruan
requires_python<4,>=3.7
licenseMIT
keywords network tcp non-blocking proxy
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # simple-proxy :rocket:

A very simple TCP proxy tool empowered by nio tcp framework [py-netty](https://pypi.org/project/py-netty/)

Traffic control is negociated between 2 segments of TCP connection:

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


## Installation

```bash
pip install simple-proxy
```

## Usage

```bash
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) 
```commandline
> 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
...
```

```commandline
> 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__)
```commandline
> 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](https://raw.githubusercontent.com/ruanhao/simple-proxy/master/img/tcpflow.png)

### Connection status monitor
```commandline
> $ 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.
```commandline
> 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.

```commandline
> 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.

```commandline
> 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](https://raw.githubusercontent.com/ruanhao/simple-proxy/master/img/joey.png)



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ruanhao/simple-proxy",
    "name": "simple-proxy",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4,>=3.7",
    "maintainer_email": null,
    "keywords": "network, tcp, non-blocking, proxy",
    "author": "Hao Ruan",
    "author_email": "ruanhao1116@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/f9/10/33c0476c4a616cc0a17f49b19d29be940a91c1cfdcc9dfa0075f8b8e86cb/simple-proxy-0.0.21.tar.gz",
    "platform": null,
    "description": "# simple-proxy :rocket:\n\nA very simple TCP proxy tool empowered by nio tcp framework [py-netty](https://pypi.org/project/py-netty/)\n\nTraffic control is negociated between 2 segments of TCP connection:\n\n```\nUSER <---------> simple-proxy <---------> REAL SERVER\n          |                         |\n          |---- traffic control ----|\n```\n\n\n## Installation\n\n```bash\npip install simple-proxy\n```\n\n## Usage\n\n```bash\nUsage: simple-proxy [OPTIONS]\n\nOptions:\n  -l, --local-server TEXT         Local server address  [default: localhost]\n  -lp, --local-port INTEGER       Local port  [default: 8080]\n  -r, --remote-server TEXT        Remote server address  [default: localhost]\n  -rp, --remote-port INTEGER      Remote port  [default: 80]\n  -g, --global                    Listen on 0.0.0.0\n  --workers INTEGER               Number of worker threads  [default: 1]\n  --proxy-workers INTEGER         Number of proxy threads  [default: 1]\n  -c, --tcp-flow                  Dump tcp flow on to console\n  -f, --save-tcp-flow             Save tcp flow to file\n  -s, --tls                       Denote remote server listening on secure port\n  -ss                             Denote local sever listening on secure port\n  -kf, --key-file PATH            Key file for local server\n  -cf, --cert-file PATH           Certificate file for local server\n  -sm, --speed-monitor            Print speed info to console for established connection\n  -smi, --speed-monitor-interval INTEGER\n                                  Speed monitor interval  [default: 3]\n  -dti, --disguise-tls-ip TEXT    Disguise TLS IP\n  -dtp, --disguise-tls-port INTEGER\n                                  Disguise TLS port  [default: 443]\n  -wl, --white-list TEXT          IP White list for incoming connections (comma separated)\n  --run-mock-tls-server           Run mock TLS server\n  --shadow                        Disguise if incoming connection is TLS client request\n  --alpn                          Set ALPN protocol as [h2, http/1.1]\n  --http-proxy                    HTTP proxy mode\n  --shell-proxy                   Shell proxy mode\n  -v, --verbose\n  --read-delay-millis INTEGER     Read delay in milliseconds (only apply to TCP proxy mode)  [default: 0]\n  --write-delay-millis INTEGER    Write delay in milliseconds (only apply to TCP proxy mode)  [default: 0]\n  -h, --help                      Show this message and exit.\n```\n\n\n## Features\n### Basic proxy (TLS termination) \n```commandline\n> simple-proxy --tls -r www.google.com -rp 443 -lp 8080\nProxy server started listening: localhost:8080 => www.google.com:443(TLS) ...\nconsole:False, file:False, disguise:n/a, whitelist:*\n> curl -I -H 'Host: www.google.com'  http://localhost:8080\nHTTP/1.1 200 OK\n...\n```\n\n```commandline\n> simple-proxy -r www.google.com -rp 80 -lp 8443 -ss\nProxy server started listening: localhost:8443(TLS) => www.google.com:80 ...\nconsole:False, file:False, disguise:n/a, whitelist:*\n> curl -I -H 'Host: www.google.com' -k https://localhost:8443\nHTTP/1.1 200 OK\n...\n```\n\n### Dump TCP flow\nTCP flow can be dumped into console or files (under directory __tcpflow__)\n```commandline\n> simple-proxy -r www.google.com -rp 443 -lp 8443 -ss -s -c -f\nProxy server started listening: localhost:8443(TLS) => www.google.com:443(TLS) ...\nconsole:True, file:True, disguise:n/a, whitelist:*\n> curl -k -I -H 'Host: www.google.com'  https://localhost:8443\n```\n![tcpflow](https://raw.githubusercontent.com/ruanhao/simple-proxy/master/img/tcpflow.png)\n\n### Connection status monitor\n```commandline\n> $ simple-proxy -r echo-server.proxy.com -rp 8080 -lp 48080 --speed-monitor\nProxy server started listening: localhost:48080 => echo-server.proxy.com:8080 ...\nconsole:False, file:False, disguise:n/a, whitelist:*\nConnection opened: ('127.0.0.1', 60937)\nConnection opened: ('127.0.0.1', 60938)\nConnection opened: ('127.0.0.1', 60939)\nConnection opened: ('127.0.0.1', 60940)\nConnection opened: ('127.0.0.1', 60941)\nConnection opened: ('127.0.0.1', 60942)\nConnection opened: ('127.0.0.1', 60943)\nConnection opened: ('127.0.0.1', 60944)\n---------------------------2024-02-12 17:43:02.337268 (total:8, rounds:1)---------------------------\n[  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\n[  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\n[  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\n[  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\n[  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\n[  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\n[  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\n[  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\nAverage Read Speed:  32765.0 bytes/s, Average Write Speed: 32752.88 bytes/s\n```\n\n### HTTP Proxy\nYou can set global envs *https_proxy* or *https_proxy* after http proxy server startd.\n```commandline\n> simple-proxy --http-proxy\n```\n\n### Shell Proxy\nMake shell accessible through TCP. Please run this mode with caution.\n\n:warning: Stop the server as soon as you finish your work.\n\n```commandline\n> simple-proxy --shell-proxy\n\n# How to connect:\n# socat file:`tty`,raw,echo=0 tcp:<server-ip>:<server-port> # for Bash proxy in Linux\n# socat - tcp:<server-ip>:<server-port> # for cmd.exe proxy in Windows\n```\n\n### Disguise as HTTPS server with whitelist\nAny connection beyond whitelist will be served by a mock https server. Real service can thus be hided.\n\nFor example, you can protect your Scurrying Squirrel against attack from Grim Foolish Weasel.\n\n```commandline\n> simple-proxy -rp 8388 -lp 443 -g  --run-mock-tls-server -wl=<your ip>,<your wife's ip>,<your friend's wife's ip> \n```\n\n![joey](https://raw.githubusercontent.com/ruanhao/simple-proxy/master/img/joey.png)\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A very simple NIO TCP proxy server",
    "version": "0.0.21",
    "project_urls": {
        "Homepage": "https://github.com/ruanhao/simple-proxy"
    },
    "split_keywords": [
        "network",
        " tcp",
        " non-blocking",
        " proxy"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bd87b02b6e20a1d8b6a2c5f3123b2f8edf94337b9ef3b2bf87938e289013776b",
                "md5": "6abeddcc69f30c4e442e96fdfc04c981",
                "sha256": "3db04fe3b755529773a81967f2aa5e1aac297242c01a02ca2e8f89f1f22c4303"
            },
            "downloads": -1,
            "filename": "simple_proxy-0.0.21-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6abeddcc69f30c4e442e96fdfc04c981",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4,>=3.7",
            "size": 14975,
            "upload_time": "2024-07-29T13:26:24",
            "upload_time_iso_8601": "2024-07-29T13:26:24.794646Z",
            "url": "https://files.pythonhosted.org/packages/bd/87/b02b6e20a1d8b6a2c5f3123b2f8edf94337b9ef3b2bf87938e289013776b/simple_proxy-0.0.21-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f91033c0476c4a616cc0a17f49b19d29be940a91c1cfdcc9dfa0075f8b8e86cb",
                "md5": "407eee6e4adeb38630d7edbb916f8ae5",
                "sha256": "21109feabf8a02f5b66d1516bf2c6e97d17130227ee31e7b0a884a4baa703fcc"
            },
            "downloads": -1,
            "filename": "simple-proxy-0.0.21.tar.gz",
            "has_sig": false,
            "md5_digest": "407eee6e4adeb38630d7edbb916f8ae5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4,>=3.7",
            "size": 16579,
            "upload_time": "2024-07-29T13:26:26",
            "upload_time_iso_8601": "2024-07-29T13:26:26.246046Z",
            "url": "https://files.pythonhosted.org/packages/f9/10/33c0476c4a616cc0a17f49b19d29be940a91c1cfdcc9dfa0075f8b8e86cb/simple-proxy-0.0.21.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-29 13:26:26",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ruanhao",
    "github_project": "simple-proxy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "simple-proxy"
}
        
Elapsed time: 0.96417s