Please indicate the source https://www.cnblogs.com/majianming/p/11823669.html
mitmproxy proxy is a tool written in python, can proxy https, http and other protocols
Key is a custom script e.g. the acquiring request information, and saved to the database, and the like to modify the response operation (blinking)
You can use the form of pip installation can also use the compiled binary files are installed (binaries Download https://mitmproxy.org/downloads/)
But if you need to install custom scripts and third-party libraries then you need to use the form of pip installation
pip in the form of installation, first ensure that you have already installed the python pip
A Case Study below to install windows
If the windows system also need to install the Build Tools in the Microsoft ( https://www.microsoft.com/en-us/download/confirmation.aspx?id=48159 )
then
carried out
pip install mitmproxy
If you need to be able to execute commands anywhere, it is best to follow the instructions will be similar to C: \ Users \ User \ AppData \ Roaming \ Python \ Python37 \ Scripts path added to the system environment Path, or you may need to always use the full path of the form access
After a successful installation should have these executable files under the above path
mitmweb.exe visualization and mitmproxy.exe Agent
mitmproxy.exe open displays all proxy requests in the console, but is not available under windows,
mitmweb.exe open the default browser and displays all proxy requests
Default proxy listening port 8080 can be used here -p 8081 8080 Port Command mitmweb (mitmweb -p 8080) started from the command line
Then we test results order for us to use in the browser
SwitchyOmega ( https://chrome.google.com/webstore/detail/padekgcemlokbadohgkifijomclgjgif) proxy switch

Then choose to use the proxy just created it
Then visit a website you can see all the requests just pop up window (if you need to import certificate system is https certificate generally .mitmproxy file in the user directory folder,
If Firefox is, because the root certificate mitmproxy not use your browser's certificate trust relationship (Firefox their own set of certificate system), it is necessary to Settings → Privacy and Security -> Security -> Certificates -> View Certificates → → Import Certificate Authority import certificate)
If you need some script
Can refer to the format of this script is to log off and save request the information sent to the specified server
import time
import mitmproxy.http
import requests
from mitmproxy import ctx
intercept_url = "xx"
report_server_url = "xxxx"
class LoginIntercept:
def request(self, flow: mitmproxy.http.HTTPFlow):
if intercept_url in flow.request.pretty_url:
ctx.log.info("监听地址 %s" % flow.request.pretty_url)
ctx.log.info("请求头 %s" % flow.request.headers)
info = {
"url": flow.request.pretty_url,
"headers": str(flow.request.headers),
}
init_data = {"update_timestamp": int(time.time()),
"info": info}
try:
requests.post(report_server_url, json=init_data,timeout=2)
except Exception as e:
ctx.log.error("更新信息失败!原因【%r】" % e)
addons = [
LoginIntercept()
]
Command line mitmweb -p 8080 -s script.py start
please indicate the source https://www.cnblogs.com/majianming/p/11823669.html
reference
Official website document https://mitmproxy.org/
github example https://github.com/mitmproxy/mitmproxy/tree/master/examples