aboutsummaryrefslogtreecommitdiff
path: root/custom_mutators
diff options
context:
space:
mode:
authorvan Hauser <vh@thc.org>2024-07-01 08:57:38 +0200
committerGitHub <noreply@github.com>2024-07-01 08:57:38 +0200
commit53409530b369e560c7f6f37ead5a5db9e116efd0 (patch)
tree6449fa84e6b9e26849d298af881014b18f55dc0b /custom_mutators
parent36db3428ab16156dd72196213d2a02a5eadaed11 (diff)
parent43014cd465eec8cc47eda041802001776dbb5dd5 (diff)
downloadafl++-53409530b369e560c7f6f37ead5a5db9e116efd0.tar.gz
Merge pull request #2141 from AFLplusplus/dev
push to stable
Diffstat (limited to 'custom_mutators')
-rw-r--r--custom_mutators/atnwalk/README.md2
-rw-r--r--custom_mutators/atnwalk/atnwalk.c3
-rw-r--r--custom_mutators/custom_send_tcp/Makefile7
-rw-r--r--custom_mutators/custom_send_tcp/README.md13
-rw-r--r--custom_mutators/custom_send_tcp/custom_send_tcp.c113
m---------custom_mutators/gramatron/json-c0
-rw-r--r--custom_mutators/grammar_mutator/GRAMMAR_VERSION2
m---------custom_mutators/grammar_mutator/grammar_mutator0
-rw-r--r--custom_mutators/radamsa/libradamsa.c2
9 files changed, 138 insertions, 4 deletions
diff --git a/custom_mutators/atnwalk/README.md b/custom_mutators/atnwalk/README.md
index 730349a3..7dbe8ee5 100644
--- a/custom_mutators/atnwalk/README.md
+++ b/custom_mutators/atnwalk/README.md
@@ -13,7 +13,7 @@ Just type `make` to build `atnwalk.so`.
**NOTE:** The commands below just demonstrate an example how running ATNwalk looks like and require a working [testbed](https://github.com/atnwalk/testbed)
```bash
-# create the required a random seed first
+# create the required random seed first
mkdir -p ~/campaign/example/seeds
cd ~/campaign/example/seeds
head -c1 /dev/urandom | ~/atnwalk/build/javascript/bin/decode -wb > seed.decoded 2> seed.encoded
diff --git a/custom_mutators/atnwalk/atnwalk.c b/custom_mutators/atnwalk/atnwalk.c
index c3a2cd95..45ccc181 100644
--- a/custom_mutators/atnwalk/atnwalk.c
+++ b/custom_mutators/atnwalk/atnwalk.c
@@ -180,7 +180,8 @@ size_t fail_fatal(int fd_socket, uint8_t **out_buf) {
if (fd_socket != -1) { close(fd_socket); }
*out_buf = NULL;
- return 0;
+ fprintf(stderr, "atnwalk.socket not found in current directory!\n");
+ exit(-1);
}
diff --git a/custom_mutators/custom_send_tcp/Makefile b/custom_mutators/custom_send_tcp/Makefile
new file mode 100644
index 00000000..8549ccad
--- /dev/null
+++ b/custom_mutators/custom_send_tcp/Makefile
@@ -0,0 +1,7 @@
+all: custom_send_tcp.so
+
+custom_send_tcp.so:
+ $(CC) -Wno-unused-result -g -O3 -shared -fPIC -o custom_send_tcp.so -I../../include custom_send_tcp.c
+
+clean:
+ rm -f custom_send_tcp.so *.o *~ core
diff --git a/custom_mutators/custom_send_tcp/README.md b/custom_mutators/custom_send_tcp/README.md
new file mode 100644
index 00000000..7b4bb869
--- /dev/null
+++ b/custom_mutators/custom_send_tcp/README.md
@@ -0,0 +1,13 @@
+# Send testcases via TCP custom mutator
+
+This custom mutator sends the fuzzing testcases via TCP.
+
+`AFL_CUSTOM_MUTATOR_LATE_SEND` - MUST be set!
+`CUSTOM_SEND_IP` - the IP address to send to (basically only 127.0.0.1 makes sense)
+`CUSTOM_SEND_PORT` - the TCP port to send to
+`CUSTOM_SEND_READ` - if the custom mutator should wait for a reply from the target
+
+Example:
+```
+CUSTOM_SEND_IP=127.0.0.1 CUSTOM_SEND_PORT=8000 CUSTOM_SEND_READ=1 AFL_CUSTOM_MUTATOR_LATE_SEND=1 AFL_CUSTOM_MUTATOR_LIBRARY=custom_send_tcp.so ./afl-fuzz ...
+```
diff --git a/custom_mutators/custom_send_tcp/custom_send_tcp.c b/custom_mutators/custom_send_tcp/custom_send_tcp.c
new file mode 100644
index 00000000..53689ced
--- /dev/null
+++ b/custom_mutators/custom_send_tcp/custom_send_tcp.c
@@ -0,0 +1,113 @@
+#include <time.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <arpa/inet.h>
+#include <sys/select.h>
+
+#include "afl-fuzz.h"
+
+static int my_debug = 0;
+static int my_read = 0;
+
+#define DEBUG(...) if (my_debug) printf(__VA_ARGS__)
+
+typedef struct tcp_send_mutator {
+ afl_state_t* afl;
+ struct sockaddr_in server_addr;
+} tcp_send_mutator_t;
+
+void *afl_custom_init(afl_state_t* afl, uint32_t seed) {
+ const char* ip = getenv("CUSTOM_SEND_IP");
+ const char* port = getenv("CUSTOM_SEND_PORT");
+
+ if (getenv("AFL_DEBUG")) my_debug = 1;
+ if (getenv("CUSTOM_SEND_READ")) my_read = 1;
+
+ if (!ip || !port) {
+ fprintf(stderr, "You forgot to set CUSTOM_SEND_IP and/or CUSTOM_SEND_PORT\n");
+ exit(1);
+ }
+
+ tcp_send_mutator_t* mutator = calloc(1, sizeof(tcp_send_mutator_t));
+ if (!mutator) {
+ fprintf(stderr, "Failed to allocate mutator struct\n");
+ exit(1);
+ }
+
+ mutator->afl = afl;
+
+ bzero(&mutator->server_addr, sizeof(mutator->server_addr));
+ mutator->server_addr.sin_family = AF_INET;
+ if (inet_pton(AF_INET, ip, &mutator->server_addr.sin_addr) <= 0) {
+ fprintf(stderr, "Could not convert target ip address!\n");
+ exit(1);
+ }
+ mutator->server_addr.sin_port = htons(atoi(port));
+
+ printf("[+] Custom tcp send mutator setup ready to go!\n");
+
+ return mutator;
+}
+
+int try_connect(tcp_send_mutator_t *mutator, int sock, int max_attempts) {
+ while (max_attempts > 0) {
+ if (connect(sock, (struct sockaddr*)&mutator->server_addr, sizeof(mutator->server_addr)) == 0) {
+ return 0;
+ }
+
+ // Even with AFL_CUSTOM_LATE_SEND=1, there is a race between the
+ // application under test having started to listen for connections and
+ // afl_custom_fuzz_send being called. To address this race, we attempt
+ // to connect N times and sleep a short period of time in between
+ // connection attempts.
+ struct timespec t;
+ t.tv_sec = 0;
+ t.tv_nsec = 100;
+ nanosleep(&t, NULL);
+ --max_attempts;
+ }
+ return 1;
+}
+
+void afl_custom_fuzz_send(tcp_send_mutator_t *mutator, uint8_t *buf, size_t buf_size) {
+ int sock = socket(AF_INET, SOCK_STREAM, 0);
+
+ int written = 0;
+ if (sock >= 0 && try_connect(mutator, sock, 10000) == 0) {
+ DEBUG("connected, write()\n");
+ written = write(sock, buf, buf_size);
+ } else {
+ DEBUG("socket() or connect() error: %d\n", errno);
+ }
+
+ if (written < 0) {
+ DEBUG("write() error: %d\n", errno);
+ } else if (my_read) {
+ struct timeval timeout;
+ timeout.tv_sec = 1;
+ timeout.tv_usec = 0;
+
+ fd_set set;
+ FD_ZERO(&set);
+ FD_SET(sock, &set);
+
+ int select_res = select(sock + 1, &set, NULL, NULL, &timeout);
+ if (select_res == -1) {
+ DEBUG("select() error: %d\n", errno);
+ } else if (select_res == 0) {
+ DEBUG("read() timeout!\n");
+ } else {
+ uint8_t buf[64];
+ (void)read(sock, buf, sizeof(buf));
+ }
+ }
+
+ close(sock);
+}
+
+void afl_custom_deinit(tcp_send_mutator_t* mutator) {
+ free(mutator);
+}
diff --git a/custom_mutators/gramatron/json-c b/custom_mutators/gramatron/json-c
-Subproject 11546bfd07a575c47416924cb98de3d33a4e642
+Subproject af8dd4a307e7b837f9fa2959549548ace4afe08
diff --git a/custom_mutators/grammar_mutator/GRAMMAR_VERSION b/custom_mutators/grammar_mutator/GRAMMAR_VERSION
index 02119caf..eea76ba3 100644
--- a/custom_mutators/grammar_mutator/GRAMMAR_VERSION
+++ b/custom_mutators/grammar_mutator/GRAMMAR_VERSION
@@ -1 +1 @@
-95a6857
+05d8f53
diff --git a/custom_mutators/grammar_mutator/grammar_mutator b/custom_mutators/grammar_mutator/grammar_mutator
-Subproject 95a685773e571620cb6e2788dbbdba333e1b9bf
+Subproject 05d8f537f8d656f0754e7ad5dcc653c42cb4f8f
diff --git a/custom_mutators/radamsa/libradamsa.c b/custom_mutators/radamsa/libradamsa.c
index e6838752..1dcf91d8 100644
--- a/custom_mutators/radamsa/libradamsa.c
+++ b/custom_mutators/radamsa/libradamsa.c
@@ -3707,7 +3707,7 @@ typedef intptr_t wdiff;
1024 * 1024 * 8 /* static malloc'd heap size if used as a library */
#define FBITS 24 /* bits in fixnum, on the way to 24 and beyond */
#define FMAX \
- ((1 << FBITS) - 1) /* maximum fixnum (and most negative fixnum) \
+ ((1U << FBITS) - 1) /* maximum fixnum (and most negative fixnum) \
*/
#define MAXOBJ 0xffff /* max words in tuple including header */
#define MAXPAYL \