Skip to main content

Python implementation of zzuf mutator - little bit-flip atomic bomb

Project description

Python implementation of bit-flip zzuf mutator.

No more os.system, subprocess.check_output and subprocess.Popen :thumbsup:

Basic usage

Inline

from pyZZUF import *

print pyZZUF('good').mutate()

Options

from pyZZUF import *

zzuf = pyZZUF('good')

# Random seed (default 0)
zzuf.set_seed(9)
# Bit fuzzing ratio (default 0.004)
zzuf.set_ratio(0.91)

# Offsets and ranges
zzuf.set_offset(6)
# Only fuzz bytes at offsets within <ranges>
zzuf.set_fuzz_bytes([[0, 3], [6, EOF]])

# Protect bytes and characters in <list>
zzuf.set_protected([0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39])
# Append more bytes
zzuf.set_protected("0123456789", True)

# Refuse bytes and characters in <list>
zzuf.set_refused("abcd")
# Append more bytes
zzuf.set_refused([0x00, 0xFF], True)

# Permit bytes and characters in <list>
zzuf.set_permitted('bad')
# Append more bytes
zzuf.set_permitted('!', True)

# Fuzzing mode <mode> ([xor] set unset)
zzuf.set_fuzz_mode(FUZZ_MODE_XOR)

print zzuf.mutate()

Mutagen

zzuf = pyZZUF('good')

for data in zzuf.mutagen(start=0.0, stop=1, step=0.1):
    if __debug__:
        seed, ratio, index = data.get_state()
        print data.tostring().encode('hex'), seed, ratio, index
    if data == 'bad!':
        break

Inheritance of the previous state (meat)

zzuf = pyZZUF('good')

for data in zzuf.mutagen(start=0.0, stop=1, step=0.1, inheritance=True):
    if __debug__:
        seed, ratio, index = data.get_state()
        print data.tostring().encode('hex'), seed, ratio, index
    if data == 'bad!':
        break

Stream-generator with restoring state of mutator

obj = pyZZUF('good')
gen = obj.mutagen(start=0.0, stop=1, step=0.01)

while True:
    try:
        data = gen.next()
        seed, ratio, index = data.get_state()

        if __debug__:
            print data.tostring().encode('hex'), seed, ratio, index

        if seed == 20:
            # Set next state of generator (<seed>, <ratio>).
            # In this example, it makes an infinite loop!
            gen.send((0, 0.0))

        if data == 'bad!':
            break
    except StopIteration:
        break

Check of identity

$ echo -n "The quick brown fox jumps over the lazy dog" | zzuf -r0.04 | hd

00000000  54 68 65 20 71 75 69 63  6b 20 62 72 6f 57 6c 20  |The quick broWl |
00000010  66 4f 58 20 6a 75 6f 70  73 24 6f 76 75 72 20 74  |fOX juops$ovur t|
00000020  68 65 21 6c 61 7a 78 20  66 6f 67                 |he!lazx fog|
0000002b

$ python -c "import pyZZUF, sys; sys.stdout.write(pyZZUF.pyZZUF('The quick brown fox jumps over the lazy dog', ratio=0.04).mutate().tostring())" | hd

00000000  54 68 65 20 71 75 69 63  6b 20 62 72 6f 57 6c 20  |The quick broWl |
00000010  66 4f 58 20 6a 75 6f 70  73 24 6f 76 75 72 20 74  |fOX juops$ovur t|
00000020  68 65 21 6c 61 7a 78 20  66 6f 67                 |he!lazx fog|
0000002b

Installation

pip install pyZZUF

Notes*

Use PyPy for speedup

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyZZUF-0.1-py2.7.tar.gz (4.3 kB view hashes)

Uploaded Source

Built Distributions

pyZZUF-0.1-py3-none-any.whl (4.3 kB view hashes)

Uploaded Python 3

pyZZUF-0.1-py2.7.egg (8.0 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page