ap-mgmt-fuzzer.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * hostapd - Management frame 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 "ap/hostapd.h"
  12. #include "ap/ieee802_11.h"
  13. #include "ap/sta_info.h"
  14. const struct wpa_driver_ops *const wpa_drivers[] =
  15. {
  16. NULL
  17. };
  18. struct arg_ctx {
  19. const char *fname;
  20. struct hostapd_iface iface;
  21. struct hostapd_data hapd;
  22. struct wpa_driver_ops driver;
  23. struct hostapd_config iconf;
  24. struct hostapd_bss_config conf;
  25. };
  26. static void test_send_mgmt(void *eloop_data, void *user_ctx)
  27. {
  28. struct arg_ctx *ctx = eloop_data;
  29. char *data;
  30. size_t len;
  31. struct hostapd_frame_info fi;
  32. wpa_printf(MSG_INFO, "ap-mgmt-fuzzer: Send '%s'", ctx->fname);
  33. data = os_readfile(ctx->fname, &len);
  34. if (!data) {
  35. wpa_printf(MSG_ERROR, "Could not read '%s'", ctx->fname);
  36. goto out;
  37. }
  38. wpa_hexdump(MSG_MSGDUMP, "fuzzer - WNM", data, len);
  39. os_memset(&fi, 0, sizeof(fi));
  40. ieee802_11_mgmt(&ctx->hapd, (u8 *) data, len, &fi);
  41. out:
  42. os_free(data);
  43. eloop_terminate();
  44. }
  45. static int init_hapd(struct arg_ctx *ctx)
  46. {
  47. struct hostapd_data *hapd = &ctx->hapd;
  48. struct sta_info *sta;
  49. hapd->driver = &ctx->driver;
  50. os_memcpy(hapd->own_addr, "\x02\x00\x00\x00\x03\x00", ETH_ALEN);
  51. hapd->iface = &ctx->iface;
  52. hapd->iface->conf = hostapd_config_defaults();;
  53. if (!hapd->iface->conf)
  54. return -1;
  55. hapd->iconf = hapd->iface->conf;
  56. hapd->conf = hapd->iconf->bss[0];
  57. hostapd_config_defaults_bss(hapd->conf);
  58. sta = ap_sta_add(hapd, (u8 *) "\x02\x00\x00\x00\x00\x00");
  59. if (sta)
  60. sta->flags |= WLAN_STA_ASSOC | WLAN_STA_WMM;
  61. return 0;
  62. }
  63. int main(int argc, char *argv[])
  64. {
  65. struct arg_ctx ctx;
  66. int ret = -1;
  67. if (argc < 2) {
  68. printf("usage: %s <file>\n", argv[0]);
  69. return -1;
  70. }
  71. if (os_program_init())
  72. return -1;
  73. wpa_debug_level = 0;
  74. wpa_debug_show_keys = 1;
  75. if (eloop_init()) {
  76. wpa_printf(MSG_ERROR, "Failed to initialize event loop");
  77. return -1;
  78. }
  79. os_memset(&ctx, 0, sizeof(ctx));
  80. ctx.fname = argv[1];
  81. if (init_hapd(&ctx))
  82. goto fail;
  83. eloop_register_timeout(0, 0, test_send_mgmt, &ctx, NULL);
  84. wpa_printf(MSG_DEBUG, "Starting eloop");
  85. eloop_run();
  86. wpa_printf(MSG_DEBUG, "eloop done");
  87. hostapd_free_stas(&ctx.hapd);
  88. ret = 0;
  89. fail:
  90. hostapd_config_free(ctx.hapd.iconf);
  91. eloop_destroy();
  92. os_program_deinit();
  93. return ret;
  94. }