コード例 #1
0
def launch():
    script = os.path.join(os.path.dirname(os.path.realpath(__file__)), "json_dump_input.py")

    print("\nYou are running FFRK JSON capture, version 0.1.3.")

    # This is just here so that --help returns the arguments
    args = parse_args(sys.argv)

    # Show verbosity.
    result = {
        0: "0: Show each request.",
        1: "1: Show each response.",
        2: "2: Show each response and save each to a separate file.",
        3: "3: Show and save each response except for requests in ignore_requests.csv.",
    }[args.verbosity]
    print("\nVerbosity {}".format(result))

    if sys.argv[1:]:
        arglist = " ".join(sys.argv[1:])
        scriptargs = '-s "{0}" "{1}"'.format(script, arglist)
    else:
        scriptargs = '-s "{0}"'.format(script)
    sys.argv = [sys.argv[0], scriptargs, "-q"]
    from libmproxy.main import mitmdump

    mitmdump()
コード例 #2
0
ファイル: __init__.py プロジェクト: flying0er/mastermind
def main():
    parser = cli.args()
    args, extra_args = parser.parse_known_args()

    config = cli.config(args)
    mitm_args = cli.mitm_args(config)
    is_sudo = os.getuid() == 0

    if type(mitm_args) == Exception:
        parser.error(mitm_args.message)

    say.level(config["core"]["verbose"])

    try:
        if config["os"]["proxy-settings"]:
            if not is_sudo:
                parser.error("proxy-settings is enabled, please provide sudo in order to change the OSX proxy configuration.")

            proxyswitch.enable(config["core"]["host"],
                               str(config["core"]["port"]))

        mitmdump(mitm_args + extra_args)
    finally:
        if config["os"]["proxy-settings"] and is_sudo:
            proxyswitch.disable()
コード例 #3
0
def launch():
    script = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mitmdump_input.py')

    # This is just here so that --help returns the arguments
    args = parse_args(sys.argv)
    if sys.argv[1:]:
        arglist = " ".join(sys.argv[1:])
        scriptargs = '-s "{0}" "{1}"'.format(script, arglist)
    else:
        scriptargs = '-s "{0}"'.format(script)
    sys.argv = [sys.argv[0], scriptargs, '-q']
    from libmproxy.main import mitmdump
    mitmdump()
コード例 #4
0
ファイル: benchtool.py プロジェクト: nask0/opparis
def main(profiler, clock_type, concurrency):

    outfile = "callgrind.mitmdump-{}-c{}".format(clock_type, concurrency)
    a = ApacheBenchThread(concurrency)
    a.start()

    if profiler == "yappi":
        yappi.set_clock_type(clock_type)
        yappi.start(builtins=True)

    print("Start mitmdump...")
    mitmdump(["-k", "-q", "-S", "1024example"])
    print("mitmdump stopped.")

    print("Save profile information...")
    if profiler == "yappi":
        yappi.stop()
        stats = yappi.get_func_stats()
        stats.save(outfile, type='callgrind')
    print("Done.")
コード例 #5
0
def main():
    parser = argparse.ArgumentParser(
        prog='mastermind',
        description=
        'Helper tool to orchestrate OS X proxy settings and mitmproxy.')
    parser.add_argument('-v',
                        '--version',
                        action='version',
                        version="%(prog)s" + " " + version.VERSION)

    driver = parser.add_argument_group('Driver')
    single = parser.add_argument_group('Single')
    script = parser.add_argument_group('Script')

    driver.add_argument('--with-driver',
                        action='store_true',
                        help='Activates the driver')
    driver.add_argument(
        '--source-dir',
        metavar='DIR',
        help=
        'An absolute path used as a source directory to lookup for mock rules')
    driver.add_argument(
        '--with-reverse-access',
        action='store_true',
        help=
        'Activates the reverse proxy to drive from the outside via port 5001')

    single.add_argument('--response-body',
                        metavar='FILEPATH',
                        help='A file containing the mocked response body')
    single.add_argument('--url',
                        metavar='URL',
                        help='A URL to mock its response')

    script.add_argument('--script',
                        metavar='FILEPATH',
                        help='''A mitmproxy Python script filepath.
                                  When passed, --response-body and --url are ignored'''
                        )

    parser.add_argument('--port', help='Default port 8080', default="8080")
    parser.add_argument('--host',
                        help='Default host 0.0.0.0',
                        default="0.0.0.0")
    parser.add_argument('--without-proxy-settings',
                        action='store_true',
                        help='Skips changing the OS proxy settings')

    parser.add_argument('--quiet',
                        action='store_true',
                        help='Makes mitmproxy quiet')

    args, extra_arguments = parser.parse_known_args()
    mitm_args = ["--host"]

    if args.with_driver:
        if args.script or args.response_body or args.url:
            parser.error(
                "The Driver mode does not allow a script, a response body or a URL."
            )

        if not args.source_dir:
            parser.error("--source-dir is required with the Driver mode")

        mitm_args = [
            '--script', "{}/scripts/flasked.py {} {} {} {} {}".format(
                os.path.dirname(os.path.realpath(__file__)), args.source_dir,
                args.with_reverse_access, args.without_proxy_settings,
                args.port, args.host)
        ]
    elif args.script:
        if args.response_body or args.url:
            parser.error(
                "The Script mode does not allow a response body or a URL.")

        mitm_args.append('--script')
        mitm_args.append(args.script)
    elif args.response_body:
        mitm_args = [
            '--script', "{}/scripts/simple.py {} {} {} {} {}".format(
                os.path.dirname(os.path.realpath(__file__)), args.url,
                args.response_body, args.without_proxy_settings, args.port,
                args.host)
        ]

    if args.quiet:
        mitm_args.append('--quiet')

    mitm_args = mitm_args + extra_arguments
    mitm_args = mitm_args + ["--port", args.port, "--bind-address", args.host]

    print(mitm_args)

    try:
        mitmdump(mitm_args)
    except (KeyboardInterrupt, thread.error):
        proxyswitch.disable()
コード例 #6
0
ファイル: __init__.py プロジェクト: CandiceW/mastermind
def main():
    parser = argparse.ArgumentParser(prog = 'mastermind',
                                     description = 'Helper tool to orchestrate OS X proxy settings and mitmproxy.')
    parser.add_argument('-v',
                        '--version',
                        action='version',
                        version="%(prog)s" + " " + version.VERSION)

    driver = parser.add_argument_group('Driver')
    single = parser.add_argument_group('Single')
    script = parser.add_argument_group('Script')

    driver.add_argument('--with-driver',
                        action = 'store_true',
                        help = 'Activates the driver')
    driver.add_argument('--source-dir',
                        metavar = 'DIR',
                        help = 'An absolute path used as a source directory to lookup for mock rules')
    driver.add_argument('--with-reverse-access',
                        action = 'store_true',
                        help = 'Activates the reverse proxy to drive from the outside via port 5001')


    single.add_argument('--response-body',
                        metavar = 'FILEPATH',
                        help = 'A file containing the mocked response body')
    single.add_argument('--url',
                        metavar = 'URL',
                        help = 'A URL to mock its response')

    script.add_argument('--script',
                        metavar = 'FILEPATH',
                        help = '''A mitmproxy Python script filepath.
                                  When passed, --response-body and --url are ignored''')

    parser.add_argument('--port',
                        help = 'Default port 8080',
                        default = "8080")
    parser.add_argument('--host',
                        help = 'Default host 0.0.0.0',
                        default = "0.0.0.0")
    parser.add_argument('--without-proxy-settings',
                        action='store_true',
                        help='Skips changing the OS proxy settings')

    parser.add_argument('--quiet',
                        action='store_true',
                        help='Makes mitmproxy quiet')

    args, extra_arguments = parser.parse_known_args()
    mitm_args = ["--host"]

    if args.with_driver:
        if args.script or args.response_body or args.url:
            parser.error("The Driver mode does not allow a script, a response body or a URL.")

        if not args.source_dir:
            parser.error("--source-dir is required with the Driver mode")

        mitm_args = ['--script',
                     "{}/scripts/flasked.py {} {} {} {} {}".format(os.path.dirname(os.path.realpath(__file__)),
                                                                   args.source_dir,
                                                                   args.with_reverse_access,
                                                                   args.without_proxy_settings,
                                                                   args.port,
                                                                   args.host)]
    elif args.script:
        if args.response_body or args.url:
            parser.error("The Script mode does not allow a response body or a URL.")

        mitm_args.append('--script')
        mitm_args.append(args.script)
    elif args.response_body:
        mitm_args = ['--script',
                     "{}/scripts/simple.py {} {} {} {} {}".format(os.path.dirname(os.path.realpath(__file__)),
                                                                  args.url,
                                                                  args.response_body,
                                                                  args.without_proxy_settings,
                                                                  args.port,
                                                                  args.host)]

    if args.quiet:
        mitm_args.append('--quiet')

    mitm_args = mitm_args + extra_arguments
    mitm_args = mitm_args + ["--port", args.port, "--bind-address", args.host]

    print(mitm_args)

    try:
        mitmdump(mitm_args)
    except (KeyboardInterrupt, thread.error):
        proxyswitch.disable()