def run_mitmproxy(options, event): mode = "regular" upstream = None if options.upstream: upstream = options.upstream mode = "upstream" opts = mitmproxy.options.Options( mode=mode, listen_port=int(options.proxyport), cadir=os.path.abspath(options.cadir), upstream_server=upstream ) config = ProxyConfig(opts) state = flow.State() server = ProxyServer(config) proxy = ReflashProxy(opts, server, state) proxy.options = options proxy.options.sid = 0 proxy.options.instrumented = {} if not proxy.options.input: proxy.options.mode = "pass" else: proxy.options.mode = "sandbox" proxy.stopEvent = event proxy.run()
def __init__(self, server, tasks, results, args): super(ClickProxy, self).__init__() self.tasks = tasks self.results = results self.server = server proxy_server = ProxyServer(ProxyConfig(port=int(args['port']))) self.cproxy = MasterOfProxy(proxy_server, Queue(), args)
def test_load_flows_reverse(self): r = self._treader() s = flow.State() conf = ProxyConfig(mode="reverse", upstream_server=("https", ("use-this-domain", 80))) fm = flow.FlowMaster(DummyServer(conf), s) fm.load_flows(r) assert s.flows[0].request.host == "use-this-domain"
def sniff_main(): opts = options.Options(upstream_server="http://localhost:8080", cadir="~/.mitmproxy/") config = ProxyConfig(opts) state = flow.State() server = ProxyServer(config) m = Sniff(opts, server, state) m.run()
def __init__(self, listen_host="", listen_port=8080, socks=False, auth=None, insecure=False, processes=2, cmd='tor', on_count=0, on_string=None, on_regex=None, on_rst=False, on_callback=None): self.logger = logging.getLogger(__name__) # Change IP Policy (Configuration) self.counter = itertools.count(1) self.on_count = on_count self.on_regex = on_regex self.on_rst = on_rst self.on_string = on_string if self.on_string: # For Python 3 self.on_string = str.encode(on_string) self.on_callback = None if callable(on_callback): self.on_callback = on_callback # Create MultiTor (Tor Pool) self.multitor = MultiTor(size=processes, cmd=cmd) # Create Proxy Server self.insecure = insecure options_dict = { 'listen_host': listen_host, 'listen_port': listen_port, 'ssl_insecure': self.insecure, 'mode': "socks5" if socks else "regular", 'rawtcp': False, 'auth_singleuser': auth } # options_dict['proxyauth' if new_mitmproxy else 'auth_singleuser'] = auth options = ProxyOptions(**options_dict) setattr(options, websocket_key, False) config = ProxyConfig(options) server = ProxyServer(config) if new_mitmproxy: super(self.__class__, self).__init__(options, server) else: state = State() super(self.__class__, self).__init__(options, server, state)
def test_load_flows_reverse(self): r = self._treader() s = tservers.TestState() opts = options.Options(mode="reverse:https://use-this-domain") conf = ProxyConfig(opts) fm = master.Master(opts, DummyServer(conf)) fm.addons.add(s) fm.load_flows(r) assert s.flows[0].request.host == "use-this-domain"
def test_load_flows_reverse(self): r = self._treader() s = flow.State() opts = options.Options(mode="reverse", upstream_server="https://use-this-domain") conf = ProxyConfig(opts) fm = flow.FlowMaster(opts, DummyServer(conf), s) fm.load_flows(r) assert s.flows[0].request.host == "use-this-domain"
def start_proxy(port): options = Options(listen_port=port, ) config = ProxyConfig(options=options, ) server = ProxyServer(config) print('Intercepting Proxy listening on {0}'.format(port)) m = TestInterceptor(options, server) m.addons.add(core.Core()) m.addons.add(Counter()) m.run()
def start_proxy(port): options = Options(listen_port=port, ) # options.body_size_limit='3m' config = ProxyConfig(options=options, # cacert = os.path.expanduser('./mitmproxy.pem'), ) server = ProxyServer(config) print('Intercepting Proxy listening on {0}'.format(port)) m = TestInterceptor(options, server) m.run()
def start_mitm_proxy(log_file): opts = options.Options(cadir="~/.mitmproxy/") config = ProxyConfig(opts) state = flow.State() server = ProxyServer(config) log_file = open(log_file, 'w') m = MyMaster(opts, server, state) m.set_log_file(log_file) m.run() log_file.close()
def proxy_start(): #opts = options.Options(cadir="~/.mitmproxy/") opts = options.Options(listen_port=8088) config = ProxyConfig(opts) server = ProxyServer(config) # pport = int(proxy_port) # config = proxy.ProxyConfig(options=) state = flow.State() #server = ProxyServer(config) print 'Express started on http://localhost:8088; press Ctrl-C to terminate.' m = MyMaster(opts, server, state) m.run()
def start_server(port, mode, domain): if mode == "http": mode = "regular" opts = options.Options(cadir="~/.mitmproxy/", listen_port=int(port) or 8080, mode=mode) if domain: global _domain _domain = domain config = ProxyConfig(opts) server = ProxyServer(config) m = MyMaster(opts, server) m.run()
def install_cert(): log.warning('Installing mitmproxy certificate...') # Init dummy config to generate the certificate ProxyConfig(Options()) crtPath = Path.home().joinpath('.mitmproxy', 'mitmproxy-ca-cert.cer') log.debug(f'certificate path: "{crtPath}"') if error_code := subprocess.call( f'certutil -addstore -user Root "{crtPath}"', shell=True): log.error( f'Certificate could not be installed: {hex(error_code)} - {str(FormatMessage(error_code)).strip()}' ) # noinspection PyProtectedMember,PyUnresolvedReferences os._exit(1)
def test_client_playback(self): s = flow.State() f = tutils.tflow(resp=True) pb = [tutils.tflow(resp=True), f] fm = flow.FlowMaster(options.Options(), DummyServer(ProxyConfig(options.Options())), s) assert not fm.start_client_playback(pb, False) fm.client_playback.testing = True assert not fm.state.flow_count() fm.tick(0) assert fm.state.flow_count() f.error = Error("error") fm.error(f)
def __init__(self, mode, cache_path, rewarders=[]): opts = options.Options(cadir="~/.mitmproxy/") opts.listen_port = 8888 config = ProxyConfig(opts) server = ProxyServer(config) super(ProxyController, self).__init__(opts, server) self.mode = mode self.cache = ProxyCache(cache_path) self.cache.configure(opts, {}) self.WOB_LOCK = threading.Lock() self.WOB_REWARD_GLOBAL = 0 self.WOB_DONE_GLOBAL = False self.rewarders = rewarders
def do_start(self, arg): if not self.start_status: logger.info("OK") self.prompt = "\033[1;35m [*]探测装置-> \033[0m" self.start_status = True opts = options.Options(upstream_server="http://localhost:8080", cadir="~/.mitmproxy/") config = ProxyConfig(opts) state = flow.State() server = ProxyServer(config) self.m = Sniff(opts, server, state) self.th_sniff = threading.Thread(target=self.m.run, name='sniff') self.th_sniff.setDaemon(True) self.th_sniff.start() else: logger.error("Sniff已开启")
def test_client_playback(self): s = flow.State() f = tutils.tflow(resp=True) pb = [tutils.tflow(resp=True), f] fm = flow.FlowMaster(DummyServer(ProxyConfig()), s) assert not fm.start_server_playback(pb, False, [], False, False, None, False, None, False) assert not fm.start_client_playback(pb, False) fm.client_playback.testing = True q = queue.Queue() assert not fm.state.flow_count() fm.tick(q, 0) assert fm.state.flow_count() f.error = Error("error") fm.handle_error(f)
def MainProxy(): """ The Proxy called by waunitproxy """ # Configuration file if (os.path.isfile(args.config_file)): #use ~/.mitmproxy/mitmproxy-ca.pem as default CA file. proxyconfig = ProxyConfig(port=config.getint('Proxy', 'port'), cadir="~/.mitmproxy/") state = flow.State() server = ProxyServer(proxyconfig) try: m = GoogleAnalyticsUniversal(server, state) m.run() except (KeyboardInterrupt): pass else: print "Invalid config file. Use --config to specify the configuration file (e.g. --config waunit.cfg)"
def __init__(self): options = Options( listen_port=config.port, ignore_hosts=[ ''.join([ r'^(?![0-9.]+:)', # https://docs.mitmproxy.org/stable/howto-ignoredomains/ EpicAddon.hosts, # Allow epic hosts OriginAddon.hosts, # Allow origin hosts ]) ]) options.add_option("body_size_limit", int, 0, "") # Fix for weird bug that crashes mitmproxy super().__init__(options) self.server = ProxyServer(ProxyConfig(options)) self.addons.add(EpicAddon()) self.addons.add(OriginAddon()) log.info(f'Successfully initialized mitmproxy on port {config.port}')
def __init__(self, port=12345, mode="regular", cadir="ssl/"): super(ProxyDaemon, self).__init__() if not os.path.exists(cadir): logger.error("%s does not exist" % cadir) raise ValueError("%s does not exist" % cadir) global HINT while True: try: opts = options.Options(listen_port=port + HINT, mode=mode, cadir=cadir) config = ProxyConfig(opts) server = ProxyServer(config) self.port = port + HINT self.mproxy = Proxy(opts, server) break except ServerException: pass finally: HINT += 1
def __init__(self, **options): opts = Options(**options) server = ProxyServer(ProxyConfig(opts)) super().__init__(opts, server)
class MyMaster(master.Master): def run(self): try: master.Master.run(self) except KeyboardInterrupt: self.shutdown() @controller.handler def request(self, f): print("request", f) @controller.handler def response(self, f): print("response", f) @controller.handler def error(self, f): print("error", f) @controller.handler def log(self, l): print("log", l.msg) opts = options.Options(cadir="~/.mitmproxy/") config = ProxyConfig(opts) server = ProxyServer(config) m = MyMaster(opts, server) m.run()
def test_err_2(self): conf = ProxyConfig( host="invalidhost" ) tutils.raises("error starting proxy server", ProxyServer, conf)
def test_err(self): conf = ProxyConfig( port=1 ) tutils.raises("error starting proxy server", ProxyServer, conf)
from mitmproxy import flow, controller from mitmproxy.proxy import ProxyServer, ProxyConfig class MyMaster(flow.FlowMaster): def run(self): try: flow.FlowMaster.run(self) except KeyboardInterrupt: self.shutdown() @controller.handler def request(self, f): f = flow.FlowMaster.request(self, f) print(f) @controller.handler def response(self, f): f = flow.FlowMaster.response(self, f) print(f) config = ProxyConfig( port=8080, # use ~/.mitmproxy/mitmproxy-ca.pem as default CA file. cadir="~/.mitmproxy/") state = flow.State() server = ProxyServer(config) m = MyMaster(server, state) m.run()
def test_err(self): conf = ProxyConfig(options.Options(listen_port=1), ) tutils.raises("error starting proxy server", ProxyServer, conf)
def test_err_2(self): conf = ProxyConfig(options.Options(listen_host="256.256.256.256")) with pytest.raises(Exception, match="Error starting proxy server"): ProxyServer(conf)
def test_err(self): # binding to 0.0.0.0:1 works without special permissions on Windows and macOS Mojave+ conf = ProxyConfig(options.Options(listen_port=1)) with pytest.raises(Exception, match="Error starting proxy server"): ProxyServer(conf)
def test_err_2(self): conf = ProxyConfig(options.Options(listen_host="invalidhost"), ) tutils.raises("error starting proxy server", ProxyServer, conf)
def test_err_2(self): conf = ProxyConfig(options.Options(listen_host="invalidhost")) with pytest.raises("error starting proxy server"): ProxyServer(conf)