diff options
author | van Hauser <vh@thc.org> | 2019-09-05 10:06:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-05 10:06:02 +0200 |
commit | 5955dd4e25c9f7dd46e19ea246b14734822d1759 (patch) | |
tree | 802c5b59ee18a2977aa10740105a62e04423a06e /custom_mutators/simple_mutator.c | |
parent | abf61ecc8f1b4ea3de59f818d859139637b29f32 (diff) | |
parent | e0f9aa35081b0dffba1476192bc071848082c504 (diff) | |
download | afl++-5955dd4e25c9f7dd46e19ea246b14734822d1759.tar.gz |
Merge pull request #54 from code-intelligence-gmbh/custom_mutator_docs
Custom mutator docs
Diffstat (limited to 'custom_mutators/simple_mutator.c')
-rw-r--r-- | custom_mutators/simple_mutator.c | 40 |
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; +} |