mitmproxy第一次尝试-猿人学第九题

启动

mitmdump -s http_proxy.py -p 9000 

替换js代码

# -*- coding: utf-8 -*-

import re

main_url = 'http://match.yuanrenxue.com/match/9'  # 9
js_url = 'http://match.yuanrenxue.com/static/match/safety/match9/udc.js'
# http://match.yuanrenxue.com/static/match/safety/match9/udc.js


def response(flow):
    if flow.request.url.startswith(main_url):
        # if(flow.response.text.startswith('<body>')):
        #     file_path = "C:/Users/natpacket/Desktop/js/yuanrenxue/9/replace_9.html"
        #     with open(file=file_path, mode='r', encoding='utf-8') as f:
        #         replace_js = f.read()
        #     flow.response.text = replace_js
        #     print('debugger替换成功')
        if (flow.response.text.startswith('<body>')):
            # file_path = "C:/Users/natpacket/Desktop/js/yuanrenxue/9/replace_9.html"
            # with open(file=file_path, mode='r', encoding='utf-8') as f:
            #     replace_js = f.read()
            # flow.response.text = replace_js
            # print('debugger替换成功')
            replace_str = r'location.reload\(\)'
            replace_str1 = r'setInterval'
            replace_str2 = r'}\[[\s\S]*?\)\);'
            flow.response.text = re.sub(replace_str, '', flow.response.text)
            flow.response.text = re.sub(replace_str1,
                                        'function setInterval(a,b){console.log("正在调用setInterval");};setInterval',
                                        flow.response.text)
            # flow.response.text = re.sub(replace_str2,
            #                     "});",
            #                     flow.response.text)
    if flow.request.url.startswith(js_url):
        file_path = "C:/Users/natpacket/Desktop/js/udc.js"
        with open(file=file_path, mode='r', encoding='utf-8') as f:
            replace_js = f.read()
        flow.response.text = replace_js+"console.log('当前时间戳',Math.round(new Date().getTime()/1000).toString());var _decrypt = decrypt;decrypt = function(a){console.log('时间戳',a);var res =  _decrypt(a);console.log('结果',res);return res};"
        # flow.response.text="test"
        print('js注入成功')

posted @ 2021-06-03 15:06  SirPi  阅读(159)  评论(0编辑  收藏  举报