$ brew install mitmproxy
8080
8090
mitmproxy
프로파일 설치mitmproxy
인증서 ✅$ mitmproxy
$ mitmweb
from mitmproxy import http
from urllib.parse import urlparse
mapping = {
"https://server-api.com": "http://localhost:8080"
}
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.
for org_url, redirect_url in mapping.items():
org_parsed = urlparse(org_url)
if flow.request.pretty_host == org_parsed.hostname:
redirect_parsed = urlparse(redirect_url)
flow.request.host = redirect_parsed.hostname
if redirect_parsed.port is not None:
flow.request.port = redirect_parsed.port
else:
if redirect_parsed.scheme == "https":
flow.request.port = 443
else:
flow.request.port = 80
flow.request.scheme = redirect_parsed.scheme
redirect.py
를 위 코드처럼 작성하여 ~/.mitmproxy
폴더 안에 저장하고 mapping 부분을 적절히 변경합니다.
mapping = {
"https://server-api.com": "http://127.0.0.1:8080",
}
mapping = {
"https://server-api.com": "http://127.0.0.1:8080",
}
mapping = {
"https://server-api.com": "http://localhost:8083",
}
$ mitmweb -s ~/.mitmproxy/redirect.py --no-http2 -p 8090 --ssl-insecure
~/.mitmproxy/config.yaml
파일을 오버라이딩 하고 있어 항상 붙어서 쓸 옵션이 있다면 아래와 같이 config.yaml
파일을 생성하면 된다.# example
scripts: ["~/Downloads/redirect.py"]
http2: false
listen_port: 8090
mitmweb --no-http2 -p 8090 --ssl-insecure
https://blog.outsider.ne.kr/1514