fuzzSSID.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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 "../frameDefinitions.h"
  9. //Indecates whether the ssidFuzzer is running
  10. int ssidRunningState = 0;
  11. //Number of fuzzing states
  12. const int ssidStates = 5;
  13. //Steps of fuzzers for each fuzzing state
  14. const int ssidSteps[] = {45, 45, 16, 256, 1};
  15. //Current state and step of the ssidFuzzer
  16. int fuzzState;
  17. int fuzzStep;
  18. void ssidPrintCurrentState()
  19. {
  20. switch (fuzzState)
  21. {
  22. case 0:
  23. {
  24. printf("\e[33mFuzzing SSID IE\e[39m\n");
  25. printf("Fuzzing SSID incorrect length with data\n");
  26. break;
  27. }
  28. case 1:
  29. {
  30. printf("Fuzzing SSID incorrect length without data\n");
  31. break;
  32. }
  33. case 2:
  34. {
  35. printf("Fuzzing SSID oversized length\n");
  36. break;
  37. }
  38. case 3:
  39. {
  40. printf("Fuzzing SSID characters\n");
  41. break;
  42. }
  43. case 4:
  44. {
  45. printf("Trying 255*0xFF data\n");
  46. break;
  47. }
  48. case 5:
  49. {
  50. printf("\e[33mDone with fuzzing SSID IE\e[39m\n");
  51. break;
  52. }
  53. }
  54. }
  55. //Updates ssidFuzzer
  56. //Status 0 indicates start
  57. //Status 1 indicates increaseStep
  58. //Status 2 indicates stop
  59. //Returns -1 if done with fuzzing
  60. int ssidFuzzUpdate(int status)
  61. {
  62. switch (status)
  63. {
  64. case 0: //start fuzzer
  65. {
  66. ssidRunningState = 1;
  67. fuzzState = 0;
  68. fuzzStep = 0;
  69. ssidPrintCurrentState();
  70. break;
  71. }
  72. case 1: //update fuzzer
  73. {
  74. if (ssidRunningState == 1) //sanity check
  75. {
  76. //increase steps until all steps are done
  77. if (fuzzStep < ssidSteps[fuzzState]-1)
  78. fuzzStep = fuzzStep + 1;
  79. //then increase state and notify
  80. else
  81. {
  82. fuzzStep = 0;
  83. fuzzState = fuzzState + 1;
  84. ssidPrintCurrentState();
  85. }
  86. //when all states are done, stop
  87. if (fuzzState == ssidStates)
  88. {
  89. ssidRunningState = 0;
  90. return -1;
  91. }
  92. }
  93. break;
  94. }
  95. case 2: //stop fuzzer
  96. {
  97. ssidRunningState = 0;
  98. break;
  99. }
  100. }
  101. return 0;
  102. }
  103. //Returns an SSID information element
  104. infoElem ssidFuzz()
  105. {
  106. infoElem ssid;
  107. //What to return when not fuzzed
  108. //We do return an SSID, because it is required
  109. if (ssidRunningState == 0)
  110. {
  111. ssid.id = 0;
  112. ssid.len = 4;
  113. ssid.len_data = 4;
  114. ssid.data = "\x46\x55\x5a\x5a";
  115. }
  116. else
  117. {
  118. switch (fuzzState)
  119. {
  120. case 0: //SSID incorrect length with data
  121. {
  122. if (fuzzStep <= 38)
  123. {
  124. ssid.id = 0;
  125. ssid.len = fuzzStep;
  126. ssid.len_data = 4;
  127. ssid.data = "\x46\x55\x5a\x5a";
  128. }
  129. else
  130. {
  131. ssid.id = 0;
  132. ssid.len = 255 - (fuzzStep - 39);
  133. ssid.len_data = 4;
  134. ssid.data = "\x46\x55\x5a\x5a";
  135. }
  136. break;
  137. }
  138. case 1: //SSID incorrect length without data
  139. {
  140. if (fuzzStep <= 38)
  141. {
  142. ssid.id = 0;
  143. ssid.len = fuzzStep;
  144. ssid.len_data = 0;
  145. ssid.data = "";
  146. }
  147. else
  148. {
  149. ssid.id = 0;
  150. ssid.len = 255 - (fuzzStep - 39);
  151. ssid.len_data = 0;
  152. ssid.data = "";
  153. }
  154. break;
  155. }
  156. case 2: //SSID oversized length
  157. {
  158. if (fuzzStep < 8)
  159. {
  160. int dataSize = 33 + fuzzStep;
  161. ssid.id = 0;
  162. ssid.len = dataSize;
  163. ssid.len_data = dataSize;
  164. //create data of datasize times 0x61
  165. u_char *data = malloc(dataSize);
  166. memset(data, 0x61, dataSize);
  167. ssid.data = data;
  168. }
  169. else
  170. {
  171. int dataSize = 255 - fuzzStep + 8;
  172. ssid.id = 0;
  173. ssid.len = dataSize;
  174. ssid.len_data = dataSize;
  175. //create data of datasize times 0x61
  176. u_char *data = malloc(dataSize);
  177. memset(data, 0x61, dataSize);
  178. ssid.data = data;
  179. }
  180. break;
  181. }
  182. case 3: //SSID characters
  183. {
  184. ssid.id = 0;
  185. ssid.len = 32;
  186. ssid.len_data = 32;
  187. //create characters
  188. u_char *data = malloc(32);
  189. for (int i = 0; i < 32; i++)
  190. {
  191. data[i] = fuzzStep;
  192. }
  193. ssid.data = data;
  194. break;
  195. }
  196. case 4: //255*0xff
  197. {
  198. ssid.id = 0;
  199. ssid.len = 255;
  200. ssid.len_data = 255;
  201. //create data of 255 times 0xff
  202. u_char *data = malloc(255);
  203. memset(data, 0xff, 255);
  204. ssid.data = data;
  205. break;
  206. }
  207. }
  208. }
  209. return ssid;
  210. }