X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=client%2Fexperiments.py;h=12ccfd96f83cb060ee384fc66edb82978af2cf15;hp=04777da1e8b4f8ca96f8a6bcbdac639765da6411;hb=0ec610ab9c97dd3301957256f8c61014f1c7b8f4;hpb=ca0811466affbfafaff5ddb0f0d7bfb13e5f48c8 diff --git a/client/experiments.py b/client/experiments.py index 04777da..12ccfd9 100644 --- a/client/experiments.py +++ b/client/experiments.py @@ -179,7 +179,69 @@ class experiments(GoodFETMCPCANCommunication): # where low is the low end of values for the fuzz, high is the high end value # period is the time between sending packets in milliseconds, writesPerFuzz is the times the # same fuzzed packet will be injecetez. Fuzzes is the number of different packets to be injected - def generationFuzzer(self,freq, standardId, dbLimits, period, writesPerFuzz, Fuzzes): + def generationFuzzer(self,freq, standardIDs, dbLimits, period, writesPerFuzz, Fuzzes): + #print "Fuzzing on standard ID: %d" %standardId + self.client.serInit() + self.spitSetup(freq) + packet = [0,0,0x00,0x00,0x08,0,0,0,0,0,0,0,0] #empty template + #form a basic packet + +# #### split SID into different regs +# SIDlow = (standardIds[0] & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5 +# SIDhigh = (standardIds[0] >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0 +# +# packet = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs +# 0x08, # bit 6 must be set to 0 for data frame (1 for RTR) +# # lower nibble is DLC +# packetTemp[0],packetTemp[1],packetTemp[2],packetTemp[3],packetTemp[4],packetTemp[5],packetTemp[6],packetTemp[7]] +# + + #get folder information (based on today's date) + now = datetime.datetime.now() + datestr = now.strftime("%Y%m%d") + path = self.DATALOCATION+"InjectedData/"+datestr+"_GenerationFuzzedPackets.csv" + filename = path + outfile = open(filename,'a'); + dataWriter = csv.writer(outfile,delimiter=','); + #dataWriter.writerow(['# Time Error Bytes 1-13']); + #dataWriter.writerow(['#' + description]) + + numIds = len(standardIDs) + fuzzNumber = 0; + while( fuzzNumber < Fuzzes): + id_new = standardIDs[random.randint(0,numIds-1)] + #### split SID into different regs + SIDlow = (id_new & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5 + SIDhigh = (id_new >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0 + packet[0] = SIDhigh + packet[1] = SIDlow + + #generate a fuzzed packet + for i in range(0,8): # for each databyte, fuzz it + idx = "db%d"%i + limits = dbLimits[idx] + value = random.randint(limits[0],limits[1]) #generate pseudo-random integer value + packet[i+5] = value + + #put a rough time stamp on the data and get all the data bytes + row = [time.time(), id_new,8] + msg = "Injecting: " + for i in range(5,13): + row.append(packet[i]) + msg += " %d"%packet[i] + #print msg + dataWriter.writerow(row) + self.client.txpacket(packet) + #inject the packet repeatily + for i in range(1,writesPerFuzz): + self.client.MCPrts(TXB0=True) + time.sleep(period/1000) + fuzzNumber += 1 + print "Fuzzing Complete" + outfile.close() + + + def generationFuzzRandomID(self, freq, standardIDs, dbLimits, period, writesPerFuzz, Fuzzes): print "Fuzzing on standard ID: %d" %standardId self.client.serInit() self.spitSetup(freq) @@ -199,16 +261,23 @@ class experiments(GoodFETMCPCANCommunication): #get folder information (based on today's date) now = datetime.datetime.now() datestr = now.strftime("%Y%m%d") - path = self.DATALOCATION+datestr+"_GenerationFuzzedPackets.csv" + path = self.DATALOCATION+"InjectedData/"+datestr+"_GenerationFuzzedPackets.csv" filename = path outfile = open(filename,'a'); dataWriter = csv.writer(outfile,delimiter=','); #dataWriter.writerow(['# Time Error Bytes 1-13']); #dataWriter.writerow(['#' + description]) - + numIds = len(standardIDs) fuzzNumber = 0; while( fuzzNumber < Fuzzes): + id_new = standsardIDs[random.randint(0,numIds-1)] + #### split SID into different regs + SIDlow = (id_new & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5 + SIDhigh = (id_new >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0 + packet[0] = SIDhigh + packet[1] = SIDlow + #generate a fuzzed packet for i in range(0,8): # for each databyte, fuzz it idx = "db%d"%i @@ -217,12 +286,12 @@ class experiments(GoodFETMCPCANCommunication): packet[i+5] = value #put a rough time stamp on the data and get all the data bytes - row = ['#',time.time(), standardId] + row = [time.time(), standardId,8] msg = "Injecting: " for i in range(5,13): row.append(packet[i]) msg += " %d"%packet[i] - print msg + #print msg dataWriter.writerow(row) self.client.txpacket(packet) #inject the packet repeatily @@ -230,9 +299,5 @@ class experiments(GoodFETMCPCANCommunication): self.client.MCPrts(TXB0=True) time.sleep(period/1000) fuzzNumber += 1 - + print "Fuzzing Complete" outfile.close() - - - -