{"id":13827222,"url":"https://github.com/kevcui/mitm-scripts","last_synced_at":"2025-04-10T01:15:56.223Z","repository":{"id":47441725,"uuid":"95378388","full_name":"KevCui/mitm-scripts","owner":"KevCui","description":"🔄 A collection of mitmproxy inline scripts","archived":false,"fork":false,"pushed_at":"2023-04-10T10:57:02.000Z","size":104,"stargazers_count":267,"open_issues_count":0,"forks_count":47,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-10T01:15:50.740Z","etag":null,"topics":["inline-script","mitm-script","mitmdump","mitmproxy","mock-server","penetration-testing","pentest-tool","proxy","script","testing","testing-tools"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KevCui.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-06-25T18:31:47.000Z","updated_at":"2025-03-24T19:31:07.000Z","dependencies_parsed_at":"2022-09-23T03:32:51.782Z","dependency_job_id":"13d47346-5995-4ffd-8a3c-481e2a93d217","html_url":"https://github.com/KevCui/mitm-scripts","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KevCui%2Fmitm-scripts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KevCui%2Fmitm-scripts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KevCui%2Fmitm-scripts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KevCui%2Fmitm-scripts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KevCui","download_url":"https://codeload.github.com/KevCui/mitm-scripts/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248137891,"owners_count":21053775,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["inline-script","mitm-script","mitmdump","mitmproxy","mock-server","penetration-testing","pentest-tool","proxy","script","testing","testing-tools"],"created_at":"2024-08-04T09:01:52.258Z","updated_at":"2025-04-10T01:15:56.206Z","avatar_url":"https://github.com/KevCui.png","language":"Python","readme":"# mitm-scripts\n\n\u003e A collection of some handy [mitmproxy](https://github.com/mitmproxy/mitmproxy) inline scripts.\n\n## Table of Contents\n\n- [Precondition](#precondition)\n- [List of Scripts](#list-of-scripts)\n  - [mitm-rewrite](#mitm-rewrite)\n  - [mitm-replace](#mitm-replace)\n  - [mitm-redirect-host](#mitm-redirect-host)\n  - [mitm-redirect-url](#mitm-redirect-url)\n  - [mitm-delay-request](#mitm-delay-request)\n  - [mitm-kill-request](#mitm-kill-request)\n  - [mitm-show-header](#mitm-show-header)\n  - [mitm-check-analytics](#mitm-check-analytics)\n  - [mitm-dump-curl](#mitm-dump-curl)\n  - [mitm-record](#mitm-record)\n  - [mitm-random-outage](#mitm-random-outage)\n\n## Precondition\n\n1. Install [mitmproxy](https://docs.mitmproxy.org/stable/overview-installation/)\n\n2. [Configure client browser or device](https://docs.mitmproxy.org/stable/overview-getting-started/#configure-your-browser-or-device): configure proxy settings and install CA on client.\n\n## List of Scripts\n\n- [mitm-rewrite](#mitm-rewrite): ./mitm-rewrite.py, ./rewrite-router.yaml\n- [mitm-replace](#mitm-replace): ./mitm-replace.py, ./replace-router.yaml\n- [mitm-redirect-host](#mitm-redirect-host): ./mitm-redirect-host.py, ./redirect-request.yaml\n- [mitm-redirect-url](#mitm-redirect-url): ./mitm-redirect-url.py, ./redirect-request.yaml\n- [mitm-delay-request](#mitm-delay-request): ./mitm-delay-request.py, ./delay-request.yaml\n- [mitm-kill-request](#mitm-kill-request): ./mitm-kill-request.py, ./kill-request.yaml\n- [mitm-show-header](#mitm-show-header): ./mitm-show-header.py, ./show-header.yaml\n- [mitm-check-analytics](#mitm-check-analytics): ./mitm-check-analytics.py, ./check-analytics.yaml\n- [mitm-dump-curl](#mitm-dump-curl): ./mitm-dump-curl.py, ./dump-curl.yaml\n- [mitm-record](#mitm-record): ./mitm-record.py, ./record-request.yaml\n- [mitm-random-outage](#mitm-random-outage): ./mitm-random-outage.py\n\nAll the scripts above can be used with `mitmproxy` and `mitmdump` command:\n\n```bash\n$ mitmproxy -s \u003cscript-name\u003e.py\n```\n\nOR\n\n```bash\n$ mitmdump -s \u003cscript-name\u003e.py\n```\n\n### mitm-rewrite\n\n`./mitm-rewrite.py` can return mock JSON response for certain target URLs.\n\n1. Run `mitmdump`:\n\n```bash\n$ mitmdump -s mitm-rewrite.py\n```\n\n2. Check `rewrite-router.yaml`, to link response JSON file, for e.g:\n\n```yaml\nhttp://example.com/pass: test_pass\nhttp://example.com/fail: test_fail\n```\n\nIt means that the response of \"http://exmaple.com/pass\" will be overwritten by the content in `./response/test_pass.json` file and the response of \"http://exmaple.com/fail\" will be overwritten by the content in `./response/test_fail.json` file.\n\n3. Edit response JSON file to put mock data you want:\n\n```json\n{\n  \"status\": 200,\n  \"header\": { ... },\n  \"content\": ...\n}\n```\n\n- status: http status code, an INT number\n- header: http response headers\n- content: response body\n\nThe changes in router yaml file and json response files will be applied **on the fly**, no need to restart proxy. Here is an example how it looks like:\n\n![mitm-rewrite-example](screenshot/mitm-rewrite-example.jpg)\n\n**[`^ back to top ^`](#mitm-scripts)**\n\n---\n\n### mitm-replace\n\n`./mitm-replace.py` can replace the specific string to another one. `replace-router.yaml` is used to link URL and yaml file in `response` folder. In the response yaml file, the matching string and result strings can be defined as a pair. Don't forget to uncomment URLs in `replace-router.yaml` and make it work on the fly!\n\n```\n$ mitmdump -s mitm-replace.py\n```\n\n**[`^ back to top ^`](#mitm-scripts)**\n\n---\n\n### mitm-redirect-host\n\n`./mitm-redirect-host.py` can redirect the request **host** of URL request to another host. The matching URL and redirect host can be defined in `redirect-requenst.yaml`. Attention: only the host part of request URL will be replaced.\n\n```bash\n$ mitmdump -s mitm-redirect-host.py\n```\n\n**[`^ back to top ^`](#mitm-scripts)**\n\n---\n\n### mitm-redirect-url\n\n`./mitm-redirect-url.py` can redirect the whole request to another URL. The matching URL and redirect URL can be defined in `redirect-request.yaml`.\n\n```bash\n$ mitmdump -s mitm-redirect-url.py\n```\n\n**[`^ back to top ^`](#mitm-scripts)**\n\n---\n\n### mitm-delay-request\n\n`./mitm-delay-request.py` can delay HTTP/HTTPS request time and response time, in order to simulate the slow network. To configure matching URL and delay time, edit `delay-request.yaml`.\n\n```bash\n$ mitmdump -s mitm-delay-request.py\n```\n\n**[`^ back to top ^`](#mitm-scripts)**\n\n---\n\n### mitm-kill-request\n\n`./mitm-kill-request.py` can kill all matching requests. The matching request methods and URls can be defined in `kill-request.yaml`.\n\n```bash\n$ mitmdump -s mitm-kill-request.py\n```\n\n**[`^ back to top ^`](#mitm-scripts)**\n\n---\n\n### mitm-show-header\n\n`./mitm-show-header.py` can print out matched request header and response header, with its value. The matching URL and header can be defined in `show-header.yaml`.\n\n```bash\n$ mitmdump -s mitm-show-header.py | grep '\u003e\u003e\\|-\u003e'\n```\n\n**[`^ back to top ^`](#mitm-scripts)**\n\n---\n\n### mitm-check-analytics\n\n`./mitm-check-analytics.py` can display real-time analytics key and value, in order to help checking analytics efficiently. To configure URL and keywords, edit `check-analytics.yaml`.\n\n1. Run mitmdump:\n\n```bash\n$ mitmdump -s mitm-check_analytics.py\n```\n\n2. Visit target web page in clients: browsers or apps. The matched analytics keyword and value will show up in terminal.\n\n**[`^ back to top ^`](#mitm-scripts)**\n\n---\n\n### mitm-dump-curl\n\n`./mitm-dump-curl` can find matching request URL and dump the request to a file in as cURL format. The matching URL and dump folder can be defined in `dump-curl.yaml`.\n\n```bash\n$ mitmdump -s mitm-dump-curl.py\n```\n\n**[`^ back to top ^`](#mitm-scripts)**\n\n---\n\n### mitm-record\n\n`./mitm-record.py` can save matching request details (request headers, request body, response headers and response body) to a specific file. The matching URl and dump folder can be defined in `record-request.yaml`.\n\n```bash\n$ mitmdump -s mitm-record.py\n```\n\n**[`^ back to top ^`](#mitm-scripts)**\n\n---\n\n### mitm-random-outage\n\n`./mitm-random-outage.py` can 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` inside the script.\n\n```bash\n$ mitmdump -s mitm-random-outage.py\n```\n\n**[`^ back to top ^`](#mitm-scripts)**\n\n---\n\n\u003ca href=\"https://www.buymeacoffee.com/kevcui\" target=\"_blank\"\u003e\u003cimg src=\"https://cdn.buymeacoffee.com/buttons/v2/default-orange.png\" alt=\"Buy Me A Coffee\" height=\"60px\" width=\"217px\"\u003e\u003c/a\u003e\n","funding_links":["https://www.buymeacoffee.com/kevcui"],"categories":["\u003ca id=\"42f9e068b6511bcbb47d6b2b273097da\"\u003e\u003c/a\u003e未分类"],"sub_categories":["\u003ca id=\"3bd67ee9f322e2c85854991c85ed6da0\"\u003e\u003c/a\u003e投毒\u0026\u0026Poisoning"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevcui%2Fmitm-scripts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkevcui%2Fmitm-scripts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevcui%2Fmitm-scripts/lists"}