前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python mitmproxy浏览器抓包 脚本

python mitmproxy浏览器抓包 脚本

作者头像
用户5760343
发布2022-05-13 16:55:33
9790
发布2022-05-13 16:55:33
举报
文章被收录于专栏:sktj

GIT:git clone https://github.com/huangantai/GetHttpHeaders.git

运行结果:

通过getId.py来过滤浏览器请求,可以通过getId.py自定义处理逻辑,修改后的脚本实时运行不用重启mitmproxy,浏览器事件流程:https://github.com/mitmproxy/mitmproxy/blob/master/examples/addons/events.py

启动mitmproxy时将浏览器安装代理,关闭时浏览器删除代理,ips.txt中定义不需要经过代理的域名

代码语言:javascript
复制
from mitmproxy import ctx
 from mitmproxy import http
 from mitmproxy.proxy.protocol import Layer
 import winreg
 import os
 from mitmproxy.connections import ServerConnection
class RequestId:
 def running(self):
 key = winreg.OpenKey(winreg.HKEY_CURRENT_USER,r"Software\Microsoft\Windows\CurrentVersion\Internet Settings",access=winreg.KEY_ALL_ACCESS)
 winreg.SetValueEx(key,"ProxyEnable", 0,winreg.REG_DWORD,1)
 winreg.SetValueEx(key, "ProxyServer", 0,winreg.REG_SZ,"127.0.0.1:8080")
 a=os.path.dirname(sys.argv[0])
 b=os.path.join(a,"ips.txt")
 with open(b) as ips:
 iplist=ips.readlines()
 ipstring=';'.join(iplist)
 winreg.SetValueEx(key, "ProxyOverride", 0,winreg.REG_SZ,ipstring)
def serverdisconnect(self, conn:ServerConnection):
 ctx.log.info("--"*30)
def response(self,flow: http.HTTPFlow) -> None:
for a in flow.request.headers:
print("{}:{}".format(a,flow.request.headers[a]))
if "requestId" in flow.response.headers:
 ctx.log.info("url:{}{}".format(flow.request.host,flow.request.path))
 ctx.log.warn("requestId:{}".format(flow.response.headers["requestId"]))
def done(self):
donekey = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
r"Software\Microsoft\Windows\CurrentVersion\Internet Settings",
access=winreg.KEY_ALL_ACCESS)
winreg.SetValueEx(donekey, "ProxyEnable", 0, winreg.REG_DWORD, 0)
addons = [
 RequestId()
 ]
import signal
 import sys
 import win32api
 def on_close(sig):
 donekey = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
 r"Software\Microsoft\Windows\CurrentVersion\Internet Settings",
 access=winreg.KEY_ALL_ACCESS)
 winreg.SetValueEx(donekey, "ProxyEnable", 0, winreg.REG_DWORD, 0)
 win32api.SetConsoleCtrlHandler(on_close, True)
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-05-13,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • GIT:git clone https://github.com/huangantai/GetHttpHeaders.git
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档