fuzzTEMPLATE.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. Fuzzes template Information element
  3. Sub-fuzzer template for fuzzing a specific information element.
  4. Change all places with "update this" as comment.
  5. Also change all words with template in them.
  6. Files to change when adding subfuzzer:
  7. - subfuzzer header file
  8. - fuzzer.c with includes
  9. - frameCreator.c with includes
  10. */
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <stdint.h>
  14. #include <string.h>
  15. #include "../frameDefinitions.h"
  16. //Indecates whether the templateFuzzer is running
  17. int templateRunningState = 0;
  18. //Number of fuzzing states
  19. const int templateStates = 2; //update this
  20. //Steps of fuzzers for each fuzzing state
  21. const int templateSteps[] = {1, 3}; //update this
  22. //Current state and step of the templateFuzzer
  23. int fuzzState;
  24. int fuzzStep;
  25. void templatePrintCurrentState() //update this
  26. {
  27. switch (fuzzState)
  28. {
  29. case 0:
  30. {
  31. printf("\e[33mFuzzing TEMPLATE IE\e[39m\n");
  32. printf("Trying 255*0xFF data\n");
  33. break;
  34. }
  35. case 1:
  36. {
  37. printf("Fuzzing template state 2\n");
  38. break;
  39. }
  40. case 2:
  41. {
  42. printf("\e[33mDone with fuzzing template\e[39m\n");
  43. break;
  44. }
  45. }
  46. }
  47. //Updates templateFuzzer
  48. //Status 0 indicates start
  49. //Status 1 indicates increaseStep
  50. //Status 2 indicates stop
  51. //Returns -1 if done with fuzzing
  52. int templateFuzzUpdate(int status)
  53. {
  54. switch (status)
  55. {
  56. case 0: //start fuzzer
  57. {
  58. templateRunningState = 1;
  59. fuzzState = 0;
  60. fuzzStep = 0;
  61. templatePrintCurrentState();
  62. break;
  63. }
  64. case 1: //update fuzzer
  65. {
  66. if (templateRunningState == 1) //sanity check
  67. {
  68. //increase steps until all steps are done
  69. if (fuzzStep < templateSteps[fuzzState]-1)
  70. fuzzStep = fuzzStep + 1;
  71. //then increase state and notify
  72. else
  73. {
  74. fuzzStep = 0;
  75. fuzzState = fuzzState + 1;
  76. templatePrintCurrentState();
  77. }
  78. //when all states are done, stop
  79. if (fuzzState == templateStates)
  80. {
  81. templateRunningState = 0;
  82. return -1;
  83. }
  84. }
  85. break;
  86. }
  87. case 2: //stop fuzzer
  88. {
  89. templateRunningState = 0;
  90. break;
  91. }
  92. }
  93. return 0;
  94. }
  95. //Returns an template information element
  96. infoElem templateFuzz()
  97. {
  98. infoElem template;
  99. //What to return when not fuzzed
  100. if (templateRunningState == 0)
  101. {
  102. template.id = 0;
  103. template.len = 1;
  104. template.len_data = -1;
  105. template.data = "\xab";
  106. }
  107. else
  108. {
  109. switch (fuzzState) //update this
  110. {
  111. case 0: //255*0xff
  112. {
  113. template.id = 0; //update this
  114. template.len = 255;
  115. template.len_data = 255;
  116. //create data of 255 times 0xff
  117. u_char *data = malloc(255);
  118. memset(data, 0xff, 255);
  119. template.data = data;
  120. break;
  121. }
  122. case 1: //template null data
  123. {
  124. template.id = 0; //update this
  125. template.len = 1;
  126. template.len_data = 1;
  127. template.data = "\x00";
  128. break;
  129. }
  130. }
  131. }
  132. return template;
  133. }