|
@@ -180,6 +180,7 @@ class MembersMgmtCommAttack(BaseAttack.BaseAttack):
|
|
limit_packetcount = self.get_param_value(Param.PACKETS_LIMIT)
|
|
limit_packetcount = self.get_param_value(Param.PACKETS_LIMIT)
|
|
limit_duration = self.get_param_value(Param.ATTACK_DURATION)
|
|
limit_duration = self.get_param_value(Param.ATTACK_DURATION)
|
|
path_attack_pcap = None
|
|
path_attack_pcap = None
|
|
|
|
+ overThousand = False
|
|
|
|
|
|
msg_packet_mapping = MessageMapping(messages)
|
|
msg_packet_mapping = MessageMapping(messages)
|
|
|
|
|
|
@@ -222,18 +223,33 @@ class MembersMgmtCommAttack(BaseAttack.BaseAttack):
|
|
if total_pkts <= 1:
|
|
if total_pkts <= 1:
|
|
self.attack_start_utime = packets[0].time
|
|
self.attack_start_utime = packets[0].time
|
|
elif total_pkts % BUFFER_SIZE == 0: # every 1000 packets write them to the PCAP file (append)
|
|
elif total_pkts % BUFFER_SIZE == 0: # every 1000 packets write them to the PCAP file (append)
|
|
- packets = list(packets)
|
|
|
|
- Generator.equal_length(packets, padding = padding)
|
|
|
|
- last_packet = packets[-1]
|
|
|
|
- path_attack_pcap = self.write_attack_pcap(packets, True, path_attack_pcap)
|
|
|
|
- packets = deque(maxlen=BUFFER_SIZE)
|
|
|
|
|
|
+ if overThousand: # if over 1000 packets written, there may be a different packet-length for the last few packets
|
|
|
|
+ packets = list(packets)
|
|
|
|
+ Generator.equal_length(packets, length = max_len, padding = padding, force_len = True)
|
|
|
|
+ last_packet = packets[-1]
|
|
|
|
+ path_attack_pcap = self.write_attack_pcap(packets, True, path_attack_pcap)
|
|
|
|
+ packets = deque(maxlen=BUFFER_SIZE)
|
|
|
|
+ else:
|
|
|
|
+ packets = list(packets)
|
|
|
|
+ Generator.equal_length(packets, padding = padding)
|
|
|
|
+ last_packet = packets[-1]
|
|
|
|
+ max_len = len(last_packet)
|
|
|
|
+ overThousand = True
|
|
|
|
+ path_attack_pcap = self.write_attack_pcap(packets, True, path_attack_pcap)
|
|
|
|
+ packets = deque(maxlen=BUFFER_SIZE)
|
|
|
|
|
|
# if there are unwritten packets remaining, write them to the PCAP file
|
|
# if there are unwritten packets remaining, write them to the PCAP file
|
|
if len(packets) > 0:
|
|
if len(packets) > 0:
|
|
- packets = list(packets)
|
|
|
|
- Generator.equal_length(packets, padding = padding)
|
|
|
|
- path_attack_pcap = self.write_attack_pcap(packets, True, path_attack_pcap)
|
|
|
|
- last_packet = packets[-1]
|
|
|
|
|
|
+ if overThousand:
|
|
|
|
+ packets = list(packets)
|
|
|
|
+ Generator.equal_length(packets, length = max_len, padding = padding, force_len = True)
|
|
|
|
+ path_attack_pcap = self.write_attack_pcap(packets, True, path_attack_pcap)
|
|
|
|
+ last_packet = packets[-1]
|
|
|
|
+ else:
|
|
|
|
+ packets = list(packets)
|
|
|
|
+ Generator.equal_length(packets, padding = padding)
|
|
|
|
+ path_attack_pcap = self.write_attack_pcap(packets, True, path_attack_pcap)
|
|
|
|
+ last_packet = packets[-1]
|
|
|
|
|
|
# write the mapping to a file
|
|
# write the mapping to a file
|
|
msg_packet_mapping.write_to(context.allocate_file("_mapping.xml"))
|
|
msg_packet_mapping.write_to(context.allocate_file("_mapping.xml"))
|
|
@@ -319,7 +335,7 @@ class MembersMgmtCommAttack(BaseAttack.BaseAttack):
|
|
def assign_realistic_timestamps(messages: list, external_ids: set, local_ids: set, avg_delay_local:float, avg_delay_external: float, zero_reference:float):
|
|
def assign_realistic_timestamps(messages: list, external_ids: set, local_ids: set, avg_delay_local:float, avg_delay_external: float, zero_reference:float):
|
|
"""
|
|
"""
|
|
Assigns realistic timestamps to a set of messages
|
|
Assigns realistic timestamps to a set of messages
|
|
-
|
|
|
|
|
|
+
|
|
:param messages: the set of messages to be updated
|
|
:param messages: the set of messages to be updated
|
|
:param external_ids: the set of bot ids, that are outside the network, i.e. external
|
|
:param external_ids: the set of bot ids, that are outside the network, i.e. external
|
|
:param local_ids: the set of bot ids, that are inside the network, i.e. local
|
|
:param local_ids: the set of bot ids, that are inside the network, i.e. local
|
|
@@ -331,7 +347,7 @@ class MembersMgmtCommAttack(BaseAttack.BaseAttack):
|
|
last_response = {} # Dict, takes a tuple of 2 Bot_IDs as a key (requester, responder), returns the time of the last response, the requester received
|
|
last_response = {} # Dict, takes a tuple of 2 Bot_IDs as a key (requester, responder), returns the time of the last response, the requester received
|
|
# necessary in order to make sure, that additional requests are sent only after the response to the last one was received
|
|
# necessary in order to make sure, that additional requests are sent only after the response to the last one was received
|
|
for msg in messages: # init
|
|
for msg in messages: # init
|
|
- last_response[(msg.src, msg.dst)] = -1
|
|
|
|
|
|
+ last_response[(msg.src, msg.dst)] = -1
|
|
|
|
|
|
# update all timestamps
|
|
# update all timestamps
|
|
for req_msg in messages:
|
|
for req_msg in messages:
|
|
@@ -357,7 +373,7 @@ class MembersMgmtCommAttack(BaseAttack.BaseAttack):
|
|
if req_msg.src in external_ids or req_msg.dst in external_ids:
|
|
if req_msg.src in external_ids or req_msg.dst in external_ids:
|
|
#external communication
|
|
#external communication
|
|
respns_msg.time = req_msg.time + avg_delay_external + uniform(-0.1*avg_delay_external, 0.1*avg_delay_external)
|
|
respns_msg.time = req_msg.time + avg_delay_external + uniform(-0.1*avg_delay_external, 0.1*avg_delay_external)
|
|
-
|
|
|
|
|
|
+
|
|
else:
|
|
else:
|
|
#local communication
|
|
#local communication
|
|
respns_msg.time = req_msg.time + avg_delay_local + uniform(-0.1*avg_delay_local, 0.1*avg_delay_local)
|
|
respns_msg.time = req_msg.time + avg_delay_local + uniform(-0.1*avg_delay_local, 0.1*avg_delay_local)
|
|
@@ -385,12 +401,12 @@ class MembersMgmtCommAttack(BaseAttack.BaseAttack):
|
|
with open("resources/CaidaTTL_perIP.csv", "r") as file:
|
|
with open("resources/CaidaTTL_perIP.csv", "r") as file:
|
|
# every line consists of: IP, TTL, Frequency
|
|
# every line consists of: IP, TTL, Frequency
|
|
next(file) # skip CSV header line
|
|
next(file) # skip CSV header line
|
|
- for line in file:
|
|
|
|
|
|
+ for line in file:
|
|
ip_addr, ttl, freq = line.split(",")
|
|
ip_addr, ttl, freq = line.split(",")
|
|
if ip_addr not in ip_based_distrib:
|
|
if ip_addr not in ip_based_distrib:
|
|
ip_based_distrib[ip_addr] = {} # the values for ip_based_distrib are dicts with key=TTL, value=Frequency
|
|
ip_based_distrib[ip_addr] = {} # the values for ip_based_distrib are dicts with key=TTL, value=Frequency
|
|
ip_based_distrib[ip_addr][ttl] = int(freq)
|
|
ip_based_distrib[ip_addr][ttl] = int(freq)
|
|
-
|
|
|
|
|
|
+
|
|
return ip_based_distrib
|
|
return ip_based_distrib
|
|
|
|
|
|
def get_total_ttl_distrib():
|
|
def get_total_ttl_distrib():
|
|
@@ -403,12 +419,12 @@ class MembersMgmtCommAttack(BaseAttack.BaseAttack):
|
|
with open("resources/CaidaTTL_total.csv", "r") as file:
|
|
with open("resources/CaidaTTL_total.csv", "r") as file:
|
|
# every line consists of: TTL, Frequency, Fraction
|
|
# every line consists of: TTL, Frequency, Fraction
|
|
next(file) # skip CSV header line
|
|
next(file) # skip CSV header line
|
|
- for line in file:
|
|
|
|
|
|
+ for line in file:
|
|
ttl, freq, _ = line.split(",")
|
|
ttl, freq, _ = line.split(",")
|
|
total_ttl_distrib[ttl] = int(freq)
|
|
total_ttl_distrib[ttl] = int(freq)
|
|
-
|
|
|
|
|
|
+
|
|
return total_ttl_distrib
|
|
return total_ttl_distrib
|
|
-
|
|
|
|
|
|
+
|
|
# get the TTL distribution for every IP that is available in "resources/CaidaTTL_perIP.csv"
|
|
# get the TTL distribution for every IP that is available in "resources/CaidaTTL_perIP.csv"
|
|
ip_ttl_distrib = get_ip_ttl_distrib()
|
|
ip_ttl_distrib = get_ip_ttl_distrib()
|
|
# build a probability dict for the total TTL distribution
|
|
# build a probability dict for the total TTL distribution
|
|
@@ -423,7 +439,7 @@ class MembersMgmtCommAttack(BaseAttack.BaseAttack):
|
|
bot_configs[bot_id]["TTL"] = 128
|
|
bot_configs[bot_id]["TTL"] = 128
|
|
|
|
|
|
# if there exists detailed information about the TTL distribution of this IP
|
|
# if there exists detailed information about the TTL distribution of this IP
|
|
- elif bot_ip in ip_ttl_distrib:
|
|
|
|
|
|
+ elif bot_ip in ip_ttl_distrib:
|
|
ip_ttl_freqs = ip_ttl_distrib[bot_ip]
|
|
ip_ttl_freqs = ip_ttl_distrib[bot_ip]
|
|
source_ttl_prob_dict = Lea.fromValFreqsDict(ip_ttl_freqs) # build a probability dict from this IP's TTL distribution
|
|
source_ttl_prob_dict = Lea.fromValFreqsDict(ip_ttl_freqs) # build a probability dict from this IP's TTL distribution
|
|
bot_configs[bot_id]["TTL"] = source_ttl_prob_dict.random()
|
|
bot_configs[bot_id]["TTL"] = source_ttl_prob_dict.random()
|