|
| 1 | +import sys |
1 | 2 | from functools import reduce |
2 | 3 | from operator import iconcat |
3 | 4 |
|
4 | 5 | import click |
5 | | -from tqdm.auto import trange |
6 | | - |
| 6 | +from pirebok.banner import banner |
7 | 7 | from pirebok.fuzzers import Fuzzer, FuzzerBuilder |
8 | 8 |
|
9 | 9 |
|
10 | | -@click.command(no_args_is_help=True, context_settings={'show_default': True}) |
| 10 | +class BannerCommand(click.Command): |
| 11 | + def format_help(self, ctx: click.Context, formatter: click.HelpFormatter) -> None: |
| 12 | + if not ctx.params.get("silent"): |
| 13 | + print(banner(), file=sys.stderr) |
| 14 | + super().format_help(ctx, formatter) |
| 15 | + |
| 16 | + |
| 17 | +@click.command(cls=BannerCommand, no_args_is_help=True, context_settings={'show_default': True}) |
11 | 18 | @click.option( |
12 | 19 | "-f", |
13 | 20 | "--fuzzer", |
|
20 | 27 | ) |
21 | 28 | @click.option("-s", "--steps", default=10, help="Number of iteration") |
22 | 29 | @click.option("-t", "--threshold", default=0.5, help="Threshold for the guided fuzzers") |
| 30 | +@click.option("--max-rounds", default=100, help="Maximum mutation rounds for guided fuzzers") |
| 31 | +@click.option("--round-size", default=20, help="Mutations per round for guided fuzzers") |
| 32 | +@click.option("--timeout", default=0, help="Timeout in seconds, 0=unlimited") |
23 | 33 | @click.option("-p", "--payload", required=True, help="Payload to fuzz") |
24 | | -def main(fuzzer: str, steps: int, threshold: float, payload: str) -> None: |
| 34 | +@click.option("-q", "--silent", is_flag=True, default=False, help="Suppress banner") |
| 35 | +def main( |
| 36 | + fuzzer: str, |
| 37 | + steps: int, |
| 38 | + threshold: float, |
| 39 | + max_rounds: int, |
| 40 | + round_size: int, |
| 41 | + timeout: int, |
| 42 | + payload: str, |
| 43 | + silent: bool, |
| 44 | +) -> None: |
| 45 | + if not silent: |
| 46 | + print(banner(), file=sys.stderr) |
25 | 47 | fuzzer_builder = FuzzerBuilder() |
26 | | - fzzer = fuzzer_builder.choice(fuzzer).threshold(threshold).build() |
27 | | - print("\n".join(map(repr, set(map(lambda _: fzzer.fuzz(payload), trange(steps)))))) |
| 48 | + fzzer = ( |
| 49 | + fuzzer_builder.choice(fuzzer) |
| 50 | + .threshold(threshold) |
| 51 | + .max_rounds(max_rounds) |
| 52 | + .round_size(round_size) |
| 53 | + .timeout(timeout) |
| 54 | + .build() |
| 55 | + ) |
| 56 | + print("\n".join(map(repr, set(map(lambda _: fzzer.fuzz(payload), range(steps)))))) |
28 | 57 |
|
29 | 58 |
|
30 | 59 | if __name__ == "__main__": |
|
0 commit comments