From 46c3e0e276e62b6be76e69b68de56432692efcf3 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 30 Oct 2017 21:39:56 +0100 Subject: [SERVER] Add AFL support AFL is an instrumenting fuzzer. It expects to pass input to the program to be tested via command line (file name) or via stdin. This adds support for reading messages that normally would arrive via network directly from stdin. In this mode, the server is pretty useless otherwise. http://lcamtuf.coredump.cx/afl/ --- src/server/server.c | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'src/server/server.c') diff --git a/src/server/server.c b/src/server/server.c index 5932b0b..5776765 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -28,6 +28,7 @@ #include "altservers.h" #include "integrity.h" #include "threadpool.h" +#include "rpc.h" #include "../version.h" #include "../shared/sockhelper.h" @@ -227,6 +228,40 @@ int main(int argc, char *argv[]) exit( EXIT_FAILURE ); } + timing_setBase(); + timing_get( &startupTime ); + +#ifdef AFL_MODE + // ###### AFL + // + image_serverStartup(); + net_init(); + uplink_globalsInit(); + rpc_init(); + if ( !image_loadAll( NULL ) || _shutdown ) { + fprintf( stderr, "Error loading images\n" ); + exit( 3 ); + } + { + struct sockaddr_storage client; + memset( &client, 0, sizeof client ); + client.ss_family = AF_INET; + dnbd3_client_t *dnbd3_client = dnbd3_prepareClient( &client, 1 ); + if ( dnbd3_client == NULL ) { + fprintf( stderr, "New client failed\n" ); + exit( 1 ); + } +#ifdef __AFL_HAVE_MANUAL_CONTROL + __AFL_INIT(); +#endif + net_handleNewConnection( dnbd3_client ); + exit( 0 ); + } + // + // ###### AFL END +#endif + + // One-shots first: if ( paramCreate != NULL ) { @@ -236,12 +271,12 @@ int main(int argc, char *argv[]) // No one-shot detected, normal server operation if ( demonize ) daemon( 1, 0 ); - timing_setBase(); image_serverStartup(); altservers_init(); integrity_init(); net_init(); uplink_globalsInit(); + rpc_init(); logadd( LOG_INFO, "DNBD3 server starting.... Machine type: " ENDIAN_MODE ); if ( altservers_load() < 0 ) { @@ -268,8 +303,6 @@ int main(int argc, char *argv[]) return 0; } - timing_get( &startupTime ); - // Give other threads some time to start up before accepting connections sleep( 1 ); -- cgit v1.2.3-55-g7522