fuzzFH.c 4.0 KB

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