Beispiel #1
0
def run(compile, test, fuzz):
    # instantiate RAFT CLI
    cli = RaftCLI()

    # Create compilation job configuration
    compile_job_config = RaftJobConfig(file_path=compile)
    print('Compile')
    # submit a new job with the Compile config and get new job ID
    compile_job = cli.new_job(compile_job_config)
    # wait for a job with ID from compile_job to finish the run
    cli.poll(compile_job['jobId'])

    # use compile job as input for fuzz job
    subs = {}
    subs['{compile.jobId}'] = compile_job['jobId']

    test_job_config = RaftJobConfig(file_path=test, substitutions=subs)
    print('Test')
    # create new fuzz job configuration
    test_job = cli.new_job(test_job_config)
    # wait for job ID from fuzz_job to finish the run
    cli.poll(test_job['jobId'])

    # create a new job config with Fuzz configuration JSON
    fuzz_job_config = RaftJobConfig(file_path=fuzz, substitutions=subs)
    print('Fuzz')
    # create new fuzz job configuration
    fuzz_job = cli.new_job(fuzz_job_config)

    # wait for job ID from fuzz_job to finish the run
    cli.poll(fuzz_job['jobId'])
Beispiel #2
0
def run(cli, compile, test, fuzz):
    substitutions = {
        '{defaults.deploymentName}': (RaftCLI().definitions.deployment)
    }
    compile_job_config = RaftJobConfig(file_path=compile,
                                       substitutions=substitutions)
    print('Compile')
    # create a new job with the Compile config and get new job ID
    # in compile_job
    compile_job = cli.new_job(compile_job_config)
    # wait for a job with ID from compile_job to finish the run
    cli.poll(compile_job['jobId'])
    substitutions['{compile.jobId}'] = compile_job['jobId']

    print('Test')
    test_job_config = RaftJobConfig(file_path=test,
                                    substitutions=substitutions)
    test_job = cli.new_job(test_job_config)
    cli.poll(test_job['jobId'])

    print('Fuzz')
    fuzz_job_config = RaftJobConfig(file_path=fuzz,
                                    substitutions=substitutions)
    fuzz_job = cli.new_job(fuzz_job_config)
    cli.poll(fuzz_job['jobId'])
Beispiel #3
0
def run(cli, compile, fuzz):
    # instantiate RAFT CLI
    substitutions = { }
    # Create compilation step job configuratin
    compile_job_config = RaftJobConfig(file_path = compile, substitutions=substitutions)
    # add webhook metadata that will be included in every triggered webhook by Compile job
    compile_job_config.add_metadata({"branch":"wizbangFeature"})

    print('Compile')
    # create a new job with the Compile config and get new job ID
    # in compile_job
    compile_job = cli.new_job(compile_job_config)

    # wait for a job with ID from compile_job to finish the run
    cli.poll(compile_job['jobId'])

    substitutions['{compile.jobId}'] = compile_job['jobId']
    # create a new job config with Fuzz configuration JSON
    fuzz_job_config = RaftJobConfig(file_path = fuzz, substitutions=substitutions)
    print('Fuzz')
    # add webhook metadata that will included in every triggered webhook by Fuzz job
    fuzz_job_config.add_metadata({"branch":"wizbangFeature"})
    # create new fuzz job configuration
    fuzz_job = cli.new_job(fuzz_job_config)
    # wait for job ID from fuzz_job to finish the run
    cli.poll(fuzz_job['jobId'])
Beispiel #4
0
def compile_and_dredd_and_schemathesis(cli, configs):
    compile_count = 0
    dredd_count = 0
    schemathesis_count = 0
    for c in configs:
        if configs[c].get('compile'):
            compile_job_config = RaftJobConfig(file_path=configs[c]['compile'],
                                               substitutions=subs)
            compile_job = cli.new_job(compile_job_config)
            configs[c]['compile_job_id'] = compile_job['jobId']
            compile_count = compile_count + 1

        if configs[c].get('dredd'):
            dredd_job_config = RaftJobConfig(file_path=configs[c]['dredd'],
                                             substitutions=subs)
            dredd_job = cli.new_job(dredd_job_config)
            configs[c]['dredd_job_id'] = dredd_job['jobId']
            dredd_count = dredd_count + 1

        if configs[c].get('schemathesis'):
            schemathesis_job_config = RaftJobConfig(
                file_path=configs[c]['schemathesis'], substitutions=subs)
            schemathesis_job = cli.new_job(schemathesis_job_config)
            configs[c]['schemathesis_job_id'] = schemathesis_job['jobId']
            schemathesis_count = schemathesis_count + 1

    print('Compiling all ' + str(compile_count) + ' and running Dredd on ' +
          str(dredd_count) + ' and running Schemathesis on ' +
          str(schemathesis_count) + ' samples ...')
    wait(configs, compile_count, 'compile', 'compile_job_id')
    wait(configs, dredd_count, 'dredd', 'dredd_job_id')
    wait(configs, schemathesis_count, 'schemathesis', 'schemathesis_job_id')
def run(compile, fuzz, host):
    # instantiate RAFT CLI
    cli = RaftCLI()

    # will replace {sample.host} with the value of host variable
    # see sample.restler.compile.json and sample.restler.fuzz.json
    subs = {'{sample.host}': host}
    # Create compilation job configuration
    compile_job_config = RaftJobConfig(file_path=compile, substitutions=subs)
    # add webhook metadata that will be included in every triggered webhook by Compile job
    compile_job_config.add_metadata({"branch": "wizbangFeature"})
    print('Compile')

    # submit a new job with the Compile config and get new job ID
    compile_job = cli.new_job(compile_job_config)

    # wait for a job with ID from compile_job to finish the run
    cli.poll(compile_job['jobId'])

    # use compile job as input for fuzz job
    subs['{compile.jobId}'] = compile_job['jobId']

    # create a new job config with Fuzz configuration JSON
    fuzz_job_config = RaftJobConfig(file_path=fuzz, substitutions=subs)
    print('Fuzz')
    # add webhook metadata that will included in every triggered webhook by Fuzz job
    fuzz_job_config.add_metadata({"branch": "wizbangFeature"})
    # create new fuzz job configuration
    fuzz_job = cli.new_job(fuzz_job_config)

    # wait for job ID from fuzz_job to finish the run
    cli.poll(fuzz_job['jobId'])
Beispiel #6
0
def run(compile, test):
    cli = RaftCLI()
    substitutions = {}
    compile_job_config = RaftJobConfig(file_path=compile,
                                       substitutions=substitutions)

    compile_task = compile_job_config.config['testtasks']['tasks'][0]
    #use first task as template and create 30 compile task
    compile_tasks = []
    for t in range(30):
        new_task = copy.deepcopy(compile_task)
        new_task['outputFolder'] = compile_task['outputFolder'] + f"-{t}"
        new_task['toolConfiguration']['compileConfiguration'] = {}
        new_task['toolConfiguration']['compileConfiguration'][
            'mutationsSeed'] = random.randint(0, 1000)
        compile_tasks.append(new_task)

    compile_job_config.config['testtasks']['tasks'] = compile_tasks

    print('Compile')
    # create a new job with the Compile config and get new job ID
    # in compile_job
    compile_json = json.dumps(compile_job_config.config)
    compile_job = cli.new_job(compile_job_config)
    # wait for a job with ID from compile_job to finish the run
    cli.poll(compile_job['jobId'])

    substitutions['{compile.jobId}'] = compile_job['jobId']

    print('Test')
    test_job_config = RaftJobConfig(file_path=test,
                                    substitutions=substitutions)

    task_test_fuzz_lean = test_job_config.config['testtasks']['tasks'][0]
    task_test = test_job_config.config['testtasks']['tasks'][1]
    test_tasks = []
    for t in range(30):
        new_task_test = copy.deepcopy(task_test)
        new_task_test_fuzz_lean = copy.deepcopy(task_test_fuzz_lean)

        new_task_test['outputFolder'] = task_test['outputFolder'] + f"-{t}"
        new_task_test['toolConfiguration']['runConfiguration'][
            'inputFolderPath'] += '/' + compile_tasks[t]['outputFolder']

        new_task_test_fuzz_lean[
            'outputFolder'] = task_test_fuzz_lean['outputFolder'] + f"-{t}"
        new_task_test_fuzz_lean['toolConfiguration']['runConfiguration'][
            'inputFolderPath'] += '/' + compile_tasks[t]['outputFolder']

        test_tasks.append(new_task_test)
        test_tasks.append(new_task_test_fuzz_lean)

    test_job_config.config['testtasks']['tasks'] = test_tasks
    test_job = cli.new_job(test_job_config)
    cli.poll(test_job['jobId'])
Beispiel #7
0
def run(args):
    def ArgumentRequired(name):
        print(f'The {name} parameter is required')
        quit()

    job_action = args.get('job-action')
    local_action = args.get('local-action')

    work_dir = os.path.join(script_dir, 'local')
    if local_action == 'init':
        storage, secrets = init_local(work_dir)
        print(f'Created results storage folder: {storage}')
        print(f'Created secrets folder: {secrets}')

    if job_action == 'create':
        cli = RaftLocalCLI(work_dir)
        json_config_path = args.get('file')
        if json_config_path is None:
            ArgumentRequired('--file')

        substitutionDictionary = {}
        substitutionParameter = args.get('substitute')
        if substitutionParameter:
            substitutionDictionary = json.loads(substitutionParameter,
                                                object_hook=json_hook)

        job_config = (RaftJobConfig(file_path=json_config_path,
                                    substitutions=substitutionDictionary))

        print(job_config.config)
        duration = args.get('duration')
        if duration:
            job_config.config['duration'] = duration

        cli.new_job(job_config)
def run(replay, fuzz_job_id, replay_job_id=None):
    cli = RaftCLI()
    substitutions = {
        '{defaults.deploymentName}': cli.definitions.deployment,
        '{jobRunId}': fuzz_job_id
    }
    replay_job_config = RaftJobConfig(file_path=replay,
                                      substitutions=substitutions)

    print('Replay')
    isIdle = False
    for task in replay_job_config.config['tasks']:
        isIdle = isIdle or task['isIdling']

    if isIdle and replay_job_id:
        cli.update_job(replay_job_id, replay_job_config)
        print(f'Idle Job: {replay_job_id}')
    else:
        # create new fuzz job configuration
        replay_job_id = cli.new_job(replay_job_config)
        if isIdle:
            print(f'New Idle Job: {replay_job_id}')
        else:
            print(f'New Job: {replay_job_id}')

    if not isIdle:
        # wait for job ID from fuzz_job to finish the run
        cli.poll(replay_job_id['jobId'])
def run(run_zap):
    cli = RaftCLI()
    run_zap_config = RaftJobConfig(file_path=run_zap,
                        substitutions={'{defaults.deploymentName}' : cli.definitions.deployment})
    zap_job = cli.new_job(run_zap_config)
    print(zap_job)
    cli.poll(zap_job['jobId'])
Beispiel #10
0
def run(compile, test, fuzz, replay):
    # instantiate RAFT CLI
    cli = RaftCLI()
    # Create compilation job configuration
    compile_job_config = RaftJobConfig(file_path=compile)
    print('Compile')
    # submit a new job with the Compile config and get new job ID
    compile_job = cli.new_job(compile_job_config)
    # wait for a job with ID from compile_job to finish the run
    cli.poll(compile_job['jobId'])

    subs = {}
    # use compile job as input for fuzz job
    subs['{compile.jobId}'] = compile_job['jobId']

    test_job_config = RaftJobConfig(file_path=test, substitutions=subs)
    print('Test')
    # create new fuzz job configuration
    test_job = cli.new_job(test_job_config)
    # wait for job ID from fuzz_job to finish the run
    cli.poll(test_job['jobId'])

    subs['{outputFolder}'] = 'fuzz'
    # create a new job config with Fuzz configuration JSON
    fuzz_job_config = RaftJobConfig(file_path=fuzz, substitutions=subs)
    print('Fuzz')
    # create new fuzz job configuration
    fuzz_job = cli.new_job(fuzz_job_config)

    # wait for job ID from fuzz_job to finish the run
    cli.poll(fuzz_job['jobId'])

    status = cli.job_status(fuzz_job['jobId'])
    experiment = None
    for s in status:
        if (s['agentName'] != s['jobId']):
            if (int(s['details']['numberOfBugsFound']) > 0):
                experiment = s['details']['experiment']
            else:
                print("Did not find any bugs")

    subs['{experiment}'] = experiment
    subs['{jobId}'] = fuzz_job['jobId']

    replay_job_config = RaftJobConfig(file_path=replay, substitutions=subs)
    replay_job = cli.new_job(replay_job_config)
    cli.poll(replay_job['jobId'])
Beispiel #11
0
def run(cli, run_config):
    substitutions = {
        '{defaults.deploymentName}': (RaftCLI()).definitions.deployment
    }
    run_job_config = RaftJobConfig(file_path=run_config, substitutions=substitutions)
    run_job = cli.new_job(run_job_config)
    # wait for a job with ID from compile_job to finish the run
    cli.poll(run_job['jobId'])
Beispiel #12
0
def run(cli, run_file):
    run_config = RaftJobConfig(file_path=run_file,
                               substitutions={
                                   '{defaults.deploymentName}':
                                   (RaftCLI().definitions.deployment)
                               })
    job = cli.new_job(run_config)
    print(job)
    cli.poll(job['jobId'])
Beispiel #13
0
def run(cli, config, subs):
    # Create compilation job configuration
    job_config = RaftJobConfig(file_path=config, substitutions=subs)
    print(f'Running {config}')
    # submit a new job with the Compile config and get new job ID
    job = cli.new_job(job_config)
    # wait for a job with ID from compile_job to finish the run
    cli.poll(job['jobId'])
    return job['jobId']
Beispiel #14
0
def test(cli, configs):
    test_count = 0
    for c in configs:
        if configs[c].get('test'):
            subs['{compile.jobId}'] = configs[c]['compile_job_id']
            test_job_config = RaftJobConfig(file_path=configs[c]['test'],
                                            substitutions=subs)
            test_job = cli.new_job(test_job_config)
            configs[c]['test_job_id'] = test_job['jobId']
            test_count = test_count + 1
    print('Testing all ' + str(test_count) + ' samples ...')
    wait(configs, test_count, 'test', 'test_job_id')
Beispiel #15
0
def fuzz_and_zap(cli, configs):
    fuzz_count = 0
    zap_count = 0
    for c in configs:
        if configs[c].get('fuzz'):
            subs['{compile.jobId}'] = configs[c]['compile_job_id']
            fuzz_job_config = RaftJobConfig(file_path=configs[c]['fuzz'],
                                            substitutions=subs)
            fuzz_job = cli.new_job(fuzz_job_config)
            configs[c]['fuzz_job_id'] = fuzz_job['jobId']
            fuzz_count = fuzz_count + 1

        if configs[c].get('zap'):
            zap_job_config = RaftJobConfig(file_path=configs[c]['zap'],
                                           substitutions=subs)
            zap_job = cli.new_job(zap_job_config)
            configs[c]['zap_job_id'] = zap_job['jobId']
            zap_count = zap_count + 1

    print('Fuzzing all ' + str(fuzz_count) + ' and ZAP: ' + str(zap_count) +
          ' samples ...')
    wait(configs, fuzz_count, 'fuzz', 'fuzz_job_id')
    wait(configs, zap_count, 'zap', 'zap_job_id')
Beispiel #16
0
def run(args):
    def ArgumentRequired(name):
        print(f'The {name} parameter is required')
        quit()

    job_action = args.get('job-action')
    local_action = args.get('local-action')

    if local_action == 'init':
        storage, secrets, event_sink = init_local()
        print(f'Created results storage folder: {storage}')
        print(f'Created secrets folder: {secrets}')
        print(f'Created events_sink folder: {event_sink}')

    if job_action == 'create':
        cli = RaftLocalCLI(network=args.get('network'),
                           telemetry=args.get('no_telemetry'))
        json_config_path = args.get('file')
        if json_config_path is None:
            ArgumentRequired('--file')

        substitutionDictionary = {}
        substitutionParameter = args.get('substitute')
        if substitutionParameter:
            substitutionDictionary = json.loads(substitutionParameter,
                                                object_hook=json_hook)

        job_config = (RaftJobConfig(file_path=json_config_path,
                                    substitutions=substitutionDictionary))

        print(job_config.config)
        duration = args.get('duration')
        if duration:
            job_config.config['duration'] = duration

        cli.new_job(job_config, args.get('jobStatusWebhookUrl'),
                    args.get('bugFoundWebhookUrl'))
Beispiel #17
0
def run(args):
    def validate(defaults):
        s = defaults.get('subscription')
        d = defaults.get('deploymentName')
        r = defaults.get('region')
        return (s and d and r)

    defaults_path = args['defaults_context_path']
    defaults_json = args['defaults_context_json']

    if defaults_json:
        print(f"Loading defaults from command line: {defaults_json}")
        defaults = json.loads(defaults_json)
        if not validate(defaults):
            print(defaults_help)
            return
    # check if defaults.json is set in the context and it exists
    elif os.path.isfile(defaults_path):
        with open(defaults_path, 'r') as d:
            defaults = json.load(d)
            if not validate(defaults):
                print(defaults_help)
                return
    else:
        with open(defaults_path, 'w') as d:
            d.write(fresh_defaults)
        print(defaults_help)
        return

    defaults['secret'] = args.get('secret')
    if 'metricsOptIn' not in defaults:
        defaults['metricsOptIn'] = True

    if defaults.get('useAppInsights') is None:
        defaults['useAppInsights'] = True

    cli_action = args.get('logout')
    service_action = args.get('service-action')
    job_action = args.get('job-action')
    webhook_action = args.get('webhook-action')

    if cli_action == 'logout':
        raft_sdk.raft_common.delete_token_cache()
    elif service_action:
        service_cli = RaftServiceCLI(defaults, defaults_path,
                                     args.get('secret'))
        if service_action == 'restart':
            service_cli.restart()
        elif service_action == 'info':
            info = service_cli.service_info()
            print(info)
        elif service_action == 'deploy':
            skip_sp_deployment = args.get('skip_sp_deployment')
            service_cli.deploy(
                args['sku'], skip_sp_deployment and skip_sp_deployment is True)
        elif service_action == 'upload-tools':
            utils_file_share = f'{uuid.uuid4()}'
            service_cli.upload_utils(utils_file_share,
                                     args.get('custom_tools_path'))
            service_cli.restart()
        else:
            raise Exception(f'Unhandled service argument: {service_action}')

    elif job_action:
        cli = RaftCLI()
        if job_action == 'create':
            json_config_path = args.get('file')
            if json_config_path is None:
                ArgumentRequired('--file')

            substitutionDictionary = {}
            substitutionParameter = args.get('substitute')
            if substitutionParameter:
                substitutionDictionary = json.loads(substitutionParameter)

            job_config = RaftJobConfig(file_path=json_config_path,
                                       substitutions=substitutionDictionary)

            print(job_config.config)
            duration = args.get('duration')
            if duration:
                job_config.config['duration'] = duration

            metadata = args.get('metadata')
            if metadata:
                job_config.config['metadata'] = json.loads(metadata)

            newJob = cli.new_job(job_config, args.get('region'))
            poll_interval = args.get('poll')
            if poll_interval:
                print(newJob)
                cli.poll(newJob['jobId'], poll_interval)
            else:
                print(newJob)

        elif job_action == 'status':
            job_id = args.get('job_id')
            if job_id is None:
                ArgumentRequired('--job-id')
            job_status = cli.job_status(job_id)
            poll_interval = args.get('poll')
            cli.print_status(job_status)
            if poll_interval:
                cli.poll(job_id, poll_interval)

        elif job_action == 'list':
            jobs_list = cli.list_jobs(args['look_back_hours'])
            sorted = {}
            for job in jobs_list:
                if sorted.get(job['jobId']):
                    sorted[job['jobId']].append(job)
                else:
                    sorted[job['jobId']] = [job]

            for s in sorted:
                cli.print_status(sorted[s])
                print()

            print(f"Total number of jobs: {len(sorted)}")

        elif job_action == 'update':
            json_config_path = args.get('file')
            if json_config_path is None:
                ArgumentRequired('--file')

            substitutionDictionary = {}
            substitutionParameter = args.get('substitute')
            if substitutionParameter:
                substitutionDictionary = json.loads(substitutionParameter)

            job_update = cli.update_job(
                args.get('job_id'),
                RaftJobConfig(file_path=json_config_path,
                              substitutions=substitutionDictionary))
            print(job_update)

        elif job_action == 'results':
            job_id = args.get('job_id')
            if job_id is None:
                ArgumentRequired('--job-id')
            url = cli.result_url(job_id)
            print(url)

        elif job_action == 'delete':
            job_id = args.get('job_id')
            if job_id is None:
                ArgumentRequired('--job-id')
            job_delete = cli.delete_job(job_id)
            print(job_delete)

    elif webhook_action:
        cli = RaftCLI()
        if webhook_action == 'events':
            webhook_events = cli.list_available_webhooks_events()
            print(webhook_events)

        elif webhook_action == 'create':
            name_parameter = args.get('name')
            if name_parameter is None:
                ArgumentRequired('--name')

            event_parameter = args.get('event')
            if event_parameter is None:
                ArgumentRequired('--event')

            uri_parameter = args.get('url')
            if uri_parameter is None:
                ArgumentRequired('--url')

            webhook_create_or_update = cli.set_webhooks_subscription(
                name_parameter, event_parameter, uri_parameter)
            print(webhook_create_or_update)

        elif webhook_action == 'test':
            name_parameter = args.get('name')
            if name_parameter is None:
                ArgumentRequired('--name')

            event_parameter = args.get('event')
            if event_parameter is None:
                ArgumentRequired('--event')

            webhook_test = cli.test_webhook(name_parameter, event_parameter)
            print(webhook_test)

        elif webhook_action == 'delete':
            name_parameter = args.get('name')
            if name_parameter is None:
                ArgumentRequired('--name')

            event_parameter = args.get('event')
            if event_parameter is None:
                ArgumentRequired('--event')

            webhook_delete = cli.delete_webhook(name_parameter,
                                                event_parameter)
            print(webhook_delete)

        elif webhook_action == 'list':
            name_parameter = args.get('name')
            if name_parameter is None:
                ArgumentRequired('--name')

            # the event name is not required.
            # If not supplied all events will be listed.
            event_parameter = args.get('event')

            webhooks_list = cli.list_webhooks(name_parameter, event_parameter)
            print(webhooks_list)

        else:
            raise Exception('Expected arguments could not be found in args')