fuzzREQUEST.c 3.5 KB

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