gramfuzz - A grammar-based fuzzing library

gramfuzz allows one to define grammars and use them to generate random data for fuzzing.

Installation

gramfuzz is available on PyPI and can be installed via pip!

pip install gramfuzz

TLDR Example

Suppose we define a grammar for generating names and their prefixes and suffixes:

# names_grammar.py
from gramfuzz.fields import *

class NRef(Ref):
    cat = "name_def"
class NDef(Def):
    cat = "name_def"

Def("name",
    Join(
        Opt(NRef("name_prefix")),
        NRef("first_name"),
        Opt(NRef("middle_initial")),
        Opt(NRef("last_name")),
        Opt(NRef("name_suffix")),
    sep=" "),
    cat="name"
)
NDef("name_prefix", Or("Sir", "Ms", "Mr"))
NDef("first_name", Or("Henry", "Susy"))
NDef("middle_initial", String(min=1, max=2), ".")
NDef("last_name", Or("Blart", "Tralb"))
NDef("name_suffix", Or("Phd.", "II", "III"))

We could then use this grammar like so:

import gramfuzz

fuzzer = gramfuzz.GramFuzzer()
fuzzer.load_grammar("names_grammar.py")
names = fuzzer.gen(cat="name", num=10)
# or like this if GRAMFUZZ_TOP_LEVEL_CAT="name" was defined in the
# names_grammar.py file:
#     names = fuzzer.gen(cat_group="names_grammar", num=10)
print("\n".join(names))

Which would output something like this:

Susy
Henry Blart
Susy J. Tralb Phd.
Ms Susy p. Tralb Phd.
Henry Blart II
Henry T. Blart
Sir Susy D.
Ms Henry Blart II
Susy Z. Phd.
Susy Tralb

Indices and tables