fuzzer.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. Manages what to fuzz when.
  3. */
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <stdint.h>
  7. #include <string.h>
  8. #include "frameDefinitions.h"
  9. #include "fuzzChallenge.h"
  10. #include "fuzzAuth.h"
  11. //CHANGE WHEN NEW SUBFUZZER
  12. //CHANGE WHEN NEW SUBFUZZER
  13. //Number of subfuzzers
  14. #define SUBFUZZERS (1)
  15. //CHANGE WHEN NEW SUBFUZZER
  16. //Array of pointers to subfuzzers update functions
  17. int (*p[SUBFUZZERS]) (int i) = {
  18. challengeFuzzUpdate};
  19. //State of sub-fuzzer
  20. //-1 = Done
  21. //0 = In progress
  22. int subFuzzState = -1;
  23. //State of generic fuzzer
  24. //-1 = Done
  25. //0 = In progress
  26. int genFuzzState = -1;
  27. //Current sub-fuzzer
  28. //Starts with -1 to prevent skipping the first sub-fuzzer
  29. int subFuzzerIdx = -1;
  30. //int subFuzzerIdx = 99; //to test generic fuzzing part
  31. //Flag to indicate if the done with all subfuzzers notification has been sent
  32. int notifyDone = 0;
  33. int getNotifyDone()
  34. {
  35. return notifyDone;
  36. }
  37. //Number of different sent frames (-1 because we start with increaseFuzzer)
  38. int frameCounter = -1;
  39. //Controls state of fuzzer, and therefore what to fuzz next
  40. void increaseFuzzer()
  41. {
  42. frameCounter = frameCounter + 1;
  43. //while we still have sub-fuzzers to go
  44. if (subFuzzerIdx < SUBFUZZERS)
  45. {
  46. if (subFuzzState == -1)
  47. {
  48. subFuzzerIdx = subFuzzerIdx + 1;
  49. if (subFuzzerIdx < SUBFUZZERS)
  50. {
  51. subFuzzState = (*p[subFuzzerIdx]) (0);
  52. }
  53. }
  54. else
  55. {
  56. subFuzzState = (*p[subFuzzerIdx]) (1);
  57. }
  58. }
  59. //Done with all sub-fuzzers
  60. else
  61. {
  62. //Only do first time
  63. if (notifyDone == 0)
  64. {
  65. notifyDone = 1;
  66. printf("Done with all subfuzzers\n");
  67. printf("Sent %d different frames in total\n", frameCounter);
  68. printf("Moving on to generic fuzzing\n");
  69. genFuzzState = AuthFuzzUpdate(0);
  70. }
  71. else
  72. {
  73. if (genFuzzState != -1)
  74. {
  75. genFuzzState = AuthFuzzUpdate(1);
  76. if (genFuzzState == -1)
  77. {
  78. printf("Done with generic fuzzing\n");
  79. printf("Done with all Authentication fuzzing\n");
  80. printf("Fuzzer will now exit\n");
  81. exit(0);
  82. }
  83. }
  84. else
  85. {
  86. printf("Fuzzer is done, but code should not get here\n");
  87. printf("Fuzzer will now exit\n");
  88. exit(0);
  89. }
  90. }
  91. }
  92. }