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()
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()
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)
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()
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 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_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 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 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 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 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 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(): 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(): 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_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(): 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(): 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(): 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(): 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(): 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()
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()
def run_input_loop(m: DumpMaster, addon: CaptureAddon): while True: print( "Select an option:\n" "1. Start new site session\n" "2. Finish capture and quit" ) option = None while option not in [1, 2]: try: option = int(input("> ")) except: pass if option == 1: label = input("Enter label for session:\n> ") addon.label = label elif option == 2: m.shutdown() with open(f"dump-{time.strftime('%Y%m%d-%H.%M.%S')}.json", "w") as file: json.dump(addon.captures, file) break
class MitmWebWraper(object): mitmweb = None thread = None def loop_in_thread(self, loop, mitmweb): asyncio.set_event_loop(loop) mitmweb.run() def start(self): opts = options.Options(listen_host='0.0.0.0', listen_port=8080) pconf = proxy.config.ProxyConfig(opts) self.mitmweb = DumpMaster(opts) self.mitmweb.server = proxy.server.ProxyServer(pconf) self.mitmweb.addons.add(addon) self.mitmweb.addons.add(tls_passthrough1) loop = asyncio.get_event_loop() self.thread = threading.Thread(target=self.loop_in_thread, args=(loop, self.mitmweb)) try: self.thread.start() except KeyboardInterrupt: self.mitmweb.shutdown()
# see source mitmproxy/master.py for details def loop_in_thread(loop, m): asyncio.set_event_loop(loop) # This is the key. m.run_loop(loop.run_forever) if __name__ == "__main__": # try: options = Options(listen_host="0.0.0.0", listen_port=8080, http2=True) m = DumpMaster(options, with_termlog=False, with_dumper=False) config = ProxyConfig(options) m.server = ProxyServer(config) colorama.init() m.addons.add(Addon()) loop = asyncio.get_event_loop() t = threading.Thread(target=loop_in_thread, args=(loop, m)) t.start() print("hello") # Other servers might be started too. time.sleep(3000) print("going to shutdown mitmproxy") m.shutdown() # except Exception as e: # print("--------------") # print(e)
def startProxyAndExec(runtime, sProcessor, sampleLogDir, enableSimulation): from mitmproxy import proxy, options from mitmproxy.tools.dump import DumpMaster opts = options.Options(listen_host='0.0.0.0', listen_port=8080, mode='transparent', confdir='/home/user/.mitmproxy', ssl_insecure=True) pconf = proxy.config.ProxyConfig(opts) master = DumpMaster(opts) master.server = proxy.server.ProxyServer(pconf) #create addons addons = [] #Main addons addons.append(mitmProxyAddons.TimerAddon( master, runtime)) #this addon is needed, otherwise mitmProxy will run forever if sProcessor.execWithExternalCallback: addons.append( mitmProxyAddons.LauncherAddon(sProcessor) ) #this addon is needed to execute sample after mitmProxy started running #Simulation addons if enableSimulation: simAddons = [] simAddons.append( mitmProxyAddons.RemoteServerSimulation_AZORultVariant1( "AZORult_variant1", sampleLogDir)) # make our own responses simAddons.append( mitmProxyAddons.RemoteServerSimulation_AZORultVariant2( "AZORult_variant2", sampleLogDir)) simAddons.append( mitmProxyAddons.RemoteServerSimulation_Evrial( "Evrial", sampleLogDir)) simAddons.append( mitmProxyAddons.RemoteServerSimulation_AZORult_3_2( "AZORult_3_2", sampleLogDir)) simAddons.append( mitmProxyAddons.RemoteServerSimulation_AcridRain( "AcridRain", sampleLogDir)) simAddons.append( mitmProxyAddons.RemoteServerSimulation_KpotStealer( "KpotStealer", sampleLogDir)) # add only the needed simulation addons (try to find the name in the path of the sample) for simAddon in simAddons: if sProcessor.currentSampleLocalFilePath.find(simAddon.name) != -1: addons.append(simAddon) break #print(addons) #Logger addons addons.append(mitmProxyAddons.TcpLoggerAddon()) addons.append( mitmProxyAddons.HttpLoggerAddon(sampleLogDir) ) # we can log here own responses, since its after our simulation addons in the addon chain addons.append(mitmProxyAddons.DummyAddon()) #changes request #add addons (and automatically registered) for addon in addons: master.addons.add(addon) for addon in master.addons.chain: if addon.__class__.__name__ == "ClientPlayback": #threads of RequestReplayThread are not terminating. have to terminate them manually? master.addons.remove(addon) break # run proxy try: master.run() # this cant be run in a new thread except KeyboardInterrupt as e: master.shutdown() asyncio.set_event_loop(asyncio.new_event_loop())