ap-mgmt-fuzzer.c 2.2 KB

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