frameCreator.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  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 "fuzzRates.h"
  12. #include "fuzzEXTRATES.h"
  13. #include "fuzzHTCAPAB.h"
  14. #include "fuzzHTINFO.h"
  15. #include "fuzzEXTCAPAB.h"
  16. #include "fuzzEDCA.h"
  17. #include "fuzzAssResponse.h"
  18. //CHANGE WHEN NEW SUBFUZZER
  19. //Creates Authentication frame
  20. u_char *createAuthResponse(u_char *dstAddress, int *packetSize, u_char * radioTapHeader, u_char *myMAC)
  21. {
  22. //fill in struct
  23. authResponse authResp = {
  24. 36, radioTapHeader, //RadioTap hdr
  25. 1, "\xb0", //Type
  26. 1, "\x00", //Subtype
  27. 2, "\x3a\x01", //Duration
  28. 6, dstAddress, //DST addr
  29. 6, myMAC, //Source addr
  30. 6, myMAC, //BSS addr
  31. 2, "\x00\x00", //Seq nr (overwritten by firmware)
  32. 2, "\x00\x00", //Auth alg
  33. 2, "\x02\x00", //Auth seq
  34. 2, "\x00\x00", //Status code
  35. 4, "\x00\x00\x00\x00" //FSC (overwritten by firmware)
  36. };
  37. //calculate size of final packet
  38. *packetSize = authResp.len_radioTapHdr
  39. + authResp.len_type
  40. + authResp.len_flags
  41. + authResp.len_duration
  42. + authResp.len_destAddr
  43. + authResp.len_sourceAddr
  44. + authResp.len_bssAddr
  45. + authResp.len_seqNr
  46. + authResp.len_authAlg
  47. + authResp.len_authSeq
  48. + authResp.len_status
  49. + authResp.len_fsc;
  50. //define packet
  51. u_char *authRespPacket = malloc(*packetSize);
  52. if(!authRespPacket)
  53. {
  54. printf("Memory allocation error!\n");
  55. exit(-1);
  56. }
  57. //copy all struct fields into packet
  58. int copyOffset = 0;
  59. memcpy(authRespPacket + copyOffset, authResp.radioTapHdr, authResp.len_radioTapHdr);
  60. copyOffset = copyOffset + authResp.len_radioTapHdr;
  61. memcpy(authRespPacket + copyOffset, authResp.type, authResp.len_type);
  62. copyOffset = copyOffset + authResp.len_type;
  63. memcpy(authRespPacket + copyOffset, authResp.flags, authResp.len_flags);
  64. copyOffset = copyOffset + authResp.len_flags;
  65. memcpy(authRespPacket + copyOffset, authResp.duration, authResp.len_duration);
  66. copyOffset = copyOffset + authResp.len_duration;
  67. memcpy(authRespPacket + copyOffset, authResp.destAddr, authResp.len_destAddr);
  68. copyOffset = copyOffset + authResp.len_destAddr;
  69. memcpy(authRespPacket + copyOffset, authResp.sourceAddr, authResp.len_sourceAddr);
  70. copyOffset = copyOffset + authResp.len_sourceAddr;
  71. memcpy(authRespPacket + copyOffset, authResp.bssAddr, authResp.len_bssAddr);
  72. copyOffset = copyOffset + authResp.len_bssAddr;
  73. memcpy(authRespPacket + copyOffset, authResp.seqNr, authResp.len_seqNr);
  74. copyOffset = copyOffset + authResp.len_seqNr;
  75. memcpy(authRespPacket + copyOffset, authResp.authAlg, authResp.len_authAlg);
  76. copyOffset = copyOffset + authResp.len_authAlg;
  77. memcpy(authRespPacket + copyOffset, authResp.authSeq, authResp.len_authSeq);
  78. copyOffset = copyOffset + authResp.len_authSeq;
  79. memcpy(authRespPacket + copyOffset, authResp.status, authResp.len_status);
  80. copyOffset = copyOffset + authResp.len_status;
  81. memcpy(authRespPacket + copyOffset, authResp.fsc, authResp.len_fsc);
  82. copyOffset = copyOffset + authResp.len_fsc;
  83. //send packet
  84. return authRespPacket;
  85. }
  86. //Creates Association response
  87. u_char *createAssResponse(u_char *dstAddress, int *packetSize, u_char * radioTapHeader, u_char *myMAC)
  88. {
  89. //when done with all subfuzzers, we want to return frames from the generic fuzzer
  90. if (getNotifyDone() != 0)
  91. return AssRespFuzz(dstAddress, packetSize, radioTapHeader, myMAC);
  92. #define numberOfAssInfoElems (6) //number of information elements
  93. //definition of all info elements
  94. //CHANGE WHEN NEW SUBFUZZER
  95. infoElem suppRates = ratesFuzz();
  96. infoElem extrates = extratesFuzz();
  97. infoElem htcapab = htcapabFuzz();
  98. infoElem htinfo = htinfoFuzz();
  99. infoElem extcapab = extcapabFuzz();
  100. infoElem edca = edcaFuzz();
  101. //CHANGE WHEN NEW SUBFUZZER
  102. //create array of information elements
  103. infoElem taggedParams[numberOfAssInfoElems] = {suppRates, extrates, htcapab,
  104. htinfo, extcapab, edca};
  105. //length of all info elements, including id and len field
  106. int len_taggedParams = 0;
  107. for(int i = 0; i < numberOfAssInfoElems; i++)
  108. {
  109. if (taggedParams[i].len_data != -1) //do not include if len_data == -1
  110. {
  111. //+2 to include id and len field size
  112. len_taggedParams = len_taggedParams + taggedParams[i].len_data+2;
  113. }
  114. }
  115. //fill in struct
  116. assResponse assResp = {
  117. 36, radioTapHeader, //RadioTap hdr
  118. 1, "\x10", //Type
  119. 1, "\x00", //Flags
  120. 2, "\x40\x01", //Duration
  121. 6, dstAddress, //DST addr
  122. 6, myMAC, //Source addr
  123. 6, myMAC, //BSS addr
  124. 2, "\x00\x00", //Seq nr (overwritten by firmware)
  125. 2, "\x01\x00", //Capab info
  126. 2, "\x00\x00", //Status code
  127. 2, "\x01\xc0", //Association id
  128. len_taggedParams,
  129. taggedParams, //Information elements
  130. 4, "\x00\x00\x00\x00" //FSC (overwritten by firmware)
  131. };
  132. //calculate size of final packet
  133. *packetSize = assResp.len_radioTapHdr
  134. + assResp.len_type
  135. + assResp.len_flags
  136. + assResp.len_duration
  137. + assResp.len_destAddr
  138. + assResp.len_sourceAddr
  139. + assResp.len_bssAddr
  140. + assResp.len_seqNr
  141. + assResp.len_capabInfo
  142. + assResp.len_status
  143. + assResp.len_assId
  144. + assResp.len_taggedParams
  145. + assResp.len_fsc;
  146. //define packet
  147. u_char *assRespPacket = malloc(*packetSize);
  148. if(!assRespPacket)
  149. {
  150. printf("Memory allocation error!\n");
  151. exit(-1);
  152. }
  153. //copy all struct fields into packet
  154. int copyOffset = 0;
  155. memcpy(assRespPacket + copyOffset, assResp.radioTapHdr, assResp.len_radioTapHdr);
  156. copyOffset = copyOffset + assResp.len_radioTapHdr;
  157. memcpy(assRespPacket + copyOffset, assResp.type, assResp.len_type);
  158. copyOffset = copyOffset + assResp.len_type;
  159. memcpy(assRespPacket + copyOffset, assResp.flags, assResp.len_flags);
  160. copyOffset = copyOffset + assResp.len_flags;
  161. memcpy(assRespPacket + copyOffset, assResp.duration, assResp.len_duration);
  162. copyOffset = copyOffset + assResp.len_duration;
  163. memcpy(assRespPacket + copyOffset, assResp.destAddr, assResp.len_destAddr);
  164. copyOffset = copyOffset + assResp.len_destAddr;
  165. memcpy(assRespPacket + copyOffset, assResp.sourceAddr, assResp.len_sourceAddr);
  166. copyOffset = copyOffset + assResp.len_sourceAddr;
  167. memcpy(assRespPacket + copyOffset, assResp.bssAddr, assResp.len_bssAddr);
  168. copyOffset = copyOffset + assResp.len_bssAddr;
  169. memcpy(assRespPacket + copyOffset, assResp.seqNr, assResp.len_seqNr);
  170. copyOffset = copyOffset + assResp.len_seqNr;
  171. memcpy(assRespPacket + copyOffset, assResp.capabInfo, assResp.len_capabInfo);
  172. copyOffset = copyOffset + assResp.len_capabInfo;
  173. memcpy(assRespPacket + copyOffset, assResp.status, assResp.len_status);
  174. copyOffset = copyOffset + assResp.len_status;
  175. memcpy(assRespPacket + copyOffset, assResp.assId, assResp.len_assId);
  176. copyOffset = copyOffset + assResp.len_assId;
  177. //copy all information elements
  178. for(int i = 0; i < numberOfAssInfoElems; i++)
  179. {
  180. if (taggedParams[i].len_data != -1) //if id == -1, we do not want to include the information element
  181. {
  182. memcpy(assRespPacket + copyOffset, &taggedParams[i].id, 1);
  183. copyOffset = copyOffset + 1;
  184. memcpy(assRespPacket + copyOffset, &taggedParams[i].len, 1);
  185. copyOffset = copyOffset + 1;
  186. memcpy(assRespPacket + copyOffset, taggedParams[i].data, taggedParams[i].len_data);
  187. copyOffset = copyOffset + taggedParams[i].len_data;
  188. }
  189. }
  190. memcpy(assRespPacket + copyOffset, assResp.fsc, assResp.len_fsc);
  191. copyOffset = copyOffset + assResp.len_fsc;
  192. //send packet
  193. return assRespPacket;
  194. }
  195. //Creates Probe response frame
  196. u_char *createProbeResponse(u_char *dstAddress, int *packetSize, u_char * radioTapHeader, u_char *myMAC)
  197. {
  198. #define numberOfProbeInfoElems (3) //number of information elements
  199. //definition of all info elements
  200. infoElem ssid = {
  201. 0, //id
  202. 4, //len
  203. 4, //real length of data
  204. "\x46\x55\x5a\x5a" //data
  205. };
  206. infoElem suppRates = {
  207. 1, //id
  208. 7, //len
  209. 7, //real length of data
  210. "\x96\x18\x24\x30\x48\x60\x6c" //data
  211. };
  212. infoElem ds = {
  213. 3, //id
  214. 1, //len
  215. 1, //real length of data
  216. "\x01" //data
  217. };
  218. //CHANGE WHEN NEW SUBFUZZER
  219. //create array of information elements
  220. infoElem taggedParams[numberOfProbeInfoElems] = {ssid, suppRates, ds};
  221. //length of all info elements, including id and len field
  222. int len_taggedParams = 0;
  223. for(int i = 0; i < numberOfProbeInfoElems; i++)
  224. {
  225. if (taggedParams[i].len_data != -1) //do not include when len_data == -1
  226. {
  227. //+2 to include id and len field size
  228. len_taggedParams = len_taggedParams + taggedParams[i].len_data+2;
  229. }
  230. }
  231. //fill in struct
  232. probeResponse probeResp = {
  233. 36, radioTapHeader, //RadioTap hdr
  234. 1, "\x50", //Type
  235. 1, "\x00", //Flags
  236. 2, "\x3a\x01", //Duration
  237. 6, dstAddress, //DST addr
  238. 6, myMAC, //Source addr
  239. 6, myMAC, //BSS addr
  240. 2, "\x00\x00", //Seq nr (overwritten by firmware)
  241. 8, "\x00\x00\x00\x00\x00\x00\x00\x00", //Timestamp (overwritten by firmware)
  242. 2, "\x64\x00", //Beacon interval
  243. 2, "\x01\x00", //Capab info
  244. len_taggedParams,
  245. taggedParams, //Information elements
  246. 4, "\x00\x00\x00\x00" //FSC (overwritten by firmware)
  247. };
  248. //calculate size of final packet
  249. *packetSize = probeResp.len_radioTapHdr
  250. + probeResp.len_type
  251. + probeResp.len_flags
  252. + probeResp.len_duration
  253. + probeResp.len_destAddr
  254. + probeResp.len_sourceAddr
  255. + probeResp.len_bssAddr
  256. + probeResp.len_seqNr
  257. + probeResp.len_timeStamp
  258. + probeResp.len_beaconInterval
  259. + probeResp.len_capabInfo
  260. + probeResp.len_taggedParams
  261. + probeResp.len_fsc;
  262. //define packet
  263. u_char *probeRespPacket = malloc(*packetSize);
  264. if(!probeRespPacket)
  265. {
  266. printf("Memory allocation error!\n");
  267. exit(-1);
  268. }
  269. //copy all struct fields into packet
  270. int copyOffset = 0;
  271. memcpy(probeRespPacket + copyOffset, probeResp.radioTapHdr, probeResp.len_radioTapHdr);
  272. copyOffset = copyOffset + probeResp.len_radioTapHdr;
  273. memcpy(probeRespPacket + copyOffset, probeResp.type, probeResp.len_type);
  274. copyOffset = copyOffset + probeResp.len_type;
  275. memcpy(probeRespPacket + copyOffset, probeResp.flags, probeResp.len_flags);
  276. copyOffset = copyOffset + probeResp.len_flags;
  277. memcpy(probeRespPacket + copyOffset, probeResp.duration, probeResp.len_duration);
  278. copyOffset = copyOffset + probeResp.len_duration;
  279. memcpy(probeRespPacket + copyOffset, probeResp.destAddr, probeResp.len_destAddr);
  280. copyOffset = copyOffset + probeResp.len_destAddr;
  281. memcpy(probeRespPacket + copyOffset, probeResp.sourceAddr, probeResp.len_sourceAddr);
  282. copyOffset = copyOffset + probeResp.len_sourceAddr;
  283. memcpy(probeRespPacket + copyOffset, probeResp.bssAddr, probeResp.len_bssAddr);
  284. copyOffset = copyOffset + probeResp.len_bssAddr;
  285. memcpy(probeRespPacket + copyOffset, probeResp.seqNr, probeResp.len_seqNr);
  286. copyOffset = copyOffset + probeResp.len_seqNr;
  287. memcpy(probeRespPacket + copyOffset, probeResp.timeStamp, probeResp.len_timeStamp);
  288. copyOffset = copyOffset + probeResp.len_timeStamp;
  289. memcpy(probeRespPacket + copyOffset, probeResp.beaconInterval, probeResp.len_beaconInterval);
  290. copyOffset = copyOffset + probeResp.len_beaconInterval;
  291. memcpy(probeRespPacket + copyOffset, probeResp.capabInfo, probeResp.len_capabInfo);
  292. copyOffset = copyOffset + probeResp.len_capabInfo;
  293. //copy all information elements
  294. for(int i = 0; i < numberOfProbeInfoElems; i++)
  295. {
  296. if (taggedParams[i].len_data != -1) //if id == -1, we do not want to include the information element
  297. {
  298. memcpy(probeRespPacket + copyOffset, &taggedParams[i].id, 1);
  299. copyOffset = copyOffset + 1;
  300. memcpy(probeRespPacket + copyOffset, &taggedParams[i].len, 1);
  301. copyOffset = copyOffset + 1;
  302. memcpy(probeRespPacket + copyOffset, taggedParams[i].data, taggedParams[i].len_data);
  303. copyOffset = copyOffset + taggedParams[i].len_data;
  304. }
  305. }
  306. memcpy(probeRespPacket + copyOffset, probeResp.fsc, probeResp.len_fsc);
  307. copyOffset = copyOffset + probeResp.len_fsc;
  308. //return packet
  309. return probeRespPacket;
  310. }
  311. //Creates Desassociation frame
  312. u_char *createDisAss(u_char *dstAddress, int *packetSize, u_char * radioTapHeader, u_char *myMAC)
  313. {
  314. //fill in struct
  315. disAss dis = {
  316. 36, radioTapHeader, //RadioTap hdr
  317. 1, "\xC0", //Type (set to deAUTHentication instead, since some devices ignore the disassociation frame)
  318. 1, "\x00", //Flags
  319. 2, "\x3a\x01", //Duration
  320. 6, dstAddress, //DST addr
  321. 6, myMAC, //Source addr
  322. 6, myMAC, //BSS addr
  323. 2, "\x00\x00", //Seq nr (overwritten by firmware)
  324. 2, "\x01\x00", //Reason code
  325. 4, "\x00\x00\x00\x00" //FSC (overwritten by firmware)
  326. };
  327. //calculate size of final packet
  328. *packetSize = dis.len_radioTapHdr
  329. + dis.len_type
  330. + dis.len_flags
  331. + dis.len_duration
  332. + dis.len_destAddr
  333. + dis.len_sourceAddr
  334. + dis.len_bssAddr
  335. + dis.len_seqNr
  336. + dis.len_reasonCode
  337. + dis.len_fsc;
  338. //define packet
  339. u_char *disPacket = malloc(*packetSize);
  340. if(!disPacket)
  341. {
  342. printf("Memory allocation error!\n");
  343. exit(-1);
  344. }
  345. //copy all struct fields into packet
  346. int copyOffset = 0;
  347. memcpy(disPacket + copyOffset, dis.radioTapHdr, dis.len_radioTapHdr);
  348. copyOffset = copyOffset + dis.len_radioTapHdr;
  349. memcpy(disPacket + copyOffset, dis.type, dis.len_type);
  350. copyOffset = copyOffset + dis.len_type;
  351. memcpy(disPacket + copyOffset, dis.flags, dis.len_flags);
  352. copyOffset = copyOffset + dis.len_flags;
  353. memcpy(disPacket + copyOffset, dis.duration, dis.len_duration);
  354. copyOffset = copyOffset + dis.len_duration;
  355. memcpy(disPacket + copyOffset, dis.destAddr, dis.len_destAddr);
  356. copyOffset = copyOffset + dis.len_destAddr;
  357. memcpy(disPacket + copyOffset, dis.sourceAddr, dis.len_sourceAddr);
  358. copyOffset = copyOffset + dis.len_sourceAddr;
  359. memcpy(disPacket + copyOffset, dis.bssAddr, dis.len_bssAddr);
  360. copyOffset = copyOffset + dis.len_bssAddr;
  361. memcpy(disPacket + copyOffset, dis.seqNr, dis.len_seqNr);
  362. copyOffset = copyOffset + dis.len_seqNr;
  363. memcpy(disPacket + copyOffset, dis.reasonCode, dis.len_reasonCode);
  364. copyOffset = copyOffset + dis.len_reasonCode;
  365. memcpy(disPacket + copyOffset, dis.fsc, dis.len_fsc);
  366. copyOffset = copyOffset + dis.len_fsc;
  367. //return packet
  368. return disPacket;
  369. }