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.
Metadata
Release files for proxy3 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| proxy3-0.2.1.tar.gz | 8.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| proxy3-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.3 kB
Release files / proxy3-0.2.1.tar.gz
| Download URL | proxy3-0.2.1.tar.gz |
|---|---|
| Size | 8.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8c8c6eb7048a0455db193f5024ee542c3564f1ed15809761ddc072c7ae13b8de
|
|
BLAKE2b-256 checksum How to use checksums |
c0c4f4535a689fafa37c9e14463bd9a96464c4bd5b50a672c45a1bbb1272e82d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.8
|
Release files / proxy3-0.2.1-py3-none-any.whl
| Download URL | proxy3-0.2.1-py3-none-any.whl |
|---|---|
| Size | 9.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2bee37c2199739a9b0a07e6f7bdf14d542a3200956ed402cc644a9b451db647d
|
|
BLAKE2b-256 checksum How to use checksums |
8d06cb8a40ce491f2bee0f13739e424ab6215b6fdb4a008656de9d40fed47443
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.8
|