mitmproxy, traffic playback tool

Install

  • Install the python module

pip install mitmproxy

  • After the installation is complete, the system will have  mitmproxy, mitmdump, and mitmweb three commands. Since  mitmproxy the commands do not support running in the windows system, we can  mitmdump test whether the installation is successful by executing:

mitmdump --version

GitHub:https://github.com/mitmproxy/mitmproxy

Certificate Configuration & Proxy Configuration

web side

  • Enter the path: C:\Users\Administrator\.mitmproxy, double-click mitmproxy-ca.p12, go to the next step, select to put all certificates into the following storage, trusted root certification authority, and the import is successful.

  •  Manually set the proxy

mobile terminal

  • Set the proxy in WiFi, the host name of the proxy server is the local IP address, if the port is not customized, fill in 8080
  • Enter http://mitm.it to install the certificate in the browser, and install the certificate after the download is complete

start up

To start mitmproxy  mitmproxy,  you can use any one of the three commands , , and these three commands have the same function and can load custom scripts. The only difference is the difference in the interactive interface mitmdump.mitmweb

mitmweb After the command is started, a web interface will be provided, and the user can see the request in real time, filter the request and view the request data through GUI interaction. Shaped like:

 After the mitmdump command is started, you can view it on the console

 custom script

This is where mitmproxy is really powerful. Write a py file for mitmproxy to load, the file defines the variable addons, addons is an array, each element is a class instance, these classes have several methods, these methods implement some events provided by mitmproxy, mitmproxy will happen in a certain event When the corresponding method is called. These classes are called one by one  addon, such as an addon called Counter:

import mitmproxy.http
from mitmproxy import ctx

class Counter:
    def __init__(self):
    self.num = 0

def request(self, flow: mitmproxy.http.HTTPFlow):
    self.num = self.num + 1
    ctx.log.info("We've seen %d flows" % self.num)

addons = [
    Counter()
]

 We save the script as addon.py

 See more scripts: https://github.com/mitmproxy/mitmproxy/tree/main/examples

Then restart mitmproxy, mitmweb -s addons.py, you will see a log like this

Guess you like

Origin blog.csdn.net/qq_38312411/article/details/127405274