How Will This Framework Work
- If you query information using www.baidu.com, it will response with code 404, and it will suggest you to use www.bing.com to search whatever you want.
- When you open www.bing.com and enter what you want to search, you will find that no matter what you have entered, the response result wiil always be yandex.
- Again, you click the link and open yandex to query information, it seems that everything is working properly this time.
- Wait a moment, you can find that the search button has been replaced with “Try Google”.
Scripting
Here gives all the code:
1 | import mitmproxy.http |
Start up the proxy server to load the script, there are basically three ways to run the proxy:
- Only run the server on the backend.
1
mitmdump --listen-port 9090 -s tamper.py
- Run the server with a terminal-based GUI.
1
mitmproxy --listen-port 9090 -s tamper.py
- Run the server with a web-based GUI.
1
mitmweb --web-port 9091 --listen-port 9090 -s tamper.py
Install The Certificate
You will get the wrong-certificate error if you directly access the HTTPS sites through proxy server. For Chrome, you can type “thisisunsafe” to bypass it or install and trust the certificate to access the proxy server permanently.
Access the proxy server with certificate:
- curl on the command line:
1
curl --proxy 127.0.0.1:9090 --cacert ~/.mitmproxy/mitmproxy-ca-cert.pem https://example.com/
- wget on the command line:Or execute the ~/.mitmproxy/mitmproxy-ca-cert.pem file to install the certificate.
1
wget -e https_proxy=127.0.0.1:9090 --ca-certificate ~/.mitmproxy/mitmproxy-ca-cert.pem https://example.com/
Verification
After all done, you can check the proxy result to verify it’s working properly.