首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >python mitmproxy介绍

python mitmproxy介绍

作者头像
用户5760343
发布2022-05-13 18:31:43
发布2022-05-13 18:31:43
8230
举报
文章被收录于专栏:sktjsktj

mitmproxy是一款支持HTTP(S)的中间人代理工具。不同于Fiddler2,burpsuite等类似功能工具,mitmproxy可在终端下运行。mitmproxy使用Python开发,是辅助web开发&测试,移动端调试,渗透测试的工具。 1、篡改图片的例子:

代码语言:javascript
复制
 from libmproxy.protocol.http import decoded
def response(context, flow):
 if flow.response.headers.get_first("content-type", "").startswith("image"):
 with decoded(flow.response):
 try:
 img = cStringIO.StringIO(open('freebuf.jpg', 'rb').read())
 flow.response.content = img.getvalue()
 flow.response.headers["content-type"] = ["image/jpg"]
 except:
 pass
mitmdump --script pic.py

2、保存所有图片:

代码语言:javascript
复制
!/usr/bin/mitmdump -s
from future import print_function
import os
 from urlparse import urlsplit
from libmproxy.protocol.http import decoded
def response(context, flow):
 with decoded(flow.response):
 if flow.response.headers['Content-Type'][0].startswith('image/'):
 url = urlsplit(flow.request.url)
 name = os.path.basename(url.path)
 with open(name, 'wb') as f:
 f.write(flow.response.content)
 print(name, 'written')
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-05-13,如有侵权请联系 cloudcommunity@tencent.com 删除
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档