1
0

fuzzChallenge.c 3.9 KB

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