mirror of
https://github.com/AFLplusplus/AFLplusplus.git
synced 2025-06-17 12:18:08 +00:00
small adjustments for custom mutator
This commit is contained in:
@ -3,9 +3,10 @@
|
|||||||
|
|
||||||
Written by Khaled Yakdan <yakdan@code-intelligence.de>
|
Written by Khaled Yakdan <yakdan@code-intelligence.de>
|
||||||
|
|
||||||
This a simple mutator that assumes that the generates messages starting with one
|
This a simple mutator that assumes that the generates messages starting with
|
||||||
of the three strings GET, PUT, or DEL followed by a payload. The mutator randomly
|
one of the three strings GET, PUT, or DEL followed by a payload. The mutator
|
||||||
selects a commend and mutates the payload of the seed provided as input.
|
randomly selects a commend and mutates the payload of the seed provided as
|
||||||
|
input.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@ -13,28 +14,36 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
static const char *commands[] = {
|
static const char *commands[] = {
|
||||||
|
|
||||||
"GET",
|
"GET",
|
||||||
"PUT",
|
"PUT",
|
||||||
"DEL",
|
"DEL",
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static size_t data_size = 100;
|
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) {
|
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
|
// Seed the PRNG
|
||||||
srand(seed);
|
srand(seed);
|
||||||
|
|
||||||
// Make sure that the packet size does not exceed the maximum size expected by the fuzzer
|
// 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;
|
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
|
// Randomly select a command string to add as a header to the packet
|
||||||
memcpy(mutated_out, commands[rand() % 3], 3);
|
memcpy(mutated_out, commands[rand() % 3], 3);
|
||||||
|
|
||||||
// Mutate the payload of the packet
|
// Mutate the payload of the packet
|
||||||
for (int i = 3 ; i < mutated_size ; i++) {
|
for (int i = 3; i < mutated_size; i++) {
|
||||||
|
|
||||||
mutated_out[i] = (data[i] + rand() % 10) & 0xff;
|
mutated_out[i] = (data[i] + rand() % 10) & 0xff;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return mutated_size;
|
return mutated_size;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -426,20 +426,24 @@ u8* (*post_handler)(u8* buf, u32* len);
|
|||||||
* @param data Input data to be mutated
|
* @param data Input data to be mutated
|
||||||
* @param size Size of input data
|
* @param size Size of input data
|
||||||
* @param mutated_out Buffer to store the mutated input
|
* @param mutated_out Buffer to store the mutated input
|
||||||
* @param max_size Maximum size of the mutated output. The mutation must not produce data larger than max_size.
|
* @param max_size Maximum size of the mutated output. The mutation must not
|
||||||
* @param seed Seed used for the mutation. The mutation should produce the same output given the same seed.
|
* produce data larger than max_size.
|
||||||
|
* @param seed Seed used for the mutation. The mutation should produce the same
|
||||||
|
* output given the same seed.
|
||||||
* @return Size of the mutated output.
|
* @return Size of the mutated output.
|
||||||
*/
|
*/
|
||||||
size_t (*custom_mutator)(u8 *data, size_t size, u8* mutated_out, size_t max_size, unsigned int seed);
|
size_t (*custom_mutator)(u8* data, size_t size, u8* mutated_out,
|
||||||
|
size_t max_size, unsigned int seed);
|
||||||
/**
|
/**
|
||||||
* A post-processing function to use right before AFL writes the test case to disk in order to execute the target.
|
* A post-processing function to use right before AFL writes the test case to
|
||||||
* If this functionality is not needed, Simply don't define this function.
|
* disk in order to execute the target. If this functionality is not needed,
|
||||||
|
* Simply don't define this function.
|
||||||
* @param data Buffer containing the test case to be executed.
|
* @param data Buffer containing the test case to be executed.
|
||||||
* @param size Size of the test case.
|
* @param size Size of the test case.
|
||||||
* @param new_data Buffer to store the test case after processing
|
* @param new_data Buffer to store the test case after processing
|
||||||
* @return Size of data after processing.
|
* @return Size of data after processing.
|
||||||
*/
|
*/
|
||||||
size_t (*pre_save_handler)(u8 *data, size_t size, u8 **new_data);
|
size_t (*pre_save_handler)(u8* data, size_t size, u8** new_data);
|
||||||
|
|
||||||
/* Interesting values, as per config.h */
|
/* Interesting values, as per config.h */
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user