fuzzSSID.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. Fuzzes SSID Information element
  3. */
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <stdint.h>
  7. #include <string.h>
  8. #include <math.h>
  9. #include "../frameDefinitions.h"
  10. //Indecates whether the ssidFuzzer is running
  11. int ssidRunningState = 0;
  12. //Number of fuzzing states
  13. const int ssidStates = 1;
  14. //Steps of fuzzers for each fuzzing state
  15. const int ssidSteps[] = {256};
  16. //Current state and step of the ssidFuzzer
  17. int fuzzState;
  18. int fuzzStep;
  19. void ssidPrintCurrentState()
  20. {
  21. switch (fuzzState)
  22. {
  23. case 0:
  24. {
  25. printf("\e[33mFuzzing SSID IE\e[39m\n");
  26. printf("SSID name counter\n");
  27. break;
  28. }
  29. case 1:
  30. {
  31. printf("\e[33mDone with SSID IE\e[39m\n");
  32. break;
  33. }
  34. }
  35. }
  36. //Updates ssidFuzzer
  37. //Status 0 indicates start
  38. //Status 1 indicates increaseStep
  39. //Status 2 indicates stop
  40. //Returns -1 if done with fuzzing
  41. int ssidFuzzUpdate(int status)
  42. {
  43. switch (status)
  44. {
  45. case 0: //start fuzzer
  46. {
  47. ssidRunningState = 1;
  48. fuzzState = 0;
  49. fuzzStep = 0;
  50. ssidPrintCurrentState();
  51. break;
  52. }
  53. case 1: //update fuzzer
  54. {
  55. if (ssidRunningState == 1) //sanity check
  56. {
  57. //increase steps until all steps are done
  58. if (fuzzStep < ssidSteps[fuzzState]-1)
  59. fuzzStep = fuzzStep + 1;
  60. //then increase state and notify
  61. else
  62. {
  63. fuzzStep = 0;
  64. fuzzState = fuzzState + 1;
  65. ssidPrintCurrentState();
  66. }
  67. //when all states are done, stop
  68. if (fuzzState == ssidStates)
  69. {
  70. ssidRunningState = 0;
  71. return -1;
  72. }
  73. }
  74. break;
  75. }
  76. case 2: //stop fuzzer
  77. {
  78. ssidRunningState = 0;
  79. break;
  80. }
  81. }
  82. return 0;
  83. }
  84. //Returns an SSID information element
  85. infoElem ssidFuzz()
  86. {
  87. infoElem ssid;
  88. //What to return when not fuzzed
  89. //We do not return an SSID, because of the experiment
  90. if (ssidRunningState == 0)
  91. {
  92. ssid.id = 0;
  93. ssid.len = 4;
  94. ssid.len_data = -1;
  95. ssid.data = "\x46\x55\x5a\x5a";
  96. }
  97. else
  98. {
  99. switch (fuzzState)
  100. {
  101. case 0: //SSID incorrect length with data
  102. {
  103. int i;
  104. if (fuzzStep == 0)
  105. i = 1;
  106. else
  107. i = floor(log10(abs(fuzzStep))) + 1;
  108. //printf("SSID := %d\n", fuzzStep);
  109. ssid.id = 0;
  110. ssid.len = i;
  111. ssid.len_data = i;
  112. u_char *buffer = malloc(32);
  113. sprintf(buffer,"%d", fuzzStep);
  114. ssid.data = buffer;
  115. break;
  116. }
  117. }
  118. }
  119. return ssid;
  120. }