【问题标题】:MITMPROXY make output human readable to fileMITMPROXY 使输出对文件具有可读性
【发布时间】:2018-05-07 04:27:36
【问题描述】:

我的系统:

Ubuntu 16.04
Mitmproxy version 3.0.4
Python version 3.5.2

我已经成功地在我的服务器上安装了来自:docs.mitmproxy.orgmitmproxy。但是现在我很困惑如何将日志 mitmproxy 保存到文件中?我尝试使用mitmdump --mode transparent --showhost -p 9001 -w output_file

当我打开 output_file 时,它不是人类可读的。我阅读了文档并尝试了 mitmproxy 的 Github 中的脚本,但没有任何线索。

有人知道如何将日志 mitmproxy 保存到文件中,但人类可读吗?
谢谢!

【问题讨论】:

    标签: proxy mitmproxy


    【解决方案1】:

    您可能已经注意到,mitmproxy 以二进制格式生成流。如果您想以人类可读的格式保存流,您可以在运行 mitmproxy 时传递一个脚本来执行此操作。

    save.py

    from mitmproxy.net.http.http1.assemble import assemble_request, assemble_response
    
    f = open('/tmp/test/output.txt', 'w')
    
    def response(flow):
        f.write(assemble_request(flow.request).decode('utf-8'))
    

    现在运行mitmproxy -s save.py,输出将以人类可读的格式写入output.txt

    请注意响应,因为它们可能包含大量二进制数据。但如果您确实想以人类可读的格式编写响应,则可以将 f.write(assemble_response(flow.response).decode('utf-8', 'replace')) 添加到脚本中。

    脚本的示例输出:

    ❯❯ tail -f output.txt
    GET / HTTP/1.1
    Host: example.com
    User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:77.0) Gecko/20100101 Firefox/77.0
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
    Accept-Language: en-US,en;q=0.5
    Accept-Encoding: gzip, deflate
    Connection: keep-alive
    Upgrade-Insecure-Requests: 1
    If-Modified-Since: Thu, 17 Oct 2019 07:18:26 GMT
    If-None-Match: "3147526947"
    Cache-Control: max-age=0
    

    【讨论】:

      猜你喜欢
      • 2014-12-24
      • 1970-01-01
      • 1970-01-01
      • 2022-11-11
      • 2017-11-07
      • 2017-04-21
      • 1970-01-01
      • 2011-08-02
      • 2013-10-01
      相关资源
      最近更新 更多