Пример #1
0
def run(MasterKlass, args):  # pragma: no cover
    version_check.check_pyopenssl_version()
    debug.register_info_dumpers()

    opts = options.Options()
    parser = cmdline.mitmdump(opts)
    args = parser.parse_args(args)
    master = None
    try:
        unknown = optmanager.load_paths(opts, args.conf)
        server = process_options(parser, opts, args)
        master = MasterKlass(opts, server)
        master.addons.configure_all(opts, opts.keys())
        remaining = opts.update_known(**unknown)
        if remaining and opts.verbosity > 1:
            print("Ignored options: %s" % remaining)
        if args.options:
            print(optmanager.dump_defaults(opts))
            sys.exit(0)
        opts.set(*args.setoptions)

        def cleankill(*args, **kwargs):
            master.shutdown()

        signal.signal(signal.SIGTERM, cleankill)
        master.run()
    except exceptions.OptionsError as e:
        print("%s: %s" % (sys.argv[0], e), file=sys.stderr)
        sys.exit(1)
    except (KeyboardInterrupt, RuntimeError):
        pass
    return master
Пример #2
0
def mitmdump(args=None):  # pragma: no cover
    from mitmproxy.tools import dump

    version_check.check_pyopenssl_version()

    parser = cmdline.mitmdump()
    args = parser.parse_args(args)
    if args.quiet:
        args.flow_detail = 0

    master = None
    try:
        dump_options = dump.Options(**cmdline.get_common_options(args))
        dump_options.flow_detail = args.flow_detail
        dump_options.keepserving = args.keepserving
        dump_options.filtstr = " ".join(args.filter) if args.filter else None
        server = process_options(parser, dump_options, args)
        master = dump.DumpMaster(dump_options, server)

        def cleankill(*args, **kwargs):
            master.shutdown()

        signal.signal(signal.SIGTERM, cleankill)
        master.run()
    except (dump.DumpError, exceptions.OptionsError) as e:
        print("mitmdump: %s" % e, file=sys.stderr)
        sys.exit(1)
    except (KeyboardInterrupt, RuntimeError):
        pass
    if master is None or master.has_errored:
        print("mitmdump: errors occurred during run", file=sys.stderr)
        sys.exit(1)
Пример #3
0
    def setup_proxy(self, args):

        parser = cmdline.mitmdump()
        args = parser.parse_args(args)
        if args.quiet:
            args.flow_detail = 0


        dump_options = options.Options()
        dump_options.load_paths(args.conf)
        dump_options.merge(cmdline.get_common_options(args))
        dump_options.merge(
            dict(
                flow_detail = args.flow_detail,
                keepserving = args.keepserving,
                filtstr = " ".join(args.filter) if args.filter else None,
            )
        )
        dump_options.listen_host = self.proxy_host
        dump_options.listen_port = self.proxy_port

        pconf = config.ProxyConfig(dump_options)
        proxy_server = server.ProxyServer(pconf)

        master = dump.DumpMaster(dump_options, proxy_server)

        self.proxy_master = master
Пример #4
0
def mitmdump(args=None):  # pragma: no cover
    from mitmproxy.tools import dump

    version_check.check_pyopenssl_version()

    parser = cmdline.mitmdump()
    args = parser.parse_args(args)
    if args.quiet:
        args.flow_detail = 0

    master = None
    try:
        dump_options = dump.Options(**cmdline.get_common_options(args))
        dump_options.flow_detail = args.flow_detail
        dump_options.keepserving = args.keepserving
        dump_options.filtstr = " ".join(args.args) if args.args else None
        server = process_options(parser, dump_options, args)
        master = dump.DumpMaster(dump_options, server)

        def cleankill(*args, **kwargs):
            master.shutdown()

        signal.signal(signal.SIGTERM, cleankill)
        master.run()
    except (dump.DumpError, exceptions.OptionsError) as e:
        print("mitmdump: %s" % e, file=sys.stderr)
        sys.exit(1)
    except (KeyboardInterrupt, RuntimeError):
        pass
    if master is None or master.has_errored:
        print("mitmdump: errors occurred during run", file=sys.stderr)
        sys.exit(1)
Пример #5
0
    def run(self):
        def process_options(_, _options, _args):
            from mitmproxy.proxy import server  # noqa

            if _args.version:
                print(debug.dump_system_info())
                sys.exit(0)

            # debug.register_info_dumpers()
            pconf = config.ProxyConfig(_options)
            if _options.no_server:
                return server.DummyServer(pconf)
            else:
                try:
                    return server.ProxyServer(pconf)
                except exceptions.ServerException as v:
                    print(str(v), file=sys.stderr)
                    sys.exit(1)

        from mitmproxy.tools import dump

        args = ['-b', self.address[0], '-p', str(self.address[1]), '-q']

        version_check.check_pyopenssl_version()

        parser = cmdline.mitmdump()
        args = parser.parse_args(args)
        if args.quiet:
            args.flow_detail = 0

        master = None
        try:
            dump_options = options.Options()
            dump_options.load_paths(args.conf)
            dump_options.merge(cmdline.get_common_options(args))
            dump_options.merge(
                dict(
                    flow_detail=args.flow_detail,
                    keepserving=args.keepserving,
                    filtstr=" ".join(args.filter) if args.filter else None,
                ))

            server = process_options(parser, dump_options, args)
            self._master = master = self._master_type(dump_options, server)

            # def clean_kill(*args, **kwargs):
            #    master.shutdown()

            # signal.signal(signal.SIGTERM, clean_kill)
            self.info('bind at tcp:{}'.format(self.server_address))
            master.run()
            self.info('stopped')
        except (dump.DumpError, exceptions.OptionsError) as e:
            print("mitmdump: %s" % e, file=sys.stderr)
            sys.exit(1)
        except (KeyboardInterrupt, RuntimeError):
            pass
        if master is None or master.has_errored:
            print("mitmdump: errors occurred during run", file=sys.stderr)
            sys.exit(1)
Пример #6
0
def run(MasterKlass, args):  # pragma: no cover
    version_check.check_pyopenssl_version()
    debug.register_info_dumpers()

    opts = options.Options()
    parser = cmdline.mitmdump(opts)
    args = parser.parse_args(args)
    master = None
    try:
        opts.load_paths(args.conf)
        server = process_options(parser, opts, args)
        master = MasterKlass(opts, server)

        def cleankill(*args, **kwargs):
            master.shutdown()

        signal.signal(signal.SIGTERM, cleankill)
        master.run()
    except exceptions.OptionsError as e:
        print("%s: %s" % (sys.argv[0], e), file=sys.stderr)
        sys.exit(1)
    except (KeyboardInterrupt, RuntimeError):
        pass
    if master is None or getattr(master, "has_errored", None):
        print("%s: errors occurred during run" % sys.argv[0], file=sys.stderr)
        sys.exit(1)
Пример #7
0
def run(MasterKlass, args, extra=None):  # pragma: no cover
    """
        extra: Extra argument processing callable which returns a dict of
        options.
    """
    version_check.check_pyopenssl_version()
    debug.register_info_dumpers()

    opts = options.Options()
    parser = cmdline.mitmdump(opts)
    args = parser.parse_args(args)
    master = None
    try:
        unknown = optmanager.load_paths(opts, args.conf)
        pconf = process_options(parser, opts, args)
        if pconf.options.server:
            try:
                server = proxy.server.ProxyServer(pconf)
            except exceptions.ServerException as v:
                print(str(v), file=sys.stderr)
                sys.exit(1)
        else:
            server = proxy.server.DummyServer(pconf)

        master = MasterKlass(opts, server)
        master.addons.trigger("configure", opts.keys())
        master.addons.trigger("tick")
        remaining = opts.update_known(**unknown)
        if remaining and opts.verbosity > 1:
            print("Ignored options: %s" % remaining)
        if args.options:
            print(optmanager.dump_defaults(opts))
            sys.exit(0)
        if args.commands:
            master.commands.dump()
            sys.exit(0)
        opts.set(*args.setoptions)
        if extra:
            opts.update(**extra(args))

        def cleankill(*args, **kwargs):
            master.shutdown()

        signal.signal(signal.SIGTERM, cleankill)
        master.run()
    except exceptions.OptionsError as e:
        print("%s: %s" % (sys.argv[0], e), file=sys.stderr)
        sys.exit(1)
    except (KeyboardInterrupt, RuntimeError) as e:
        pass
    return master
Пример #8
0
def test_mitmdump():
    opts = options.Options()
    ap = cmdline.mitmdump(opts)
    assert ap
Пример #9
0
def test_mitmdump():
    opts = options.Options()
    dump.DumpMaster(opts)
    ap = cmdline.mitmdump(opts)
    assert ap
Пример #10
0
def test_mitmdump():
    ap = cmdline.mitmdump()
    assert ap
Пример #11
0
def test_mitmdump():
    opts = options.Options()
    ap = cmdline.mitmdump(opts)
    assert ap
Пример #12
0
def test_mitmdump():
    ap = cmdline.mitmdump()
    assert ap
Пример #13
0
    def json_travel(self, data):
        # 判断传入的数据类型{"a": {"b":{"c":1}}}
        if isinstance(data, dict):
            # 遍历字典的数据
            # 当字典格式,递归value值
            for key, value in data.items():
                data[key] = self.json_travel(value)
        elif isinstance(data, list):
            # 当数据类型 为 list 的时候, 添加到结构内,并继续递归遍历,
            # 知道数据类型不为可迭代对象时
            data = [self.json_travel(value) for value in data]
        elif isinstance(data, bool):
            data = data
        elif isinstance(data, int) or isinstance(data, float):
            data = data * 2
        elif isinstance(data, str):
            data = data
        else:
            data = data
        return data


addons = [Counter()]

if __name__ == '__main__':
    sys.argv = [__file__, "-s", __file__]
    #
    # 官方要求必须主线程
    mitmdump()