diff --git a/mythx_cli/fuzz/faas.py b/mythx_cli/fuzz/faas.py index d7ab516..4eeed7e 100644 --- a/mythx_cli/fuzz/faas.py +++ b/mythx_cli/fuzz/faas.py @@ -1,3 +1,4 @@ +import json import logging import random import string @@ -54,7 +55,7 @@ def start_faas_campaign(self, payload): raise e raise RequestError(f"Error starting FaaS campaign.") - def create_faas_campaign(self, campaign_data, seed_state): + def create_faas_campaign(self, campaign_data, seed_state, dry_run = False): """Submit a campaign to the FaaS and start that campaign. This function takes a FaaS payload and makes an HTTP request to the Faas backend, which @@ -102,6 +103,11 @@ def create_faas_campaign(self, campaign_data, seed_state): f"Error getting Scribble arming metadata." ) from e + if dry_run: + print("Printing output \n --------") + print(f"{json.dumps(api_payload)}") + print("End of output \n --------") + return "campaign not started due to --dry-run option" campaign_id = self.start_faas_campaign(api_payload) return campaign_id diff --git a/mythx_cli/fuzz/run.py b/mythx_cli/fuzz/run.py index c48de59..a8d4e37 100644 --- a/mythx_cli/fuzz/run.py +++ b/mythx_cli/fuzz/run.py @@ -57,7 +57,7 @@ def determine_ide() -> IDE: "--corpus-target", type=click.STRING, help="Project UUID, Campaign UUID or Corpus UUID to reuse the corpus from. " - "In case of a project, corpus from the project's latest submitted campaign will be used", + "In case of a project, corpus from the project's latest submitted campaign will be used", default=None, required=False, ) @@ -69,8 +69,16 @@ def determine_ide() -> IDE: help="Map the analyses results to the original source code, instead of the instrumented one. " "This is meant to be used with Scribble.", ) + +@click.option( + "--dry-run", + is_flag=True, + default=False, + help="Outputs the data to be sent to the FaaS API without making the request.", +) + @click.pass_obj -def fuzz_run(ctx, address, more_addresses, corpus_target, map_to_original_source, target): +def fuzz_run(ctx, address, more_addresses, corpus_target, map_to_original_source, dry_run, target): # read YAML config params from ctx dict, e.g. ganache rpc url # Introduce a separate `fuzz` section in the YAML file @@ -119,11 +127,11 @@ def fuzz_run(ctx, address, more_addresses, corpus_target, map_to_original_source if not target: target = analyze_config["targets"] if not map_to_original_source: - map_to_original_source = ( - analyze_config["map_to_original_source"] - if "map_to_original_source" in config_options - else default_config["map_to_original_source"] - ) + map_to_original_source = ( + analyze_config["map_to_original_source"] + if "map_to_original_source" in config_options + else default_config["map_to_original_source"] + ) # Optional config parameters # Here we parse the config parameters from the config file and use defaults for non available values contract_address = analyze_config["deployed_contract_address"] @@ -193,7 +201,7 @@ def fuzz_run(ctx, address, more_addresses, corpus_target, map_to_original_source ) try: campaign_id = faas_client.create_faas_campaign( - campaign_data=artifacts, seed_state=seed_state + campaign_data=artifacts, seed_state=seed_state, dry_run=dry_run ) click.echo( "You can view campaign here: " + faas_url + "/campaigns/" + str(campaign_id)