PRBtemplate.c 5.3 KB

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