今天主要讲解如何使用mitmdump配合python来实现抓包,修改请求头和响应内容,目的是希望各位千万别只看网站是不是加了https就安全了,并不是使用了HTTPS,浏览器显示个绿色的小锁就代表网站是安全的,当黑客通过MITM中间人攻击,只要有权限,是可以随意篡改请求和响应头或响应内容的。
增加请求头
def response(flow): flow.response.headers["newheader"] = "foo"
改写请求参数
实现,改写百度的搜索关键词,不管输入任何关键词都替换成网易云
from mitmproxy import ctxdef request(flow): # 忽略非百度搜索地址 if flow.request.host != "www.baidu.com" or not flow.request.path.startswith("/s"): return # 确认请求参数中有搜索词 if "wd" not in flow.request.query.keys(): return # 替换搜索词为“网易云” flow.request.query.set_all("wd", ["网易云"]) flow.request.host http请求host
效果

关于流量请求的一些方法
- flow.request.method请求方法
- flow.request.scheme请求协议
- flow.request.url请求URL链接
- flow.request.query请求URL查询参数
- flow.request.path请求URL路径
- flow.request.urlencoded_form请求POST数据
- flow.response.status_code HTTP响应状态码
- flow.response.headers HTTP响应头信息
- flow.response.get_text HTTP响应内容
改写响应信息
def response(flow): # 忽略非百度搜索地址 if flow.request.host != "www.baidu.com": return # 将响应中百度的 logo“”替换为“谷歌的 logo” text = flow.response.get_text() text = text.replace("//www.baidu.com/img/bd_logo1.png", "https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_120x44dp.png") flow.response.set_text(text)
效果

爬取得到APP电子书存入MongoDB(来源python爬虫)
import jsonimport pymongofrom mitmproxy import ctxclient = pymongo.MongoClient('localhost')db = client['igetget']collection = db['books']def response(flow): global collection url = 'https://dedao.igetget.com/v3/discover/bookList' if flow.request.url.startswith(url): text = flow.response.text data = json.loads(text) books = data.get('c').get('list') for book in books: data = { 'title': book.get('operating_title'), 'cover': book.get('cover'), 'summary': book.get('other_share_summary'), 'price': book.get('price') } ctx.log.info(str(data)) collection.insert(data)
本文最后更新于2018年11月20日,已超过 1 年没有更新,如果文章内容或图片资源失效,请留言xichengyouju#163.com(#换成@)反馈,我们会及时处理,谢谢!
未经允许不得转载:作者:知道君, 转载或复制请以 超链接形式 并注明出处 夏末浅笑。
原文地址:《并不是有了HTTPS,浏览器显示绿色的小锁就安全了》 发布于2018-11-20
评论 抢沙发