|
@@ -5,6 +5,7 @@ from scipy.stats import gamma
|
|
|
from lea import Lea
|
|
|
from datetime import datetime
|
|
|
import os
|
|
|
+import sys
|
|
|
|
|
|
import ID2TLib.libbotnet as lb
|
|
|
from Attack import BaseAttack
|
|
@@ -471,6 +472,8 @@ class MembersMgmtCommAttack(BaseAttack.BaseAttack):
|
|
|
context.add_other_created_file(new_xml_path)
|
|
|
return new_xml_path
|
|
|
|
|
|
+ # print a line break to have follwing status messages on a new line
|
|
|
+ print()
|
|
|
|
|
|
# parse input CSV or XML
|
|
|
filepath_xml = self.get_param_value(Param.FILE_XML)
|
|
@@ -483,11 +486,25 @@ class MembersMgmtCommAttack(BaseAttack.BaseAttack):
|
|
|
# --> prefer XML input over CSV input (in case both are given)
|
|
|
if filepath_csv and filepath_xml == self.DEFAULT_XML_PATH:
|
|
|
filename = os.path.splitext(filepath_csv)[0]
|
|
|
+ filesize = os.path.getsize(filepath_csv) / 2**20 # get filesize in MB
|
|
|
+ if filesize > 10:
|
|
|
+ print("Parsing input CSV file...", end=" ")
|
|
|
+ sys.stdout.flush()
|
|
|
cpp_comm_proc.parse_csv(filepath_csv)
|
|
|
+ print("done.")
|
|
|
+ print("Writing corresponding XML file...", end=" ")
|
|
|
+ sys.stdout.flush()
|
|
|
filepath_xml = cpp_comm_proc.write_xml(filename)
|
|
|
filepath_xml = move_xml_to_outdir(filepath_xml)
|
|
|
+ print("done.")
|
|
|
else:
|
|
|
+ filesize = os.path.getsize(filepath_xml) / 2**20 # get filesize in MB
|
|
|
+ if filesize > 10:
|
|
|
+ print("Parsing input XML file...", end=" ")
|
|
|
+ sys.stdout.flush()
|
|
|
cpp_comm_proc.parse_xml(filepath_xml)
|
|
|
+ print("done.")
|
|
|
+
|
|
|
|
|
|
# find a good communication mapping in the input file that matches the users parameters
|
|
|
nat = self.get_param_value(Param.NAT_PRESENT)
|
|
@@ -498,11 +515,19 @@ class MembersMgmtCommAttack(BaseAttack.BaseAttack):
|
|
|
start_idx = self.get_param_value(Param.INTERVAL_SELECT_START)
|
|
|
end_idx = self.get_param_value(Param.INTERVAL_SELECT_END)
|
|
|
|
|
|
+ print("Selecting communication interval from input CSV/XML file...", end=" ")
|
|
|
+ sys.stdout.flush()
|
|
|
+ if strategy == "optimal" and filesize > 4 and self.statistics.get_packet_count() > 1000:
|
|
|
+ print("\nWarning: Because of the large input files and the (chosen) interval selection strategy 'optimal',")
|
|
|
+ print("this may take a while. Consider using selection strategy 'random' or 'custom'...", end=" ")
|
|
|
+ sys.stdout.flush()
|
|
|
+
|
|
|
comm_interval = comm_proc.get_comm_interval(cpp_comm_proc, strategy, number_init_bots, duration, start_idx, end_idx)
|
|
|
|
|
|
if not comm_interval:
|
|
|
- print("Error: There is no interval in the given CSV/XML that has enough communicating initiating bots.")
|
|
|
+ print("Error: An interval that satisfies the input cannot be found.")
|
|
|
return []
|
|
|
+ print("done.") # print corresponding message to interval finding message
|
|
|
|
|
|
# retrieve the mapping information
|
|
|
mapped_ids, packet_start_idx, packet_end_idx = comm_interval["IDs"], comm_interval["Start"], comm_interval["End"]
|
|
@@ -511,6 +536,8 @@ class MembersMgmtCommAttack(BaseAttack.BaseAttack):
|
|
|
rm_idx = randrange(0, len(mapped_ids))
|
|
|
del mapped_ids[rm_idx]
|
|
|
|
|
|
+ print("Generating attack packets...", end=" ")
|
|
|
+ sys.stdout.flush()
|
|
|
# get the messages contained in the chosen interval
|
|
|
abstract_packets = cpp_comm_proc.get_messages(packet_start_idx, packet_end_idx);
|
|
|
comm_proc.set_mapping(abstract_packets, mapped_ids)
|