-
Notifications
You must be signed in to change notification settings - Fork 0
/
BurstSize6.py
52 lines (44 loc) · 1.75 KB
/
BurstSize6.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
# 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
# This doesn't allow a Burst to have more than bsize packets.
# But allows all Bursts less than bsize to stay the same size.
class BurstSize6:
@staticmethod
def applyCountermeasure(trace):
# bsize = random.choice(range(2, 10, 1))
bsize = 6
rand = 0
newTrace = Trace(trace.getId())
# rand = random.choice(range(8,256,8))
count = 0
curDir = 0
for packet in trace.getPackets():
direction = packet.getDirection()
length = packet.getLength()
newlength = min(length + rand, Packet.MTU)
time = packet.getTime()
newPacket = Packet(direction,
time,
newlength )
newTrace.addPacket(newPacket)
if (((direction == 0 and curDir == 0) | (direction == 1 and curDir == 1)) and count < bsize):
count +=1
elif (((direction == 0 and curDir == 0) | (direction == 1 and curDir == 1)) and count == bsize):
BurstSize6.makeDummy(newTrace, time)
count = 0
else:
count = 1
if(curDir):
curDir = 0
else:
curDir = 1
return newTrace
@staticmethod
def makeDummy(newTrace, time):
templength = 638
dummyPacket = Packet(0, time, templength)
newTrace.addPacket(dummyPacket)