1
0

ASSstatic.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. Fuzzes AssResp static elements
  3. */
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <stdint.h>
  7. #include <string.h>
  8. #include <math.h>
  9. #include "../frameDefinitions.h"
  10. //Creates Probe response frame
  11. u_char *Assstatic(u_char *dstAddress, int *packetSize, u_char * radioTapHeader, u_char *myMAC, int step)
  12. {
  13. #define AssstaticIES (1) //number of information elements
  14. infoElem suppRates = {
  15. 1, //id
  16. 7, //len
  17. 7, //real length of data
  18. "\x96\x18\x24\x30\x48\x60\x6c" //data
  19. };
  20. //create array of information elements
  21. infoElem taggedParams[AssstaticIES] = {suppRates};
  22. //length of all info elements, including id and len field
  23. int len_taggedParams = 0;
  24. for(int i = 0; i < AssstaticIES; i++)
  25. {
  26. if (taggedParams[i].len_data != -1) //do not include when len_data == -1
  27. {
  28. //+2 to include id and len field size
  29. len_taggedParams = len_taggedParams + taggedParams[i].len_data+2;
  30. }
  31. }
  32. //fill in struct
  33. assResponse assResp = {
  34. 36, radioTapHeader, //RadioTap hdr
  35. 1, "\x10", //Type
  36. 1, "\x00", //Flags
  37. 2, "\x40\x01", //Duration
  38. 6, dstAddress, //DST addr
  39. 6, myMAC, //Source addr
  40. 6, myMAC, //BSS addr
  41. 2, "\x00\x00", //Seq nr (overwritten by firmware)
  42. 2, "\x01\x00", //Capab info
  43. 2, "\x00\x00", //Status code
  44. 2, "\x01\xc0", //Association id
  45. len_taggedParams,
  46. taggedParams, //Information elements
  47. 4, "\x00\x00\x00\x00" //FSC (overwritten by firmware)
  48. };
  49. if (step == 0)
  50. {
  51. u_char *value = malloc(2);
  52. memset(value, 0x00, 2);
  53. assResp.assId = value;
  54. }
  55. if (step == 1)
  56. {
  57. u_char *value = malloc(2);
  58. memset(value, 0xFF, 2);
  59. assResp.assId = value;
  60. }
  61. if (step == 2)
  62. {
  63. u_char *value = malloc(2);
  64. memset(value, 0x00, 2);
  65. assResp.capabInfo = value;
  66. }
  67. if (step == 3)
  68. {
  69. u_char *value = malloc(2);
  70. memset(value, 0xFF, 2);
  71. assResp.capabInfo = value;
  72. }
  73. //calculate size of final packet
  74. *packetSize = assResp.len_radioTapHdr
  75. + assResp.len_type
  76. + assResp.len_flags
  77. + assResp.len_duration
  78. + assResp.len_destAddr
  79. + assResp.len_sourceAddr
  80. + assResp.len_bssAddr
  81. + assResp.len_seqNr
  82. + assResp.len_capabInfo
  83. + assResp.len_status
  84. + assResp.len_assId
  85. + assResp.len_taggedParams
  86. + assResp.len_fsc;
  87. //define packet
  88. u_char *assRespPacket = malloc(*packetSize);
  89. if(!assRespPacket)
  90. {
  91. printf("Memory allocation error!\n");
  92. exit(-1);
  93. }
  94. //copy all struct fields into packet
  95. int copyOffset = 0;
  96. memcpy(assRespPacket + copyOffset, assResp.radioTapHdr, assResp.len_radioTapHdr);
  97. copyOffset = copyOffset + assResp.len_radioTapHdr;
  98. memcpy(assRespPacket + copyOffset, assResp.type, assResp.len_type);
  99. copyOffset = copyOffset + assResp.len_type;
  100. memcpy(assRespPacket + copyOffset, assResp.flags, assResp.len_flags);
  101. copyOffset = copyOffset + assResp.len_flags;
  102. memcpy(assRespPacket + copyOffset, assResp.duration, assResp.len_duration);
  103. copyOffset = copyOffset + assResp.len_duration;
  104. memcpy(assRespPacket + copyOffset, assResp.destAddr, assResp.len_destAddr);
  105. copyOffset = copyOffset + assResp.len_destAddr;
  106. memcpy(assRespPacket + copyOffset, assResp.sourceAddr, assResp.len_sourceAddr);
  107. copyOffset = copyOffset + assResp.len_sourceAddr;
  108. memcpy(assRespPacket + copyOffset, assResp.bssAddr, assResp.len_bssAddr);
  109. copyOffset = copyOffset + assResp.len_bssAddr;
  110. memcpy(assRespPacket + copyOffset, assResp.seqNr, assResp.len_seqNr);
  111. copyOffset = copyOffset + assResp.len_seqNr;
  112. memcpy(assRespPacket + copyOffset, assResp.capabInfo, assResp.len_capabInfo);
  113. copyOffset = copyOffset + assResp.len_capabInfo;
  114. memcpy(assRespPacket + copyOffset, assResp.status, assResp.len_status);
  115. copyOffset = copyOffset + assResp.len_status;
  116. memcpy(assRespPacket + copyOffset, assResp.assId, assResp.len_assId);
  117. copyOffset = copyOffset + assResp.len_assId;
  118. //copy all information elements
  119. for(int i = 0; i < AssstaticIES; i++)
  120. {
  121. if (taggedParams[i].len_data != -1) //if id == -1, we do not want to include the information element
  122. {
  123. memcpy(assRespPacket + copyOffset, &taggedParams[i].id, 1);
  124. copyOffset = copyOffset + 1;
  125. memcpy(assRespPacket + copyOffset, &taggedParams[i].len, 1);
  126. copyOffset = copyOffset + 1;
  127. memcpy(assRespPacket + copyOffset, taggedParams[i].data, taggedParams[i].len_data);
  128. copyOffset = copyOffset + taggedParams[i].len_data;
  129. }
  130. }
  131. memcpy(assRespPacket + copyOffset, assResp.fsc, assResp.len_fsc);
  132. copyOffset = copyOffset + assResp.len_fsc;
  133. //send packet
  134. return assRespPacket;
  135. }