aboutsummaryrefslogtreecommitdiff
path: root/python_mutators/simple-chunk-replace.py
diff options
context:
space:
mode:
authorvan Hauser <vh@thc.org>2019-06-20 12:22:46 +0200
committervan Hauser <vh@thc.org>2019-06-20 12:22:46 +0200
commitd10ebd1a6837f9fc42886fd5debe5311784be75a (patch)
tree38a04cb84b2815af7b2f588cb0b1ee04edf0a0b4 /python_mutators/simple-chunk-replace.py
parent4e3d921f1a7016755721cec0141ae0978621669f (diff)
downloadafl++-d10ebd1a6837f9fc42886fd5debe5311784be75a.tar.gz
python mutator examples added
Diffstat (limited to 'python_mutators/simple-chunk-replace.py')
-rw-r--r--python_mutators/simple-chunk-replace.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/python_mutators/simple-chunk-replace.py b/python_mutators/simple-chunk-replace.py
new file mode 100644
index 00000000..218dd4f8
--- /dev/null
+++ b/python_mutators/simple-chunk-replace.py
@@ -0,0 +1,59 @@
+#!/usr/bin/env python
+# encoding: utf-8
+'''
+Simple Chunk Cross-Over Replacement Module for AFLFuzz
+
+@author: Christian Holler (:decoder)
+
+@license:
+
+This Source Code Form is subject to the terms of the Mozilla Public
+License, v. 2.0. If a copy of the MPL was not distributed with this
+file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+@contact: choller@mozilla.com
+'''
+
+import random
+
+def init(seed):
+ '''
+ Called once when AFLFuzz starts up. Used to seed our RNG.
+
+ @type seed: int
+ @param seed: A 32-bit random value
+ '''
+ # Seed our RNG
+ random.seed(seed)
+ return 0
+
+def fuzz(buf, add_buf):
+ '''
+ Called per fuzzing iteration.
+
+ @type buf: bytearray
+ @param buf: The buffer that should be mutated.
+
+ @type add_buf: bytearray
+ @param add_buf: A second buffer that can be used as mutation source.
+
+ @rtype: bytearray
+ @return: A new bytearray containing the mutated data
+ '''
+ # Make a copy of our input buffer for returning
+ ret = bytearray(buf)
+
+ # Take a random fragment length between 2 and 32 (or less if add_buf is shorter)
+ fragment_len = random.randint(1, min(len(add_buf), 32))
+
+ # Determine a random source index where to take the data chunk from
+ rand_src_idx = random.randint(0, len(add_buf) - fragment_len)
+
+ # Determine a random destination index where to put the data chunk
+ rand_dst_idx = random.randint(0, len(buf))
+
+ # Make the chunk replacement
+ ret[rand_dst_idx:rand_dst_idx + fragment_len] = add_buf[rand_src_idx:rand_src_idx + fragment_len]
+
+ # Return data
+ return ret