2
0

2 Ревизии 6563638d06 ... 3ce59c8634

Автор SHA1 Съобщение Дата
  Denis Waßmann 6563638d06 Added regression test преди 6 години
  Denis Waßmann 4d4c1b0298 Integrated the first 2 testcases of the old Project преди 6 години

+ 0 - 168
code/Test/TestUtil.py

@@ -1,168 +0,0 @@
-#!/usr/bin/python3
-
-import scapy.all
-import scapy.packet
-import shlex
-import subprocess
-import os
-
-
-# You could compare pcaps by byte or by hash too, but this class tells you
-# where exactly pcaps differ
-class PcapComparator:
-    def compare_files(self, file: str, other_file: str):
-        self.compare_captures(scapy.all.rdpcap(file), scapy.all.rdpcap(other_file))
-
-    def compare_captures(self, packetsA, packetsB):
-        if len(packetsA) != len(packetsB):
-            self.fail("Both pcap's have to have the same amount of packets")
-
-        for i in range(len(packetsA)):
-            p, p2 = packetsA[i], packetsB[i]
-
-            if abs(p.time - p2.time) > (10 ** -7):
-                self.fail("Packets no %i in the pcap's don't appear at the same time" % (i + 1))
-            self.compare_packets(p, p2, i + 1)
-
-    def compare_packets(self, p: scapy.packet.BasePacket, p2: scapy.packet.BasePacket, packet_number: int):
-        if p == p2:
-            return
-
-        while type(p) != scapy.packet.NoPayload or type(p2) != scapy.packet.NoPayload:
-            if type(p) != type(p2):
-                self.fail("Packets %i are of incompatible types: %s and %s" % (packet_number, type(p).__name__, type(p2).__name__))
-
-            for field in p.fields:
-                if p.fields[field] != p2.fields[field]:
-                    packet_type = type(p).__name__
-                    v, v2 = p.fields[field], p2.fields[field]
-
-                    self.fail("Packets %i differ in field %s.%s: %s != %s" %
-                                (packet_number, packet_type, field, v, v2))
-
-            p = p.payload
-            p2 = p2.payload
-
-    def fail(self, message: str):
-        raise AssertionError(message)
-
-
-class ID2TExecution:
-    ID2T_PATH = ".."
-    ID2T_LOCATION = ID2T_PATH + "/" + "id2t"
-
-    OUTPUT_FILES_PREFIX_LINE = "Output files created:"
-
-    def __init__(self, input_filename, id2t_path=ID2T_LOCATION, seed=None):
-        self.input_file = input_filename
-        self.seed = str(seed)
-        self.id2t_path = id2t_path
-
-        self.generated_files = [] # files generated by id2t
-        self.keep_files = []
-        self.return_code = None
-        self.id2t_output = None
-
-    def has_run(self):
-        return self.return_code is not None
-
-    def run(self, parameters):
-        if self.has_run():
-            raise RuntimeError("This instance has already run and can't do it again")
-
-        command = self.get_run_command(parameters)
-        return_code, output = subprocess.getstatusoutput(command)
-        self.return_code = return_code
-        self.id2t_output = output
-
-        self.generated_files = self._parse_files(output)
-
-    def get_run_command(self, parameters):
-        command_args = [self.id2t_path, "-i", self.input_file]
-        if self.seed is not None:
-            command_args.extend(["-S", self.seed])
-        command_args.extend(["-a", "MembersMgmtCommAttack"])
-        command_args.extend(parameters)
-
-        return " ".join(map(shlex.quote, command_args))
-
-    def _parse_files(self, program_output: str) -> "list[str]":
-        lines = program_output.split(os.linesep)
-
-        if self.OUTPUT_FILES_PREFIX_LINE not in lines:
-            raise AssertionError("The magic string is not in the program output anymore, has the program output structure changed?")
-        index = lines.index(self.OUTPUT_FILES_PREFIX_LINE)
-        next_empty_line_index = lines.index("", index) if "" in lines[index:] else len(lines)
-
-        return lines[index + 1:next_empty_line_index]
-
-    def get_pcap_filename(self):
-        self._require_run()
-        return self._find_pcap()
-
-    def get_output(self):
-        self._require_run()
-        return self.id2t_output
-
-    def get_return_code(self):
-        self._require_run()
-        return self.return_code
-
-    def keep_file(self, file):
-        self._require_run()
-
-        if file not in self.generated_files:
-            raise ValueError("%s is not generated by id2t" % file)
-        if file not in self.keep_files:
-            self.keep_files.append()
-
-    def get_kept_files(self):
-        self._require_run()
-        return self.keep_files
-
-    def get_generated_files(self):
-        self._require_run()
-        return self.generated_files
-
-    def get_files_for_deletion(self):
-        self._require_run()
-        return [file for file in self.generated_files if file not in self.keep_files]
-
-    def _find_pcap(self) -> str:
-        return next(file for file in self.generated_files if file.endswith(".pcap"))
-
-    def _require_run(self):
-        if not self.has_run():
-            raise RuntimeError("You have to execute run() before you can call this method")
-
-    def cleanup(self):
-        if self.has_run():
-            id2t_relative = os.path.dirname(self.id2t_path)
-
-            for file in self.get_files_for_deletion():
-                try:
-                    os.unlink(id2t_relative + "/" + file)
-                except: pass
-
-    def __del__(self):
-        self.cleanup()
-
-
-if __name__ == "__main__":
-    import sys
-
-    if len(sys.argv) < 3:
-        print("Usage: %s one.pcap other.pcap" % sys.argv[0])
-        exit(0)
-
-    try:
-        PcapComparator().compare_files(sys.argv[1], sys.argv[2])
-        print("The given pcaps are equal")
-    except AssertionError as e:
-        print("The given pcaps are not equal")
-        print("Error message:", *e.args)
-        exit(1)
-    except Exception as e:
-        print("During the comparison an unexpected error happened")
-        print(type(e).__name__ + ":", *e.args)
-        exit(1)

+ 0 - 15
code/Test/regression_files/fileinfo.xml

@@ -1,15 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!--
-This file contains the information on how to recreate the files used for
-regression testing. For every file there is a test that contains the file, the
-rng-seed, a name for the test and a list of parameters. The regression test
-will attempt to recreate all of these files via the parameters given and
-compare the newly created files to the existing ones.
-
-Paths are relative to this files location
--->
-<tests>
-    <test name="first_test" infile="../../../resources/telnet-raw.pcap" outfile="telnet_regression.pcap" seed="42">
-        <param key="hidden_mark" value="True"/>
-    </test>
-</tests>

BIN
code/Test/regression_files/telnet_regression.pcap


+ 0 - 15
code/Test/regression_files/telnet_regression_labels.xml

@@ -1,15 +0,0 @@
-<?xml version="1.0" ?>
-<LABELS version_parser="0.2">
-	<attack>
-		<attack_name>MembersMgmtCommAttack</attack_name>
-		<attack_note></attack_note>
-		<timestamp_start>
-			<timestamp>944192097.1481651</timestamp>
-			<timestamp_hr>1999-12-03 04:34:57.148165</timestamp_hr>
-		</timestamp_start>
-		<timestamp_end>
-			<timestamp>944192103.4367249</timestamp>
-			<timestamp_hr>1999-12-03 04:35:03.436725</timestamp_hr>
-		</timestamp_end>
-	</attack>
-</LABELS>

+ 0 - 101
code/Test/regression_files/telnet_regression_mapping.xml

@@ -1,101 +0,0 @@
-<?xml version="1.0" ?>
-<mappings>
-	<mapping CSV_XML_Time="3712.30121813772" Dst="239" PCAP_Time-Datetime="1999-12-03 04:34:57.148165" PCAP_Time-Relative="8.892634" PCAP_Time-Timestamp="944192097.1481651" Src="53" Type="103" id="0" line_number="-1" mapped="true" packet_time="944192097.1481651"/>
-	<mapping CSV_XML_Time="3712.30121813772" Dst="285" PCAP_Time-Datetime="1999-12-03 04:34:57.186668" PCAP_Time-Relative="8.931137" PCAP_Time-Timestamp="944192097.1866676" Src="53" Type="103" id="1" line_number="-1" mapped="true" packet_time="944192097.1866676"/>
-	<mapping CSV_XML_Time="3712.30121813772" Dst="175" PCAP_Time-Datetime="1999-12-03 04:34:57.240449" PCAP_Time-Relative="8.984918" PCAP_Time-Timestamp="944192097.2404487" Src="53" Type="103" id="2" line_number="-1" mapped="true" packet_time="944192097.2404487"/>
-	<mapping CSV_XML_Time="3712.30121813772" Dst="32" PCAP_Time-Datetime="1999-12-03 04:34:57.240685" PCAP_Time-Relative="8.985154" PCAP_Time-Timestamp="944192097.2406845" Src="53" Type="103" id="3" line_number="-1" mapped="true" packet_time="944192097.2406845"/>
-	<mapping CSV_XML_Time="3712.50121813772" Dst="142" PCAP_Time-Datetime="1999-12-03 04:34:57.362154" PCAP_Time-Relative="9.106623" PCAP_Time-Timestamp="944192097.3621544" Src="53" Type="103" id="4" line_number="-1" mapped="true" packet_time="944192097.3621544"/>
-	<mapping CSV_XML_Time="3712.50121813772" Dst="2" PCAP_Time-Datetime="1999-12-03 04:34:57.367359" PCAP_Time-Relative="9.111828" PCAP_Time-Timestamp="944192097.367359" Src="53" Type="103" id="5" line_number="-1" mapped="true" packet_time="944192097.367359"/>
-	<mapping CSV_XML_Time="3712.50121813772" Dst="33" PCAP_Time-Datetime="1999-12-03 04:34:57.428766" PCAP_Time-Relative="9.173235" PCAP_Time-Timestamp="944192097.428766" Src="53" Type="103" id="6" line_number="-1" mapped="true" packet_time="944192097.428766"/>
-	<mapping CSV_XML_Time="3712.50121813772" Dst="195" PCAP_Time-Datetime="1999-12-03 04:34:57.428925" PCAP_Time-Relative="9.173394" PCAP_Time-Timestamp="944192097.4289254" Src="53" Type="103" id="7" line_number="-1" mapped="true" packet_time="944192097.4289254"/>
-	<mapping CSV_XML_Time="3712.70121813772" Dst="292" PCAP_Time-Datetime="1999-12-03 04:34:57.577792" PCAP_Time-Relative="9.322261" PCAP_Time-Timestamp="944192097.5777917" Src="53" Type="103" id="8" line_number="-1" mapped="true" packet_time="944192097.5777917"/>
-	<mapping CSV_XML_Time="3712.70121813772" Dst="50" PCAP_Time-Datetime="1999-12-03 04:34:57.602007" PCAP_Time-Relative="9.346476" PCAP_Time-Timestamp="944192097.6020068" Src="53" Type="103" id="9" line_number="-1" mapped="true" packet_time="944192097.6020068"/>
-	<mapping CSV_XML_Time="3712.70121813772" Dst="128" PCAP_Time-Datetime="1999-12-03 04:34:57.611193" PCAP_Time-Relative="9.355662" PCAP_Time-Timestamp="944192097.6111931" Src="53" Type="103" id="10" line_number="-1" mapped="true" packet_time="944192097.6111931"/>
-	<mapping CSV_XML_Time="3712.90121813772" Dst="271" PCAP_Time-Datetime="1999-12-03 04:34:57.741621" PCAP_Time-Relative="9.486090" PCAP_Time-Timestamp="944192097.7416214" Src="53" Type="103" id="11" line_number="-1" mapped="true" packet_time="944192097.7416214"/>
-	<mapping CSV_XML_Time="3712.90121813772" Dst="268" PCAP_Time-Datetime="1999-12-03 04:34:57.806237" PCAP_Time-Relative="9.550706" PCAP_Time-Timestamp="944192097.8062367" Src="53" Type="103" id="12" line_number="-1" mapped="true" packet_time="944192097.8062367"/>
-	<mapping CSV_XML_Time="3712.90121813772" Dst="184" PCAP_Time-Datetime="1999-12-03 04:34:57.822549" PCAP_Time-Relative="9.567018" PCAP_Time-Timestamp="944192097.8225495" Src="53" Type="103" id="13" line_number="-1" mapped="true" packet_time="944192097.8225495"/>
-	<mapping CSV_XML_Time="3712.90121813772" Dst="294" PCAP_Time-Datetime="1999-12-03 04:34:57.839562" PCAP_Time-Relative="9.584031" PCAP_Time-Timestamp="944192097.8395624" Src="53" Type="103" id="14" line_number="-1" mapped="true" packet_time="944192097.8395624"/>
-	<mapping CSV_XML_Time="3713.10121813772" Dst="71" PCAP_Time-Datetime="1999-12-03 04:34:57.954268" PCAP_Time-Relative="9.698737" PCAP_Time-Timestamp="944192097.9542681" Src="53" Type="103" id="15" line_number="-1" mapped="true" packet_time="944192097.9542681"/>
-	<mapping CSV_XML_Time="3713.10121813772" Dst="161" PCAP_Time-Datetime="1999-12-03 04:34:57.970777" PCAP_Time-Relative="9.715246" PCAP_Time-Timestamp="944192097.9707769" Src="53" Type="103" id="16" line_number="-1" mapped="true" packet_time="944192097.9707769"/>
-	<mapping CSV_XML_Time="3713.10121813772" Dst="246" PCAP_Time-Datetime="1999-12-03 04:34:58.7178" PCAP_Time-Relative="9.751647" PCAP_Time-Timestamp="944192098.0071778" Src="53" Type="103" id="17" line_number="-1" mapped="true" packet_time="944192098.0071778"/>
-	<mapping CSV_XML_Time="3713.10121813772" Dst="58" PCAP_Time-Datetime="1999-12-03 04:34:58.34732" PCAP_Time-Relative="9.779201" PCAP_Time-Timestamp="944192098.034732" Src="53" Type="103" id="18" line_number="-1" mapped="true" packet_time="944192098.034732"/>
-	<mapping CSV_XML_Time="3713.30121813772" Dst="148" PCAP_Time-Datetime="1999-12-03 04:34:58.151543" PCAP_Time-Relative="9.896012" PCAP_Time-Timestamp="944192098.1515427" Src="53" Type="103" id="19" line_number="-1" mapped="true" packet_time="944192098.1515427"/>
-	<mapping CSV_XML_Time="3713.30121813772" Dst="57" PCAP_Time-Datetime="1999-12-03 04:34:58.152382" PCAP_Time-Relative="9.896851" PCAP_Time-Timestamp="944192098.1523819" Src="53" Type="103" id="20" line_number="-1" mapped="true" packet_time="944192098.1523819"/>
-	<mapping CSV_XML_Time="3713.30121813772" Dst="10" PCAP_Time-Datetime="1999-12-03 04:34:58.168074" PCAP_Time-Relative="9.912543" PCAP_Time-Timestamp="944192098.1680739" Src="53" Type="103" id="21" line_number="-1" mapped="true" packet_time="944192098.1680739"/>
-	<mapping CSV_XML_Time="3713.30121813772" Dst="60" PCAP_Time-Datetime="1999-12-03 04:34:58.196161" PCAP_Time-Relative="9.940630" PCAP_Time-Timestamp="944192098.1961614" Src="53" Type="103" id="22" line_number="-1" mapped="true" packet_time="944192098.1961614"/>
-	<mapping CSV_XML_Time="3713.50121813772" Dst="256" PCAP_Time-Datetime="1999-12-03 04:34:58.361199" PCAP_Time-Relative="10.105668" PCAP_Time-Timestamp="944192098.3611987" Src="53" Type="103" id="23" line_number="-1" mapped="true" packet_time="944192098.3611987"/>
-	<mapping CSV_XML_Time="3713.50121813772" Dst="51" PCAP_Time-Datetime="1999-12-03 04:34:58.401322" PCAP_Time-Relative="10.145791" PCAP_Time-Timestamp="944192098.401322" Src="53" Type="103" id="24" line_number="-1" mapped="true" packet_time="944192098.401322"/>
-	<mapping CSV_XML_Time="3713.50121813772" Dst="70" PCAP_Time-Datetime="1999-12-03 04:34:58.404263" PCAP_Time-Relative="10.148732" PCAP_Time-Timestamp="944192098.4042628" Src="53" Type="103" id="25" line_number="-1" mapped="true" packet_time="944192098.4042628"/>
-	<mapping CSV_XML_Time="3713.50121813772" Dst="216" PCAP_Time-Datetime="1999-12-03 04:34:58.412600" PCAP_Time-Relative="10.157069" PCAP_Time-Timestamp="944192098.4126002" Src="53" Type="103" id="26" line_number="-1" mapped="true" packet_time="944192098.4126002"/>
-	<mapping CSV_XML_Time="3712.60121813772" Dst="53" PCAP_Time-Datetime="1999-12-03 04:34:58.501824" PCAP_Time-Relative="10.246293" PCAP_Time-Timestamp="944192098.5018237" Src="2" Type="104" id="27" line_number="-1" mapped="true" packet_time="944192098.5018237"/>
-	<mapping CSV_XML_Time="3712.70121813772" Dst="2" PCAP_Time-Datetime="1999-12-03 04:34:58.527598" PCAP_Time-Relative="10.272067" PCAP_Time-Timestamp="944192098.5275983" Src="53" Type="101" id="28" line_number="-1" mapped="true" packet_time="944192098.5275983"/>
-	<mapping CSV_XML_Time="3713.70121813772" Dst="269" PCAP_Time-Datetime="1999-12-03 04:34:58.567237" PCAP_Time-Relative="10.311706" PCAP_Time-Timestamp="944192098.5672374" Src="53" Type="103" id="29" line_number="-1" mapped="true" packet_time="944192098.5672374"/>
-	<mapping CSV_XML_Time="3713.70121813772" Dst="230" PCAP_Time-Datetime="1999-12-03 04:34:58.589692" PCAP_Time-Relative="10.334161" PCAP_Time-Timestamp="944192098.5896922" Src="53" Type="103" id="30" line_number="-1" mapped="true" packet_time="944192098.5896922"/>
-	<mapping CSV_XML_Time="3713.70121813772" Dst="105" PCAP_Time-Datetime="1999-12-03 04:34:58.625449" PCAP_Time-Relative="10.369918" PCAP_Time-Timestamp="944192098.6254494" Src="53" Type="103" id="31" line_number="-1" mapped="true" packet_time="944192098.6254494"/>
-	<mapping CSV_XML_Time="3713.70121813772" Dst="91" PCAP_Time-Datetime="1999-12-03 04:34:58.631373" PCAP_Time-Relative="10.375842" PCAP_Time-Timestamp="944192098.6313727" Src="53" Type="103" id="32" line_number="-1" mapped="true" packet_time="944192098.6313727"/>
-	<mapping CSV_XML_Time="3713.90121813772" Dst="66" PCAP_Time-Datetime="1999-12-03 04:34:58.741194" PCAP_Time-Relative="10.485663" PCAP_Time-Timestamp="944192098.7411937" Src="53" Type="103" id="33" line_number="-1" mapped="true" packet_time="944192098.7411937"/>
-	<mapping CSV_XML_Time="3713.90121813772" Dst="23" PCAP_Time-Datetime="1999-12-03 04:34:58.750069" PCAP_Time-Relative="10.494538" PCAP_Time-Timestamp="944192098.7500689" Src="53" Type="103" id="34" line_number="-1" mapped="true" packet_time="944192098.7500689"/>
-	<mapping CSV_XML_Time="3713.90121813772" Dst="13" PCAP_Time-Datetime="1999-12-03 04:34:58.768507" PCAP_Time-Relative="10.512976" PCAP_Time-Timestamp="944192098.7685071" Src="53" Type="103" id="35" line_number="-1" mapped="true" packet_time="944192098.7685071"/>
-	<mapping CSV_XML_Time="3713.90121813772" Dst="277" PCAP_Time-Datetime="1999-12-03 04:34:58.783197" PCAP_Time-Relative="10.527666" PCAP_Time-Timestamp="944192098.7831967" Src="53" Type="103" id="36" line_number="-1" mapped="true" packet_time="944192098.7831967"/>
-	<mapping CSV_XML_Time="3714.10121813772" Dst="52" PCAP_Time-Datetime="1999-12-03 04:34:58.967035" PCAP_Time-Relative="10.711504" PCAP_Time-Timestamp="944192098.9670346" Src="53" Type="103" id="37" line_number="-1" mapped="true" packet_time="944192098.9670346"/>
-	<mapping CSV_XML_Time="3714.10121813772" Dst="129" PCAP_Time-Datetime="1999-12-03 04:34:59.4550" PCAP_Time-Relative="10.749019" PCAP_Time-Timestamp="944192099.0045503" Src="53" Type="103" id="38" line_number="-1" mapped="true" packet_time="944192099.0045503"/>
-	<mapping CSV_XML_Time="3714.10121813772" Dst="14" PCAP_Time-Datetime="1999-12-03 04:34:59.14962" PCAP_Time-Relative="10.759431" PCAP_Time-Timestamp="944192099.0149621" Src="53" Type="103" id="39" line_number="-1" mapped="true" packet_time="944192099.0149621"/>
-	<mapping CSV_XML_Time="3714.10121813772" Dst="169" PCAP_Time-Datetime="1999-12-03 04:34:59.17951" PCAP_Time-Relative="10.762420" PCAP_Time-Timestamp="944192099.0179509" Src="53" Type="103" id="40" line_number="-1" mapped="true" packet_time="944192099.0179509"/>
-	<mapping CSV_XML_Time="3714.30121813772" Dst="108" PCAP_Time-Datetime="1999-12-03 04:34:59.141806" PCAP_Time-Relative="10.886275" PCAP_Time-Timestamp="944192099.141806" Src="53" Type="103" id="41" line_number="-1" mapped="true" packet_time="944192099.141806"/>
-	<mapping CSV_XML_Time="3714.30121813772" Dst="49" PCAP_Time-Datetime="1999-12-03 04:34:59.148363" PCAP_Time-Relative="10.892832" PCAP_Time-Timestamp="944192099.1483635" Src="53" Type="103" id="42" line_number="-1" mapped="true" packet_time="944192099.1483635"/>
-	<mapping CSV_XML_Time="3714.30121813772" Dst="73" PCAP_Time-Datetime="1999-12-03 04:34:59.183608" PCAP_Time-Relative="10.928077" PCAP_Time-Timestamp="944192099.1836077" Src="53" Type="103" id="43" line_number="-1" mapped="true" packet_time="944192099.1836077"/>
-	<mapping CSV_XML_Time="3714.30121813772" Dst="135" PCAP_Time-Datetime="1999-12-03 04:34:59.196007" PCAP_Time-Relative="10.940476" PCAP_Time-Timestamp="944192099.1960071" Src="53" Type="103" id="44" line_number="-1" mapped="true" packet_time="944192099.1960071"/>
-	<mapping CSV_XML_Time="3714.50121813772" Dst="16" PCAP_Time-Datetime="1999-12-03 04:34:59.395398" PCAP_Time-Relative="11.139867" PCAP_Time-Timestamp="944192099.395398" Src="53" Type="103" id="45" line_number="-1" mapped="true" packet_time="944192099.395398"/>
-	<mapping CSV_XML_Time="3714.50121813772" Dst="249" PCAP_Time-Datetime="1999-12-03 04:34:59.399090" PCAP_Time-Relative="11.143559" PCAP_Time-Timestamp="944192099.3990899" Src="53" Type="103" id="46" line_number="-1" mapped="true" packet_time="944192099.3990899"/>
-	<mapping CSV_XML_Time="3714.50121813772" Dst="144" PCAP_Time-Datetime="1999-12-03 04:34:59.424299" PCAP_Time-Relative="11.168768" PCAP_Time-Timestamp="944192099.4242985" Src="53" Type="103" id="47" line_number="-1" mapped="true" packet_time="944192099.4242985"/>
-	<mapping CSV_XML_Time="3714.50121813772" Dst="4" PCAP_Time-Datetime="1999-12-03 04:34:59.429150" PCAP_Time-Relative="11.173619" PCAP_Time-Timestamp="944192099.4291496" Src="53" Type="103" id="48" line_number="-1" mapped="true" packet_time="944192099.4291496"/>
-	<mapping CSV_XML_Time="3714.70121813772" Dst="182" PCAP_Time-Datetime="1999-12-03 04:34:59.571665" PCAP_Time-Relative="11.316134" PCAP_Time-Timestamp="944192099.5716648" Src="53" Type="103" id="49" line_number="-1" mapped="true" packet_time="944192099.5716648"/>
-	<mapping CSV_XML_Time="3714.70121813772" Dst="185" PCAP_Time-Datetime="1999-12-03 04:34:59.620451" PCAP_Time-Relative="11.364920" PCAP_Time-Timestamp="944192099.6204512" Src="53" Type="103" id="50" line_number="-1" mapped="true" packet_time="944192099.6204512"/>
-	<mapping CSV_XML_Time="3714.70121813772" Dst="258" PCAP_Time-Datetime="1999-12-03 04:34:59.630737" PCAP_Time-Relative="11.375206" PCAP_Time-Timestamp="944192099.6307372" Src="53" Type="103" id="51" line_number="-1" mapped="true" packet_time="944192099.6307372"/>
-	<mapping CSV_XML_Time="3712.80121813772" Dst="53" PCAP_Time-Datetime="1999-12-03 04:34:59.641284" PCAP_Time-Relative="11.385753" PCAP_Time-Timestamp="944192099.6412842" Src="2" Type="102" id="52" line_number="-1" mapped="true" packet_time="944192099.6412842"/>
-	<mapping CSV_XML_Time="3714.90121813772" Dst="155" PCAP_Time-Datetime="1999-12-03 04:34:59.761847" PCAP_Time-Relative="11.506316" PCAP_Time-Timestamp="944192099.7618468" Src="53" Type="103" id="53" line_number="-1" mapped="true" packet_time="944192099.7618468"/>
-	<mapping CSV_XML_Time="3714.90121813772" Dst="177" PCAP_Time-Datetime="1999-12-03 04:34:59.765792" PCAP_Time-Relative="11.510261" PCAP_Time-Timestamp="944192099.765792" Src="53" Type="103" id="54" line_number="-1" mapped="true" packet_time="944192099.765792"/>
-	<mapping CSV_XML_Time="3714.90121813772" Dst="156" PCAP_Time-Datetime="1999-12-03 04:34:59.826909" PCAP_Time-Relative="11.571378" PCAP_Time-Timestamp="944192099.8269093" Src="53" Type="103" id="55" line_number="-1" mapped="true" packet_time="944192099.8269093"/>
-	<mapping CSV_XML_Time="3714.90121813772" Dst="278" PCAP_Time-Datetime="1999-12-03 04:34:59.830732" PCAP_Time-Relative="11.575201" PCAP_Time-Timestamp="944192099.8307315" Src="53" Type="103" id="56" line_number="-1" mapped="true" packet_time="944192099.8307315"/>
-	<mapping CSV_XML_Time="3715.10121813772" Dst="260" PCAP_Time-Datetime="1999-12-03 04:34:59.951118" PCAP_Time-Relative="11.695587" PCAP_Time-Timestamp="944192099.9511184" Src="53" Type="103" id="57" line_number="-1" mapped="true" packet_time="944192099.9511184"/>
-	<mapping CSV_XML_Time="3715.10121813772" Dst="202" PCAP_Time-Datetime="1999-12-03 04:34:59.956294" PCAP_Time-Relative="11.700763" PCAP_Time-Timestamp="944192099.9562943" Src="53" Type="103" id="58" line_number="-1" mapped="true" packet_time="944192099.9562943"/>
-	<mapping CSV_XML_Time="3715.10121813772" Dst="222" PCAP_Time-Datetime="1999-12-03 04:34:59.981477" PCAP_Time-Relative="11.725946" PCAP_Time-Timestamp="944192099.9814768" Src="53" Type="103" id="59" line_number="-1" mapped="true" packet_time="944192099.9814768"/>
-	<mapping CSV_XML_Time="3715.10121813772" Dst="217" PCAP_Time-Datetime="1999-12-03 04:35:00.29253" PCAP_Time-Relative="11.773722" PCAP_Time-Timestamp="944192100.0292525" Src="53" Type="103" id="60" line_number="-1" mapped="true" packet_time="944192100.0292525"/>
-	<mapping CSV_XML_Time="3715.30121813772" Dst="76" PCAP_Time-Datetime="1999-12-03 04:35:00.143318" PCAP_Time-Relative="11.887787" PCAP_Time-Timestamp="944192100.1433177" Src="53" Type="103" id="61" line_number="-1" mapped="true" packet_time="944192100.1433177"/>
-	<mapping CSV_XML_Time="3715.30121813772" Dst="194" PCAP_Time-Datetime="1999-12-03 04:35:00.238460" PCAP_Time-Relative="11.982929" PCAP_Time-Timestamp="944192100.2384597" Src="53" Type="103" id="62" line_number="-1" mapped="true" packet_time="944192100.2384597"/>
-	<mapping CSV_XML_Time="3715.50121813772" Dst="250" PCAP_Time-Datetime="1999-12-03 04:35:00.374058" PCAP_Time-Relative="12.118527" PCAP_Time-Timestamp="944192100.3740575" Src="53" Type="103" id="63" line_number="-1" mapped="true" packet_time="944192100.3740575"/>
-	<mapping CSV_XML_Time="3715.50121813772" Dst="137" PCAP_Time-Datetime="1999-12-03 04:35:00.414495" PCAP_Time-Relative="12.158964" PCAP_Time-Timestamp="944192100.4144955" Src="53" Type="103" id="64" line_number="-1" mapped="true" packet_time="944192100.4144955"/>
-	<mapping CSV_XML_Time="3715.50121813772" Dst="109" PCAP_Time-Datetime="1999-12-03 04:35:00.427245" PCAP_Time-Relative="12.171714" PCAP_Time-Timestamp="944192100.4272454" Src="53" Type="103" id="65" line_number="-1" mapped="true" packet_time="944192100.4272454"/>
-	<mapping CSV_XML_Time="3715.50121813772" Dst="178" PCAP_Time-Datetime="1999-12-03 04:35:00.433921" PCAP_Time-Relative="12.178390" PCAP_Time-Timestamp="944192100.4339206" Src="53" Type="103" id="66" line_number="-1" mapped="true" packet_time="944192100.4339206"/>
-	<mapping CSV_XML_Time="3715.70121813772" Dst="1" PCAP_Time-Datetime="1999-12-03 04:35:00.551649" PCAP_Time-Relative="12.296118" PCAP_Time-Timestamp="944192100.5516486" Src="53" Type="103" id="67" line_number="-1" mapped="true" packet_time="944192100.5516486"/>
-	<mapping CSV_XML_Time="3714.60121813772" Dst="53" PCAP_Time-Datetime="1999-12-03 04:35:00.557490" PCAP_Time-Relative="12.301959" PCAP_Time-Timestamp="944192100.55749" Src="4" Type="104" id="68" line_number="-1" mapped="true" packet_time="944192100.55749"/>
-	<mapping CSV_XML_Time="3715.70121813772" Dst="225" PCAP_Time-Datetime="1999-12-03 04:35:00.567520" PCAP_Time-Relative="12.311989" PCAP_Time-Timestamp="944192100.5675195" Src="53" Type="103" id="69" line_number="-1" mapped="true" packet_time="944192100.5675195"/>
-	<mapping CSV_XML_Time="3714.70121813772" Dst="4" PCAP_Time-Datetime="1999-12-03 04:35:00.582299" PCAP_Time-Relative="12.326768" PCAP_Time-Timestamp="944192100.5822994" Src="53" Type="101" id="70" line_number="-1" mapped="true" packet_time="944192100.5822994"/>
-	<mapping CSV_XML_Time="3715.90121813772" Dst="3" PCAP_Time-Datetime="1999-12-03 04:35:00.760152" PCAP_Time-Relative="12.504621" PCAP_Time-Timestamp="944192100.7601521" Src="53" Type="103" id="71" line_number="-1" mapped="true" packet_time="944192100.7601521"/>
-	<mapping CSV_XML_Time="3715.20121813772" Dst="53" PCAP_Time-Datetime="1999-12-03 04:35:01.50671" PCAP_Time-Relative="12.795140" PCAP_Time-Timestamp="944192101.050671" Src="222" Type="104" id="72" line_number="-1" mapped="true" packet_time="944192101.050671"/>
-	<mapping CSV_XML_Time="3715.20121813772" Dst="53" PCAP_Time-Datetime="1999-12-03 04:35:01.53607" PCAP_Time-Relative="12.798076" PCAP_Time-Timestamp="944192101.0536066" Src="260" Type="104" id="73" line_number="-1" mapped="true" packet_time="944192101.0536066"/>
-	<mapping CSV_XML_Time="3715.30121813772" Dst="222" PCAP_Time-Datetime="1999-12-03 04:35:01.141748" PCAP_Time-Relative="12.886217" PCAP_Time-Timestamp="944192101.1417481" Src="53" Type="101" id="74" line_number="-1" mapped="true" packet_time="944192101.1417481"/>
-	<mapping CSV_XML_Time="3715.30121813772" Dst="260" PCAP_Time-Datetime="1999-12-03 04:35:01.156595" PCAP_Time-Relative="12.901064" PCAP_Time-Timestamp="944192101.1565946" Src="53" Type="101" id="75" line_number="-1" mapped="true" packet_time="944192101.1565946"/>
-	<mapping CSV_XML_Time="3716.30121813772" Dst="95" PCAP_Time-Datetime="1999-12-03 04:35:01.168752" PCAP_Time-Relative="12.913221" PCAP_Time-Timestamp="944192101.1687516" Src="53" Type="103" id="76" line_number="-1" mapped="true" packet_time="944192101.1687516"/>
-	<mapping CSV_XML_Time="3715.60121813772" Dst="53" PCAP_Time-Datetime="1999-12-03 04:35:01.536130" PCAP_Time-Relative="13.280599" PCAP_Time-Timestamp="944192101.5361298" Src="109" Type="104" id="77" line_number="-1" mapped="true" packet_time="944192101.5361298"/>
-	<mapping CSV_XML_Time="3715.60121813772" Dst="53" PCAP_Time-Datetime="1999-12-03 04:35:01.541027" PCAP_Time-Relative="13.285496" PCAP_Time-Timestamp="944192101.5410273" Src="178" Type="104" id="78" line_number="-1" mapped="true" packet_time="944192101.5410273"/>
-	<mapping CSV_XML_Time="3714.80121813772" Dst="53" PCAP_Time-Datetime="1999-12-03 04:35:01.548510" PCAP_Time-Relative="13.292979" PCAP_Time-Timestamp="944192101.54851" Src="4" Type="102" id="79" line_number="-1" mapped="true" packet_time="944192101.54851"/>
-	<mapping CSV_XML_Time="3715.70121813772" Dst="109" PCAP_Time-Datetime="1999-12-03 04:35:01.627788" PCAP_Time-Relative="13.372257" PCAP_Time-Timestamp="944192101.6277884" Src="53" Type="101" id="80" line_number="-1" mapped="true" packet_time="944192101.6277884"/>
-	<mapping CSV_XML_Time="3715.70121813772" Dst="178" PCAP_Time-Datetime="1999-12-03 04:35:01.636887" PCAP_Time-Relative="13.381356" PCAP_Time-Timestamp="944192101.6368866" Src="53" Type="101" id="81" line_number="-1" mapped="true" packet_time="944192101.6368866"/>
-	<mapping CSV_XML_Time="3715.80121813772" Dst="53" PCAP_Time-Datetime="1999-12-03 04:35:01.671523" PCAP_Time-Relative="13.415992" PCAP_Time-Timestamp="944192101.6715233" Src="225" Type="104" id="82" line_number="-1" mapped="true" packet_time="944192101.6715233"/>
-	<mapping CSV_XML_Time="3715.80121813772" Dst="53" PCAP_Time-Datetime="1999-12-03 04:35:01.673357" PCAP_Time-Relative="13.417826" PCAP_Time-Timestamp="944192101.6733571" Src="1" Type="104" id="83" line_number="-1" mapped="true" packet_time="944192101.6733571"/>
-	<mapping CSV_XML_Time="3715.90121813772" Dst="1" PCAP_Time-Datetime="1999-12-03 04:35:01.706117" PCAP_Time-Relative="13.450586" PCAP_Time-Timestamp="944192101.7061167" Src="53" Type="101" id="84" line_number="-1" mapped="true" packet_time="944192101.7061167"/>
-	<mapping CSV_XML_Time="3715.90121813772" Dst="225" PCAP_Time-Datetime="1999-12-03 04:35:01.712042" PCAP_Time-Relative="13.456511" PCAP_Time-Timestamp="944192101.7120423" Src="53" Type="101" id="85" line_number="-1" mapped="true" packet_time="944192101.7120423"/>
-	<mapping CSV_XML_Time="3716.00121813772" Dst="53" PCAP_Time-Datetime="1999-12-03 04:35:01.768293" PCAP_Time-Relative="13.512762" PCAP_Time-Timestamp="944192101.7682933" Src="3" Type="104" id="86" line_number="-1" mapped="true" packet_time="944192101.7682933"/>
-	<mapping CSV_XML_Time="3716.10121813772" Dst="3" PCAP_Time-Datetime="1999-12-03 04:35:01.864728" PCAP_Time-Relative="13.609197" PCAP_Time-Timestamp="944192101.8647285" Src="53" Type="101" id="87" line_number="-1" mapped="true" packet_time="944192101.8647285"/>
-	<mapping CSV_XML_Time="3716.40121813772" Dst="53" PCAP_Time-Datetime="1999-12-03 04:35:02.242293" PCAP_Time-Relative="13.986762" PCAP_Time-Timestamp="944192102.242293" Src="95" Type="104" id="88" line_number="-1" mapped="true" packet_time="944192102.242293"/>
-	<mapping CSV_XML_Time="3715.40121813772" Dst="53" PCAP_Time-Datetime="1999-12-03 04:35:02.265388" PCAP_Time-Relative="14.009857" PCAP_Time-Timestamp="944192102.2653878" Src="222" Type="102" id="89" line_number="-1" mapped="true" packet_time="944192102.2653878"/>
-	<mapping CSV_XML_Time="3715.40121813772" Dst="53" PCAP_Time-Datetime="1999-12-03 04:35:02.276724" PCAP_Time-Relative="14.021193" PCAP_Time-Timestamp="944192102.2767243" Src="260" Type="102" id="90" line_number="-1" mapped="true" packet_time="944192102.2767243"/>
-	<mapping CSV_XML_Time="3716.50121813772" Dst="95" PCAP_Time-Datetime="1999-12-03 04:35:02.292261" PCAP_Time-Relative="14.036730" PCAP_Time-Timestamp="944192102.2922608" Src="53" Type="101" id="91" line_number="-1" mapped="true" packet_time="944192102.2922608"/>
-	<mapping CSV_XML_Time="3715.80121813772" Dst="53" PCAP_Time-Datetime="1999-12-03 04:35:02.622931" PCAP_Time-Relative="14.367400" PCAP_Time-Timestamp="944192102.6229308" Src="178" Type="102" id="92" line_number="-1" mapped="true" packet_time="944192102.6229308"/>
-	<mapping CSV_XML_Time="3716.00121813772" Dst="53" PCAP_Time-Datetime="1999-12-03 04:35:02.650658" PCAP_Time-Relative="14.395127" PCAP_Time-Timestamp="944192102.6506579" Src="1" Type="102" id="93" line_number="-1" mapped="true" packet_time="944192102.6506579"/>
-	<mapping CSV_XML_Time="3715.80121813772" Dst="53" PCAP_Time-Datetime="1999-12-03 04:35:02.663500" PCAP_Time-Relative="14.407969" PCAP_Time-Timestamp="944192102.6634997" Src="109" Type="102" id="94" line_number="-1" mapped="true" packet_time="944192102.6634997"/>
-	<mapping CSV_XML_Time="3716.00121813772" Dst="53" PCAP_Time-Datetime="1999-12-03 04:35:02.817711" PCAP_Time-Relative="14.562180" PCAP_Time-Timestamp="944192102.8177105" Src="225" Type="102" id="95" line_number="-1" mapped="true" packet_time="944192102.8177105"/>
-	<mapping CSV_XML_Time="3716.20121813772" Dst="53" PCAP_Time-Datetime="1999-12-03 04:35:03.6215" PCAP_Time-Relative="14.750684" PCAP_Time-Timestamp="944192103.006215" Src="3" Type="102" id="96" line_number="-1" mapped="true" packet_time="944192103.006215"/>
-	<mapping CSV_XML_Time="3716.60121813772" Dst="53" PCAP_Time-Datetime="1999-12-03 04:35:03.436725" PCAP_Time-Relative="15.181194" PCAP_Time-Timestamp="944192103.4367249" Src="95" Type="102" id="97" line_number="-1" mapped="true" packet_time="944192103.4367249"/>
-</mappings>

+ 0 - 57
code/Test/test_regression.py

@@ -1,57 +0,0 @@
-import unittest
-import xml.etree.ElementTree
-import os.path
-import sys
-
-from Test.TestUtil import PcapComparator, ID2TExecution
-
-
-class RegressionTest(unittest.TestCase):
-    REGRESSION_DIRECTORY = "../code/Test/regression_files"
-    REGRESSION_DIRECTORY_ID2T_RELATIVE = "code/Test/regression_files"
-    ID2T_RELATIVE_TO_LOCAL_PREFIX = "../"
-
-    META_FILE = "fileinfo.xml"
-
-    def test_regression(self):
-        config_location = self.REGRESSION_DIRECTORY + os.sep + self.META_FILE
-        xml_root = xml.etree.ElementTree.parse(config_location).getroot()
-        comparator = PcapComparator()
-
-        for test in xml_root.getchildren():
-            self.assertXMLTagHasAttribute(test, "seed", "<test>s needs a seed-attribute")
-            self.assertXMLTagHasAttribute(test, "outfile", "<test>s needs a outfile-attribute")
-            self.assertXMLTagHasAttribute(test, "infile", "<test>s needs a infile-attribute")
-            self.assertXMLTagHasAttribute(test, "name", "<test>s needs a name-attribute")
-
-            params = []
-            for param in test.getchildren():
-                self.assertEqual(param.tag, "param", "<test>-children must be <params>s")
-                self.assertIsNotNone(param.get("key"), "<param> needs a key-attribute")
-                self.assertIsNotNone(param.get("value"), "<param> needs a value-attribute")
-
-                params.append("%s=%s" % (param.get("key"), param.get("value")))
-
-            infile = os.path.join(self.REGRESSION_DIRECTORY_ID2T_RELATIVE, test.get("infile"))
-            outfile = os.path.join(self.REGRESSION_DIRECTORY, test.get("outfile"))
-
-            execution = ID2TExecution(infile, seed=test.get("seed"))
-            self.print_warning(execution.get_run_command(params))
-            execution.run(params)
-
-            new_file = self.ID2T_RELATIVE_TO_LOCAL_PREFIX + os.sep + execution.get_pcap_filename()
-            old_file = outfile
-
-            try:
-                comparator.compare_files(new_file, old_file)
-            except AssertionError as e:
-                execution.cleanup()
-                raise AssertionError("Test %s failed" % test.get("name")) from e
-
-            self.print_warning("Regression-test %s passed" % test.get("name"))
-
-    def assertXMLTagHasAttribute(self, tag, attribute, msg=None):
-        self.assertIsNotNone(tag.get(attribute), msg)
-
-    def print_warning(self, *text):
-        print(*text, file=sys.stderr)

+ 332 - 0
test/PcapComparator.py

@@ -0,0 +1,332 @@
+import logging
+logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
+
+from scapy.all import rdpcap, wrpcap
+from scapy.all import IP, Ether, TCP, UDP
+import sys
+
+file_tel = "telnet-raw.pcap"
+
+from scapy.utils import PcapWriter
+
+
+def change_pcap(filepath):
+    packets = rdpcap(filepath)
+    split_filepath = filepath.split(".")
+    new_filename = ".".join(split_filepath[:-1]) + "_new." + split_filepath[-1]
+
+    #pktdump = PcapWriter(new_filename, append=True)
+
+    for pkt in packets:
+        """
+        if pkt is packets[-1]:
+            # test ethernet
+            pkt[Ether].src = "AA:AA:AA:AA:AA:AA"
+            pkt[Ether].dst = "BB:BB:BB:BB:BB:BB"
+            #pkt[Ether].type = 0x1000
+
+            pkt[IP].src = "255.255.255.255"
+            pkt[IP].dst = "0.0.0.0"
+            #pkt[IP].version = 0x1000
+            #pkt[IP].ihl = 10
+            pkt[IP].tos = 127
+            #pkt[IP].len = 200
+
+            # pkttwo = pkt
+            #print(pkt.show)
+            wrpcap(new_filename, pkt, append=True)
+            #print("OK")
+            #pktdump.write(pkt)
+        """
+        if pkt is packets[0]:
+            wrpcap(new_filename, pkt)
+        elif not pkt is packets[-1]:
+            wrpcap(new_filename, pkt, append=True)
+
+
+    ethernet = Ether(src="AA:AA:AA:AA:AA:AA", dst="BB:BB:BB:BB:BB:BB")
+    ip = IP(src="255.255.255.255", dst="0.0.0.0", tos=127)
+    tcp = TCP(sport=80, dport=50000, flags="SAF")
+    pkt = ethernet/ip/tcp
+    pkt.time = packets[-1].time
+    wrpcap(new_filename, pkt, append=True)
+    #print("OK")
+    #pktdump.write(pkt)
+
+def check_l2_diff(idx, payload_one, payload_two):
+    # assumes that the L2 protocol of both packets are the same
+    # assumes Ethernet as L2 protocol
+    err_msg = ""
+    if payload_one.name == "Ethernet":
+        if payload_one[Ether].src != payload_two[Ether].src:
+            err_msg += "Reason: the packets at index %d have a different source MAC address.\n" % (idx+1)
+            err_msg += "Packet 1: %s \t Packet 2: %s\n\n" % (payload_one[Ether].src.upper(), payload_two[Ether].src.upper())
+        if payload_one[Ether].dst != payload_two[Ether].dst:
+            err_msg += "Reason: the packets at index %d have a different destination MAC address.\n" % (idx+1)
+            err_msg += "Packet 1: %s \t Packet 2: %s\n\n" % (payload_one[Ether].dst.upper(), payload_two[Ether].dst.upper())
+        if payload_one[Ether].type != payload_two[Ether].type:
+            err_msg += "Reason: the packets at index %d have a different Ethernet type.\n" % (idx+1)
+            err_msg += "Packet 1: %s \t Packet 2: %s\n\n" % (payload_one[Ether].type, payload_two[Ether].type)
+        
+        if err_msg == "":
+            return False, err_msg
+
+        return True, err_msg
+    else:
+        return False, ""
+
+
+def check_l3_diff(idx, payload_one, payload_two):
+    # assumes that the L3 protocol of both packets are the same
+    # assumes IPv4 as L3 protocol
+    err_msg = ""
+    if payload_one.name == "IP":
+        ip_one, ip_two = payload_one[IP], payload_two[IP]
+        if ip_one.src != ip_two.src:
+            err_msg += "Reason: the packets at index %d have a different source IP address.\n" % (idx+1)
+            err_msg += "Packet 1: %s \t Packet 2: %s\n\n" % (ip_one.src, ip_two.src)
+        if ip_one.dst != ip_two.dst:
+            err_msg += "Reason: the packets at index %d have a different destination IP address.\n" % (idx+1)
+            err_msg += "Packet 1: %s \t Packet 2: %s\n\n" % (ip_one.dst, ip_two.dst)
+        if ip_one.version != ip_two.version:
+            err_msg += "Reason: the packets at index %d have a different IP version.\n" % (idx+1)
+            err_msg += "Packet 1: %s \t Packet 2: %s\n\n" % (ip_one.version, ip_two.version)
+        if ip_one.ihl != ip_two.ihl:
+            err_msg += "Reason: the packets at index %d have a different IP IHL.\n" % (idx+1)
+            err_msg += "Packet 1: %s \t Packet 2: %s\n\n" % (ip_one.ihl, ip_two.ihl)
+        if ip_one.tos != ip_two.tos:
+            err_msg += "Reason: the packets at index %d have a different IP TOS.\n" % (idx+1)
+            err_msg += "Packet 1: %s \t Packet 2: %s\n\n" % (ip_one.tos, ip_two.tos)
+        if ip_one.len != ip_two.len:
+            err_msg += "Reason: the packets at index %d have a different length.\n" % (idx+1)
+            err_msg += "Packet 1: %s \t Packet 2: %s\n\n" % (ip_one.len, ip_two.len)
+        if ip_one.id != ip_two.id:
+            err_msg += "Reason: the packets at index %d have a different IP ID.\n" % (idx+1)
+            err_msg += "Packet 1: %s \t Packet 2: %s\n\n" % (ip_one.id, ip_two.id)
+        if ip_one.flags != ip_two.flags:
+            err_msg += "Reason: the packets at index %d have different IP flags.\n" % (idx+1)
+            err_msg += "Packet 1: %s \t Packet 2: %s\n\n" % (ip_one.flags, ip_two.flags)
+        if ip_one.frag != ip_two.frag:
+            err_msg += "Reason: the packets at index %d have a different IP fragmentation offset.\n" % (idx+1)
+            err_msg += "Packet 1: %s \t Packet 2: %s\n\n" % (ip_one.frag, ip_two.frag)
+        if ip_one.ttl != ip_two.ttl:
+            err_msg += "Reason: the packets at index %d have a different TTL.\n" % (idx+1)
+            err_msg += "Packet 1: %s \t Packet 2: %s\n\n" % (ip_one.ttl, ip_two.ttl)
+        if ip_one.proto != ip_two.proto:
+            err_msg += "Reason: the packets at index %d have a different IP protocol field value.\n" % (idx+1)
+            err_msg += "Packet 1: %s \t Packet 2: %s\n\n" % (ip_one.proto, ip_two.proto)
+        if ip_one.chksum != ip_two.chksum:
+            err_msg += "Reason: the packets at index %d have a different IP checksum.\n" % (idx+1)
+            err_msg += "Packet 1: %s \t Packet 2: %s\n\n" % (ip_one.chksum, ip_two.chksum)
+        if ip_one.options != ip_two.options:
+            err_msg += "Reason: the packets at index %d have different IP options.\n" % (idx+1)
+            err_msg += "Packet 1: %s \t Packet 2: %s\n\n" % (ip_one.options, ip_two.options)
+        
+        if err_msg == "":
+            return False, err_msg
+
+        return True, err_msg
+    else:
+        return False, ""
+
+def check_l4_diff(idx, payload_one, payload_two):
+    # assumes that the L4 protocol of both packets are the same
+    # assumes UDP or TCP as L4 protocol
+    
+    err_msg = ""
+    if payload_one.name == "UDP":
+        udp_one, udp_two = payload_one[UDP], payload_two[UDP]
+        if udp_one.sport != udp_two.sport:
+            err_msg += "Reason: the packets at index %d have a different source port.\n" % (idx+1)
+            err_msg += "Packet 1: %s \t Packet 2: %s\n\n" % (udp_one.sport, udp_two.sport)
+        if udp_one.dport != udp_two.dport:
+            err_msg += "Reason: the packets at index %d have a different destination port.\n" % (idx+1)
+            err_msg += "Packet 1: %s \t Packet 2: %s\n\n" % (udp_one.dport, udp_two.dport)
+        if udp_one.len != udp_two.len:
+            err_msg += "Reason: the packets at index %d have a different length.\n" % (idx+1)
+            err_msg += "Packet 1: %s \t Packet 2: %s\n\n" % (udp_one.len, udp_two.len)
+        if udp_one.chksum != udp_two.chksum:
+            err_msg += "Reason: the packets at index %d have a different UDP checksum.\n" % (idx+1)
+            err_msg += "Packet 1: %s \t Packet 2: %s\n\n" % (udp_one.chksum, udp_two.chksum)
+        
+        if err_msg == "":
+            return False, err_msg
+
+        return True, err_msg
+    elif payload_one.name == "TCP":
+        tcp_one, tcp_two = payload_one[TCP], payload_two[TCP]
+        if tcp_one.sport != tcp_two.sport:
+            err_msg += "Reason: the packets at index %d have a different source port.\n" % (idx+1)
+            err_msg += "Packet 1: %s \t Packet 2: %s\n\n" % (tcp_one.sport, tcp_two.sport)
+        if tcp_one.dport != tcp_two.dport:
+            err_msg += "Reason: the packets at index %d have a different destination port.\n" % (idx+1)
+            err_msg += "Packet 1: %s \t Packet 2: %s\n\n" % (tcp_one.dport, tcp_two.dport)
+        if tcp_one.seq != tcp_two.seq:
+            err_msg += "Reason: the packets at index %d have a different TCP sequence number.\n" % (idx+1)
+            err_msg += "Packet 1: %s \t Packet 2: %s\n\n" % (tcp_one.seq, tcp_two.seq)
+        if tcp_one.ack != tcp_two.ack:
+            err_msg += "Reason: the packets at index %d have a different TCP acknowledge number.\n" % (idx+1)
+            err_msg += "Packet 1: %s \t Packet 2: %s\n\n" % (tcp_one.ack, tcp_two.ack)
+        if tcp_one.dataofs != tcp_two.dataofs:
+            err_msg += "Reason: the packets at index %d have a different TCP data offset.\n" % (idx+1)
+            err_msg += "Packet 1: %s \t Packet 2: %s\n\n" % (tcp_one.dataofs, tcp_two.dataofs)
+        if tcp_one.reserved != tcp_two.reserved:
+            err_msg += "Reason: the packets at index %d have a different TCP reserved value.\n" % (idx+1)
+            err_msg += "Packet 1: %s \t Packet 2: %s\n\n" % (tcp_one.reserved, tcp_two.reserved)
+        if tcp_one.flags != tcp_two.flags:
+            err_msg += "Reason: the packets at index %d have different TCP flags.\n" % (idx+1)
+            err_msg += "Packet 1: %s \t Packet 2: %s\n\n" % (tcp_one.flags, tcp_two.flags)
+        if tcp_one.window != tcp_two.window:
+            err_msg += "Reason: the packets at index %d have a different advertised window size.\n" % (idx+1)
+            err_msg += "Packet 1: %s \t Packet 2: %s\n\n" % (tcp_one.window, tcp_two.window)
+        if tcp_one.chksum != tcp_two.chksum:
+            err_msg += "Reason: the packets at index %d have a different TCP checksum.\n" % (idx+1)
+            err_msg += "Packet 1: %s \t Packet 2: %s\n\n" % (tcp_one.chksum, tcp_two.chksum)
+        if tcp_one.urgptr != tcp_two.urgptr:
+            err_msg += "Reason: the packets at index %d have a different TCP urgent pointer.\n" % (idx+1)
+            err_msg += "Packet 1: %s \t Packet 2: %s\n\n" % (tcp_one.urgptr, tcp_two.urgptr)
+        if tcp_one.options != tcp_two.options:
+            err_msg += "Reason: the packets at index %d have different TCP options.\n" % (idx+1)
+            err_msg += "Packet 1: %s \t Packet 2: %s\n\n" % (tcp_one.options, tcp_two.options)
+        
+        if err_msg == "":
+            return False, err_msg
+
+        return True, err_msg
+    else:
+        return False, err_msg
+
+def check_payload_diff(idx, payload_one, payload_two):
+    if payload_one != payload_two:
+        err_msg = "Reason: the packets at index %d have different payloads.\n" % (idx+1)
+        err_msg += "Packet 1:\n===================\n"
+        if payload_one.load is not None:
+            err_msg += str(payload_one.load)
+        else:
+            err_msg += "None"
+        err_msg += "\n\n"
+        err_msg += "Packet 2:\n===================\n"
+        if payload_two.load is not None:
+            err_msg += str(payload_two.load)
+        else:
+            err_msg += "None"
+        return True, err_msg
+    else:
+        return False, ""
+
+def check_different_layers(idx, layer_num, payload_one, payload_two):
+    if payload_one.name != payload_two.name:
+        err_msg = "Reason: the packets at index %d have a different layer %d protocol.\n" % (idx+1, layer_num)
+        err_msg += "Packet 1: %s \t Packet 2: %s\n" % (payload_one.name, payload_two.name)
+        return True, err_msg
+    else:
+        return False, ""
+
+def find_detailed_diff(idx, pkt_one, pkt_two):
+    def check_reason(check_func, check_same_layer=False):
+        nonlocal printed_result
+        nonlocal layer_num
+
+        if not check_same_layer:
+            status, msg = check_func(idx, payload_one, payload_two)
+        else:
+            status, msg = check_func(idx, layer_num, payload_one, payload_two)
+        if status:
+            if not printed_result:
+                print("Result: the two PCAPs are not equal.")
+                print("============================================")
+                printed_result = True
+            print("Layer %d:" % layer_num)
+            print(msg)
+        return status
+
+    payload_one, payload_two = pkt_one, pkt_two
+    printed_result = False
+    layer_num = 2
+
+    status = check_reason(check_different_layers, True)
+    if not status:
+        check_reason(check_l2_diff)
+
+    while len(payload_one.payload) != 0:
+        layer_num += 1
+        payload_one = payload_one.payload
+        payload_two = payload_two.payload
+        if len(payload_two) == 0:
+            if not printed_result:
+                print("Result: the two PCAPs are not equal.")
+                print("============================================")
+                printed_result = True
+            print("Reason: the packets at index %d have a different number of layers.\n" % (idx+1))
+            return
+
+        status = check_reason(check_different_layers, True)
+
+        if not status:
+            if layer_num == 3:
+                check_reason(check_l3_diff)
+            elif layer_num == 4:
+                check_reason(check_l4_diff)
+            elif layer_num > 4:
+                check_reason(check_payload_diff)
+
+    if printed_result:
+        return
+
+    if len(payload_one) == 0 and len(payload_two) != 0:
+        if not printed_result:
+            print("Result: the two PCAPs are not equal.")
+            print("============================================")
+        print("Reason: the packets at index %d have a different number of layers.\n" % (idx+1))
+        return
+
+    print("Result: the two PCAPs are not equal.")
+    print("============================================")
+    print("Reason: could not automatically find a detailed reason.")
+
+
+def do_rough_comparison(filepath_one, filepath_two):
+    packets_one = rdpcap(filepath_one)
+    packets_two = rdpcap(filepath_two)
+
+    if len(packets_one) != len(packets_two):
+        print("Result: the two PCAPs are not equal.")
+        print("============================================")
+        print("Reason: they contain a different number of packets.")
+        return
+
+    for i, pkt_one in enumerate(packets_one):
+        pkt_two = packets_two[i]
+        # print(pkt_one.payload.payload.payload.name)
+        # print()
+        # print(pkt_one.show())
+        if pkt_one.time != pkt_two.time:
+            print("Result: the two PCAPs are not equal.")
+            print("============================================")
+            print("Reason: the packets at index %d have a different timestamp." % (i+1))
+            return
+
+        if pkt_one != pkt_two:
+            #print("Result: the two PCAPs are not equal.")
+            #print("Reason: the packets at index %d have different contents." % (i+1))
+            find_detailed_diff(i, pkt_one, pkt_two)
+            return
+
+    print("Success")
+    print("There are no differences between %s and %s" % (filepath_one, filepath_two))
+
+
+def init_comparison():
+    if len(sys.argv) != 3:
+        print("Error: you need to specify two files to compare.\nCannot accept %d argument(s)" % (len(sys.argv)-1))
+
+    filepath_one, filepath_two = sys.argv[1], sys.argv[2]
+    #filepath_one, filepath_two = file_tel, file_tel
+    #filepath_one, filepath_two = "shortcap.pcap", "shortcap.pcap"
+    #filepath_one, filepath_two = "file1.pcap", "file3_new.pcap"
+    print("Comparing %s and %s.\n" % (filepath_one, filepath_two))
+    do_rough_comparison(filepath_one, filepath_two)
+
+
+init_comparison()
+#change_pcap("file3.pcap")

+ 64 - 0
test/TestUtil.py

@@ -0,0 +1,64 @@
+#!/usr/bin/python3
+
+import scapy.all
+import scapy.packet
+
+
+# You could compare pcaps by byte or by hash too, but this class tells you
+# where exactly pcaps differ
+class PcapComparator:
+    def compare_files(self, file: str, other_file: str):
+        self.compare_captures(scapy.all.rdpcap(file), scapy.all.rdpcap(other_file))
+
+    def compare_captures(self, packetsA, packetsB):
+        if len(packetsA) != len(packetsB):
+            self.fail("Both pcap's have to have the same amount of packets")
+
+        for i in range(len(packetsA)):
+            p, p2 = packetsA[i], packetsB[i]
+
+            if abs(p.time - p2.time) > (10 ** -7):
+                self.fail("Packets no %i in the pcap's don't appear at the same time" % (i + 1))
+            self.compare_packets(p, p2, i + 1)
+
+    def compare_packets(self, p: scapy.packet.BasePacket, p2: scapy.packet.BasePacket, packet_number: int):
+        if p == p2:
+            return
+
+        while type(p) != scapy.packet.NoPayload or type(p2) != scapy.packet.NoPayload:
+            if type(p) != type(p2):
+                self.fail("Packets %i are of incompatible types: %s and %s" % (packet_number, type(p).__name__, type(p2).__name__))
+
+            for field in p.fields:
+                if p.fields[field] != p2.fields[field]:
+                    packet_type = type(p).__name__
+                    v, v2 = p.fields[field], p2.fields[field]
+
+                    self.fail("Packets %i differ in field %s.%s: %s != %s" %
+                                (packet_number, packet_type, field, v, v2))
+
+            p = p.payload
+            p2 = p2.payload
+
+    def fail(self, message: str):
+        raise AssertionError(message)
+
+
+if __name__ == "__main__":
+    import sys
+
+    if len(sys.argv) < 3:
+        print("Usage: %s one.pcap other.pcap" % sys.argv[0])
+        exit(0)
+
+    try:
+        PcapComparator().compare_files(sys.argv[1], sys.argv[2])
+        print("The given pcaps are equal")
+    except AssertionError as e:
+        print("The given pcaps are not equal")
+        print("Error message:", *e.args)
+        exit(1)
+    except Exception as e:
+        print("During the comparison an unexpected error happened")
+        print(type(e).__name__ + ":", *e.args)
+        exit(1)

+ 0 - 0
test/__init__.py


+ 1 - 1
code/Test/test_ipgenerator.py → test/test_ipgenerator.py

@@ -1,4 +1,4 @@
-from ID2TLib.Generator import IPGenerator
+from ID2TLib.OldLibs.IPGenerator import IPGenerator
 import unittest
 
 class IPGeneratorTestCase(unittest.TestCase):

+ 32 - 25
code/Test/test_pcap_comparator.py → test/test_pcap_comparator.py

@@ -7,7 +7,7 @@ import unittest
 import random
 
 import scapy.all
-from Test.TestUtil import PcapComparator, ID2TExecution
+from TestUtil import PcapComparator
 
 # this dictionary holds the generators (functions) for the parameters
 # that will be passed to the MembershipMgmtCommAttack
@@ -35,11 +35,9 @@ ID2T_PARAMETER_GENERATORS = {
     "ttl.from.caida": _random_bool,
 }
 
-
 class PcapComparison(unittest.TestCase):
     ID2T_PATH = ".."
     ID2T_LOCATION = ID2T_PATH + "/" + "id2t"
-
     NUM_ITERATIONS_PER_PARAMS = 3
     NUM_ITERATIONS = 5
 
@@ -49,6 +47,8 @@ class PcapComparison(unittest.TestCase):
     DEFAULT_PCAP = "resources/telnet-raw.pcap"
     DEFAULT_SEED = "42"
 
+    OUTPUT_FILES_PREFIX_LINE = "Output files created:"
+
     def __init__(self, *args, **kwargs):
         unittest.TestCase.__init__(self, *args, **kwargs)
 
@@ -61,7 +61,8 @@ class PcapComparison(unittest.TestCase):
         self.id2t_params = params
 
     def setUp(self):
-        self.executions = []
+        self.generated_files = []
+        self.keep_files = []
 
     def test_determinism(self):
         input_pcap = os.environ.get(self.PCAP_ENVIRONMENT_VALUE, self.DEFAULT_PCAP)
@@ -74,28 +75,26 @@ class PcapComparison(unittest.TestCase):
             self.do_test_round(input_pcap, seed, params)
 
     def do_test_round(self, input_pcap, seed, additional_params):
+        command_args = [self.ID2T_LOCATION, "-i", input_pcap, "--seed", seed, "-a", "MembersMgmtCommAttack"] + additional_params
+        command = " ".join(map(shlex.quote, command_args))
+        self.print_warning("The command that gets executed is:", command)
+
         generated_pcap = None
         for i in range(self.NUM_ITERATIONS_PER_PARAMS):
-            execution = ID2TExecution(input_pcap, seed=seed)
-            self.print_warning("The command that gets executed is:", execution.get_run_command(additional_params))
-            self.executions.append(execution)
+            retcode, output = subprocess.getstatusoutput(command)
 
-            try:
-                execution.run(additional_params)
-            except AssertionError as e:
-                self.print_warning(execution.get_output())
-                self.assertEqual(execution.get_return_code(), 0, "For some reason id2t completed with an error")
-                raise e
+            self.print_warning(output)
+            self.assertEqual(retcode, 0, "For some reason id2t completed with an error")
 
-            self.print_warning(execution.get_output())
+            files = self.parse_files(output)
+            self.generated_files.extend(files)
 
-            pcap = execution.get_pcap_filename()
+            pcap = self.find_pcap(files)
             if generated_pcap is not None:
                 try:
                     self.compare_pcaps(generated_pcap, pcap)
                 except AssertionError as e:
-                    execution.keep_file(pcap)
-                    self.executions[-2].keep_file(generated_pcap)
+                    self.keep_files = [generated_pcap, pcap]
                     raise e
             else:
                 generated_pcap = pcap
@@ -105,16 +104,25 @@ class PcapComparison(unittest.TestCase):
 
     def tearDown(self):
         self.print_warning("Cleaning up files generated by the test-calls...")
-        for id2t_run in self.executions:
-            for file in id2t_run.get_files_for_deletion():
-                self.print_warning(file)
-
-            id2t_run.cleanup()
+        for file in self.generated_files:
+            if file in self.keep_files: continue
 
+            self.print_warning(file)
+            os.remove(self.ID2T_PATH + os.path.sep + file)
         self.print_warning("Done")
+        self.print_warning("The following files have been kept: " + ", ".join(self.keep_files))
 
-        kept = [file for file in id2t_run.get_kept_files() for id2t_run in self.executions]
-        self.print_warning("The following files have been kept: " + ", ".join(kept))
+    def parse_files(self, program_output: str) -> "list[str]":
+        lines = program_output.split(os.linesep)
+
+        self.assertIn(self.OUTPUT_FILES_PREFIX_LINE, lines,
+                "The magic string is not in the program output anymore, has the program output structure changed?")
+        index = lines.index(self.OUTPUT_FILES_PREFIX_LINE)
+
+        return lines[index + 1:]
+
+    def find_pcap(self, files: "list[str]") -> str:
+        return next(file for file in files if file.endswith(".pcap"))
 
     def compare_pcaps(self, one: str, other: str):
         PcapComparator().compare_files(self.ID2T_PATH + "/" + one, self.ID2T_PATH + "/" + other)
@@ -149,7 +157,6 @@ class PcapComparison(unittest.TestCase):
 
         return params
 
-
 if __name__ == "__main__":
     import sys