1
0

fuzzer.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. Manages what to fuzz when.
  3. */
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <stdint.h>
  7. #include <string.h>
  8. #include "frameDefinitions.h"
  9. #include "fuzzSSID.h"
  10. #include "fuzzRates.h"
  11. #include "fuzzFH.h"
  12. #include "fuzzDS.h"
  13. #include "fuzzCF.h"
  14. #include "fuzzTIM.h"
  15. #include "fuzzIBSS.h"
  16. #include "fuzzCOUNTRY.h"
  17. #include "fuzzHOPPARM.h"
  18. #include "fuzzHOPTABLE.h"
  19. #include "fuzzREQUEST.h"
  20. #include "fuzzERP.h"
  21. #include "fuzzEXTRATES.h"
  22. #include "fuzzHTCAPAB.h"
  23. #include "fuzzHTINFO.h"
  24. #include "fuzzAPREPORT.h"
  25. #include "fuzzEXTCAPAB.h"
  26. #include "fuzzBSSLOAD.h"
  27. #include "fuzzRSN.h"
  28. #include "fuzzVENDOR.h"
  29. #include "fuzzProbeResponse.h"
  30. //CHANGE WHEN NEW SUBFUZZER
  31. //CHANGE WHEN NEW SUBFUZZER
  32. //Number of subfuzzers
  33. #define SUBFUZZERS (20)
  34. //CHANGE WHEN NEW SUBFUZZER
  35. //Array of pointers to subfuzzers update functions
  36. /*int (*p[SUBFUZZERS]) (int i) = {vendorFuzzUpdate, rsnFuzzUpdate, bssloadFuzzUpdate,
  37. extcapabFuzzUpdate, apreportFuzzUpdate, htinfoFuzzUpdate, htcapabFuzzUpdate, extratesFuzzUpdate,
  38. erpFuzzUpdate, requestFuzzUpdate, hoptableFuzzUpdate, hopparmFuzzUpdate, countryFuzzUpdate,
  39. ibssFuzzUpdate, cfFuzzUpdate, timFuzzUpdate, dsFuzzUpdate, fhFuzzUpdate, ratesFuzzUpdate,
  40. ssidFuzzUpdate}; */
  41. int (*p[SUBFUZZERS]) (int i) = {
  42. ssidFuzzUpdate, ratesFuzzUpdate, fhFuzzUpdate, dsFuzzUpdate, cfFuzzUpdate, timFuzzUpdate,
  43. ibssFuzzUpdate, countryFuzzUpdate, hopparmFuzzUpdate, hoptableFuzzUpdate, requestFuzzUpdate,
  44. erpFuzzUpdate, extratesFuzzUpdate, htcapabFuzzUpdate, htinfoFuzzUpdate, apreportFuzzUpdate,
  45. extcapabFuzzUpdate, bssloadFuzzUpdate, rsnFuzzUpdate, vendorFuzzUpdate};
  46. //State of sub-fuzzer
  47. //-1 = Done
  48. //0 = In progress
  49. int subFuzzState = -1;
  50. //State of generic fuzzer
  51. //-1 = Done
  52. //0 = In progress
  53. int genFuzzState = -1;
  54. //Current sub-fuzzer
  55. //Starts with -1 to prevent skipping the first sub-fuzzer
  56. int subFuzzerIdx = -1;
  57. //int subFuzzerIdx = 99; //to test generic fuzzing part
  58. //Flag to indicate if the done with all subfuzzers notification has been sent
  59. int notifyDone = 0;
  60. int getNotifyDone()
  61. {
  62. return notifyDone;
  63. }
  64. //Number of different sent frames (-1 because we start with increaseFuzzer)
  65. int frameCounter = -1;
  66. //Controls state of fuzzer, and therefore what to fuzz next
  67. void increaseFuzzer()
  68. {
  69. frameCounter = frameCounter + 1;
  70. //while we still have sub-fuzzers to go
  71. if (subFuzzerIdx < SUBFUZZERS)
  72. {
  73. if (subFuzzState == -1)
  74. {
  75. subFuzzerIdx = subFuzzerIdx + 1;
  76. if (subFuzzerIdx < SUBFUZZERS)
  77. {
  78. subFuzzState = (*p[subFuzzerIdx]) (0);
  79. }
  80. }
  81. else
  82. {
  83. subFuzzState = (*p[subFuzzerIdx]) (1);
  84. }
  85. }
  86. //Done with all sub-fuzzers
  87. else
  88. {
  89. //Only do first time
  90. if (notifyDone == 0)
  91. {
  92. notifyDone = 1;
  93. printf("Done with all subfuzzers\n");
  94. printf("Sent %d different frames in total\n", frameCounter);
  95. printf("Moving on to generic fuzzing\n");
  96. genFuzzState = PrbRespFuzzUpdate(0);
  97. }
  98. else
  99. {
  100. if (genFuzzState != -1)
  101. {
  102. genFuzzState = PrbRespFuzzUpdate(1);
  103. if (genFuzzState == -1)
  104. {
  105. printf("Done with generic fuzzing\n");
  106. printf("Done with all probe response fuzzing\n");
  107. printf("Fuzzer will now exit\n");
  108. exit(0);
  109. }
  110. }
  111. else
  112. {
  113. printf("Fuzzer is done, but code should not get here\n");
  114. printf("Fuzzer will now exit\n");
  115. exit(0);
  116. }
  117. }
  118. }
  119. }