Git Product home page Git Product logo

mitm-scripts's Introduction

mitm-scripts

A collection of some handy mitmproxy inline scripts.

Table of Contents

Precondition

  1. Install mitmproxy

  2. Configure client browser or device: configure proxy settings and install CA on client.

List of Scripts

All the scripts above can be used with mitmproxy and mitmdump command:

$ mitmproxy -s <script-name>.py

OR

$ mitmdump -s <script-name>.py

mitm-rewrite

./mitm-rewrite.py can return mock JSON response for certain target URLs.

  1. Run mitmdump:
$ mitmdump -s mitm-rewrite.py
  1. Check rewrite-router.yaml, to link response JSON file, for e.g:
http://example.com/pass: test_pass
http://example.com/fail: test_fail

It 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.

  1. Edit response JSON file to put mock data you want:
{
  "status": 200,
  "header": { ... },
  "content": ...
}
  • status: http status code, an INT number
  • header: http response headers
  • content: response body

The 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:

mitm-rewrite-example

^ back to top ^


mitm-replace

./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!

$ mitmdump -s mitm-replace.py

^ back to top ^


mitm-redirect-host

./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.

$ mitmdump -s mitm-redirect-host.py

^ back to top ^


mitm-redirect-url

./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.

$ mitmdump -s mitm-redirect-url.py

^ back to top ^


mitm-delay-request

./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.

$ mitmdump -s mitm-delay-request.py

^ back to top ^


mitm-kill-request

./mitm-kill-request.py can kill all matching requests. The matching request methods and URls can be defined in kill-request.yaml.

$ mitmdump -s mitm-kill-request.py

^ back to top ^


mitm-show-header

./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.

$ mitmdump -s mitm-show-header.py | grep '>>\|->'

^ back to top ^


mitm-check-analytics

./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.

  1. Run mitmdump:
$ mitmdump -s mitm-check_analytics.py
  1. Visit target web page in clients: browsers or apps. The matched analytics keyword and value will show up in terminal.

^ back to top ^


mitm-dump-curl

./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.

$ mitmdump -s mitm-dump-curl.py

^ back to top ^


mitm-record

./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.

$ mitmdump -s mitm-record.py

^ back to top ^


mitm-random-outage

./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.

$ mitmdump -s mitm-random-outage.py

^ back to top ^


Buy Me A Coffee

mitm-scripts's People

Contributors

kevcui avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

mitm-scripts's Issues

Possible bug in mitm-rewrite logic ?

Hi there,
thanks for this useful repo.

I was playing with your first example, mitm-rewrite.

I've found it useful but also either bugged or hiding a side effect that was not obvious from the Readme:

Since the behavior is implemented in response method instead of request, the original request is still forwarded to the original URL.

Using request, would fully short circuit the communication and work without hitting the real endpoint.

You can verify this is what's happening if you run mitmdump adding the -v flag.

I've noticed this because in my case, I was mocking a host that blacklisted me, so dropping all my calls. With the rule still implemented of response the behavior never worked, since I've never got any response from the server.

This is my version, in case the behavior depends on it:

17:03 $ /data/sw/mitm/mitmdump --version
Mitmproxy: 5.1.1 binary
Python:    3.7.6
OpenSSL:   OpenSSL 1.1.1f  31 Mar 2020
Platform:  Linux-5.6.7-300.fc32.x86_64-x86_64-with-fedora-32-Thirty_Two

No module named 'mitmutils'

Hi!

I'm using:

Mitmproxy: 7.0.0 binary
Python: 3.9.5

to run mitm-record.py on transparent mode, but i get this error:

No module named 'mitmutils'

Tthe module name was changed on recent version of mitmproxy?

Mimweb is not responding to requests during delay

I use web version of mimproxy so I run it like this:
mitmweb --listen-port 8866 -s mitm-delay-request.py

I configured delay-request.yaml it works perfectly. I setup quite long delay time 50s and sometime even couple of minutes.

But as delay in utils.py file use sleep function and stop whole process. And it impossible to open other response while it sleeps.

Maybe someone have any idea how overcome this, or maybe using not sleep, but something else

I've attached screenshot where you can see delay is significant (35 seconds) to open previous response, which already executed. So mitmweb not responding during this delay.

mitmweb

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.