Skip to content

Latest commit

 

History

History
70 lines (54 loc) · 2.22 KB

mitm-proxy.md

File metadata and controls

70 lines (54 loc) · 2.22 KB

MITM Proxy

  • partial solution
  • revised solution
    • mitmproxy -p 8081 -s ./replace.py --no-http2
      • port 8081
      • use replace.py script
      • don't use http2 for tls (to make less secure so it can be rewritten)
    • configuration
      • in firefox about:profiles create a new profile
      • with mitmproxy running go to http://mitm.it/
      • download cert and install with directions
      • (will only work for that profile in firefox so safest way to install)

use replace.py config

http-server . -p 9000 & mitmproxy -p 8081 -s ./replace.py --no-http2 --ssl-insecure

replace.py

'''Redirect HTTP requests to another server.'''
from mitmproxy import http
from mitmproxy import ctx

class MyConfig:
    def response(self, flow):
        h = flow.request.headers
        origin = h['origin'] if 'origin' in h else '*'
        flow.response.headers['Access-Control-Allow-Origin'] = origin

    def request(self, flow: http.HTTPFlow) -> None:
        ctx.log.info('>> ' + flow.request.pretty_host)

        if flow.request.path == 'path/to/rewrite':
            flow.request.host = 'localhost'
            flow.request.port = 9000
            flow.request.scheme = 'http'
            flow.request.path = '/proxy-data.json'
 

        if flow.request.method == 'OPTIONS':
            h = flow.request.headers
            origin = h['origin'] if 'origin' in h else '*'
            ctx.log.info('++ origin:' + origin);
            flow.response = http.HTTPResponse.make(200, b'', {
                'access-control-allow-credentials': 'true',
                'access-control-allow-origin': origin,
                'Access-Control-Allow-Methods': 'GET',
                'Access-Control-Allow-Headers': '*',
                'Access-Control-Max-Age': '1800',
                'Content-Type': 'application/json'
            })

addons = [
    MyConfig()
]

Alternatives