mitmproxy是一款支持HTTP(S)的中间人代理工具。不同于Fiddler2,burpsuite等类似功能工具,mitmproxy可在终端下运行。mitmproxy使用Python开发,是辅助web开发&测试,移动端调试,渗透测试的工具。 1、篡改图片的例子:
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.py2、保存所有图片:
!/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')