What is man-in-the-middle-proxy

2023-04-28

TL;DR

A Man In The Middle Proxy (MITM) is a proxy server that intercepts all traffic between a client and a server. This allows the proxy to inspect, modify, or even block the traffic. The object of this post directory is to explain the construction of man in the middle proxy in rust 🦀. Currently man-in-the-middle-proxy, displays both HTTP and HTTPS requests and responses, future goal is to allow for manipulation of the traffic for more advanced use cases. It is a learning project and I am aware that the code is not the most idiomatic or optimized, I will work on in over time to improve it more and more.

Toc
[ Hide]

mitm proxy

I took inspiration from mitmproxy, I like that project, it is built mainly with python but some parts (lower level parts) are built in Rust. I want to basically clone that project completely in Rust adding some features.

mitmproxy.org

Features and Roadmap

  • 🔐 HTTP / HTTP(s)
  • 🖱 ️ Gui
  • ⌨ Possibility of choosing a customised address and listening port
  • 🔍 Details for each request and response
  • 🎯 Filtering the list of requests by method
  • ❌ Deleting a single request from the list
  • 🚫 Clear all requests and clean the table
  • 🌌 Dark / light theme
  • 🫳 Requests manipulation and replication
  • 👻 Transparent mode

The structure

The application is splitted into two main parts:

The two parts run in different threads and communicate through a channel. The channel is not multiplexed; the receiver is the GUI, and the transmitter is the API, probably this communication method will change, the goal is to manipulate requests allowing to handle them from Gui, and the handled request will be sended to Api through another channel from Gui (tx) to Api (rx) but currently Data is generated on the API side and sent to the other side in order to display them.

In order to launch the app is mandatory to generate a self-signed certificate through openssl. The generation is very simple and could be done directly running this command in the terminal:

openssl req -x509 -newkey rsa:4096 -keyout mitmproxy.key -out mitmproxy.cer -sha256 -days 700000 -nodes

this command will generate 2 files, a private key "mitmproxy.key" and a certificate "mitmproxy.cer". Both formats map to major encoding schemes for x.509 certificates and keys. You have to manually trust .cer file to proceed.

When the app is launched a starter menu appears, it allow you to chose custom listener address and port, if you want to listen traffic only in localhost keep the default value. To intercept local network remember to trust the .cer also on every single network device.

Preview