简体   繁体   English

Mitmproxy:捕获 HTTP 请求/响应标头?

[英]Mitmproxy: Capture HTTP request / response headers?

I'm following the code from the following question (reproduced below):我正在关注以下问题的代码(转载如下):

def response(flow):
    print("")
    print("="*50)
    print(flow.request.method + " " + flow.request.path + " " + flow.request.http_version)

    print("-"*25 + " request headers " + "-"*25)
    for k, v in flow.request.headers.items():
        print("%-30s: %s" % (k.upper(), v))

    print("-"*25 + " response headers " + "-"*25)
    for k, v in flow.response.headers.items():
        print("%-30s: %s" % (k.upper(), v))

    print("-"*25 + " body (first 100 bytes) " + "-"*25)
    print(flow.request.content[0:100])

I have trouble understanding where, when using mitmproxy, you find the flow variable.我无法理解在使用 mitmproxy 时在哪里可以找到flow变量。 How do you connect mitmproxy such that you could receive that flow of requests?你如何连接 mitmproxy 以便你可以接收请求流?

I was wrong.我错了。 It looks like you pass in the script with the -s flag Something like:看起来你在脚本中传递了-s标志是这样的:

mitmproxy -s myscript.py

Basically you pass in the file name and mitmproxy will load it and call the request() function, passing in the flow variable you mentioned.基本上你传入文件名,mitmproxy 将加载它并调用request() function,传入你提到的流变量。

I think reading these two pages might help.我认为阅读这两页可能会有所帮助。 Note that they have different kinds of add-ons.请注意,它们有不同种类的附加组件。 I think the simple classless request() function you have would make it a 'script' type.我认为您拥有的简单无类request() function 会使它成为“脚本”类型。

https://docs.mitmproxy.org/stable/addons-overview/ https://docs.mitmproxy.org/stable/addons-overview/

https://docs.mitmproxy.org/stable/addons-scripting/ https://docs.mitmproxy.org/stable/addons-scripting/

There are also more examples in the docs.文档中还有更多示例。 Also, I've found this GitHub repo to be helpful for examples:此外,我发现这个 GitHub 回购协议对示例很有帮助:

https://github.com/KevCui/mitm-scripts https://github.com/KevCui/mitm-scripts

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM