Skip to content

petrvlcek/mitmproxy-docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Docker + mitmproxy = ❤️

mitmproxy is a very powerful interactive proxy for intercepting HTTP/HTTPS communication.

Start the proxy

  1. Clone this repository
git clone git@github.com:petrvlcek/mitmproxy-docker.git
cd mitmproxy-docker
  1. Start the Docker container and mount project root as a /data volume.
docker run --name mitmproxy --rm -d -p 8888:8080 -p 127.0.0.1:8889:8081 -v $(pwd):/data  mitmproxy/mitmproxy mitmweb --web-host 0.0.0.0 --web-port 8081 -s /data/scripts/redirect.py -s /data/scripts/modify_response.py
docker logs mitmproxy -f

or just

./run.sh
  1. Open mitmproxy's web console in the browser: http://127.0.0.1:8889

  2. Try it out

curl --proxy localhost:8888 -X GET http://old.host.com

Example scripts

Scripts can be used for intercepting requests passing throught the proxy. In the scripts directory you can find some basic examples ready for use.

You can point to the script (or multiple scripts) when starting the container and you can switch to another script any time later from the web console (in the Options). Scripts are also reloaded whenever you modify them.

  1. Redirecting requests
"""
This example shows two ways to redirect flows to another server.
"""
from mitmproxy import http

def request(flow: http.HTTPFlow) -> None:
    # pretty_host takes the "Host" header of the request into account,
    # which is useful in transparent mode where we usually only have the IP
    # otherwise.
    if flow.request.pretty_host == "original.host.com":
        flow.request.host = "new.host.com"
  1. Response modification

More examples are in mitmproxy's GitHub repository.

About

Docker + mitmproxy = ❤️

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published