MitmProxy Python API 脚本无法导入其他模块

2019-04-21 12:13:56 +08:00
 claysec

起因

我想按照 MitmProxy API 写个加密的中转转发脚本。却无奈发现无法载入其他包。

环境

mitmproxy version : 4.0.4
system: windows10 

代码

import base64
import mitmproxy.http
import pyDes
import random


# 加密
def encrypt_str(key,data):
    # 加密方法
    method = pyDes.des(key, pyDes.ECB,pad=None, padmode=pyDes.PAD_PKCS5)
    # 执行加密码
    k = method.encrypt(data)
    # 转 base64 编码并返回
    return base64.b64encode(k)


# 解密
def decrypt_str(key,data):
    method = pyDes.des(key, pyDes.ECB,pad=None, padmode=pyDes.PAD_PKCS5)
    # 对 base64 编码解码
    k = base64.b64decode(data)
    # 再执行 Des 解密并返回
    return method.decrypt(k)

class Counter:
    def __init__(self):
        pass

    def request(self, flow: mitmproxy.http.HTTPFlow):
        key = str(random.randint(10000000,99999999))
        flow.request.headers['key'] = key
        #print(key)
        #print(encrypt_str(key.encode(encoding="utf-8"),flow.request.content))

    def response(self,flow: mitmproxy.http.HTTPFlow):
        key = flow.response.headers['key']
        # print(key)
        # print(decrypt_str(key.encode(encoding="utf-8"),flow.response.content))

addons = [
    Counter()
]


备注

2241 次点击
所在节点    Python
1 条回复
claysec
2019-04-23 17:14:09 +08:00
纠正一下是 append :) 2. 若是通过官网下载的 exe 进行安装请使用第二种方法

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/557208

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX