|
@@ -55,26 +55,24 @@ class Controller:
|
|
:param attacks_config: A list of attacks with their attack parameters.
|
|
:param attacks_config: A list of attacks with their attack parameters.
|
|
"""
|
|
"""
|
|
|
|
|
|
|
|
+ # get output directory
|
|
|
|
+ if self.pcap_out_path:
|
|
|
|
+ out_dir = os.path.dirname(self.pcap_out_path)
|
|
|
|
+ else:
|
|
|
|
+ out_dir = os.path.dirname(self.pcap_src_path)
|
|
|
|
+ # if out_dir is cwd
|
|
|
|
+ if out_dir == "":
|
|
|
|
+ out_dir = "."
|
|
|
|
+
|
|
# context for the attack(s)
|
|
# context for the attack(s)
|
|
- context = AttackContext()
|
|
|
|
|
|
+ context = AttackContext(out_dir)
|
|
|
|
|
|
# note if new xml file has been created by MembersMgmtCommAttack
|
|
# note if new xml file has been created by MembersMgmtCommAttack
|
|
- created_xml = None
|
|
|
|
# load attacks sequentially
|
|
# load attacks sequentially
|
|
for attack in attacks_config:
|
|
for attack in attacks_config:
|
|
- # check if new xml file has been created by MembersMgmtCommAttack
|
|
|
|
- if attack[0] == "MembersMgmtCommAttack":
|
|
|
|
- for param in attack[1:]:
|
|
|
|
- key, value = param.split("=")
|
|
|
|
- if key == "file.csv":
|
|
|
|
- if os.path.isfile(value):
|
|
|
|
- created_xml, _ = os.path.splitext(value)
|
|
|
|
- created_xml += ".xml"
|
|
|
|
- break
|
|
|
|
temp_attack_pcap = self.attack_controller.process_attack(attack[0], attack[1:], context)
|
|
temp_attack_pcap = self.attack_controller.process_attack(attack[0], attack[1:], context)
|
|
self.written_pcaps.append(temp_attack_pcap)
|
|
self.written_pcaps.append(temp_attack_pcap)
|
|
|
|
|
|
-
|
|
|
|
# merge attack pcaps to get single attack pcap
|
|
# merge attack pcaps to get single attack pcap
|
|
if len(self.written_pcaps) > 1:
|
|
if len(self.written_pcaps) > 1:
|
|
print("\nMerging temporary attack pcaps into single pcap file...", end=" ")
|
|
print("\nMerging temporary attack pcaps into single pcap file...", end=" ")
|
|
@@ -110,29 +108,24 @@ class Controller:
|
|
# write label file with attacks
|
|
# write label file with attacks
|
|
self.label_manager.write_label_file(self.pcap_dest_path)
|
|
self.label_manager.write_label_file(self.pcap_dest_path)
|
|
|
|
|
|
- # if MembersMgmtCommAttack created an xml file, move it into input pcap directory
|
|
|
|
- if created_xml:
|
|
|
|
- pcap_dir = os.path.splitext(self.pcap_dest_path)[0]
|
|
|
|
- if "/" in pcap_dir:
|
|
|
|
- pcap_dir = "/".join(pcap_dir.split("/")[:-1])
|
|
|
|
- xml_name = os.path.splitext(created_xml)[0] + ".xml"
|
|
|
|
- if "/" in xml_name:
|
|
|
|
- xml_name = xml_name.split("/")[-1]
|
|
|
|
- new_xml_path = pcap_dir + "/" + xml_name
|
|
|
|
- os.rename(created_xml, new_xml_path)
|
|
|
|
-
|
|
|
|
# pcap_base contains the name of the pcap-file without the ".pcap" extension
|
|
# pcap_base contains the name of the pcap-file without the ".pcap" extension
|
|
pcap_base = os.path.splitext(self.pcap_dest_path)[0]
|
|
pcap_base = os.path.splitext(self.pcap_dest_path)[0]
|
|
|
|
+ created_files = [self.pcap_dest_path, self.label_manager.label_file_path]
|
|
for suffix, filename in context.get_allocated_files():
|
|
for suffix, filename in context.get_allocated_files():
|
|
print(filename, pcap_base + suffix)
|
|
print(filename, pcap_base + suffix)
|
|
shutil.move(filename, pcap_base + suffix)
|
|
shutil.move(filename, pcap_base + suffix)
|
|
|
|
+ created_files.append(pcap_base + suffix)
|
|
context.reset()
|
|
context.reset()
|
|
|
|
|
|
# print status message
|
|
# print status message
|
|
- if created_xml:
|
|
|
|
- print('\nOutput files created: \n', self.pcap_dest_path, '\n', self.label_manager.label_file_path, '\n', new_xml_path)
|
|
|
|
- else:
|
|
|
|
- print('\nOutput files created: \n', self.pcap_dest_path, '\n', self.label_manager.label_file_path)
|
|
|
|
|
|
+ created_files += context.get_other_created_files()
|
|
|
|
+ created_files.sort()
|
|
|
|
+ print("\nOutput files created:")
|
|
|
|
+ for file in created_files:
|
|
|
|
+ # remove ./ at beginning of file to have only one representation for cwd
|
|
|
|
+ if file.startswith("./"):
|
|
|
|
+ file = file[2:]
|
|
|
|
+ print(file)
|
|
|
|
|
|
def process_db_queries(self, query, print_results=False):
|
|
def process_db_queries(self, query, print_results=False):
|
|
"""
|
|
"""
|