wnm-fuzzer.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * wpa_supplicant - WNM fuzzer
  3. * Copyright (c) 2015, Jouni Malinen <j@w1.fi>
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #include "utils/includes.h"
  9. #include "utils/common.h"
  10. #include "utils/eloop.h"
  11. #include "common/ieee802_11_defs.h"
  12. #include "rsn_supp/wpa.h"
  13. #include "rsn_supp/wpa_i.h"
  14. #include "../../wpa_supplicant/wpa_supplicant_i.h"
  15. #include "../../wpa_supplicant/bss.h"
  16. #include "../../wpa_supplicant/wnm_sta.h"
  17. struct arg_ctx {
  18. const char *fname;
  19. struct wpa_supplicant wpa_s;
  20. struct wpa_bss bss;
  21. struct wpa_driver_ops driver;
  22. struct wpa_sm wpa;
  23. };
  24. static void test_send_wnm(void *eloop_data, void *user_ctx)
  25. {
  26. struct arg_ctx *ctx = eloop_data;
  27. char *data;
  28. size_t len;
  29. struct ieee80211_mgmt *mgmt;
  30. wpa_printf(MSG_INFO, "wnm-fuzzer: Send '%s'", ctx->fname);
  31. data = os_readfile(ctx->fname, &len);
  32. if (!data) {
  33. wpa_printf(MSG_ERROR, "Could not read '%s'", ctx->fname);
  34. goto out;
  35. }
  36. wpa_hexdump(MSG_MSGDUMP, "fuzzer - WNM", data, len);
  37. mgmt = (struct ieee80211_mgmt *) data;
  38. ieee802_11_rx_wnm_action(&ctx->wpa_s, mgmt, len);
  39. out:
  40. os_free(data);
  41. eloop_terminate();
  42. }
  43. static int init_wpa(struct arg_ctx *ctx)
  44. {
  45. ctx->wpa_s.wpa_state = WPA_COMPLETED;
  46. os_memcpy(ctx->wpa_s.bssid, "\x02\x00\x00\x00\x03\x00", ETH_ALEN);
  47. ctx->wpa_s.current_bss = &ctx->bss;
  48. ctx->wpa_s.driver = &ctx->driver;
  49. ctx->wpa_s.wpa = &ctx->wpa;
  50. return 0;
  51. }
  52. int main(int argc, char *argv[])
  53. {
  54. struct arg_ctx ctx;
  55. int ret = -1;
  56. if (argc < 2) {
  57. printf("usage: %s <file>\n", argv[0]);
  58. return -1;
  59. }
  60. if (os_program_init())
  61. return -1;
  62. wpa_debug_level = 0;
  63. wpa_debug_show_keys = 1;
  64. if (eloop_init()) {
  65. wpa_printf(MSG_ERROR, "Failed to initialize event loop");
  66. return -1;
  67. }
  68. os_memset(&ctx, 0, sizeof(ctx));
  69. ctx.fname = argv[1];
  70. if (init_wpa(&ctx))
  71. goto fail;
  72. eloop_register_timeout(0, 0, test_send_wnm, &ctx, NULL);
  73. wpa_printf(MSG_DEBUG, "Starting eloop");
  74. eloop_run();
  75. wpa_printf(MSG_DEBUG, "eloop done");
  76. ret = 0;
  77. fail:
  78. eloop_destroy();
  79. os_program_deinit();
  80. return ret;
  81. }