我正在尝试实现一个 mitmproxy 插件脚本,以篡改特定的 https 数据包数据 - 这是通过 mitmproxy 的证书注入动态解密的方式。
我正在关注这个Stack Overflow对一个相当相似的问题的回答,以及mitmproxy 文档中的本教程,但到目前为止没有任何成功。
我要定位的数据包来自https://api.example.com/api/v1/user/info
.
现在这是我编写的用于篡改此数据包数据的整个 python 脚本,基于上述来源:
from mitmproxy import ctx
class RespModif:
def _init_(self):
self.num = 0
def response(self, flow):
ctx.log.info("RespModif triggered")
if flow.request.url == "https://api.example.com/api/v1/user/info":
ctx.log.info("RespModif triggered -- In the if statement")
self.num = self.num + 1
ctx.log.info("RespModif -- Proceeded to %d response modifications "
"of the targetted URLs" % self.num)
addons = [
RespModif()
]
查看事件日志,我可以看到第一个日志信息(“ RespModif 触发”)正在报告到日志中,但其他两个日志信息(从if
语句内部完成)从未报告,这意味着我认为if
语句永远不会成功。
我的代码有问题吗?
我怎样才能让if
声明成功?
PS:目标 URL 绝对正确,而且我将它与来自客户端应用程序的注册帐户一起使用,该应用程序正在被 mitmproxy 嗅探。