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

Using the default values for the MITM class:

from mitm import MITM, protocol, middleware, crypto

mitm = MITM(
    host="127.0.0.1",
    port=8888,
    protocols=[protocol.HTTP], 
    middlewares=[middleware.Log], # middleware.HTTPLog used for the example below.
    certificate_authority = crypto.CertificateAuthority()
)
mitm.run()

This will start a proxy on port 8888 that is capable of intercepting all HTTP traffic (with support for SSL/TLS) and log all activity.

Extensions

mitm can be customized through the implementations of middlewares and protocols.

Middlewares are event-driven hooks that are called when connections are made, requests are sent, responses are received, and connections are closed.

Protocols are implementations on how the data flows between the client and server, and is used to implement application layer protocols and/or more complex extensions.

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:

2022-06-08 15:07:10 INFO     MITM server started on 127.0.0.1:8888.
2022-06-08 15:07:11 INFO     Client 127.0.0.1:64638 has connected.
2022-06-08 15:07:11 INFO     Client 127.0.0.1:64638 to mitm: 

→ CONNECT httpbin.org:443 HTTP/1.0

2022-06-08 15:07:12 INFO     Client 127.0.0.1:64638 has connected to server 34.206.80.189:443.
2022-06-08 15:07:12 INFO     Client 127.0.0.1:64638 to 34.206.80.189:443: 

→ GET /anything HTTP/1.1
→ Host: httpbin.org
→ User-Agent: python-requests/2.26.0
→ Accept-Encoding: gzip, deflate
→ Accept: */*
→ Connection: keep-alive

2022-06-08 15:07:12 INFO     Server 34.206.80.189:443 to client 127.0.0.1:64638: 

← HTTP/1.1 200 OK
← Date: Wed, 08 Jun 2022 19:07:12 GMT
← Content-Type: application/json
← Content-Length: 396
← Connection: keep-alive
← Server: gunicorn/19.9.0
← Access-Control-Allow-Origin: *
← Access-Control-Allow-Credentials: true
← 
← {
←   "args": {}, 
←   "data": "", 
←   "files": {}, 
←   "form": {}, 
←   "headers": {
←     "Accept": "*/*", 
←     "Accept-Encoding": "gzip, deflate", 
←     "Host": "httpbin.org", 
←     "User-Agent": "python-requests/2.26.0", 
←     "X-Amzn-Trace-Id": "Root=1-62a0f360-774052c80b60f4ea049f5665"
←   }, 
←   "json": null, 
←   "method": "GET", 
←   "origin": "xxx.xxx.xxx.xxx", 
←   "url": "https://httpbin.org/anything"
← }

2022-06-08 15:07:27 INFO     Server 34.206.80.189:443 has disconnected.
2022-06-08 15:07:27 INFO     Client 127.0.0.1:64638 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.5.0.tar.gz (26.8 kB view details)

Uploaded Source

Built Distribution

mitm-1.5.0-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mitm-1.5.0.tar.gz
  • Upload date:
  • Size: 26.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for mitm-1.5.0.tar.gz
Algorithm Hash digest
SHA256 1ad93afcebc7624a01d8a45d1a9a3a2c9909d0d6b9277b4e8f9604d0032f2ad8
MD5 89485788cfda9923ef51b1a83c9cd771
BLAKE2b-256 576d2d9feb9f0f7f681e8e86c67e7570c5e40724f69160103a05d160d8b3ec4b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mitm-1.5.0-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for mitm-1.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a7facc301f0092feccb9538c4b7f4c2c0cb6f3c9578f702750c055a2a57ed7bc
MD5 bb45ff14ad837ce106927c8f8b085dc2
BLAKE2b-256 a9445b6abe9d14f77d4ed138ed62e13f567639c514f9480a29cce02d8ab87e50

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