-
Notifications
You must be signed in to change notification settings - Fork 0
/
BurstPadAllRand.py
71 lines (61 loc) · 2.54 KB
/
BurstPadAllRand.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# This is a Python framework to compliment "Peek-a-Boo, I Still See You: Why Efficient Traffic Analysis Countermeasures Fail".
# Copyright (C) 2012 Kevin P. Dyer (kpdyer.com)
# See LICENSE for more details.
import random
from Trace import Trace
from Packet import Packet
class BurstPadAllRand:
@staticmethod
def applyCountermeasure(trace):
bsize = random.choice(range(2,10,1))
newTrace = Trace(trace.getId())
count = 0
curDir = 0
rand = random.choice(range(8,256,8))
for packet in trace.getPackets():
direction = packet.getDirection()
length = packet.getLength()
newlength = min( packet.getLength()+rand, Packet.MTU )
time = packet.getTime()
newPacket = Packet(direction,
time,
newlength )
if (direction == 1 and curDir == 1 and (count < bsize)):
count +=1
newTrace.addPacket(newPacket)
elif (direction == 1 and curDir == 1 and (count == bsize)):
BurstPadAllRand.sendDummyAck(newTrace, time)
newTrace.addPacket(newPacket)
bsize = random.choice(range(2,10,1))
count = 1
elif (direction == 0 and curDir == 0):
count = 0
newTrace.addPacket(newPacket)
elif (direction == 1 and curDir == 0):
curDir = 1
count = 1
newTrace.addPacket(newPacket)
elif (direction == 0 and curDir == 1):
BurstPadAllRand.makeDummy(newTrace, length, time, bsize, count, rand)
newTrace.addPacket(newPacket)
curDir = 0
count = 0
bsize = random.choice(range(2,10,1))
return newTrace
@staticmethod
def sendDummyAck(newTrace, time):
length = 638
ack = Packet(0, time, length)
newTrace.addPacket(ack)
@staticmethod
def makeDummy(newTrace, length, time, bsize, count, rand):
# templength = Packet.MTU
# if Packet.MTU-length>0:
# templength = length+random.choice(range(0,Packet.MTU-length,8))
# dummyPacket = Packet(curDir,
# time,
# templength)
for val in range(count, bsize):
newlength = Packet.MTU
dummyPac = Packet(1, time, newlength)
newTrace.addPacket(dummyPac)