How to use the mitmproxy.ctx.options function in mitmproxy

To help you get started, we’ve selected a few mitmproxy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github demisto / content / Tests / timestamp_replacer.py View on Github external
def modify_json_body(self, flow: flow.Flow, json_body: dict) -> None:
        '''Modify the json body of a request by replacing any timestampt data with the number of the current request.

        Args:
            flow (flow.Flow): The flow whose request body is to be modified.
            json_body (dict): The request body to modify.
        '''
        original_content = deepcopy(json_body)
        body = json_body
        modified = False
        keys_to_replace = ctx.options.keys_to_replace.split() or []
        ctx.log.info('{}'.format(keys_to_replace))
        for key_path in keys_to_replace:
            body = json_body
            keys = key_path.split('.')
            ctx.log.info('keypath parts: {}'.format(keys))
            lastkey = keys[-1]
            ctx.log.info('lastkey: {}'.format(lastkey))
            skip_key = False
            for k in keys[:-1]:
                if k in body:
                    body = body[k]
                    # ctx.log.info('updated body: {}'.format(body))
                elif isinstance(body, list) and k.isdigit():
                    if int(k) > len(body) - 1:
                        skip_key = True
                        break
github mitmproxy / mitmproxy / mitmproxy / addons / tlsconfig.py View on Github external
elif client.alpn_offers:
                server.alpn_offers = client.alpn_offers

        # We pass through the list of ciphers send by the client, because some HTTP/2 servers
        # will select a non-HTTP/2 compatible cipher from our default list and then hang up
        # because it's incompatible with h2.
        if not server.cipher_list:
            if ctx.options.ciphers_server:
                server.cipher_list = ctx.options.ciphers_server.split(":")
            elif client.cipher_list:
                server.cipher_list = [
                    x for x in client.cipher_list
                    if x in CIPHER_ID_NAME_MAP
                ]

        args = net_tls.client_arguments_from_options(ctx.options)

        client_certs = args.pop("client_certs")
        client_cert: Optional[str] = None
        if client_certs:
            client_certs = os.path.expanduser(client_certs)
            if os.path.isfile(client_certs):
                client_cert = client_certs
            else:
                server_name: str = (server.sni or server.address[0].encode("idna")).decode()
                path = os.path.join(client_certs, f"{server_name}.pem")
                if os.path.exists(path):
                    client_cert = path

        args["cipher_list"] = ':'.join(server.cipher_list) if server.cipher_list else None
        ssl_ctx = net_tls.create_client_context(
            cert=client_cert,
github zlorb / locust.replay / locust_extractor.py View on Github external
def configure(self, _) -> None:
        """Keep configuration options in context."""
        self.context.dump_file = ctx.options.filename_prefix
        ctx.log.info('Dump file prefix "{}"'.format(repr(self.context.dump_file)))
github viraja1 / mitm_postman / lib / postman.py View on Github external
def configure(updated):
    if HOST_FILTER_PARAM in updated or COLLECTION_NAME_PARAM in updated :
        ctx.log.info("host filter : " + ctx.options.host_filter)
        ctx.log.info("collection name : " + ctx.options.collection_name)
        global addons
        addons = [Postman(ctx.options.host_filter, ctx.options.collection_name)]
github mitmproxy / mitmproxy / mitmproxy / tools / console / keymap.py View on Github external
def running(self):
        p = os.path.join(os.path.expanduser(ctx.options.confdir), self.defaultFile)
        if os.path.exists(p):
            try:
                self.load_path(ctx.master.keymap, p)
            except KeyBindingError as e:
                ctx.log.error(e)
github mitmproxy / mitmproxy / mitmproxy / addons / session.py View on Github external
def configure(self, updated):
        if "view_order" in updated:
            self.set_order(ctx.options.view_order)
        if "view_filter" in updated:
            self.set_filter(ctx.options.view_filter)
github mitmproxy / mitmproxy / mitmproxy / addons / keepserving.py View on Github external
def running(self):
        opts = [
            ctx.options.client_replay,
            ctx.options.server_replay,
            ctx.options.rfile,
        ]
        if any(opts) and not ctx.options.keepserving:
            asyncio.get_event_loop().create_task(self.watch())
github mitmproxy / mitmproxy / mitmproxy / addons / intercept.py View on Github external
def configure(self, updated):
        if "intercept" in updated:
            if not ctx.options.intercept:
                self.filt = None
                ctx.options.intercept_active = False
                return
            self.filt = flowfilter.parse(ctx.options.intercept)
            if not self.filt:
                raise exceptions.OptionsError(
                    "Invalid interception filter: %s" % ctx.options.intercept
                )
            ctx.options.intercept_active = True
github mitmproxy / mitmproxy / mitmproxy / addons / view.py View on Github external
def configure(self, updated):
        if "view_filter" in updated:
            filt = None
            if ctx.options.view_filter:
                filt = flowfilter.parse(ctx.options.view_filter)
                if not filt:
                    raise exceptions.OptionsError(
                        "Invalid interception filter: %s" % ctx.options.view_filter
                    )
            self.set_filter(filt)
        if "view_order" in updated:
            if ctx.options.view_order not in self.orders:
                raise exceptions.OptionsError(
                    "Unknown flow order: %s" % ctx.options.view_order
                )
            self.set_order(ctx.options.view_order)
        if "view_order_reversed" in updated:
            self.set_reversed(ctx.options.view_order_reversed)
        if "console_focus_follow" in updated:
            self.focus_follow = ctx.options.console_focus_follow
github mitmproxy / mitmproxy / mitmproxy / addons / clientplayback.py View on Github external
def configure(self, updated):
        if "client_replay" in updated and ctx.options.client_replay:
            try:
                flows = io.read_flows_from_paths(ctx.options.client_replay)
            except exceptions.FlowReadException as e:
                raise exceptions.OptionsError(str(e))
            self.start_replay(flows)