This is a collection of some handy mitmproxy inline scripts.
-
Install mitmproxy
-
Client side CA setup: http://docs.mitmproxy.org/en/stable/certinstall.html
The purpose of this script is to return mock JSON response for certain target URLs.
- Run mitmdump:
~$ mitmdump -s mitm-rewrite.py
- Quick check setup on client side:
- Open http://example.com/pass should return data in test_pass.json
- Open http://example.com/fail should return data in test_fail.json
- Update
rewrite-router.yaml
, pair URL with JSON file, for e.g:
http://example.com: example
The response of "http://exmaple.com" will be rewrote by the content in example.json file. Using yaml file is easy for human to read and it's possible to add comment in yaml.
- Add static JSON file, file example:
{
"status": 200,
"header": { ... },
"content": ...
}
- status: http status code, an INT number
- header: http response headers
- content: response body
The changes in yaml files will be applied on the fly, no need to restart proxy. Here is an example how it looks like:
The usage of this script is to display real-time analytics key and value, in order to help checking analytics efficiently.
To configure URL and keywords, edit analytics.yaml
It's possible to configure the url and
- Run mitmdump:
~$ mitmdump -s mitm-check_analytics.py
- Visit target web page in clients: browsers or apps. The matched analytics keyword and value will show up in terminal.
This script will randomly delay HTTP/HTTPS request time and response time, in order to simulate the slow network.
To configure URL and delay time, edit request.yaml
~$ mitmdump -s mitm-delay-request.py
This scrip will replace the specific string to another on. Like mitm-rewrite, a replace-router.yaml
is used to link URL and yaml file in response
folder. In the yaml file, the old and new strings can be defined. Don't forget to uncomment URLs in replace-router.yaml
and make it work on the fly!
~$ mitmdump -s mitm-replace.py
This script will simulate sever outage and return 503 code. It will pick randomly the requests to make it 503. The percentage of outage can be changed as the variable percentage in the script.
~$ mitmproxy -s mitm-random-outage.py