From 718ae61ae551c72defdbe774d4958c687c6f976f Mon Sep 17 00:00:00 2001 From: Marco d'Itri Date: Tue, 8 Dec 2015 08:38:50 +0100 Subject: [PATCH] Support american fuzzy lop When built with AFL_MODE set to true, whois will use the first line of standard input as command line parameters and the rest as network input. --- Makefile | 13 +++++++++++++ utils.h | 4 ++++ whois.c | 21 +++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/Makefile b/Makefile index 8d8f69b..2634a9a 100644 --- a/Makefile +++ b/Makefile @@ -96,6 +96,19 @@ tld_serv.h: tld_serv_list make_tld_serv.pl servers_charset.h: servers_charset_list make_servers_charset.pl $(PERL) make_servers_charset.pl < $< > $@ +############################################################################## +afl: + $(MAKE) whois \ + CC=afl-gcc AFL_HARDEN=1 \ + HAVE_LIBIDN=1 HAVE_ICONV=1 DEFS=-DAFL_MODE=1 + +afl2: + $(MAKE) whois \ + HAVE_LIBIDN=1 HAVE_ICONV=1 DEFS=-DAFL_MODE=1 + +afl-run: + nice afl-fuzz -i ../afl_in -o ../afl_out -- ./whois + ############################################################################## install: install-whois install-mkpasswd install-pos diff --git a/utils.h b/utils.h index 0f226ae..4523266 100644 --- a/utils.h +++ b/utils.h @@ -9,6 +9,10 @@ #define NOFAIL(ptr) do_nofail((ptr), __FILE__, __LINE__) +#ifndef AFL_MODE +# define AFL_MODE 0 +#endif + /* Portability macros */ #ifdef __GNUC__ # define NORETURN __attribute__((noreturn)) diff --git a/whois.c b/whois.c index 49df0ad..7262bea 100644 --- a/whois.c +++ b/whois.c @@ -140,6 +140,20 @@ int main(int argc, char *argv[]) fstring = malloc(fstringlen + 1); *fstring = '\0'; + /* interface for American Fuzzy Lop */ + if (AFL_MODE) { + FILE *fp = fdopen(0, "r"); + char *buf = NULL; + size_t len = 0; + + /* read one line from stdin */ + if (getline(&buf, &len, fp) < 0) + err_sys("getline"); + fflush(fp); + /* and use it as command line arguments */ + argv = merge_args(buf, argv, &argc); + } + /* prepend options from environment */ argv = merge_args(getenv("WHOIS_OPTIONS"), argv, &argc); @@ -907,6 +921,13 @@ int openconn(const char *server, const char *port) struct sockaddr_in saddr; #endif + /* + * When using American Fuzzy Lop get the data from it using stdin + * instead of connecting to the actual whois server. + */ + if (AFL_MODE) + return (dup(0)); + alarm(60); #ifdef HAVE_GETADDRINFO