Skip to main content

Man-in-the-middle proxy with customizable options.

Project description

👨‍💻 mitm

A customizable man-in-the-middle TCP proxy with support for HTTP & HTTPS.

Installing

pip install mitm

Note that OpenSSL 1.1.1 or greater is required.

Documentation

Documentation can be found here.

Using

You can easily boot-up the proxy and start intercepting traffic:

from mitm import MITM, protocol, middleware, crypto

mitm = MITM(
    host="127.0.0.1",
    port=8888,
    protocols=[protocol.HTTP],
    middlewares=[middleware.Log],
    buffer_size=8192,
    timeout=5,
    ssl_context=crypto.mitm_ssl_default_context(),
)
mitm.run()

Above is the default values for the MITM class.

While the example above is sufficient for printing out incoming/outgoing messages, the bread and butter of mitm is the ability to add custom protocols and middlewares.

Protocols

mitm allows the addition of custom application-layer protocols that can be used to intercept and redirect traffic. Built-into the mitm library is the HTTP protocol (with TLS/CONNECT support). To read and understand more about protocols check out the documentations.

Middlewares

Custom middlewares allow programmatic customizations to incoming and outgoing requests. Middlewares can be used to modify the request, response, or both. To read and understand more about middlewares check out the documentation.

Example

Using the example above we can send a request to the server via another script:

import requests

proxies = {"http": "http://127.0.0.1:8888", "https": "http://127.0.0.1:8888"}
requests.get("https://httpbin.org/anything", proxies=proxies, verify=False)

Which will lead to the following being logged where mitm is running in:

2021-11-29 10:33:02 INFO     MITM started on 127.0.0.1:8888.
2021-11-29 10:33:03 INFO     Client 127.0.0.1:54771 has connected.
2021-11-29 10:33:03 INFO     Client to server:

	b'CONNECT httpbin.org:443 HTTP/1.0\r\n\r\n'

2021-11-29 10:33:03 INFO     Connected to server 18.232.227.86:443.
2021-11-29 10:33:03 INFO     Client to server:

	b'GET /anything HTTP/1.1\r\nHost: httpbin.org\r\nUser-Agent: python-requests/2.26.0\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\n\r\n'

2021-11-29 10:33:03 INFO     Server to client:

	b'HTTP/1.1 200 OK\r\nDate: Mon, 29 Nov 2021 15:33:03 GMT\r\nContent-Type: application/json\r\nContent-Length: 396\r\nConnection: keep-alive\r\nServer: gunicorn/19.9.0\r\nAccess-Control-Allow-Origin: *\r\nAccess-Control-Allow-Credentials: true\r\n\r\n{\n  "args": {}, \n  "data": "", \n  "files": {}, \n  "form": {}, \n  "headers": {\n    "Accept": "*/*", \n    "Accept-Encoding": "gzip, deflate", \n    "Host": "httpbin.org", \n    "User-Agent": "python-requests/2.26.0", \n    "X-Amzn-Trace-Id": "Root=1-61a4f2af-2de4362101f0cab43f6407b1"\n  }, \n  "json": null, \n  "method": "GET", \n  "origin": "xxx.xx.xxx.xx", \n  "url": "https://httpbin.org/anything"\n}\n'

2021-11-29 10:33:08 INFO     Client has disconnected.
2021-11-29 10:33:08 INFO     Server has disconnected.

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

mitm-1.2.0.tar.gz (21.4 kB view details)

Uploaded Source

Built Distribution

mitm-1.2.0-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file mitm-1.2.0.tar.gz.

File metadata

  • Download URL: mitm-1.2.0.tar.gz
  • Upload date:
  • Size: 21.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1

File hashes

Hashes for mitm-1.2.0.tar.gz
Algorithm Hash digest
SHA256 a2a9562cec693e65cbe4fff42fb80e350d8e7b82f893416cc06262d9cab86ab4
MD5 be34d965847ca750b6f9f50cd6c1baa3
BLAKE2b-256 70deed71ae0c2218bbd82b3ec6bf322d9e7fdafe36e84b4d6856d21170d33ff1

See more details on using hashes here.

File details

Details for the file mitm-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: mitm-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1

File hashes

Hashes for mitm-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f682b248efff2cc902a5a2604dea67229df6869be1d8a5333716257627067af8
MD5 e7d8afc16874264027142e270aa5966f
BLAKE2b-256 4e1d07952f3c4c92dd936113551778a9052b8cbbc80e744f63fd3399605c4ce5

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