From 84e4615e7ad715e2070c35414dafdf5b97aaaed5 Mon Sep 17 00:00:00 2001 From: Cosmin Bianu Date: Tue, 4 Apr 2023 15:55:25 +0300 Subject: [PATCH 1/2] Translated print messages to English --- AttackerCalc.py | 22 +++++++++++----------- CreateFeaturesHandler.py | 6 +++--- FeaturesCalc.py | 10 +++++----- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/AttackerCalc.py b/AttackerCalc.py index 4b01f9a..6b41a11 100644 --- a/AttackerCalc.py +++ b/AttackerCalc.py @@ -9,8 +9,8 @@ def __init__(self, pcap=None, list_of_packets=None, policy='first_ip', window_si self.filter = filter_ip self.number_of_ip = number_of_ip self.list_of_packets = list_of_packets - assert self.get_number_of_ip() == 1, "La classe non e' ancora implementata per riconoscere piu' attacanti" - assert self.get_window_size() > 0, "Dimensioni della finestra non valide" + assert self.get_number_of_ip() == 1, "Multiple attackers are not supported (yet)" + assert self.get_window_size() > 0, "Invalid window size (it must be >=1)" def compute_attacker(self): policy = self.get_policy() @@ -19,18 +19,18 @@ def compute_attacker(self): elif(policy == "max_in_window"): ip = self.max_in_window_policy() else: - print("Selezionare una policy.") + print("Please select a policy.") return ip def first_ip_policy(self): - assert self.list_of_packets is not None or self.pcap is not None, "Assegnare un pcap o una lista di pacchetti" - print("\n" + "Calcolo attaccante" + "\n") + assert self.list_of_packets is not None or self.pcap is not None, "No PCAP or packets list has been provided" + print("\n" + "Processing attacker information" + "\n") if(self.get_list_of_packets() is not None): pkts = self.get_list_of_packets() elif(self.get_pcap() is not None): pkts = rdpcap(self.get_pcap()) else: - print("Assegnare un pcap o una lista di pacchetti.") + print("No PCAP or packets list has been provided.") return [] ip_list = [] for i in range(0, len(pkts) - 1): @@ -45,14 +45,14 @@ def first_ip_policy(self): return ip_list def max_in_window_policy(self): - assert self.list_of_packets is not None or self.pcap is not None, "Assegnare un pcap o una lista di pacchetti" - print("\n" + "Calcolo attaccante" + "\n") + assert self.list_of_packets is not None or self.pcap is not None, "No PCAP or packets list has been provided" + print("\n" + "Processing attacker information" + "\n") if(self.get_list_of_packets() is not None): pkts = self.get_list_of_packets() elif(self.get_pcap() is not None): pkts = rdpcap(self.get_pcap()) else: - print("Assegnare un pcap o una lista di pacchetti.") + print("No PCAP or packets list has been provided.") return [] ip_dict = {} if(len(pkts) >= self.get_window_size()): @@ -71,7 +71,7 @@ def max_in_window_policy(self): else: pass else: - print("Fornita una finestra troppo piccola.") + print("Window size is too small") return [] def find_max_between_IP(ip_dict): @@ -103,7 +103,7 @@ def get_filter(self): return self.filter def add_ip_to_filter(self, list_of_ip): - assert isinstance(list_of_ip, list), "Inserire gli ip in una lista." + assert isinstance(list_of_ip, list), "IPs must be added to the filter in the form of a list" for ip in list_of_ip: self.filter.append(ip) diff --git a/CreateFeaturesHandler.py b/CreateFeaturesHandler.py index 77911f2..1951e33 100644 --- a/CreateFeaturesHandler.py +++ b/CreateFeaturesHandler.py @@ -9,9 +9,9 @@ class CreateFeaturesHandler(): def __init__(self, pkts_window_size=10, single_csv=True): self.pkts_window_size = pkts_window_size - assert self.pkts_window_size >=1, "Valore per la finestra non valido" + assert self.pkts_window_size >=1, "Invalid window size (it must be >=1)" self.single_csv = single_csv - assert (self.single_csv is True) or (self.single_csv is False), "Valore non valido per il flag single_csv" + assert (self.single_csv is True) or (self.single_csv is False), "Invalid value for the single_csv option (it must be a boolean)" self.featuresCalc = FeaturesCalc(flow_type="malware", min_window_size=pkts_window_size) ip_to_ignore = ["127.0.0.1"] self.filter_1 = PacketFilter(ip_whitelist_filter=[], ip_blacklist_filter=ip_to_ignore, TCP=True) @@ -84,7 +84,7 @@ def legitimate_features(): csv.add_row(self.featuresCalc.get_features_name()) array_of_pkts = [] filter_res = [] - print("\nCalcolo features di " + pcap + "\n") + print("\nComputing features for " + pcap + "\n") pkts = rdpcap(pcap) for pkt in pkts: for filter in self.filters: diff --git a/FeaturesCalc.py b/FeaturesCalc.py index 061370d..72f1a6c 100644 --- a/FeaturesCalc.py +++ b/FeaturesCalc.py @@ -9,8 +9,8 @@ class FeaturesCalc(): def __init__(self, flow_type, min_window_size=2): self.flow_type = flow_type self.min_window_size = int(min_window_size) - assert self.flow_type == "malware" or self.flow_type == "legitimate", "Flow_type non valido. Valori validi sono malware o legitimate." - assert self.min_window_size > 0, "Valore non valido per min_windows_size. Deve essere maggiore di 0." + assert self.flow_type == "malware" or self.flow_type == "legitimate", "flow_type is invalid (must be either 'malware' or 'legitimate')" + assert self.min_window_size > 0, "Invalid min_windows_size (it must be >=0)." self.label = None if(self.flow_type == "malware"): self.label = self.malware_label @@ -88,7 +88,7 @@ def DNS_over_TCP_ratio(packets_list): else: total_packet_high_level_list.append(0.0) else: - print("Errore imprevisto in dnsOverTCPRatio()") + print("Unexpected error in dnsOverTCPRatio()") total_packet_high_level = float(sum(total_packet_high_level_list)) if (total_packet_high_level != 0): ratio_list.append(float(total_DNS / total_packet_high_level)) @@ -266,7 +266,7 @@ def compute_tcp_flags(packets_list): return (syn_counter, fin_counter, ack_counter, psh_counter, urg_counter, rst_counter) if(len(packets_list) < self.get_min_window_size()): - print("\nNumero di paccheti troppo basso\n") + print("\nPacket count in list is smaller than the minimum window size\n") return None else: syn_lst, fin_lst, ack_lst, psh_lst, urg_lst, rst_lst = compute_tcp_flags(packets_list) @@ -323,7 +323,7 @@ def get_min_window_size(self): return self.min_window_size def set_flow_type(self, flow_type): - assert self.flow_type == "malware" or self.flow_type == "legitimate", "Flow_type non valido. Valori validi sono malware o legitimate." + assert self.flow_type == "malware" or self.flow_type == "legitimate", "flow_type is invalid (must be either 'malware' or 'legitimate')" self.flow_type = flow_type if(self.flow_type == "malware"): self.label = self.malware_label From 673f074bb78a9bfbecdb4700aea5663e47457e44 Mon Sep 17 00:00:00 2001 From: Cosmin Bianu Date: Tue, 4 Apr 2023 16:15:04 +0300 Subject: [PATCH 2/2] Fixed untranslated print statement --- CreateFeaturesHandler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CreateFeaturesHandler.py b/CreateFeaturesHandler.py index 1951e33..c3a70ca 100644 --- a/CreateFeaturesHandler.py +++ b/CreateFeaturesHandler.py @@ -43,7 +43,7 @@ def malware_features(): csv.create_empty_csv() csv.add_row(self.featuresCalc.get_features_name()) array_of_pkts = [] - print("\nCalcolo features di " + pcap + "\n") + print("\nComputing features for " + pcap + "\n") attacker = AttackerCalc(pcap=pcap) ip_to_consider = attacker.compute_attacker() for filter in self.filters: