1
0

frameCreator.c 5.3 KB

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