aboutsummaryrefslogtreecommitdiff
path: root/custom_mutators
diff options
context:
space:
mode:
authorKhaled Yakdan <yakdan@code-intelligence.de>2019-09-04 22:57:52 +0200
committerKhaled Yakdan <yakdan@code-intelligence.de>2019-09-04 22:57:52 +0200
commit1b3f9713309d27c49b153f9b3af12d208076e93c (patch)
treeba5924f622e579dda32f2f2674b9381e3c2580f5 /custom_mutators
parentaad485128e746d3e11f99a78b8bd77ed2b0354f0 (diff)
downloadAFLplusplus-1b3f9713309d27c49b153f9b3af12d208076e93c.tar.gz
Added documentation and a simple example for the custom mutator functionality
Diffstat (limited to 'custom_mutators')
-rw-r--r--custom_mutators/simple_mutator.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/custom_mutators/simple_mutator.c b/custom_mutators/simple_mutator.c
new file mode 100644
index 00000000..5c40d462
--- /dev/null
+++ b/custom_mutators/simple_mutator.c
@@ -0,0 +1,40 @@
+/*
+ Simple Custom Mutator for AFL
+
+ Written by Khaled Yakdan <yakdan@code-intelligence.de>
+
+ This a simple mutator that assumes that the generates messages starting with one
+ of the three strings GET, PUT, or DEL followed by a payload. The mutator randomly
+ selects a commend and mutates the payload of the seed provided as input.
+*/
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+static const char *commands[] = {
+ "GET",
+ "PUT",
+ "DEL",
+};
+
+static size_t data_size = 100;
+
+size_t afl_custom_mutator (uint8_t *data, size_t size, uint8_t* mutated_out, size_t max_size, unsigned int seed) {
+
+ // Seed the PRNG
+ srand(seed);
+
+ // Make sure that the packet size does not exceed the maximum size expected by the fuzzer
+ size_t mutated_size = data_size <= max_size ? data_size : max_size;
+
+ // Randomly select a command string to add as a header to the packet
+ memcpy(mutated_out, commands[rand() % 3], 3);
+
+ // Mutate the payload of the packet
+ for (int i = 3 ; i < mutated_size ; i++) {
+ mutated_out[i] = (data[i] + rand() % 10) & 0xff;
+ }
+
+ return mutated_size;
+}