fuzzAPREPORT.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. Fuzzes ap channel report 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 apreportFuzzer is running
  10. int apreportRunningState = 0;
  11. //Number of fuzzing states
  12. const int apreportStates = 4;
  13. //Steps of fuzzers for each fuzzing state
  14. const int apreportSteps[] = {1, 2, 8, 8};
  15. //Current state and step of the apreportFuzzer
  16. int fuzzState;
  17. int fuzzStep;
  18. void apreportPrintCurrentState()
  19. {
  20. switch (fuzzState)
  21. {
  22. case 0:
  23. {
  24. printf("\e[33mFuzzing apreport IE\e[39m\n");
  25. printf("Trying 255*0xFF data\n");
  26. break;
  27. }
  28. case 1:
  29. {
  30. printf("Trying length of 1\n");
  31. break;
  32. }
  33. case 2:
  34. {
  35. printf("Fuzzing large lengths with 0xFF data\n");
  36. break;
  37. }
  38. case 3:
  39. {
  40. printf("Fuzzing large lengths with 0x00 data\n");
  41. break;
  42. }
  43. case 4:
  44. {
  45. printf("\e[33mDone with fuzzing apreport\e[39m\n");
  46. break;
  47. }
  48. }
  49. }
  50. //Updates apreportFuzzer
  51. //Status 0 indicates start
  52. //Status 1 indicates increaseStep
  53. //Status 2 indicates stop
  54. //Returns -1 if done with fuzzing
  55. int apreportFuzzUpdate(int status)
  56. {
  57. switch (status)
  58. {
  59. case 0: //start fuzzer
  60. {
  61. apreportRunningState = 1;
  62. fuzzState = 0;
  63. fuzzStep = 0;
  64. apreportPrintCurrentState();
  65. break;
  66. }
  67. case 1: //update fuzzer
  68. {
  69. if (apreportRunningState == 1) //sanity check
  70. {
  71. //increase steps until all steps are done
  72. if (fuzzStep < apreportSteps[fuzzState]-1)
  73. fuzzStep = fuzzStep + 1;
  74. //then increase state and notify
  75. else
  76. {
  77. fuzzStep = 0;
  78. fuzzState = fuzzState + 1;
  79. apreportPrintCurrentState();
  80. }
  81. //when all states are done, stop
  82. if (fuzzState == apreportStates)
  83. {
  84. apreportRunningState = 0;
  85. return -1;
  86. }
  87. }
  88. break;
  89. }
  90. case 2: //stop fuzzer
  91. {
  92. apreportRunningState = 0;
  93. break;
  94. }
  95. }
  96. return 0;
  97. }
  98. //Returns an apreport information element
  99. infoElem apreportFuzz()
  100. {
  101. infoElem apreport;
  102. //What to return when not fuzzed
  103. if (apreportRunningState == 0)
  104. {
  105. apreport.id = 0;
  106. apreport.len = 1;
  107. apreport.len_data = -1;
  108. apreport.data = "\xab";
  109. }
  110. else
  111. {
  112. switch (fuzzState) //update this
  113. {
  114. case 0: //255*0xff
  115. {
  116. apreport.id = 51;
  117. apreport.len = 255;
  118. apreport.len_data = 255;
  119. //create data of 255 times 0xff
  120. u_char *data = malloc(255);
  121. memset(data, 0xff, 255);
  122. apreport.data = data;
  123. break;
  124. }
  125. case 1: //apreport data
  126. {
  127. if (fuzzStep == 0)
  128. {
  129. apreport.id = 51;
  130. apreport.len = 1;
  131. apreport.len_data = 1;
  132. apreport.data = "\x00";
  133. }
  134. else
  135. {
  136. apreport.id = 51;
  137. apreport.len = 1;
  138. apreport.len_data = 1;
  139. apreport.data = "\xFF";
  140. }
  141. break;
  142. }
  143. case 2: //length with 0xff data
  144. {
  145. int dataSize = 255 - fuzzStep;
  146. apreport.id = 51;
  147. apreport.len = dataSize;
  148. apreport.len_data = dataSize;
  149. //create data of datasize times 0xff
  150. u_char *data = malloc(dataSize);
  151. memset(data, 0xff, dataSize);
  152. apreport.data = data;
  153. break;
  154. }
  155. case 3: //length with 0x00 data
  156. {
  157. int dataSize = 255 - fuzzStep;
  158. apreport.id = 51;
  159. apreport.len = dataSize;
  160. apreport.len_data = dataSize;
  161. //create data of datasize times 0x00
  162. u_char *data = malloc(dataSize);
  163. memset(data, 0x00, dataSize);
  164. apreport.data = data;
  165. break;
  166. }
  167. }
  168. }
  169. return apreport;
  170. }