mitm#

from mitm import MITM

Man-in-the-middle.


class MITM[source]#

Man-in-the-middle server.

__init__(host, port, protocols, middlewares, certificate_authority, run)[source]#

Initializes the MITM class.

Parameters:
  • host (str) – Host to listen on. Defaults to 127.0.0.1.

  • port (int) – Port to listen on. Defaults to 8888.

  • protocols (Optional[List[Protocol]]) – List of protocols to use. Defaults to [protocol.HTTP].

  • middlewares (Optional[List[Middleware]]) – List of middlewares to use. Defaults to [middleware.Log].

  • certificate_authority (Optional[CertificateAuthority]) – Certificate authority to use. Defaults to CertificateAuthority().

  • run (bool) – Whether to start the server immediately. Defaults to False.

Example

from mitm import MITM

mitm = MITM()
mitm.run()
async entry()[source]#

Entry point for the MITM class.

The server is started by using asyncio.start_server function like so:

...
server = await asyncio.start_server(
    lambda reader, writer: self.mitm(
        Connection(
            client=Host(reader=reader, writer=writer),
            server=Host(),
        )
    ),
    host=self.host,
    port=self.port,
)
...
async mitm(connection)[source]#

Handles an incoming connection (single connection).

Warning

This method is not intended to be called directly.