123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- /*
- Fuzzes PrbResp by testing all 256 IEs on overflow in four ways
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdint.h>
- #include <string.h>
- #include <math.h>
- #include "../frameDefinitions.h"
- //Creates Probe response frame
- u_char *Prboversize(u_char *dstAddress, int *packetSize, u_char * radioTapHeader, u_char *myMAC, int step)
- {
- #define PRBoversizeIES (6) //number of information elements
- //definition of all info elements
- infoElem base255;
- base255.id = 0;
- base255.len = 255;
- base255.len_data = 255;
- u_char *data = malloc(255);
- memset(data, 0xff, 255);
- base255.data = data;
- infoElem lastBit;
- lastBit.id = 48;
- lastBit.len = 151-step;
- lastBit.len_data = 151-step;
- u_char *data2 = malloc(151-step);
- memset(data2, 0xff, 151-step);
- lastBit.data = data2;
- //create array of information elements
- infoElem taggedParams[PRBoversizeIES] = {
- base255, base255, base255, base255, base255, lastBit
- };
- //length of all info elements, including id and len field
- int len_taggedParams = 0;
- for(int i = 0; i < PRBoversizeIES; i++)
- {
- if (taggedParams[i].len_data != -1) //do not include when len_data == -1
- {
- //+2 to include id and len field size
- len_taggedParams = len_taggedParams + taggedParams[i].len_data+2;
- }
- }
- //fill in struct
- probeResponse probeResp = {
- 36, radioTapHeader, //RadioTap hdr
- 1, "\x50", //Type
- 1, "\x00", //Flags
- 2, "\x3a\x01", //Duration
- 6, dstAddress, //DST addr
- 6, myMAC, //Source addr
- 6, myMAC, //BSS addr
- 2, "\x00\x00", //Seq nr (overwritten by firmware)
- 8, "\x00\x00\x00\x00\x00\x00\x00\x00", //Timestamp (overwritten by firmware)
- 2, "\x64\x00", //Beacon interval
- 2, "\x01\x00", //Capab info
-
- len_taggedParams,
- taggedParams, //Information elements
- 4, "\x00\x00\x00\x00" //FSC (overwritten by firmware)
- };
- //calculate size of final packet
- *packetSize = probeResp.len_radioTapHdr
- + probeResp.len_type
- + probeResp.len_flags
- + probeResp.len_duration
- + probeResp.len_destAddr
- + probeResp.len_sourceAddr
- + probeResp.len_bssAddr
- + probeResp.len_seqNr
- + probeResp.len_timeStamp
- + probeResp.len_beaconInterval
- + probeResp.len_capabInfo
- + probeResp.len_taggedParams
- + probeResp.len_fsc;
-
- //define packet
- u_char *probeRespPacket = malloc(*packetSize);
- if(!probeRespPacket)
- {
- printf("Memory allocation error!\n");
- exit(-1);
- }
- //copy all struct fields into packet
- int copyOffset = 0;
- memcpy(probeRespPacket + copyOffset, probeResp.radioTapHdr, probeResp.len_radioTapHdr);
- copyOffset = copyOffset + probeResp.len_radioTapHdr;
- memcpy(probeRespPacket + copyOffset, probeResp.type, probeResp.len_type);
- copyOffset = copyOffset + probeResp.len_type;
- memcpy(probeRespPacket + copyOffset, probeResp.flags, probeResp.len_flags);
- copyOffset = copyOffset + probeResp.len_flags;
- memcpy(probeRespPacket + copyOffset, probeResp.duration, probeResp.len_duration);
- copyOffset = copyOffset + probeResp.len_duration;
- memcpy(probeRespPacket + copyOffset, probeResp.destAddr, probeResp.len_destAddr);
- copyOffset = copyOffset + probeResp.len_destAddr;
- memcpy(probeRespPacket + copyOffset, probeResp.sourceAddr, probeResp.len_sourceAddr);
- copyOffset = copyOffset + probeResp.len_sourceAddr;
- memcpy(probeRespPacket + copyOffset, probeResp.bssAddr, probeResp.len_bssAddr);
- copyOffset = copyOffset + probeResp.len_bssAddr;
- memcpy(probeRespPacket + copyOffset, probeResp.seqNr, probeResp.len_seqNr);
- copyOffset = copyOffset + probeResp.len_seqNr;
- memcpy(probeRespPacket + copyOffset, probeResp.timeStamp, probeResp.len_timeStamp);
- copyOffset = copyOffset + probeResp.len_timeStamp;
- memcpy(probeRespPacket + copyOffset, probeResp.beaconInterval, probeResp.len_beaconInterval);
- copyOffset = copyOffset + probeResp.len_beaconInterval;
- memcpy(probeRespPacket + copyOffset, probeResp.capabInfo, probeResp.len_capabInfo);
- copyOffset = copyOffset + probeResp.len_capabInfo;
- //copy all information elements
- for(int i = 0; i < PRBoversizeIES; i++)
- {
- if (taggedParams[i].len_data != -1) //if id == -1, we do not want to include the information element
- {
- memcpy(probeRespPacket + copyOffset, &taggedParams[i].id, 1);
- copyOffset = copyOffset + 1;
- memcpy(probeRespPacket + copyOffset, &taggedParams[i].len, 1);
- copyOffset = copyOffset + 1;
- memcpy(probeRespPacket + copyOffset, taggedParams[i].data, taggedParams[i].len_data);
- copyOffset = copyOffset + taggedParams[i].len_data;
- }
- }
-
- memcpy(probeRespPacket + copyOffset, probeResp.fsc, probeResp.len_fsc);
- copyOffset = copyOffset + probeResp.len_fsc;
- //return packet
- return probeRespPacket;
- }
|