-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathmitm-replace.py
26 lines (20 loc) · 901 Bytes
/
mitm-replace.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from mitmproxy import http
from mitmutils import utils
import re
import logging
HOME_DIR = './'
DATA_DIR = HOME_DIR + 'response/'
ROUTER_FILE = HOME_DIR + 'replace-router.yaml'
def response(flow: http.HTTPFlow) -> None:
routers = utils.readFile(ROUTER_FILE)
url = flow.request.url
if routers is not None:
for patternURL, yamlfilename in routers.items():
if re.match(patternURL, url) is not None:
yamlfile = DATA_DIR + str(yamlfilename) + '.yaml'
logging.info('>>> FOUND "' + url + '" to replace strings from "' + yamlfile + '"')
data = utils.readFile(yamlfile)
logging.info(data)
if data is not None:
for old, new in data.items():
flow.response.content = flow.response.content.replace(bytes(old.encode('utf8')), bytes(new.encode('utf8')))