MITM Proxy - 通过python脚本拦截&修改https内容

问题描述 投票:0回答:2

我正在尝试使用

https
拦截和修改
Mitm Proxy
内容。

使用 GUI 效果非常好,但我想使用

python
脚本。

我尝试过这个脚本:

from mitmproxy import http


def request(flow: http.HTTPFlow) -> None:
    if flow.request.pretty_url == "https://www.facebook.com/?l":
        flow.response = http.HTTPResponse.make(
            200,  # (optional) status code
            b"Hello World, this is a test",  # (optional) content
            {"Content-Type": "text/html"}  # (optional) headers
        )

def response(flow: http.HTTPFlow):

    if flow.response.raw_content and flow.request.pretty_url == "https://www.facebook.com/?lol":
        file = open(b"C:\Users\myuser\PycharmProjects\mitmProx\data.txt", "a")
        file.write(str(flow.response.) + "\n")

但是,尽管网页 GUI 上的内容是清晰的,但我截获的内容是加密的且不清晰!

有谁知道为什么我的脚本拦截加密内容而 Web GUI 打印清晰的数据?

python https proxy mitmproxy
2个回答
1
投票

看起来您想使用

response.text
response.content
,而不是
response.raw_content
。 raw_content 包含原始 compressed HTTP 消息正文,而
.content
包含未压缩版本。


0
投票

你可以发送类似启动拦截的代码吗? 我是 mitmproxt 的新手,我不明白我需要添加什么代码到你的代码中,这样它就会开始拦截

© www.soinside.com 2019 - 2024. All rights reserved.