From a65d7495b52690d3a7d660b8aec50aa22f5ceda6 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Wed, 8 Apr 2015 23:12:25 +0300 Subject: [PATCH] tests: Add p2p-fuzzer This program can be used to run fuzzing tests for areas related to P2P message parsing and processing. p2p-fuzzer allows data files to be used to inject Probe Response and Action frames for processing by the P2P module. Signed-off-by: Jouni Malinen --- src/common/Makefile | 26 +++- src/p2p/Makefile | 27 +++- src/wps/Makefile | 39 ++++- tests/p2p-fuzzer/Makefile | 51 +++++++ tests/p2p-fuzzer/go-neg-req.dat | Bin 0 -> 155 bytes tests/p2p-fuzzer/invitation-req.dat | Bin 0 -> 123 bytes tests/p2p-fuzzer/p2p-fuzzer.c | 213 ++++++++++++++++++++++++++++ tests/p2p-fuzzer/p2ps-pd-req.dat | Bin 0 -> 189 bytes tests/p2p-fuzzer/proberesp-go.dat | Bin 0 -> 306 bytes tests/p2p-fuzzer/proberesp.dat | Bin 0 -> 209 bytes 10 files changed, 347 insertions(+), 9 deletions(-) create mode 100644 tests/p2p-fuzzer/Makefile create mode 100644 tests/p2p-fuzzer/go-neg-req.dat create mode 100644 tests/p2p-fuzzer/invitation-req.dat create mode 100644 tests/p2p-fuzzer/p2p-fuzzer.c create mode 100644 tests/p2p-fuzzer/p2ps-pd-req.dat create mode 100644 tests/p2p-fuzzer/proberesp-go.dat create mode 100644 tests/p2p-fuzzer/proberesp.dat diff --git a/src/common/Makefile b/src/common/Makefile index adfd3dfd5..e70363083 100644 --- a/src/common/Makefile +++ b/src/common/Makefile @@ -1,8 +1,28 @@ -all: - @echo Nothing to be made. +all: libcommon.a clean: - rm -f *~ *.o *.d *.gcno *.gcda *.gcov + rm -f *~ *.o *.d *.gcno *.gcda *.gcov libcommon.a install: @echo Nothing to be made. + +include ../lib.rules + +CFLAGS += -DCONFIG_IEEE80211R +CFLAGS += -DCONFIG_IEEE80211W +CFLAGS += -DCONFIG_HS20 +CFLAGS += -DCONFIG_SAE +CFLAGS += -DCONFIG_SUITE +CFLAGS += -DCONFIG_SUITEB + +LIB_OBJS= \ + gas.o \ + hw_features_common.o \ + ieee802_11_common.o \ + sae.o \ + wpa_common.o + +libcommon.a: $(LIB_OBJS) + $(AR) crT $@ $? + +-include $(OBJS:%.o=%.d) diff --git a/src/p2p/Makefile b/src/p2p/Makefile index adfd3dfd5..5587fcf28 100644 --- a/src/p2p/Makefile +++ b/src/p2p/Makefile @@ -1,8 +1,29 @@ -all: - @echo Nothing to be made. +all: libp2p.a clean: - rm -f *~ *.o *.d *.gcno *.gcda *.gcov + rm -f *~ *.o *.d *.gcno *.gcda *.gcov libp2p.a install: @echo Nothing to be made. + +include ../lib.rules + +CFLAGS += -DCONFIG_WIFI_DISPLAY +CFLAGS += -DCONFIG_WPS_NFC + +LIB_OBJS= \ + p2p_build.o \ + p2p.o \ + p2p_dev_disc.o \ + p2p_go_neg.o \ + p2p_group.o \ + p2p_invitation.o \ + p2p_parse.o \ + p2p_pd.o \ + p2p_sd.o \ + p2p_utils.o + +libp2p.a: $(LIB_OBJS) + $(AR) crT $@ $? + +-include $(OBJS:%.o=%.d) diff --git a/src/wps/Makefile b/src/wps/Makefile index adfd3dfd5..4806fe8da 100644 --- a/src/wps/Makefile +++ b/src/wps/Makefile @@ -1,8 +1,41 @@ -all: - @echo Nothing to be made. +all: libwps.a clean: - rm -f *~ *.o *.d *.gcno *.gcda *.gcov + rm -f *~ *.o *.d *.gcno *.gcda *.gcov libwps.a install: @echo Nothing to be made. + +include ../lib.rules + +CFLAGS += -DCONFIG_P2P +CFLAGS += -DCONFIG_WPS_OOB +CFLAGS += -DCONFIG_WPS_NFC + +LIB_OBJS= \ + http_client.o \ + httpread.o \ + http_server.o \ + ndef.o \ + upnp_xml.o \ + wps_attr_build.o \ + wps_attr_parse.o \ + wps_attr_process.o \ + wps.o \ + wps_common.o \ + wps_dev_attr.o \ + wps_enrollee.o \ + wps_er.o \ + wps_er_ssdp.o \ + wps_module_tests.o \ + wps_registrar.o \ + wps_upnp_ap.o \ + wps_upnp.o \ + wps_upnp_event.o \ + wps_upnp_ssdp.o \ + wps_upnp_web.o + +libwps.a: $(LIB_OBJS) + $(AR) crT $@ $? + +-include $(OBJS:%.o=%.d) diff --git a/tests/p2p-fuzzer/Makefile b/tests/p2p-fuzzer/Makefile new file mode 100644 index 000000000..4f81ef158 --- /dev/null +++ b/tests/p2p-fuzzer/Makefile @@ -0,0 +1,51 @@ +all: p2p-fuzzer + +ifndef CC +CC=gcc +endif + +ifndef LDO +LDO=$(CC) +endif + +ifndef CFLAGS +CFLAGS = -MMD -O2 -Wall -g +endif + +SRC=../../src + +CFLAGS += -I$(SRC) + +$(SRC)/utils/libutils.a: + $(MAKE) -C $(SRC)/utils + +$(SRC)/common/libcommon.a: + $(MAKE) -C $(SRC)/common + +$(SRC)/crypto/libcrypto.a: + $(MAKE) -C $(SRC)/crypto + +$(SRC)/tls/libtls.a: + $(MAKE) -C $(SRC)/tls + +$(SRC)/p2p/libp2p.a: + $(MAKE) -C $(SRC)/p2p + +$(SRC)/wps/libwps.a: + $(MAKE) -C $(SRC)/wps + +LIBS += $(SRC)/utils/libutils.a +LIBS += $(SRC)/common/libcommon.a +LIBS += $(SRC)/crypto/libcrypto.a +LIBS += $(SRC)/p2p/libp2p.a +LIBS += $(SRC)/tls/libtls.a +LIBS += $(SRC)/wps/libwps.a + +p2p-fuzzer: p2p-fuzzer.o $(LIBS) + $(LDO) $(LDFLAGS) -o $@ $^ $(LIBS) + +clean: + $(MAKE) -C $(SRC) clean + rm -f p2p-fuzzer *~ *.o *.d + +-include $(OBJS:%.o=%.d) diff --git a/tests/p2p-fuzzer/go-neg-req.dat b/tests/p2p-fuzzer/go-neg-req.dat new file mode 100644 index 0000000000000000000000000000000000000000..ed06834d71a15feb902334f8d676fa828ced7269 GIT binary patch literal 155 zcmcb>u!ez&fq{V$Ofo>(4h$@u0r|5y85r-zfoLWs22~CgMg}=nCWaIdHdcm+2$n!@ zPBy3}ZUKk@BNHiABJR Wfl)v}2&jcoz>|TE!CZ@hQ2_ufClN3J literal 0 HcmV?d00001 diff --git a/tests/p2p-fuzzer/invitation-req.dat b/tests/p2p-fuzzer/invitation-req.dat new file mode 100644 index 0000000000000000000000000000000000000000..5991f3e6e3f9c8c162679aa64f570f8ae233af02 GIT binary patch literal 123 zcmcb>u!ez&fq{V$Ofo>(0Sqjh0r|5ynHld!f@oHd5+Ozg20>PahzOQICU!QcdTutb p03#DWKUBoUGsx9BM7KDCR~9NF$N|(10Rn;y94@J4naQaNjsRm%4lw`# literal 0 HcmV?d00001 diff --git a/tests/p2p-fuzzer/p2p-fuzzer.c b/tests/p2p-fuzzer/p2p-fuzzer.c new file mode 100644 index 000000000..dcc1d72f3 --- /dev/null +++ b/tests/p2p-fuzzer/p2p-fuzzer.c @@ -0,0 +1,213 @@ +/* + * wpa_supplicant - P2P fuzzer + * Copyright (c) 2015, Jouni Malinen + * + * This software may be distributed under the terms of the BSD license. + * See README for more details. + */ + +#include "utils/includes.h" + +#include "utils/common.h" +#include "utils/eloop.h" +#include "common/ieee802_11_defs.h" +#include "p2p/p2p.h" + + +static void debug_print(void *ctx, int level, const char *msg) +{ + wpa_printf(level, "P2P: %s", msg); +} + + +static void find_stopped(void *ctx) +{ +} + + +static int start_listen(void *ctx, unsigned int freq, + unsigned int duration, + const struct wpabuf *probe_resp_ie) +{ + return 0; +} + + +static void stop_listen(void *ctx) +{ +} + + +static void dev_found(void *ctx, const u8 *addr, + const struct p2p_peer_info *info, + int new_device) +{ +} + + +static void dev_lost(void *ctx, const u8 *dev_addr) +{ +} + + +static int send_action(void *ctx, unsigned int freq, const u8 *dst, + const u8 *src, const u8 *bssid, const u8 *buf, + size_t len, unsigned int wait_time) +{ + return 0; +} + + +static void send_action_done(void *ctx) +{ +} + + +static void go_neg_req_rx(void *ctx, const u8 *src, u16 dev_passwd_id) +{ +} + + +static struct p2p_data * init_p2p(void) +{ + struct p2p_config p2p; + + os_memset(&p2p, 0, sizeof(p2p)); + p2p.max_peers = 100; + p2p.passphrase_len = 8; + p2p.channels.reg_classes = 1; + p2p.channels.reg_class[0].reg_class = 81; + p2p.channels.reg_class[0].channel[0] = 1; + p2p.channels.reg_class[0].channel[1] = 2; + p2p.channels.reg_class[0].channels = 2; + p2p.debug_print = debug_print; + p2p.find_stopped = find_stopped; + p2p.start_listen = start_listen; + p2p.stop_listen = stop_listen; + p2p.dev_found = dev_found; + p2p.dev_lost = dev_lost; + p2p.send_action = send_action; + p2p.send_action_done = send_action_done; + p2p.go_neg_req_rx = go_neg_req_rx; + + return p2p_init(&p2p); +} + + +struct arg_ctx { + struct p2p_data *p2p; + const char *fname; +}; + + +static void test_send_proberesp(void *eloop_data, void *user_ctx) +{ + struct arg_ctx *ctx = eloop_data; + char *data; + size_t len; + struct os_reltime rx_time; + + wpa_printf(MSG_INFO, "p2p-fuzzer: Send proberesp '%s'", ctx->fname); + + data = os_readfile(ctx->fname, &len); + if (!data) { + wpa_printf(MSG_ERROR, "Could not read '%s'", ctx->fname); + return; + } + + wpa_hexdump(MSG_MSGDUMP, "fuzzer - IEs", data, len); + + os_memset(&rx_time, 0, sizeof(rx_time)); + p2p_scan_res_handler(ctx->p2p, (u8 *) "\x02\x00\x00\x00\x01\x00", 2412, + &rx_time, 0, (u8 *) data, len); + p2p_scan_res_handled(ctx->p2p); + + os_free(data); + eloop_terminate(); +} + + +static void test_send_action(void *eloop_data, void *user_ctx) +{ + struct arg_ctx *ctx = eloop_data; + char *data; + size_t len; + struct os_reltime rx_time; + struct ieee80211_mgmt *mgmt; + + wpa_printf(MSG_INFO, "p2p-fuzzer: Send action '%s'", ctx->fname); + + data = os_readfile(ctx->fname, &len); + if (!data) { + wpa_printf(MSG_ERROR, "Could not read '%s'", ctx->fname); + return; + } + if (len < IEEE80211_HDRLEN + 1) + goto out; + + wpa_hexdump(MSG_MSGDUMP, "fuzzer - action", data, len); + + mgmt = (struct ieee80211_mgmt *) data; + os_memset(&rx_time, 0, sizeof(rx_time)); + p2p_rx_action(ctx->p2p, mgmt->da, mgmt->sa, mgmt->bssid, + mgmt->u.action.category, + (u8 *) data + IEEE80211_HDRLEN + 1, + len - IEEE80211_HDRLEN - 1, 2412); + +out: + os_free(data); + eloop_terminate(); +} + + +int main(int argc, char *argv[]) +{ + struct p2p_data *p2p; + struct arg_ctx ctx; + + /* TODO: probreq and wpas_p2p_probe_req_rx() */ + + if (argc < 3) { + printf("usage: %s \n", argv[0]); + return -1; + } + + if (os_program_init()) + return -1; + + wpa_debug_level = 0; + wpa_debug_show_keys = 1; + + if (eloop_init()) { + wpa_printf(MSG_ERROR, "Failed to initialize event loop"); + return -1; + } + + p2p = init_p2p(); + if (!p2p) { + wpa_printf(MSG_ERROR, "P2P init failed"); + return -1; + } + + ctx.p2p = p2p; + ctx.fname = argv[2]; + + if (os_strcmp(argv[1], "proberesp") == 0) { + eloop_register_timeout(0, 0, test_send_proberesp, &ctx, NULL); + } else if (os_strcmp(argv[1], "action") == 0) { + eloop_register_timeout(0, 0, test_send_action, &ctx, NULL); + } else { + wpa_printf(MSG_ERROR, "Unsupported test type '%s'", argv[1]); + return -1; + } + + wpa_printf(MSG_DEBUG, "Starting eloop"); + eloop_run(); + wpa_printf(MSG_DEBUG, "eloop done"); + + p2p_deinit(p2p); + eloop_destroy(); + os_program_deinit(); + + return 0; +} diff --git a/tests/p2p-fuzzer/p2ps-pd-req.dat b/tests/p2p-fuzzer/p2ps-pd-req.dat new file mode 100644 index 0000000000000000000000000000000000000000..7e1b6d91dead97241613c030b0ab5b02d5ae2858 GIT binary patch literal 189 zcmcb>u!ez&0R%uKBb4pHz`_}jKZ}!{@oqneW@2Jc)#8YXA`ff(#rksb!hT zsR~Z~{7`up&mdRl5ZzE0PBxehR)&ZOmOw^s0Wi(Y$i&RT%Er#Y$;B?A!+>sbu8n5t^a0!6PAunUPV8k;OoSk%57K4GR*<#KWK~Rl^|t|33p9 z0HtBTRt$*)69m%r94rhBOhAUiT?vMOPfU!A4Ghdn7#P%n*vUDTA<0OO;cg93hDE@O zfl)xfg@KVtz>$HGQ9uZ!O(2+o$THo(y~p=2}2?jBNkG;I3vs{wz)= VCI;0`URkhH85jiNCNLly0RTbSGMoSa literal 0 HcmV?d00001 diff --git a/tests/p2p-fuzzer/proberesp.dat b/tests/p2p-fuzzer/proberesp.dat new file mode 100644 index 0000000000000000000000000000000000000000..8d997d1c5e1366e19c4b83169e037ec70a39373d GIT binary patch literal 209 zcmZQzckv8zbq>*G~F9t>d0T%{FMgeOEMg{?Q27z#$ zANnW5!-8jvZ9Ttf#_Ep(iVTbj0?Hsl1w=T3h!6%21}G2^WZ-Z~Ez3+!Rd5pEU|=%z z5b$JRV=&hOs=KQhkUxu)iHSj#fmfD+38;gSK@hH!0a+{WrKxN`7feu4U