How to use the command 'mitmproxy' (with examples)

How to use the command 'mitmproxy' (with examples)

mitmproxy is an interactive man-in-the-middle HTTP proxy tool. It allows you to intercept and modify HTTP traffic between clients and servers, making it a powerful tool for testing and debugging network requests. You can start mitmproxy with various options to suit your specific needs.

Use case 1: Start mitmproxy with default settings

Code:

mitmproxy

Motivation: Starting mitmproxy with default settings allows you to quickly launch the proxy and start intercepting HTTP traffic. This is useful for general testing and analysis purposes.

Explanation: This command runs mitmproxy with the default settings. The proxy will listen on the default address (localhost) and port (8080).

Example output:

Proxy server listening at http://127.0.0.1:8080

Use case 2: Start mitmproxy bound to a custom address and port

Code:

mitmproxy --listen-host ip_address --listen-port port

Motivation: In some cases, you may want to bind mitmproxy to a specific IP address and port. This is useful when you have multiple network interfaces or when you want to listen on a non-standard port.

Explanation: This command starts mitmproxy and binds it to a custom IP address and port specified using the --listen-host and --listen-port options respectively. Replace ip_address with the desired IP address and port with the desired port number.

Example output:

Proxy server listening at http://192.168.1.100:8888

Use case 3: Start mitmproxy using a script to process traffic

Code:

mitmproxy --scripts path/to/script.py

Motivation: mitmproxy allows you to specify a Python script that will be executed to process intercepted traffic. This is useful when you need to perform custom modifications or analysis on the HTTP traffic.

Explanation: This command starts mitmproxy and uses the specified Python script (path/to/script.py) to process intercepted traffic. The script can access and modify the intercepted requests and responses.

Example output:

Proxy server listening at http://127.0.0.1:8080
Executing script: path/to/script.py

Use case 4: Export the logs with SSL/TLS master keys to external programs

Code:

SSLKEYLOGFILE="path/to/file" mitmproxy

Motivation: When intercepting HTTPS traffic, mitmproxy can generate SSL/TLS master keys, which are needed to decrypt and analyze the encrypted traffic in external programs like Wireshark. This use case allows you to export these keys.

Explanation: This command starts mitmproxy and sets the environment variable SSLKEYLOGFILE to the specified file path (path/to/file). This file will contain the SSL/TLS master keys, allowing external programs to decrypt the captured HTTPS traffic.

Example output:

Proxy server listening at http://127.0.0.1:8080
SSL master key log file: path/to/file

Conclusion

The mitmproxy command provides a versatile way to intercept and modify HTTP traffic. Whether you need to quickly start the proxy, customize the address and port, process traffic with a script, or export SSL/TLS master keys, mitmproxy has you covered. Experiment with these examples to enhance your network testing and analysis capabilities.

Related Posts

How to use the command 'screen' (with examples)

How to use the command 'screen' (with examples)

The screen command is a powerful tool that allows users to create and manage multiple terminal sessions within a single SSH connection.

Read More
How to use the command `uncrustify` (with examples)

How to use the command `uncrustify` (with examples)

uncrustify is a source code formatter for languages like C, C++, C#, D, Java, and Pawn.

Read More
How to use the command 'valac' (with examples)

How to use the command 'valac' (with examples)

Valac is a code compiler for the Vala programming language. It is used to compile Vala source code files into executable binaries.

Read More