Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install and use mitmproxy

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to install and use mitmproxy". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to install and use mitmproxy.

Mitmproxy is the abbreviation of man-in-the-middle attack proxy, translated as man-in-the-middle attack tool, which can be used to intercept, modify and save HTTP/HTTPS requests. You can't make a crawler without these tools, especially those based on APP. Mitmproxy is presented as a command line terminal and operates like Vim, while providing the mitmweb plug-in, which is a visualization tool similar to the Chrome browser developer model.

It is an open source tool based on Python development, the most important thing is that it provides Python API, you can control the request and response through Python code, which other tools can not do, which is one of the reasons I like this tool.

Install sudo pip3 install mitmproxy to start mitmproxy

# or specify a port

Mitmproxy-p 8888

After starting mitmproxy, port 8080 is enabled by default. Mitmproxy command does not support Windows platform, so you need to use mitmdump or mitmweb command instead. The Windows system can also be installed by downloading its EXE file on the official website.

After the mobile phone or browser has set up the proxy, you can grab the package and analyze it. Open the browser to visit a certain URL, and mitmproxy will see the following:

Currently, there are 136 requests. The 16th request is selected. The request method is GET. The returned status code is 200. the port of the agent is 8080. You can switch to different requests up and down through J and K keys. Enter can see the details of the currently selected request, including three parts: Request, Response and Detail.

Mitmproxy shortcut key

? Help document Q return / exit program b save response body f input filter condition k upper j lower h left l right space page enter enter interface details z clear screen e edit r re-request HTTPS grab package configuration

For HTTPS requests, in order to catch the request normally, you need to install the certificate first. The effect of a request without a certificate installed is like this.

Open the URL http://mitm.it, select the matching platform, and download the HTTPS certificate. And follow the corresponding steps to install.

Mitmweb$ mitmweb

After starting the mitmweb command, there will be a Web page similar to the Chrome developer tool, which is similar to mitmroxy in function. You can also view the details of each request, including request and response, and modify the request and response content, including common functions such as filtering and resending requests.

Mitmdump$ mitmdump-s script.py

The most important feature of mitmdump command is that you can customize the script, in which you can control the request or response content by programming, and realize the parsing, modification, storage and other work of data (the code can slide left and right).

# script.py

From mitmproxy import http

Def request (flow: http.HTTPFlow)-> None:

# add a query parameter to the request

Flow.request.query ["mitmproxy"] = "rocks"

Def response (flow: http.HTTPFlow)-> None:

# A custom header field has been added to the response header

Flow.response.headers ["newheader"] = "foo"

Print (flow.response.text)

When you request http://httpbin.org/get in your browser, you see the following effect:

At this point, I believe you have a deeper understanding of "how to install and use mitmproxy". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report