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
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()
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)
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()
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()
def create_proxy() -> Tuple[DumpMaster, CaptureAddon]: # set default proxy options opts = options.Options(listen_host="0.0.0.0", listen_port=8080) config = proxy.config.ProxyConfig(opts) # create addon addon = CaptureAddon() # create proxy m = DumpMaster(opts, with_termlog=False, with_dumper=False) m.server = proxy.server.ProxyServer(config) m.addons.add(addon) return m, addon
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()
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()
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()
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()
def shutdown_proxy(): opts = options.Options(listen_host=PROXY_LISTEN_HOST, listen_port=PROXY_LISTEN_PORT, confdir=BASE_DIR + "/ssl/", ssl_insecure=True) opts.add_option("body_size_limit", int, 0, "") pconf = ProxyConfig(opts) m = DumpMaster(opts, with_termlog=False, with_dumper=False) m.server = ProxyServer(pconf) m.addons.add(Capture()) m.shutdown()
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()
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()
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()
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 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()
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 main(): option = options.Options(listen_host='0.0.0.0', listen_port=18088, http2=True, mode="regular") #代理地址 m = DumpMaster(option, with_termlog=False, with_dumper=False) config = ProxyConfig(option) m.server = ProxyServer(config) m.addons.add(Addon()) loop = asyncio.get_event_loop() t = threading.Thread(target=loop_in_thread, args=(loop,m) ) try: t.start() except: m.shutdown() sys.exit(0)
def start_mitm(self): asyncio.set_event_loop(asyncio.new_event_loop()) print('[*] Starting mitmproxy on 127.0.0.1:8080') options = Options(listen_host='127.0.0.1', listen_port=8080, http2=True) m = DumpMaster(options, with_termlog=False, with_dumper=False) config = ProxyConfig(options) m.server = ProxyServer(config) addon = MitmAddon(self.ext_id) m.addons.add(addon) # run mitmproxy in backgroud loop = asyncio.get_event_loop() t = threading.Thread( target=loop_in_thread, args=(loop,m) ) t.start() return m
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()
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 _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()
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()
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(): 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()
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()
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()
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()
def start(): lock = Lock() q = queue.Queue() addon = Addon(q, lock) window = Window(q, lock, addon) opts = options.Options(listen_host='0.0.0.0', listen_port=8080) pconf = proxy.config.ProxyConfig(opts) master = DumpMaster(opts) master.server = proxy.server.ProxyServer(pconf) master.addons.add(addon) mitm_thread = Thread(target=start_mitm, args=(master,)) mitm_thread.daemon = True mitm_thread.start() window.run()
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()