Beispiel #1
0
def start_proxy():
    opts = options.Options(listen_host=PROXY_LISTEN_HOST,
                           listen_port=PROXY_LISTEN_PORT,
                           confdir=os.path.join(BASE_DIR, "ssl"),
                           ssl_insecure=True)
    opts.add_option("body_size_limit", int, 0, "")
    pconf = ProxyConfig(opts)

    #There is no current event loop in thread 'Thread-1'错误
    #解决方法:到mitmproxy的master.py修改Master类的init函数,
    # loop = asyncio.new_event_loop()
    # asyncio.set_event_loop(loop)
    # self.should_exit = threading.Event()
    # self.channel = controller.Channel(
    #     self,
    #     loop,
    #     self.should_exit,
    # )
    try:
        m = DumpMaster(opts, with_termlog=False, with_dumper=False)
        m.server = ProxyServer(pconf)
        m.addons.add(Capture())
        print("监听地址:{},监听端口:{}".format(PROXY_LISTEN_HOST, PROXY_LISTEN_PORT))
        m.run()
    except:
        pass
class Proxy(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        opts = options.Options(listen_host='127.0.0.1', listen_port=8080)
        opts.add_option("body_size_limit", int, 0, "")

        pconf = proxy.config.ProxyConfig(opts)

        self.m = DumpMaster(None, with_termlog=False, with_dumper=False)
        self.m.server = proxy.server.ProxyServer(pconf)
        if self.m.server.channel.loop.is_closed():
            self.m.server.channel.loop = asyncio.new_event_loop()
        self.m.addons.add(Github_Proxy())
        self.m.addons.add(wsgiapp.WSGIApp(app, "gitty.local", 443))

    def run(self):
        try:
            asyncio.set_event_loop(self.m.server.channel.loop)
            self.m.run()
        except Exception as e:
            print(e)

    def stop_proxy(self):
        try:
            self.m.shutdown()
        except Exception as e:
            print(e)
Beispiel #3
0
def capture():
    from mitmproxy.options import Options
    from mitmproxy.proxy.config import ProxyConfig
    from mitmproxy.proxy.server import ProxyServer
    from mitmproxy.tools.dump import DumpMaster
    import asyncio
    import signal

    try:
        options = Options(listen_host="0.0.0.0", listen_port=8889, http2=True)
        config = ProxyConfig(options)
        global m
        m = DumpMaster(options, with_termlog=False, with_dumper=False)
        m.server = ProxyServer(config)
        m.addons.add(Addon())
        loop = asyncio.get_event_loop()
        try:
            loop.add_signal_handler(signal.SIGINT,
                                    getattr(m, "prompt_for_exit", m.shutdown))
            loop.add_signal_handler(signal.SIGTERM, m.shutdown)
        except NotImplementedError:
            pass

        async def wakeup():
            while True:
                await asyncio.sleep(0.2)

        asyncio.ensure_future(wakeup())
        m.run()
    except KeyboardInterrupt:
        pressAnyKeyExitWithDisableProxy()
    except TypeError:
        pass
    except Exception as e:
        print("抓包模块出错:", e)
Beispiel #4
0
def runSolitude(solitudeProcess):
    # This is to prevent connection errors as the it seems like the web app tries to connect to the db before it's been created
    time.sleep(30)
    # We do this import here because it loads the db on import before the settings from the command line arg can be configured
    from solitude import Solitude
    solitudeAddon = Solitude()

    if os.getenv("DB_HOSTNAME") == 'database':
        opts = options.Options(listen_host='0.0.0.0',
                               listen_port=8080,
                               mode='transparent')
    else:
        opts = options.Options(listen_host='0.0.0.0',
                               listen_port=8080,
                               ignore_hosts=['safebrowsing.googleapis.com'])
    pconf = proxy.config.ProxyConfig(opts)
    m = DumpMaster(opts)
    m.server = proxy.server.ProxyServer(pconf)
    m.addons.add(solitudeAddon)

    try:
        m.run()
    except KeyboardInterrupt:
        solitudeProcess.kill()
        m.shutdown()
Beispiel #5
0
class ProxyWrapper(threading.Thread):
    """Runs an mitmproxy in a separate thread."""
    def __init__(self, host: str, port: int, **kwargs: typing.Any) -> None:
        self.host = host
        self.port = port
        self.options = kwargs
        super().__init__()
        self.notify = RunNotify()

    def run(self) -> None:
        # mitmproxy uses asyncio internally but the default loop policy
        # will only create event loops for the main thread, create one
        # as part of the thread startup
        asyncio.set_event_loop(asyncio.new_event_loop())
        opts = options.Options(listen_host=self.host,
                               listen_port=self.port,
                               **self.options)
        pconf = proxy.config.ProxyConfig(opts)

        self.master = DumpMaster(opts)
        self.master.server = proxy.server.ProxyServer(pconf)
        self.master.addons.add(self.notify)
        self.master.run()

    def join(self, timeout: float = None) -> None:
        self.master.shutdown()
        super().join()
Beispiel #6
0
 def run(self):
     try:
         self.logger.info("Starting Proxy. Press Ctrl+C to Stop")
         DumpMaster.run(self)
     except KeyboardInterrupt:
         self.logger.info("Stopping Proxy Server")
         self.shutdown()
Beispiel #7
0
def _run_proxy(event, namespace, service, listen_host, listen_port, verbose):
    # Run mitmproxy as a reverse-proxy to the Kubernetes ApiServer under the
    # subpath /api/v1/namespaces/{namespace}/services/{service}/proxy. See
    # https://k8s.io/docs/tasks/administer-cluster/access-cluster-services.
    client = kubernetes.config.new_client_from_config()
    prefix = f"/api/v1/namespaces/{namespace}/services/{service}/proxy"
    options = Options(listen_host=listen_host,
                      listen_port=listen_port,
                      mode=f"reverse:{client.configuration.host}")
    master = DumpMaster(options, with_termlog=verbose, with_dumper=verbose)
    options.keep_host_header = True
    options.ssl_insecure = True
    with NamedTemporaryFile() as cert_file:
        # If Kubernetes client has a client-certificate set up, then configure
        # mitmproxy to use it. Kubernetes stores the cert and key in separate
        # files, while mitmproxy expects a single file. So append the two file
        # contents into a new file and pass it to mitmproxy.
        if client.configuration.cert_file and client.configuration.key_file:
            with open(client.configuration.cert_file, "rb") as f:
                cert_file.write(f.read())
            with open(client.configuration.key_file, "rb") as f:
                cert_file.write(f.read())
            cert_file.flush()
            options.client_certs = cert_file.name
        master.server = ProxyServer(ProxyConfig(options))
        master.addons.add(_Addon(client, prefix))
        event.set()  # Port is bound by this time, unblock parent process.
        master.run()
Beispiel #8
0
    def runProxyServerOnce(codeRewriter, pathTracer, networkErrorTracer,
                           resultQueue):
        from mitmproxy import proxy, options
        from mitmproxy.tools.dump import DumpMaster
        import mitmproxy.exceptions

        loop = asyncio.new_event_loop()
        asyncio.set_event_loop(loop)

        # We have a retry mechanism here because it may take multiple attempts to get a free port
        while True:
            try:
                port = ProxyProcess.findFreePort()
                opts = options.Options(listen_port=port,
                                       http2=False,
                                       ssl_insecure=True)
                pconf = proxy.config.ProxyConfig(opts)

                m = DumpMaster(opts, with_termlog=False, with_dumper=False)
                m.server = proxy.server.ProxyServer(pconf)
                m.addons.add(codeRewriter)
                m.addons.add(pathTracer)
                m.addons.add(networkErrorTracer)
                break
            except mitmproxy.exceptions.ServerException:
                getLogger().warning(
                    f"Had to restart the mitmproxy due to an exception: {traceback.format_exc()}"
                )

        resultQueue.put(port)
        m.run()
Beispiel #9
0
class minecraftProxy(QThread):

    def __init__(self, doSkinFix, doSoundFix, doCapeFix, loop):
        super().__init__()
        self.doSkinFix = doSkinFix
        self.doCapeFix = doCapeFix
        self.doSoundFix = doSoundFix
        self.loop = loop

    def getHeader(self):
        class AddHeader:
            def __init__(self, parent):
                self.parent = parent

            def request(self, flow):
                if flow.request.pretty_host == "s3.amazonaws.com" or flow.request.pretty_host == "skins.minecraft.net" or flow.request.pretty_host == "www.minecraft.net":

                    if self.parent.doSoundFix:
                        if flow.request.path.__contains__("MinecraftResources") or flow.request.path.__contains__("/resources/"):
                            flow.request.host = "resourceproxy.pymcl.net"
                            flow.request.path = "/MinecraftResources/"

                    if self.parent.doSkinFix:
                        if flow.request.path.__contains__("MinecraftSkins"):
                            flow.request.host = "resourceproxy.pymcl.net"
                            flow.request.path = "/skinapi.php?user="******"/")[2].split(".")[0]

                    if self.parent.doCapeFix:
                        if flow.request.path.__contains__("MinecraftCloaks"):
                            flow.request.host = "resourceproxy.pymcl.net"
                            flow.request.path = "/capeapi.php?user="******"/")[2].split(".")[0]

                if flow.request.pretty_host.__contains__("minecraft.net"):
                    if self.parent.doSkinFix:
                        if flow.request.path.__contains__("skin"):
                            flow.request.host = "resourceproxy.pymcl.net"
                            flow.request.path = "/skinapi.php?user="******"/")[2].split(".")[0]

                    if self.parent.doCapeFix:
                        if flow.request.path.__contains__("cloak"):
                            flow.request.host = "resourceproxy.pymcl.net"
                            flow.request.path = "/capeapi.php?user="******"=")[1]

        return AddHeader(self)

    def run(self):
        asyncio.set_event_loop(self.loop)
        myaddon = self.getHeader()
        opts = options.Options(listen_host="0.0.0.0", listen_port=25560)
        pconf = proxy.config.ProxyConfig(opts)
        self.m = DumpMaster(opts)
        self.m.server = proxy.server.ProxyServer(pconf)
        self.m.addons.add(myaddon)

        self.m.run()

    def stop(self):
        self.m.shutdown()
Beispiel #10
0
def start():
    myaddon = Joker()
    opts = options.Options(listen_port=8080)
    pconf = proxy.config.ProxyConfig(opts)
    m = DumpMaster(opts)
    m.server = proxy.server.ProxyServer(pconf)
    m.addons.add(myaddon)
    try:
        m.run()
    except KeyboardInterrupt:
        m.shutdown()
Beispiel #11
0
def l11ll_wcplus_():
    l1ll1llll11_wcplus_ = l1lll111l1l_wcplus_()
    opts = options.Options(listen_host='0.0.0.0', listen_port=8080)
    l1ll1lll1ll_wcplus_ = proxy.config.ProxyConfig(opts)
    m = DumpMaster(opts)
    m.server = proxy.server.ProxyServer(l1ll1lll1ll_wcplus_)
    m.addons.add(l1ll1llll11_wcplus_)
    try:
        m.run()
    except KeyboardInterrupt:
        print('')
        m.shutdown()
Beispiel #12
0
def start():
    myaddon = AddHeader()
    opts = options.Options(listen_host='127.0.0.1', listen_port=8888)
    pconf = proxy.config.ProxyConfig(opts)
    m = DumpMaster(opts)
    m.server = proxy.server.ProxyServer(pconf)
    m.addons.add(myaddon)

    try:
        m.run()
    except KeyboardInterrupt:
        m.shutdown()
Beispiel #13
0
def start(url, output):
    webcopy = WebCopy(url, output)
    opts = options.Options()
    pconf = proxy.config.ProxyConfig(opts)
    m = DumpMaster(opts)
    m.server = proxy.server.ProxyServer(pconf)
    m.addons.add(webcopy)

    try:
        m.run()
    except KeyboardInterrupt:
        m.shutdown()
Beispiel #14
0
def start_proxy():
    self_addon = SelfAddon()
    opts = options.Options(listen_host='0.0.0.0', listen_port=8080)
    pconf = proxy.config.ProxyConfig(opts)
    m = DumpMaster(opts)
    m.server = proxy.server.ProxyServer(pconf)
    m.addons.add(self_addon)
    try:
        m.run()
    except KeyboardInterrupt:
        print('')
        m.shutdown()
Beispiel #15
0
def proxyMaster():
    flow_instance = ParseFlow()
    opts = options.Options(listen_host='0.0.0.0', listen_port=8080)
    proxy_config = proxy.config.ProxyConfig(opts)
    m = DumpMaster(opts)
    m.server = proxy.server.ProxyServer(proxy_config)
    m.addons.add(flow_instance)
    try:
        m.run()
    except KeyboardInterrupt:
        print('')
        m.shutdown()
Beispiel #16
0
def runProxy(port):
    from mitmproxy import proxy, options

    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)

    opts = options.Options(listen_port=port)
    pconf = proxy.config.ProxyConfig(opts)

    m = DumpMaster(opts, with_termlog=False, with_dumper=False)
    m.server = proxy.server.ProxyServer(pconf)

    m.run()
Beispiel #17
0
def start():
    #asyncio.set_event_loop()
    myaddon = SniffWebSocket()  #AddHeader()
    opts = options.Options(listen_host=proxy_ip, listen_port=proxy_port)
    pconf = proxy.config.ProxyConfig(opts)
    m = DumpMaster(opts)
    m.server = proxy.server.ProxyServer(pconf)
    m.addons.add(myaddon)

    try:
        m.run()
    except KeyboardInterrupt:
        m.shutdown()
        def _wrapper(url_list):
            asyncio.set_event_loop(asyncio.new_event_loop())
            opts = options.Options(listen_host=PROXY_HOST,
                                   listen_port=PROXY_PORT)
            opts.add_option('body_size_limit', int, 0, '')
            pconf = proxy.config.ProxyConfig(opts)

            dump_master = DumpMaster(None,
                                     with_termlog=False,
                                     with_dumper=False)
            dump_master.server = proxy.server.ProxyServer(pconf)
            dump_master.addons.add(_InjectScripts(url_list))
            dump_master.run()
def start():

    myaddon = Granville()
    opts = options.Options(ignore_hosts='^(?![0-9\\.]+:)(?!([^\\.:]+\\.)*google\\.com:)')
    pconf = proxy.config.ProxyConfig(opts)
    m = DumpMaster(opts)
    m.server = proxy.server.ProxyServer(pconf)
    m.addons.add(myaddon)

    try:
        m.run()
    except KeyboardInterrupt:
        m.shutdown()
Beispiel #20
0
def run():
    myaddon = Myaddon()
    port = 8080
    opts = options.Options(listen_port=port)
    pconf = proxy.config.ProxyConfig(opts)
    m = DumpMaster(opts)
    m.server = proxy.server.ProxyServer(pconf)
    m.addons.add(myaddon)

    print(f'启动监听 {port} 端口')
    try:
        m.run()
    except KeyboardInterrupt:
        m.shutdown()
Beispiel #21
0
def start():
    opts = options.Options(listen_port=port)
    pconf = proxy.config.ProxyConfig(opts)

    m = DumpMaster(opts, with_termlog=debug, with_dumper=debug)
    m.server = proxy.server.ProxyServer(pconf)

    m.addons.add(ChangeScore())

    try:
        print("Proxy listening at", port)
        m.run()
    except KeyboardInterrupt:
        m.shutdown()
def start_proxy():
    self_addon = SelfAddon()
    opts = options.Options(listen_host='0.0.0.0', listen_port=8080)
    pconf = proxy.config.ProxyConfig(opts)
    m = DumpMaster(opts)
    m.server = proxy.server.ProxyServer(pconf)
    m.addons.add(self_addon)
    # 找到IP地址
    # import socket
    # ip = socket.gethostbyname(socket.gethostname())
    # print("请设置手机代理IP:"+str(ip)+"端口:8080")
    try:
        m.run()
    except KeyboardInterrupt:
        print("")
        m.shutdown()
def start():
    add_on = AdjustBody()

    opts = options.Options(listen_host='192.168.1.224',
                           listen_port=8888,
                           confdir="/Users/hienphan/.mitmproxy")
    proxy_conf = proxy.config.ProxyConfig(opts)

    dump_master = DumpMaster(opts)
    dump_master.server = proxy.server.ProxyServer(proxy_conf)
    dump_master.addons.add(add_on)

    try:
        dump_master.run()
    except KeyboardInterrupt:
        dump_master.shutdown()
Beispiel #24
0
def start():
    myaddon = AddHeader()
    opts = options.Options(listen_host='127.0.0.1',
                           listen_port=8888,
                           ignore_hosts=[
                               '^(.+\.)?baidupcs\.com:', 'd.pcs.baidu.com:'
                           ])  # try to bypass download requests (failed)
    pconf = proxy.config.ProxyConfig(opts)
    m = DumpMaster(opts)
    m.server = proxy.server.ProxyServer(pconf)
    m.addons.add(myaddon)

    try:
        m.run()
    except KeyboardInterrupt:
        m.shutdown()
Beispiel #25
0
def _run_proxy(event, namespace, service, listen_host, listen_port, verbose):
    # Run mitmproxy as a reverse-proxy to the Kubernetes ApiServer under the
    # subpath /api/v1/namespaces/{namespace}/services/{service}/proxy. See
    # https://k8s.io/docs/tasks/administer-cluster/access-cluster-services.
    client = kubernetes.config.new_client_from_config()
    prefix = f"/api/v1/namespaces/{namespace}/services/{service}/proxy"
    options = Options(listen_host=listen_host,
                      listen_port=listen_port,
                      mode=f"reverse:{client.configuration.host}")
    master = DumpMaster(options, with_termlog=verbose, with_dumper=verbose)
    options.keep_host_header = True
    options.ssl_insecure = True
    master.server = ProxyServer(ProxyConfig(options))
    master.addons.add(_Addon(client, prefix))
    event.set()  # Port is bound by this time, unblock parent process.
    master.run()
Beispiel #26
0
def start():
    ip = '127.0.0.1'
    port = 8080
    print("温馨提示:服务IP {} 端口 {} 请确保代理已配置".format(ip, port))

    myaddon = RuiShuCapture()
    opts = options.Options(listen_port=port)
    pconf = proxy.config.ProxyConfig(opts)
    m = DumpMaster(opts)
    m.server = proxy.server.ProxyServer(pconf)
    m.addons.add(myaddon)

    try:
        m.run()
    except KeyboardInterrupt:
        m.shutdown()
Beispiel #27
0
def start():
    ip = IP
    port = config.get('spider').get('service_port')

    print("温馨提示:服务IP {} 端口 {} 请确保代理已配置".format(ip, port))

    myaddon = WechatCapture()
    opts = options.Options(listen_port=port)
    pconf = proxy.config.ProxyConfig(opts)
    m = DumpMaster(opts)
    m.server = proxy.server.ProxyServer(pconf)
    m.addons.add(myaddon)

    try:
        m.run()
    except KeyboardInterrupt:
        m.shutdown()
Beispiel #28
0
def start():
    global HOST
    global NAME
    global PORT
    HOST = os.getenv('PROXY_HOST')
    NAME = os.getenv('RECORD_NAME')
    PORT = int(os.getenv('PROXY_PORT'))
    myaddon = Catch()
    opts = options.Options(listen_port=PORT)
    pconf = proxy.config.ProxyConfig(opts)
    m = DumpMaster(opts)
    m.server = proxy.server.ProxyServer(pconf)
    m.addons.add(myaddon)
    try:
        m.run()
    except KeyboardInterrupt:
        m.shutdown()
Beispiel #29
0
def start():
    myaddon = DumpLoot()
    opts = options.Options(listen_host='0.0.0.0',
                           listen_port=8080,
                           confdir=os.path.expanduser('~/.mitmproxy'),
                           ignore_hosts=[
                               '^(.+\.)?apple\.com:443$',
                               '^(.+\.)?icloud\.com', '^(.+\.)?evernote\.com',
                               '^(.+\.)?.googleapis\.com'
                           ])
    pconf = proxy.config.ProxyConfig(opts)
    m = DumpMaster(opts)
    m.server = proxy.server.ProxyServer(pconf)
    m.addons.add(myaddon)

    try:
        m.run()
    except KeyboardInterrupt:
        m.shutdown()
Beispiel #30
0
def start():
    ip = IP
    port = config.get('spider').get('service_port')

    print("温馨提示:服务IP {} 端口 {} 请确保代理已配置".format(ip, port))

    myaddon = WechatCapture()
    opts = options.Options(listen_port=port)
    pconf = proxy.config.ProxyConfig(opts)
    m = DumpMaster(opts)
    m.options.set('flow_detail={mitm_log_level}'.format(
        mitm_log_level=config.get('mitm').get('log_level')))
    m.options.set('block_global=false')
    m.server = proxy.server.ProxyServer(pconf)
    m.addons.add(myaddon)

    try:
        m.run()
    except KeyboardInterrupt:
        m.shutdown()