Skip to main content

Proxy3 - Man-in-the-middle http/https proxy in a single python script

Project description

proxy3

Man-in-the-middle http/https proxy in a single python script

Features

  • easy to customize
  • require no external modules
  • support both of IPv4 and IPv6
  • support HTTP/1.1 Persistent Connection
  • support dynamic certificate generation for HTTPS intercept

This script works on Python 3.10+. You need to install openssl to intercept HTTPS connections.

Usage

Just clone and run as a script:

$ python proxy3.py

Or, install using pip:

$ pip install proxy3
$ proxy3

Above command runs the proxy on localhost:7777. Verify it works by typing the below command in another terminal of the same host.

# test http proxy
$ http_proxy=localhost:7777 curl http://www.example.com/

To bind to another host or port:

$ python proxy3.py --host 0.0.0.0 --port 3128

Enable HTTPS intercept

To intercept HTTPS connections, generate private keys and a private CA certificate:

$ python proxy3.py --make-certs
$ https_proxy=localhost:7777 curl https://www.example.com/

Through the proxy, you can access http://proxy3.test/ and install the CA certificate in the browsers.

Detailed Usage

$ python proxy3.py --help

usage: proxy3.py [-h] [-H HOST] [-p PORT] [--timeout TIMEOUT] [--ca-key CA_KEY] [--c
a-cert CA_CERT] [--ca-signing-key CA_SIGNING_KEY] [--cert-dir CERT_DIR] [--request-h
andler REQUEST_HANDLER] [--response-handler RESPONSE_HANDLER] [--save-handler SAVE_H
ANDLER] [--make-certs]

options:
  -h, --help            show this help message and exit
  -H HOST, --host HOST  Host to bind (default: localhost)
  -p PORT, --port PORT  Port to bind (default: 7777)
  --timeout TIMEOUT     Timeout (default: 5)
  --ca-key CA_KEY       CA key file (default: ./ca-key.pem)
  --ca-cert CA_CERT     CA cert file (default: ./ca-cert.pem)
  --ca-signing-key CA_SIGNING_KEY
                        CA cert key file (default: ./ca-signing-key.pem)
  --cert-dir CERT_DIR   Site certs files (default: ./certs)
  --request-handler REQUEST_HANDLER
                        Request handler function (default: None)
  --response-handler RESPONSE_HANDLER
                        Response handler function (default: None)
  --save-handler SAVE_HANDLER
                        Save handler function, use 'off' to turn off (default: None)

Customization

You can easily customize the proxy and modify the requests/responses or save something to the files. The ProxyRequestHandler class has 3 methods to customize:

  • request_handler: called before accessing the upstream server
  • response_handler: called before responding to the client
  • save_handler: called after responding to the client with the exclusive lock, so you can safely write out to the terminal or the file system

By default, only save_handler is implemented which outputs HTTP(S) headers and some useful data to the standard output.

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

proxy3-0.2.1.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

proxy3-0.2.1-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file proxy3-0.2.1.tar.gz.

File metadata

  • Download URL: proxy3-0.2.1.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for proxy3-0.2.1.tar.gz
Algorithm Hash digest
SHA256 8c8c6eb7048a0455db193f5024ee542c3564f1ed15809761ddc072c7ae13b8de
MD5 6834c6dc67770fe5439c2d103574f838
BLAKE2b-256 c0c4f4535a689fafa37c9e14463bd9a96464c4bd5b50a672c45a1bbb1272e82d

See more details on using hashes here.

File details

Details for the file proxy3-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: proxy3-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for proxy3-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2bee37c2199739a9b0a07e6f7bdf14d542a3200956ed402cc644a9b451db647d
MD5 9d3142365480425bf7ed7ef3e8454058
BLAKE2b-256 8d06cb8a40ce491f2bee0f13739e424ab6215b6fdb4a008656de9d40fed47443

See more details on using hashes here.

Supported by

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