0

所以我无法在 mimtproxy 中运行我自己的 python 类,以便通过生成到会话中的 sqlalchemy 流量进行存储

嗅探器.py:

from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import Session

from entities.models.Request import RequestModel
from entities.models.Response import ResponseModel
from entities.models.Session import SessionModel





class SaveTraffic:
    def __init__(self):
        self.server = ''
        self.world = ''
        self.user = ''
        self.version = 1.0
        self.session_object = None
        self.engine = create_engine('postgresql://xxx:xxx@xxx:xxx/xxx')
        self.Base = declarative_base()
        self.createSession()

        with Session(self.engine) as session:
            session.add(self.session_object)
            session.commit()
    def createSession(self):

        with Session(self.engine) as session:
            http_session = SessionModel(server=self.server, world=self.world, version=self.version, user=self.user)
            session.add(http_session)
            # We add created object to our DB
            session.flush()
            # At this point, the object  has been pushed to the DB,
            # and has been automatically assigned a unique primary key id
            session.refresh(http_session)
            # refresh updates given object in the session with its state in the DB
            # (and can also only refresh certain attributes - search for documentation)
            self.session_object = http_session

    def request(self, flow: http.HTTPFlow) -> None:

        if flow.request.headers['x-ig-client-version'] and self.session_object.version == None:
            self.session_object.version = flow.request.headers['x-ig-client-version']
            with Session(self.engine) as session:
                session.commit()

        request_url = flow.request.url
        request_cookies = None
        if flow.request.cookies:
            request_cookies = flow.request.cookies

        Request = RequestModel(method=flow.request.method, url=request_url)
        Request.headers = flow.request.headers
        Request.cookies = request_cookies
        Request.body = flow.request.content
        Request.timestamp_start = flow.request.timestamp_start
        Request.timestamp_end = flow.request.timestamp_end
        Request.size = len(flow.request.content)

        Response = ResponseModel(headers=flow.response.headers,
                                 status_code=flow.response.status_code, body=flow.response.content)
        Response.cookies = None
        if flow.response.cookies:
            Response.cookies = flow.response.cookies

        Request.response = Response
        self.session_object.requests.append([Request])
        with Session(self.engine) as session:
            session.commit()

我通过 pipx 安装了 mitmproxy 我 pipx 注入 mitmproxy 所有我的嗅探器使用的包,在这种情况下只是 sqlalchemy

之后似乎 mitmdump.exe 找不到我自己的模块命名实体

 C:\Users\qwert\.local\pipx\venvs\mitmproxy\Scripts>mitmdump.exe -s C:\Users\qwert\PycharmProjects\project\sniffer\sniffer.py

Loading script C:\Users\qwert\PycharmProjects\project\sniffer\sniffer.py
in script C:\Users\qwert\PycharmProjects\project\sniffer\sniffer.py: No module named 'entities'

Proxy server listening at http://*:8080

C:\Users\qwert\.local\pipx\venvs\mitmproxy\Scripts>

我在 mimtproxy 闲聊中问,他们告诉我

a) install mitmproxy via regular pip into a virtualenv and then use that,

b) patch pythonpath to pick up your own package.17:24
pipx inject --editable . (should work? 

我试图 pipx injection --editable c://mypackagedir 我自己的课程,但没有工作,给我包识别错误

但到目前为止似乎没有工作。我不知道怎么做a或b。

4

0 回答 0