티스토리 뷰
fiddler의 url call을 local file로 바꿔주는 기능이 필요해서 만들었다.
MITMProxy 2.0.2
-------------------- replacefile.py. ----------------
import argparse
from mitmproxy import http
from mitmproxy import ctx
from mitmproxy import log
class Replacer:
def __init__(self, url, localfile):
self.url, self.localfile = url, localfile
def request(self, flow):
if flow.request.pretty_url == self.url:
ctx.log.info(flow.request.pretty_url)
data = open(self.localfile).read()
flow.response = http.HTTPResponse.make(
200, # (optional) status code
data, # (optional) content
{"Content-Type":"text/html"} #(optional) headers
)
def start():
parser = argparse.ArgumentParser()
parser.add_argument("url", type=str)
parser.add_argument("localfile", type=str)
args = parser.parse_args()
return Replacer(args.url, args.localfile)
--------------- replace.sh. ----------------
#!/bin/bash
mitmproxy -s "./replacefile.py http://localhost/mitm.html fake.html"
$ ./replacefile.sh
##before replace
$ curl http://localhost/mitm.html --proxy 127.0.0.1:8080
mitm
##after replace
$ curl http://localhost/mitm.html --proxy 127.0.0.1:8080
fake