frameCreator.c 5.3 KB

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