mitmproxy无界面抓包软件的安装与使用

1,原理,和Fiddler一样,先自己搭一个服务器,开启端口
windows或手机开启代理,流量通过mitmproxy,截获数据

2,安装(用python默认的下载源可以)

cmd输入:pip install mitmproxy==5.0.1
提示:ERROR: mitmproxy 5.3.0 requires kaitaistruct<0.10,>=0.7, which is not installed.
可以先卸载pip uninstall mitmproxy
然后pip install mitmproxy kaitaistruct==0.7
pip install mitmproxy==5.0.1

3,使用
windows在小娜处输入:网络代理设置
地址框输入:http=127.0.0.1:8889;https=127.0.0.1:8889 端口框不输入

cmd输入:mitmdump -s mit.py -p 8889 --ssl-insecure

打开http://mitm.it/安装证书

mit.py代码如下:

import json

def response(flow):
    if 'wechat.zhifeishengwu.com/wx/HandlerSubscribe.ashx?act=User' in flow.request.url:
        with open("1.txt","a",encoding='UTF-8') as f:
            print(flow.request.headers)
            print(flow.request.headers['Cookie'])
            print(json.loads(flow.response.text))
            f.write("\n")

这里使用python自带写文件功能,当然你也可以使用管道

mitmdump -s mit.py -p 8889 --ssl-insecure | python extract.py

教程自己去看:《Python爬虫开发:从入门到实战(微课版)》谢乾坤

4,错误解决:

Certificate verification error for watson.telemetry.microsoft.com: unable to get local issuer certificate (errno: 20, depth: 1)

--ssl-insecure 解决


Cannot establish TLS with client (sni: wechat.zhifeishengwu.com): TlsException("(-1, 'Unexpected EOF')",)

打开http://mitm.it/安装证书

下面是测试抓微信读书的使用代码

import json
import time

def getCurrentStrTime():
    return time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))

def response(flow):
    # if 'https://question-zh.hortor.net/question/bat/findQuiz' in flow.request.url:
    #     print(json.loads(flow.request.content))
    #
    # if 'https://question-zh.hortor.net/question/bat/choose' in flow.request.url:
    #     print(json.loads(flow.request.content))



    if 'weread' in flow.request.url:
        print(flow.response.headers)
        print(flow.request.content)
        # print(flow.request.headers['Cookie'])


    if 'wechat.zhifeishengwu.com/wx/HandlerSubscribe.ashx?act=User' in flow.request.url:
        with open("1.txt","a",encoding='UTF-8') as f:
            cookie = flow.request.headers['Cookie']
            if 'ASP.NET_SessionId=' in cookie:
                f.write(getCurrentStrTime()+'\n')
                f.write(cookie+'\n')

下面是测试抓Https的包

import json
import time
from mitmproxy import ctx

def getCurrentStrTime():
    return time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))

def request(flow):
    # 获取请求对象
    request = flow.request
    # 实例化输出类
    info = ctx.log.info
    # 打印请求的url
    info(request.url)
    # 打印请求方法
    info(request.method)
    # 打印host头
    info(request.host)
    # 打印请求端口
    info(str(request.port))
    # 打印所有请求头部
    info(str(request.headers))
    # 打印cookie头
    info(str(request.cookies))

# 所有服务器响应的数据包都会被这个方法处理
# 所谓的处理,我们这里只是打印一下一些项
def response(flow):


    if "c1.5yyz.com/UserApi?" in flow.request.url:
        # 获取响应对象
        response = flow.response
        # 实例化输出类
        info = ctx.log.info
        # 打印响应码
        info(str(response.status_code))
        # 打印所有头部
        info(str(response.headers))
        # 打印cookie头部
        info(str(response.cookies))
        # 打印响应报文内容
        info(str(response.text))
    

    if 'weread' in flow.request.url:
        print(flow.response.headers)
        print(flow.request.content)
        # print(flow.request.headers['Cookie'])


    if 'c1.5yyz.com/UserApi?' in flow.request.url:
        with open("1.txt","a",encoding='UTF-8') as f:
            f.write(flow.request)
            #cookie = flow.request.headers['Cookie']
            #f.write(getCurrentStrTime()+'\n')
            #f.write(cookie+'\n')


#def response(flow):
    # if 'https://question-zh.hortor.net/question/bat/findQuiz' in flow.request.url:
    #     print(json.loads(flow.request.content))
    #
    # if 'https://question-zh.hortor.net/question/bat/choose' in flow.request.url:
    #     print(json.loads(flow.request.content))
    

### 使用 mitmproxy 对橙光游戏进行抓包 为了成功使用 `mitmproxy` 抓取橙光游戏的数据流量,需确保设备配置正确并按照特定流程操作。 #### 设备准备网络设置 确保用于测试的移动设备连接到同一Wi-Fi网络下,并将该Wi-Fi的手动代理服务器地址设为运行 `mitmproxy` 的电脑IP地址。对于安卓或iOS设备,在无线局域网设置里找到HTTP代理选项,输入主机名(即PC IP)和端口8080[^1]。 #### 启动 mitmproxy 并加载脚本 通过命令行启动工具,可以附加自定义Python脚本来处理拦截下来的请求响应数据流: ```bash mitmproxy -s path/to/your/mitmproxy_script.py ``` 此命令会打开图形界面版本;如果偏好无窗口模式,则可替换为 `mitmdump` 或者 `mitmweb` 来分别获得命令行版或是基于Web浏览器管理面板的形式。 #### 安装证书以便解密HTTPS通信 由于大多数现代应用都采用加密传输协议,因此还需要安装由 `mitmproxy` 自动生成的安全证书至目标手机上,这样才能正常查看HTTPS内容。访问 http://mitm.it/ ,下载对应平台适用格式(.cer,.crt),然后依据提示完成信任CA根证书的过程。 #### 开始监控指定域名下的活动 一旦上述准备工作就绪之后,就可以针对具体的游戏服务端API接口实施更细致化的过滤条件了。比如只关心来自某个子域(`*.chengguang.com`)的所有GET/POST方法调用了: ```python def request(flow): if "chengguang.com" in flow.request.pretty_host and (flow.request.method == "GET" or flow.request.method == "POST"): print(f"[+] {flow.request.method} Request to: {flow.request.url}") ``` 这段简单的脚本能够帮助识别出哪些URL路径被频繁访问以及它们携带了什么样的参数信息等有用情报。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值