CCSDS_study project
This commit is contained in:
68
netzob-030/test/src/common/NetzobTestCase.py
Normal file
68
netzob-030/test/src/common/NetzobTestCase.py
Normal file
@@ -0,0 +1,68 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| 01001110 01100101 01110100 01111010 01101111 01100010 |
|
||||
#| |
|
||||
#| Netzob : Inferring communication protocols |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Copyright (C) 2011-2017 Georges Bossert and Frédéric Guihéry |
|
||||
#| This program is free software: you can redistribute it and/or modify |
|
||||
#| it under the terms of the GNU General Public License as published by |
|
||||
#| the Free Software Foundation, either version 3 of the License, or |
|
||||
#| (at your option) any later version. |
|
||||
#| |
|
||||
#| This program is distributed in the hope that it will be useful, |
|
||||
#| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
#| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
#| GNU General Public License for more details. |
|
||||
#| |
|
||||
#| You should have received a copy of the GNU General Public License |
|
||||
#| along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| @url : http://www.netzob.org |
|
||||
#| @contact : contact@netzob.org |
|
||||
#| @sponsors : Amossys, http://www.amossys.fr |
|
||||
#| Supélec, http://www.rennes.supelec.fr/ren/rd/cidre/ |
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Standard library imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
import unittest
|
||||
import os.path
|
||||
import logging
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
|
||||
# from netzob.Common.ResourcesConfiguration import ResourcesConfiguration
|
||||
# from netzob import NetzobResources
|
||||
# from netzob.Common.Workspace import Workspace
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Local Imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
|
||||
class NetzobTestCase(unittest.TestCase):
|
||||
|
||||
def __init__(self, methodName='runTest'):
|
||||
unittest.TestCase.__init__(self, methodName)
|
||||
self.debug = True
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
# We compute the static resources path
|
||||
# resourcesPath = "resources/"
|
||||
# staticPath = os.path.join(resourcesPath, "static/netzob/")
|
||||
# NetzobResources.STATIC_DIR = staticPath
|
||||
|
||||
# # We compute the test (user) resources path
|
||||
# resourcesPath = "test/resources/"
|
||||
# # We retrieve the full name of the child class (the caller)
|
||||
# for m in self.__class__.__module__.split('.'):
|
||||
# resourcesPath = os.path.join(resourcesPath, m)
|
||||
# workspacePath = os.path.join(resourcesPath, ResourcesConfiguration.VAR_WORKSPACE_LOCALFILE)
|
||||
# # Before setting workspace, we verify it exists
|
||||
# if os.path.isdir(workspacePath):
|
||||
# NetzobResources.WORKSPACE_DIR = workspacePath
|
||||
0
netzob-030/test/src/common/__init__.py
Normal file
0
netzob-030/test/src/common/__init__.py
Normal file
404
netzob-030/test/src/common/xmlrunner.py
Normal file
404
netzob-030/test/src/common/xmlrunner.py
Normal file
@@ -0,0 +1,404 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
XML Test Runner for PyUnit
|
||||
"""
|
||||
|
||||
# Written by Sebastian Rittau <srittau@jroger.in-berlin.de> and placed in
|
||||
# the Public Domain. With contributions by Paolo Borelli and others.
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
__version__ = "0.3"
|
||||
|
||||
import os.path
|
||||
import re
|
||||
import sys
|
||||
import time
|
||||
import traceback
|
||||
import unittest
|
||||
import unittest.util
|
||||
from xml.sax.saxutils import escape
|
||||
|
||||
from io import StringIO, BytesIO
|
||||
|
||||
|
||||
class _TestInfo(object):
|
||||
|
||||
"""Information about a particular test.
|
||||
|
||||
Used by _XMLTestResult.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, test, time):
|
||||
(self._class, self._method) = test.id().rsplit(".", 1)
|
||||
self._time = time
|
||||
self._error = None
|
||||
self._failure = None
|
||||
|
||||
@staticmethod
|
||||
def create_success(test, time):
|
||||
"""Create a _TestInfo instance for a successful test."""
|
||||
return _TestInfo(test, time)
|
||||
|
||||
@staticmethod
|
||||
def create_failure(test, time, failure):
|
||||
"""Create a _TestInfo instance for a failed test."""
|
||||
info = _TestInfo(test, time)
|
||||
info._failure = failure
|
||||
return info
|
||||
|
||||
@staticmethod
|
||||
def create_error(test, time, error):
|
||||
"""Create a _TestInfo instance for an erroneous test."""
|
||||
info = _TestInfo(test, time)
|
||||
info._error = error
|
||||
return info
|
||||
|
||||
def print_report(self, stream):
|
||||
"""Print information about this test case in XML format to the
|
||||
supplied stream.
|
||||
|
||||
"""
|
||||
tag_template = (' <testcase classname="{class_}" name="{method}" '
|
||||
'time="{time:.4f}">')
|
||||
stream.write(tag_template.format(class_=self._class,
|
||||
method=self._method,
|
||||
time=self._time))
|
||||
if self._failure is not None:
|
||||
self._print_error(stream, 'failure', self._failure)
|
||||
if self._error is not None:
|
||||
self._print_error(stream, 'error', self._error)
|
||||
stream.write('</testcase>\n')
|
||||
|
||||
@staticmethod
|
||||
def _print_error(stream, tag_name, error):
|
||||
"""Print information from a failure or error to the supplied stream."""
|
||||
str_ = str if sys.version_info[0] >= 3 else unicode
|
||||
io_class = StringIO if sys.version_info[0] >= 3 else BytesIO
|
||||
text = escape(str_(error[1]))
|
||||
class_name = unittest.util.strclass(error[0])
|
||||
stream.write('\n')
|
||||
stream.write(' <{tag} type="{class_}">{text}\n'.format(
|
||||
tag=tag_name, class_= class_name, text=text))
|
||||
tb_stream = io_class()
|
||||
traceback.print_tb(error[2], None, tb_stream)
|
||||
tb_string = tb_stream.getvalue()
|
||||
if sys.version_info[0] < 3:
|
||||
tb_string = tb_string.decode("utf-8")
|
||||
stream.write(escape(tb_string))
|
||||
stream.write(' </{tag}>\n'.format(tag=tag_name))
|
||||
stream.write(' ')
|
||||
|
||||
|
||||
def _clsname(cls):
|
||||
return cls.__module__ + "." + cls.__name__
|
||||
|
||||
|
||||
class _XMLTestResult(unittest.TestResult):
|
||||
|
||||
"""A test result class that stores result as XML.
|
||||
|
||||
Used by XMLTestRunner.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, class_name):
|
||||
unittest.TestResult.__init__(self)
|
||||
self._test_name = class_name
|
||||
self._start_time = None
|
||||
self._tests = []
|
||||
self._error = None
|
||||
self._failure = None
|
||||
|
||||
def startTest(self, test):
|
||||
unittest.TestResult.startTest(self, test)
|
||||
self._error = None
|
||||
self._failure = None
|
||||
self._start_time = time.time()
|
||||
|
||||
def stopTest(self, test):
|
||||
time_taken = time.time() - self._start_time
|
||||
unittest.TestResult.stopTest(self, test)
|
||||
if self._error:
|
||||
info = _TestInfo.create_error(test, time_taken, self._error)
|
||||
elif self._failure:
|
||||
info = _TestInfo.create_failure(test, time_taken, self._failure)
|
||||
else:
|
||||
info = _TestInfo.create_success(test, time_taken)
|
||||
self._tests.append(info)
|
||||
|
||||
def addError(self, test, err):
|
||||
unittest.TestResult.addError(self, test, err)
|
||||
self._error = err
|
||||
|
||||
def addFailure(self, test, err):
|
||||
unittest.TestResult.addFailure(self, test, err)
|
||||
self._failure = err
|
||||
|
||||
def print_report(self, stream, time_taken, out, err):
|
||||
"""Prints the XML report to the supplied stream.
|
||||
|
||||
The time the tests took to perform as well as the captured standard
|
||||
output and standard error streams must be passed in.a
|
||||
|
||||
"""
|
||||
tag_template = ('<testsuite errors="{errors}" failures="{failures}" '
|
||||
'name="{name}" tests="{total}" time="{time:.3f}">\n')
|
||||
stream.write(tag_template.format(name=self._test_name,
|
||||
total=self.testsRun,
|
||||
errors=len(self.errors),
|
||||
failures=len(self.failures),
|
||||
time=time_taken))
|
||||
for info in self._tests:
|
||||
info.print_report(stream)
|
||||
stream.write(' <system-out><![CDATA[{0}]]></system-out>\n'.format(
|
||||
out))
|
||||
stream.write(' <system-err><![CDATA[{0}]]></system-err>\n'.format(
|
||||
err))
|
||||
stream.write('</testsuite>\n')
|
||||
|
||||
|
||||
class XMLTestRunner(object):
|
||||
|
||||
"""A test runner that stores results in XML format compatible with JUnit.
|
||||
|
||||
XMLTestRunner(stream=None) -> XML test runner
|
||||
|
||||
The XML file is written to the supplied stream. If stream is None, the
|
||||
results are stored in a file called TEST-<module>.<class>.xml in the
|
||||
current working directory (if not overridden with the path property),
|
||||
where <module> and <class> are the module and class name of the test class.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, stream=None):
|
||||
self._stream = stream
|
||||
self._path = "."
|
||||
|
||||
def run(self, test):
|
||||
"""Run the given test case or test suite."""
|
||||
class_ = test.__class__
|
||||
class_name = class_.__module__ + "." + class_.__name__
|
||||
if self._stream is None:
|
||||
filename = "TEST-{0}.xml".format(class_name)
|
||||
stream = open(os.path.join(self._path, filename), "w")
|
||||
stream.write('<?xml version="1.0" encoding="utf-8"?>\n')
|
||||
else:
|
||||
stream = self._stream
|
||||
|
||||
result = _XMLTestResult(class_name)
|
||||
start_time = time.time()
|
||||
|
||||
with _FakeStdStreams():
|
||||
test(result)
|
||||
try:
|
||||
out_s = sys.stdout.getvalue()
|
||||
except AttributeError:
|
||||
out_s = ""
|
||||
try:
|
||||
err_s = sys.stderr.getvalue()
|
||||
except AttributeError:
|
||||
err_s = ""
|
||||
|
||||
time_taken = time.time() - start_time
|
||||
result.print_report(stream, time_taken, out_s, err_s)
|
||||
if self._stream is None:
|
||||
stream.close()
|
||||
|
||||
return result
|
||||
|
||||
def _set_path(self, path):
|
||||
self._path = path
|
||||
|
||||
path = property(
|
||||
lambda self: self._path, _set_path, None,
|
||||
"""The path where the XML files are stored.
|
||||
|
||||
This property is ignored when the XML file is written to a file
|
||||
stream.""")
|
||||
|
||||
|
||||
class _FakeStdStreams(object):
|
||||
|
||||
def __enter__(self):
|
||||
self._orig_stdout = sys.stdout
|
||||
self._orig_stderr = sys.stderr
|
||||
sys.stdout = StringIO()
|
||||
sys.stderr = StringIO()
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
sys.stdout = self._orig_stdout
|
||||
sys.stderr = self._orig_stderr
|
||||
|
||||
|
||||
class XMLTestRunnerTest(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self._stream = StringIO()
|
||||
|
||||
def _try_test_run(self, test_class, expected):
|
||||
|
||||
"""Run the test suite against the supplied test class and compare the
|
||||
XML result against the expected XML string. Fail if the expected
|
||||
string doesn't match the actual string. All time attributes in the
|
||||
expected string should have the value "0.000". All error and failure
|
||||
messages are reduced to "Foobar".
|
||||
|
||||
"""
|
||||
|
||||
self._run_test_class(test_class)
|
||||
|
||||
got = self._stream.getvalue()
|
||||
# Replace all time="X.YYY" attributes by time="0.000" to enable a
|
||||
# simple string comparison.
|
||||
got = re.sub(r'time="\d+\.\d+"', 'time="0.000"', got)
|
||||
# Likewise, replace all failure and error messages by a simple "Foobar"
|
||||
# string.
|
||||
got = re.sub(r'(?s)<failure (.*?)>.*?</failure>',
|
||||
r'<failure \1>Foobar</failure>', got)
|
||||
got = re.sub(r'(?s)<error (.*?)>.*?</error>',
|
||||
r'<error \1>Foobar</error>', got)
|
||||
# And finally Python 3 compatibility.
|
||||
got = got.replace('type="builtins.', 'type="exceptions.')
|
||||
|
||||
self.assertEqual(expected, got)
|
||||
|
||||
def _run_test_class(self, test_class):
|
||||
runner = XMLTestRunner(self._stream)
|
||||
runner.run(unittest.makeSuite(test_class))
|
||||
|
||||
def test_no_tests(self):
|
||||
"""Regression test: Check whether a test run without any tests
|
||||
matches a previous run.
|
||||
|
||||
"""
|
||||
class TestTest(unittest.TestCase):
|
||||
pass
|
||||
self._try_test_run(TestTest, """<testsuite errors="0" failures="0" name="unittest.suite.TestSuite" tests="0" time="0.000">
|
||||
<system-out><![CDATA[]]></system-out>
|
||||
<system-err><![CDATA[]]></system-err>
|
||||
</testsuite>
|
||||
""")
|
||||
|
||||
def test_success(self):
|
||||
"""Regression test: Check whether a test run with a successful test
|
||||
matches a previous run.
|
||||
|
||||
"""
|
||||
class TestTest(unittest.TestCase):
|
||||
def test_foo(self):
|
||||
pass
|
||||
self._try_test_run(TestTest, """<testsuite errors="0" failures="0" name="unittest.suite.TestSuite" tests="1" time="0.000">
|
||||
<testcase classname="__main__.TestTest" name="test_foo" time="0.000"></testcase>
|
||||
<system-out><![CDATA[]]></system-out>
|
||||
<system-err><![CDATA[]]></system-err>
|
||||
</testsuite>
|
||||
""")
|
||||
|
||||
def test_failure(self):
|
||||
"""Regression test: Check whether a test run with a failing test
|
||||
matches a previous run.
|
||||
|
||||
"""
|
||||
class TestTest(unittest.TestCase):
|
||||
def test_foo(self):
|
||||
self.assertTrue(False)
|
||||
self._try_test_run(TestTest, """<testsuite errors="0" failures="1" name="unittest.suite.TestSuite" tests="1" time="0.000">
|
||||
<testcase classname="__main__.TestTest" name="test_foo" time="0.000">
|
||||
<failure type="exceptions.AssertionError">Foobar</failure>
|
||||
</testcase>
|
||||
<system-out><![CDATA[]]></system-out>
|
||||
<system-err><![CDATA[]]></system-err>
|
||||
</testsuite>
|
||||
""")
|
||||
|
||||
def test_error(self):
|
||||
"""Regression test: Check whether a test run with a erroneous test
|
||||
matches a previous run.
|
||||
|
||||
"""
|
||||
class TestTest(unittest.TestCase):
|
||||
def test_foo(self):
|
||||
raise IndexError()
|
||||
self._try_test_run(TestTest, """<testsuite errors="1" failures="0" name="unittest.suite.TestSuite" tests="1" time="0.000">
|
||||
<testcase classname="__main__.TestTest" name="test_foo" time="0.000">
|
||||
<error type="exceptions.IndexError">Foobar</error>
|
||||
</testcase>
|
||||
<system-out><![CDATA[]]></system-out>
|
||||
<system-err><![CDATA[]]></system-err>
|
||||
</testsuite>
|
||||
""")
|
||||
|
||||
def test_non_ascii_characters_in_traceback(self):
|
||||
"""Test umlauts in traceback exception messages."""
|
||||
class TestTest(unittest.TestCase):
|
||||
def test_foo(self):
|
||||
raise Exception("Test äöü")
|
||||
self._run_test_class(TestTest)
|
||||
|
||||
def test_stdout_capture(self):
|
||||
"""Regression test: Check whether a test run with output to stdout
|
||||
matches a previous run.
|
||||
|
||||
"""
|
||||
class TestTest(unittest.TestCase):
|
||||
def test_foo(self):
|
||||
sys.stdout.write("Test\n")
|
||||
self._try_test_run(TestTest, """<testsuite errors="0" failures="0" name="unittest.suite.TestSuite" tests="1" time="0.000">
|
||||
<testcase classname="__main__.TestTest" name="test_foo" time="0.000"></testcase>
|
||||
<system-out><![CDATA[Test
|
||||
]]></system-out>
|
||||
<system-err><![CDATA[]]></system-err>
|
||||
</testsuite>
|
||||
""")
|
||||
|
||||
def test_stderr_capture(self):
|
||||
"""Regression test: Check whether a test run with output to stderr
|
||||
matches a previous run.
|
||||
|
||||
"""
|
||||
class TestTest(unittest.TestCase):
|
||||
def test_foo(self):
|
||||
sys.stderr.write("Test\n")
|
||||
self._try_test_run(TestTest, """<testsuite errors="0" failures="0" name="unittest.suite.TestSuite" tests="1" time="0.000">
|
||||
<testcase classname="__main__.TestTest" name="test_foo" time="0.000"></testcase>
|
||||
<system-out><![CDATA[]]></system-out>
|
||||
<system-err><![CDATA[Test
|
||||
]]></system-err>
|
||||
</testsuite>
|
||||
""")
|
||||
|
||||
class NullStream(object):
|
||||
"""A file-like object that discards everything written to it."""
|
||||
def write(self, buffer):
|
||||
pass
|
||||
|
||||
def test_unittests_changing_stdout(self):
|
||||
"""Check whether the XMLTestRunner recovers gracefully from unit tests
|
||||
that change stdout, but don't change it back properly.
|
||||
|
||||
"""
|
||||
class TestTest(unittest.TestCase):
|
||||
def test_foo(self):
|
||||
sys.stdout = XMLTestRunnerTest.NullStream()
|
||||
|
||||
runner = XMLTestRunner(self._stream)
|
||||
runner.run(unittest.makeSuite(TestTest))
|
||||
|
||||
def test_unittests_changing_stderr(self):
|
||||
"""Check whether the XMLTestRunner recovers gracefully from unit tests
|
||||
that change stderr, but don't change it back properly.
|
||||
|
||||
"""
|
||||
class TestTest(unittest.TestCase):
|
||||
def test_foo(self):
|
||||
sys.stderr = XMLTestRunnerTest.NullStream()
|
||||
|
||||
runner = XMLTestRunner(self._stream)
|
||||
runner.run(unittest.makeSuite(TestTest))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
0
netzob-030/test/src/test_netzob/__init__.py
Normal file
0
netzob-030/test/src/test_netzob/__init__.py
Normal file
54
netzob-030/test/src/test_netzob/suite_Alignment.py
Normal file
54
netzob-030/test/src/test_netzob/suite_Alignment.py
Normal file
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| 01001110 01100101 01110100 01111010 01101111 01100010 |
|
||||
#| |
|
||||
#| Netzob : Inferring communication protocols |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Copyright (C) 2011-2017 Georges Bossert and Frédéric Guihéry |
|
||||
#| This program is free software: you can redistribute it and/or modify |
|
||||
#| it under the terms of the GNU General Public License as published by |
|
||||
#| the Free Software Foundation, either version 3 of the License, or |
|
||||
#| (at your option) any later version. |
|
||||
#| |
|
||||
#| This program is distributed in the hope that it will be useful, |
|
||||
#| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
#| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
#| GNU General Public License for more details. |
|
||||
#| |
|
||||
#| You should have received a copy of the GNU General Public License |
|
||||
#| along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| @url : http://www.netzob.org |
|
||||
#| @contact : contact@netzob.org |
|
||||
#| @sponsors : Amossys, http://www.amossys.fr |
|
||||
#| Supélec, http://www.rennes.supelec.fr/ren/rd/cidre/ |
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Standard library imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
import unittest
|
||||
from test_netzob.test_Alignment import test_Needleman
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Local application imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
|
||||
def getSuite():
|
||||
alignmentSuite = unittest.TestSuite()
|
||||
|
||||
modulesOfTests = [test_Needleman]
|
||||
modulesOfSuites = []
|
||||
|
||||
# Add individual tests
|
||||
for module in modulesOfTests:
|
||||
alignmentSuite.addTests(unittest.TestLoader().loadTestsFromModule(module))
|
||||
|
||||
# Add suites
|
||||
for module in modulesOfSuites:
|
||||
alignmentSuite.addTests(module.getSuite())
|
||||
|
||||
return alignmentSuite
|
||||
54
netzob-030/test/src/test_netzob/suite_Common.py
Normal file
54
netzob-030/test/src/test_netzob/suite_Common.py
Normal file
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| 01001110 01100101 01110100 01111010 01101111 01100010 |
|
||||
#| |
|
||||
#| Netzob : Inferring communication protocols |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Copyright (C) 2011-2017 Georges Bossert and Frédéric Guihéry |
|
||||
#| This program is free software: you can redistribute it and/or modify |
|
||||
#| it under the terms of the GNU General Public License as published by |
|
||||
#| the Free Software Foundation, either version 3 of the License, or |
|
||||
#| (at your option) any later version. |
|
||||
#| |
|
||||
#| This program is distributed in the hope that it will be useful, |
|
||||
#| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
#| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
#| GNU General Public License for more details. |
|
||||
#| |
|
||||
#| You should have received a copy of the GNU General Public License |
|
||||
#| along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| @url : http://www.netzob.org |
|
||||
#| @contact : contact@netzob.org |
|
||||
#| @sponsors : Amossys, http://www.amossys.fr |
|
||||
#| Supélec, http://www.rennes.supelec.fr/ren/rd/cidre/ |
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Standard library imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
import unittest
|
||||
from test_netzob.test_Common import suite_Type, suite_Functions, test_Field
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Local application imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
|
||||
def getSuite():
|
||||
commonSuite = unittest.TestSuite()
|
||||
|
||||
modulesOfTests = [test_Field]
|
||||
modulesOfSuites = [suite_Type, suite_Functions]
|
||||
|
||||
# Add individual tests
|
||||
for module in modulesOfTests:
|
||||
commonSuite.addTests(unittest.TestLoader().loadTestsFromModule(module))
|
||||
|
||||
# Add suites
|
||||
for module in modulesOfSuites:
|
||||
commonSuite.addTests(module.getSuite())
|
||||
|
||||
return commonSuite
|
||||
290
netzob-030/test/src/test_netzob/suite_DocTests.py
Normal file
290
netzob-030/test/src/test_netzob/suite_DocTests.py
Normal file
@@ -0,0 +1,290 @@
|
||||
# !/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# +---------------------------------------------------------------------------+
|
||||
# | 01001110 01100101 01110100 01111010 01101111 01100010 |
|
||||
# | |
|
||||
# | Netzob : Inferring communication protocols |
|
||||
# +---------------------------------------------------------------------------+
|
||||
# | Copyright (C) 2011-2017 Georges Bossert and Frédéric Guihéry |
|
||||
# | This program is free software: you can redistribute it and/or modify |
|
||||
# | it under the terms of the GNU General Public License as published by |
|
||||
# | the Free Software Foundation, either version 3 of the License, or |
|
||||
# | (at your option) any later version. |
|
||||
# | |
|
||||
# | This program is distributed in the hope that it will be useful, |
|
||||
# | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
# | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
# | GNU General Public License for more details. |
|
||||
# | |
|
||||
# | You should have received a copy of the GNU General Public License |
|
||||
# | along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
# +---------------------------------------------------------------------------+
|
||||
# | @url : http://www.netzob.org |
|
||||
# | @contact : contact@netzob.org |
|
||||
# | @sponsors : Amossys, http://www.amossys.fr |
|
||||
# | Supélec, http://www.rennes.supelec.fr/ren/rd/cidre/ |
|
||||
# +---------------------------------------------------------------------------+
|
||||
|
||||
# +---------------------------------------------------------------------------+
|
||||
# | Standard library imports
|
||||
# +---------------------------------------------------------------------------+
|
||||
import importlib
|
||||
import unittest
|
||||
import doctest
|
||||
|
||||
# +---------------------------------------------------------------------------+
|
||||
# | Local application imports
|
||||
# +---------------------------------------------------------------------------+
|
||||
from netzob.all import *
|
||||
from netzob.Common.Utils.DataAlignment import ParallelDataAlignment
|
||||
from netzob.Common.Utils.DataAlignment import DataAlignment
|
||||
from netzob.Model.Vocabulary import AbstractField
|
||||
from netzob.Model.Vocabulary.Domain.Variables import AbstractVariable
|
||||
from netzob.Model.Vocabulary.Messages import AbstractMessage
|
||||
|
||||
from netzob.Inference.Vocabulary.FormatOperations import FieldReseter
|
||||
from netzob.Inference.Vocabulary.FormatOperations.FieldSplitStatic.FieldSplitStatic import FieldSplitStatic
|
||||
from netzob.Inference.Vocabulary.FormatOperations.FieldSplitStatic.ParallelFieldSplitStatic import ParallelFieldSplitStatic
|
||||
from netzob.Inference.Vocabulary.FormatOperations import ClusterByKeyField
|
||||
from netzob.Inference.Vocabulary.FormatOperations import ClusterByApplicativeData
|
||||
from netzob.Inference.Vocabulary.FormatOperations import ClusterByAlignment
|
||||
from netzob.Inference.Vocabulary.FormatOperations import ClusterBySize
|
||||
from netzob.Inference.Vocabulary.FormatOperations import FindKeyFields
|
||||
from netzob.Common.Utils import SortedTypedList
|
||||
from netzob.Common.Utils import MessageCells
|
||||
|
||||
from netzob.Inference.Vocabulary.Search import SearchTask
|
||||
from netzob.Inference.Vocabulary.Search import SearchResult
|
||||
from netzob.Inference.Vocabulary.FormatOperations.FieldSplitAligned import FieldSplitAligned
|
||||
from netzob.Inference.Vocabulary.FormatOperations import FieldSplitDelimiter
|
||||
|
||||
from netzob.Inference.Vocabulary.FormatOperations import FieldOperations
|
||||
from netzob.Model.Vocabulary.Domain.GenericPath import GenericPath
|
||||
from netzob.Model.Vocabulary.Domain.Specializer.FieldSpecializer import FieldSpecializer
|
||||
from netzob.Model.Vocabulary.Domain.Specializer.VariableSpecializer import VariableSpecializer
|
||||
from netzob.Model.Vocabulary.Domain.Variables.Scope import Scope
|
||||
|
||||
from netzob.Model.Vocabulary.Domain.Parser.MessageParser import MessageParser
|
||||
from netzob.Model.Vocabulary.Domain.Specializer.MessageSpecializer import MessageSpecializer
|
||||
from netzob.Model.Vocabulary.Domain.Parser.FlowParser import FlowParser
|
||||
|
||||
from netzob.Model.Grammar.Transitions.AbstractTransition import AbstractTransition
|
||||
from netzob.Model.Grammar.States.AbstractState import AbstractState
|
||||
|
||||
from netzob.Simulator.AbstractionLayer import AbstractionLayer
|
||||
from netzob.Simulator.AbstractChannel import AbstractChannel
|
||||
|
||||
from netzob.Inference.Vocabulary import EntropyMeasurement
|
||||
# from netzob.Inference.Grammar.Angluin import Angluin
|
||||
from netzob.Inference.Grammar.AutomataFactories.ChainedStatesAutomataFactory import ChainedStatesAutomataFactory
|
||||
from netzob.Inference.Grammar.AutomataFactories.PTAAutomataFactory import PTAAutomataFactory
|
||||
from netzob.Inference.Grammar.AutomataFactories.OneStateAutomataFactory import OneStateAutomataFactory
|
||||
|
||||
from netzob.Fuzzing.Mutator import Mutator
|
||||
from netzob.Fuzzing.Mutators.DomainMutator import DomainMutator
|
||||
from netzob.Fuzzing.Mutators.AggMutator import AggMutator
|
||||
from netzob.Fuzzing.Mutators.AltMutator import AltMutator
|
||||
from netzob.Fuzzing.Mutators.AutomataMutator import AutomataMutator
|
||||
from netzob.Fuzzing.Mutators.BitArrayMutator import BitArrayMutator
|
||||
from netzob.Fuzzing.Mutators.IntegerMutator import IntegerMutator
|
||||
from netzob.Fuzzing.Mutators.RawMutator import RawMutator
|
||||
from netzob.Fuzzing.Mutators.IPv4Mutator import IPv4Mutator
|
||||
from netzob.Fuzzing.Mutators.RepeatMutator import RepeatMutator
|
||||
from netzob.Fuzzing.Mutators.OptMutator import OptMutator
|
||||
from netzob.Fuzzing.Mutators.StringMutator import StringMutator
|
||||
from netzob.Fuzzing.Mutators.TimestampMutator import TimestampMutator
|
||||
|
||||
from netzob.Fuzzing.Generator import Generator
|
||||
from netzob.Fuzzing.Generators.DeterministGenerator import DeterministGenerator
|
||||
from netzob.Fuzzing.Generators.XorShiftGenerator import XorShiftGenerator
|
||||
from netzob.Fuzzing.Generators.WrapperGenerator import WrapperGenerator
|
||||
from netzob.Fuzzing.Generators.GeneratorFactory import GeneratorFactory
|
||||
from netzob.Model.Vocabulary.Types.TypeConverter import TypeConverter
|
||||
|
||||
from netzob.Inference.Grammar.ProcessWrappers import ProcessWrapper
|
||||
from netzob.Inference.Grammar.ProcessWrappers import NetworkProcessWrapper
|
||||
|
||||
def getSuite():
|
||||
# List of modules to include in the list of tests
|
||||
modules = [
|
||||
|
||||
# Modules related to common types and data structures
|
||||
# ---------------------------------------------------
|
||||
AbstractType.__module__,
|
||||
String.__module__,
|
||||
Integer.__module__,
|
||||
BitArray.__module__,
|
||||
Raw.__module__,
|
||||
HexaString.__module__,
|
||||
IPv4.__module__,
|
||||
Timestamp.__module__,
|
||||
|
||||
# Modules related to the vocabulary
|
||||
# ---------------------------------
|
||||
Protocol.__module__,
|
||||
Field.__module__,
|
||||
DataAlignment,
|
||||
ParallelDataAlignment,
|
||||
AbstractField,
|
||||
Symbol.__module__,
|
||||
DomainFactory.__module__,
|
||||
Alt.__module__,
|
||||
Agg.__module__,
|
||||
Repeat.__module__,
|
||||
Opt.__module__,
|
||||
Data.__module__,
|
||||
|
||||
FieldSplitStatic.__module__,
|
||||
FieldSplitAligned,
|
||||
FieldSplitDelimiter,
|
||||
ParallelFieldSplitStatic.__module__,
|
||||
FindKeyFields,
|
||||
FieldReseter,
|
||||
AbstractMessage,
|
||||
ClusterByKeyField,
|
||||
EmptySymbol.__module__,
|
||||
UnknownSymbol.__module__,
|
||||
ChannelDownSymbol.__module__,
|
||||
|
||||
RawMessage.__module__,
|
||||
L2NetworkMessage.__module__,
|
||||
L3NetworkMessage.__module__,
|
||||
L4NetworkMessage.__module__,
|
||||
FileMessage.__module__,
|
||||
FieldOperations,
|
||||
CorrelationFinder.__module__,
|
||||
RelationFinder.__module__,
|
||||
Format.__module__,
|
||||
Session.__module__,
|
||||
SortedTypedList,
|
||||
MessageCells,
|
||||
ApplicativeData.__module__,
|
||||
DomainEncodingFunction.__module__,
|
||||
TypeEncodingFunction.__module__,
|
||||
ZLibEncodingFunction.__module__,
|
||||
Base64EncodingFunction.__module__,
|
||||
SearchEngine.__module__,
|
||||
SearchTask,
|
||||
SearchResult,
|
||||
ClusterByApplicativeData,
|
||||
ClusterByAlignment,
|
||||
ClusterBySize,
|
||||
Memory.__module__,
|
||||
TypeConverter.__module__,
|
||||
AbstractVariable,
|
||||
Size.__module__,
|
||||
Value.__module__,
|
||||
Padding.__module__,
|
||||
FieldParser.__module__,
|
||||
GenericPath.__module__,
|
||||
VariableSpecializer.__module__,
|
||||
FieldSpecializer.__module__,
|
||||
Scope.__module__,
|
||||
|
||||
# Complex relationships
|
||||
HMAC_MD5.__module__,
|
||||
HMAC_SHA1.__module__,
|
||||
HMAC_SHA1_96.__module__,
|
||||
HMAC_SHA2_224.__module__,
|
||||
HMAC_SHA2_256.__module__,
|
||||
HMAC_SHA2_384.__module__,
|
||||
HMAC_SHA2_512.__module__,
|
||||
MD5.__module__,
|
||||
SHA1.__module__,
|
||||
SHA1_96.__module__,
|
||||
SHA2_224.__module__,
|
||||
SHA2_256.__module__,
|
||||
SHA2_384.__module__,
|
||||
SHA2_512.__module__,
|
||||
CRC16.__module__,
|
||||
CRC16DNP.__module__,
|
||||
CRC16Kermit.__module__,
|
||||
CRC16SICK.__module__,
|
||||
CRC32.__module__,
|
||||
CRCCCITT.__module__,
|
||||
InternetChecksum.__module__,
|
||||
|
||||
MessageParser.__module__,
|
||||
MessageSpecializer.__module__,
|
||||
|
||||
FlowParser.__module__,
|
||||
AbstractionLayer.__module__,
|
||||
AbstractChannel.__module__,
|
||||
EntropyMeasurement,
|
||||
|
||||
# Modules related to the grammar
|
||||
# ------------------------------
|
||||
# Angluin.__module__,
|
||||
AbstractState.__module__,
|
||||
State.__module__,
|
||||
AbstractTransition.__module__,
|
||||
Transition.__module__,
|
||||
OpenChannelTransition.__module__,
|
||||
CloseChannelTransition.__module__,
|
||||
AbstractionLayer.__module__,
|
||||
Automata.__module__,
|
||||
ProcessWrapper,
|
||||
NetworkProcessWrapper,
|
||||
|
||||
OneStateAutomataFactory.__module__,
|
||||
ChainedStatesAutomataFactory.__module__,
|
||||
PTAAutomataFactory.__module__,
|
||||
|
||||
# Modules related to fuzzing
|
||||
# --------------------------
|
||||
Preset.__module__,
|
||||
Mutator.__module__,
|
||||
DomainMutator.__module__,
|
||||
AltMutator.__module__,
|
||||
AggMutator.__module__,
|
||||
AutomataMutator.__module__,
|
||||
RepeatMutator.__module__,
|
||||
OptMutator.__module__,
|
||||
Generator.__module__,
|
||||
DeterministGenerator.__module__,
|
||||
WrapperGenerator.__module__,
|
||||
XorShiftGenerator.__module__,
|
||||
GeneratorFactory.__module__,
|
||||
IntegerMutator.__module__,
|
||||
RawMutator.__module__,
|
||||
BitArrayMutator.__module__,
|
||||
StringMutator.__module__,
|
||||
IPv4Mutator.__module__,
|
||||
TimestampMutator.__module__,
|
||||
|
||||
# Modules related to the protocol simulation
|
||||
# ------------------------------------------
|
||||
Actor.__module__,
|
||||
TCPServer.__module__,
|
||||
TCPClient.__module__,
|
||||
UDPServer.__module__,
|
||||
UDPClient.__module__,
|
||||
SSLClient.__module__,
|
||||
# IPChannel.__module__, ## Does not work on Travis CI as raw socket are not supported
|
||||
# RawIPChannel.__module__, ## Does not work on Travis CI as raw socket are not supported
|
||||
# RawEthernetChannel.__module__, ## Does not work on Travis CI as raw socket are not supported
|
||||
DebugChannel.__module__,
|
||||
|
||||
# Modules related to the import
|
||||
# -----------------------------
|
||||
PCAPImporter.__module__,
|
||||
FileImporter.__module__
|
||||
|
||||
# Other
|
||||
# -----
|
||||
# JSONSerializator.__module__,
|
||||
# TCPServer.__module__,
|
||||
|
||||
]
|
||||
|
||||
def setUp_doctest(*args):
|
||||
Conf.apply()
|
||||
|
||||
suite = unittest.TestSuite()
|
||||
for mod in modules:
|
||||
suite.addTest(doctest.DocTestSuite(mod, setUp=setUp_doctest))
|
||||
if isinstance(mod, str):
|
||||
mod = importlib.import_module(mod)
|
||||
suite.addTest(unittest.defaultTestLoader.loadTestsFromModule(mod))
|
||||
return suite
|
||||
59
netzob-030/test/src/test_netzob/suite_Export.py
Normal file
59
netzob-030/test/src/test_netzob/suite_Export.py
Normal file
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| 01001110 01100101 01110100 01111010 01101111 01100010 |
|
||||
#| |
|
||||
#| Netzob : Inferring communication protocols |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Copyright (C) 2011-2014 Georges Bossert and Frédéric Guihéry |
|
||||
#| This program is free software: you can redistribute it and/or modify |
|
||||
#| it under the terms of the GNU General Public License as published by |
|
||||
#| the Free Software Foundation, either version 3 of the License, or |
|
||||
#| (at your option) any later version. |
|
||||
#| |
|
||||
#| This program is distributed in the hope that it will be useful, |
|
||||
#| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
#| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
#| GNU General Public License for more details. |
|
||||
#| |
|
||||
#| You should have received a copy of the GNU General Public License |
|
||||
#| along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| @url : http://www.netzob.org |
|
||||
#| @contact : contact@netzob.org |
|
||||
#| @sponsors : Amossys, http://www.amossys.fr |
|
||||
#| Supélec, http://www.rennes.supelec.fr/ren/rd/cidre/ |
|
||||
#+---------------------------------------------------------------------------+
|
||||
# +---------------------------------------------------------------------------+
|
||||
# | File contributors : |
|
||||
# | - Sumit Acharya <sumit.acharya@uni-ulm.de> |
|
||||
# | - Stephan Kleber <stephan.kleber@uni-ulm.de> |
|
||||
# +---------------------------------------------------------------------------+
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Standard library imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
import unittest
|
||||
from test_netzob.test_Export import test_ScapyExporter
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Local application imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
|
||||
def getSuite():
|
||||
exportSuite = unittest.TestSuite()
|
||||
|
||||
modulesOfTests = [test_ScapyExporter]
|
||||
modulesOfSuites = []
|
||||
|
||||
# Add individual tests
|
||||
for module in modulesOfTests:
|
||||
exportSuite.addTests(unittest.TestLoader().loadTestsFromModule(module))
|
||||
|
||||
# Add suites
|
||||
for module in modulesOfSuites:
|
||||
exportSuite.addTests(module.getSuite())
|
||||
|
||||
return exportSuite
|
||||
54
netzob-030/test/src/test_netzob/suite_Import.py
Normal file
54
netzob-030/test/src/test_netzob/suite_Import.py
Normal file
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| 01001110 01100101 01110100 01111010 01101111 01100010 |
|
||||
#| |
|
||||
#| Netzob : Inferring communication protocols |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Copyright (C) 2011-2017 Georges Bossert and Frédéric Guihéry |
|
||||
#| This program is free software: you can redistribute it and/or modify |
|
||||
#| it under the terms of the GNU General Public License as published by |
|
||||
#| the Free Software Foundation, either version 3 of the License, or |
|
||||
#| (at your option) any later version. |
|
||||
#| |
|
||||
#| This program is distributed in the hope that it will be useful, |
|
||||
#| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
#| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
#| GNU General Public License for more details. |
|
||||
#| |
|
||||
#| You should have received a copy of the GNU General Public License |
|
||||
#| along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| @url : http://www.netzob.org |
|
||||
#| @contact : contact@netzob.org |
|
||||
#| @sponsors : Amossys, http://www.amossys.fr |
|
||||
#| Supélec, http://www.rennes.supelec.fr/ren/rd/cidre/ |
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Standard library imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
import unittest
|
||||
from test_netzob.test_Import import suite_Type, test_ExecutionContext # to be modified by maxime
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Local application imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
|
||||
def getSuite():
|
||||
importSuite = unittest.TestSuite()
|
||||
|
||||
modulesOfTests = [test_ExecutionContext]
|
||||
modulesOfSuites = [suite_Type]
|
||||
|
||||
# Add individual tests
|
||||
for module in modulesOfTests:
|
||||
importSuite.addTests(unittest.TestLoader().loadTestsFromModule(module))
|
||||
|
||||
# Add suites
|
||||
for module in modulesOfSuites:
|
||||
importSuite.addTests(module.getSuite())
|
||||
|
||||
return importSuite
|
||||
65
netzob-030/test/src/test_netzob/suite_Tutorials.py
Normal file
65
netzob-030/test/src/test_netzob/suite_Tutorials.py
Normal file
@@ -0,0 +1,65 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| 01001110 01100101 01110100 01111010 01101111 01100010 |
|
||||
#| |
|
||||
#| Netzob : Inferring communication protocols |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Copyright (C) 2011-2017 Georges Bossert and Frédéric Guihéry |
|
||||
#| This program is free software: you can redistribute it and/or modify |
|
||||
#| it under the terms of the GNU General Public License as published by |
|
||||
#| the Free Software Foundation, either version 3 of the License, or |
|
||||
#| (at your option) any later version. |
|
||||
#| |
|
||||
#| This program is distributed in the hope that it will be useful, |
|
||||
#| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
#| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
#| GNU General Public License for more details. |
|
||||
#| |
|
||||
#| You should have received a copy of the GNU General Public License |
|
||||
#| along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| @url : http://www.netzob.org |
|
||||
#| @contact : contact@netzob.org |
|
||||
#| @sponsors : Amossys, http://www.amossys.fr |
|
||||
#| Supélec, http://www.rennes.supelec.fr/ren/rd/cidre/ |
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Standard library imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
import unittest
|
||||
from test_netzob.test_Tutorials import test_ICMP
|
||||
from test_netzob.test_Tutorials import test_USBMouseProtocol
|
||||
from test_netzob.test_Tutorials import test_ImportPCAP
|
||||
from test_netzob.test_Tutorials import test_StaticFieldSlicing
|
||||
from test_netzob.test_Tutorials import test_ManualFieldStatic
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Local application imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
|
||||
def getSuite():
|
||||
tutorialsSuite = unittest.TestSuite()
|
||||
|
||||
modulesOfTests = [
|
||||
test_ICMP,
|
||||
test_USBMouseProtocol,
|
||||
test_ImportPCAP,
|
||||
test_StaticFieldSlicing,
|
||||
test_ManualFieldStatic
|
||||
]
|
||||
modulesOfSuites = []
|
||||
|
||||
# Add individual tests
|
||||
for module in modulesOfTests:
|
||||
tests = unittest.TestLoader().loadTestsFromModule(module)
|
||||
tutorialsSuite.addTests(tests)
|
||||
|
||||
# Add suites
|
||||
for module in modulesOfSuites:
|
||||
tutorialsSuite.addTests(module.getSuite())
|
||||
|
||||
return tutorialsSuite
|
||||
55
netzob-030/test/src/test_netzob/suite_UI.py
Normal file
55
netzob-030/test/src/test_netzob/suite_UI.py
Normal file
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| 01001110 01100101 01110100 01111010 01101111 01100010 |
|
||||
#| |
|
||||
#| Netzob : Inferring communication protocols |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Copyright (C) 2011-2017 Georges Bossert and Frédéric Guihéry |
|
||||
#| This program is free software: you can redistribute it and/or modify |
|
||||
#| it under the terms of the GNU General Public License as published by |
|
||||
#| the Free Software Foundation, either version 3 of the License, or |
|
||||
#| (at your option) any later version. |
|
||||
#| |
|
||||
#| This program is distributed in the hope that it will be useful, |
|
||||
#| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
#| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
#| GNU General Public License for more details. |
|
||||
#| |
|
||||
#| You should have received a copy of the GNU General Public License |
|
||||
#| along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| @url : http://www.netzob.org |
|
||||
#| @contact : contact@netzob.org |
|
||||
#| @sponsors : Amossys, http://www.amossys.fr |
|
||||
#| Supélec, http://www.rennes.supelec.fr/ren/rd/cidre/ |
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Standard library imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
import unittest
|
||||
from test_netzob.test_UI import test_UI
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Local application imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
|
||||
def getSuite():
|
||||
UISuite = unittest.TestSuite()
|
||||
|
||||
modulesOfTests = [test_UI]
|
||||
modulesOfSuites = []
|
||||
|
||||
# Add individual tests
|
||||
for module in modulesOfTests:
|
||||
t = unittest.TestLoader().loadTestsFromModule(module)
|
||||
UISuite.addTests(t)
|
||||
|
||||
# Add suites
|
||||
for module in modulesOfSuites:
|
||||
UISuite.addTests(module.getSuite())
|
||||
|
||||
return UISuite
|
||||
88
netzob-030/test/src/test_netzob/suite_global.py
Normal file
88
netzob-030/test/src/test_netzob/suite_global.py
Normal file
@@ -0,0 +1,88 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| 01001110 01100101 01110100 01111010 01101111 01100010 |
|
||||
#| |
|
||||
#| Netzob : Inferring communication protocols |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Copyright (C) 2011-2017 Georges Bossert and Frédéric Guihéry |
|
||||
#| This program is free software: you can redistribute it and/or modify |
|
||||
#| it under the terms of the GNU General Public License as published by |
|
||||
#| the Free Software Foundation, either version 3 of the License, or |
|
||||
#| (at your option) any later version. |
|
||||
#| |
|
||||
#| This program is distributed in the hope that it will be useful, |
|
||||
#| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
#| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
#| GNU General Public License for more details. |
|
||||
#| |
|
||||
#| You should have received a copy of the GNU General Public License |
|
||||
#| along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| @url : http://www.netzob.org |
|
||||
#| @contact : contact@netzob.org |
|
||||
#| @sponsors : Amossys, http://www.amossys.fr |
|
||||
#| Supélec, http://www.rennes.supelec.fr/ren/rd/cidre/ |
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Standard library imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
import unittest
|
||||
import sys
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Local application imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
from test_netzob import suite_Common
|
||||
from test_netzob import suite_Tutorials
|
||||
from test_netzob import suite_DocTests
|
||||
import test_netzob.test_public_api as test_public_api
|
||||
|
||||
#from test_netzob import suite_Import
|
||||
from common.xmlrunner import XMLTestRunner
|
||||
|
||||
|
||||
def getSuite():
|
||||
globalSuite = unittest.TestSuite()
|
||||
|
||||
modulesOfTests = []
|
||||
modulesOfSuites = [
|
||||
suite_DocTests, # tests extracted from docstrings (doctests)
|
||||
# suite_Common,
|
||||
# suite_Tutorials
|
||||
]
|
||||
modulesOfTests = [] #test_public_api]
|
||||
|
||||
# Add individual tests
|
||||
for module in modulesOfTests:
|
||||
globalSuite.addTests(unittest.TestLoader().loadTestsFromModule(module))
|
||||
|
||||
# Add suites
|
||||
for module in modulesOfSuites:
|
||||
globalSuite.addTests(module.getSuite())
|
||||
|
||||
return globalSuite
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Output is given through argument.
|
||||
# If no argument: output to stdout
|
||||
outputStdout = True
|
||||
|
||||
if (len(sys.argv) == 2):
|
||||
outputStdout = False
|
||||
reportFile = sys.argv[1]
|
||||
|
||||
# We retrieve the current test suite
|
||||
currentTestSuite = getSuite()
|
||||
|
||||
# We execute the test suite
|
||||
if outputStdout:
|
||||
runner = unittest.TextTestRunner()
|
||||
testResult = runner.run(currentTestSuite)
|
||||
else:
|
||||
File = open(reportFile, "w")
|
||||
reporter = XMLTestRunner(File)
|
||||
reporter.run(currentTestSuite)
|
||||
File.close()
|
||||
314
netzob-030/test/src/test_netzob/test_Alignment/test_Needleman.py
Normal file
314
netzob-030/test/src/test_netzob/test_Alignment/test_Needleman.py
Normal file
@@ -0,0 +1,314 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| 01001110 01100101 01110100 01111010 01101111 01100010 |
|
||||
#| |
|
||||
#| Netzob : Inferring communication protocols |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Copyright (C) 2011-2017 Georges Bossert and Frédéric Guihéry |
|
||||
#| This program is free software: you can redistribute it and/or modify |
|
||||
#| it under the terms of the GNU General Public License as published by |
|
||||
#| the Free Software Foundation, either version 3 of the License, or |
|
||||
#| (at your option) any later version. |
|
||||
#| |
|
||||
#| This program is distributed in the hope that it will be useful, |
|
||||
#| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
#| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
#| GNU General Public License for more details. |
|
||||
#| |
|
||||
#| You should have received a copy of the GNU General Public License |
|
||||
#| along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| @url : http://www.netzob.org |
|
||||
#| @contact : contact@netzob.org |
|
||||
#| @sponsors : Amossys, http://www.amossys.fr |
|
||||
#| Supélec, http://www.rennes.supelec.fr/ren/rd/cidre/ |
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Standard library imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
import uuid
|
||||
import time
|
||||
import random
|
||||
import string
|
||||
import logging
|
||||
from datetime import datetime
|
||||
|
||||
from common.NetzobTestCase import NetzobTestCase
|
||||
from netzob.Common.ExecutionContext import ExecutionContext
|
||||
from netzob.Model.RawMessage import RawMessage
|
||||
from netzob.Common.Symbol import Symbol
|
||||
from netzob.Common.Type.TypeConvertor import TypeConvertor
|
||||
from netzob.Common.Type.UnitSize import UnitSize
|
||||
from netzob.Common.Project import Project
|
||||
from netzob.Common.ProjectConfiguration import ProjectConfiguration
|
||||
from netzob.Inference.Vocabulary.Alignment.NeedlemanAndWunsch import NeedlemanAndWunsch
|
||||
|
||||
from netzob.all import *
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Local Imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
|
||||
class test_Needleman(NetzobTestCase):
|
||||
|
||||
def generateRandomString(self, min_len, max_len):
|
||||
return ''.join((random.choice(string.letters + string.digits) for _ in range(random.randint(min_len, max_len))))
|
||||
|
||||
def generateRandomBytes(self, min_len, max_len):
|
||||
result = ""
|
||||
nb = random.randint(min_len, max_len)
|
||||
|
||||
for i in range(0, nb):
|
||||
val = str(hex(random.randint(0, 255)))[2:]
|
||||
result += "0" * (len(val) % 2) + val
|
||||
return result
|
||||
|
||||
def emptyAlignmentCB(self, stage, percent, message):
|
||||
pass
|
||||
|
||||
def test_semanticAlignment_bug1(self):
|
||||
"""test_semanticAlignment_bug1:
|
||||
A bug on the semantic alignment has been identified which prevent
|
||||
the computation of a valid regex. This test verifies the bug is not comming back.
|
||||
@date 18/04/2013
|
||||
"""
|
||||
|
||||
firstname1 = "antoine"
|
||||
email1 = "thomas@hotmail.com"
|
||||
|
||||
firstname2 = "luc"
|
||||
email2 = "thomas@kotmail.com"
|
||||
|
||||
msg1 = RawMessage(uuid.uuid4(), None, TypeConvertor.stringToNetzobRaw("6" + firstname1 + "GAHFSHQS" + email1))
|
||||
msg2 = RawMessage(uuid.uuid4(), None, TypeConvertor.stringToNetzobRaw("3" + firstname2 + "CVSDHISD" + email2))
|
||||
|
||||
project = Project(uuid.uuid4(), "Experiment", datetime.now(), "")
|
||||
nwEngine = NeedlemanAndWunsch(8, project, False, None)
|
||||
symbol = Symbol(uuid.uuid4(), "Test", project)
|
||||
|
||||
symbol.addMessages([msg1, msg2])
|
||||
msg1.addSemanticTag("firstname", 2, 2 + len(firstname1) * 2)
|
||||
msg1.addSemanticTag("email", 2 + len(firstname1) * 2 + 16, 2 + len(firstname1) * 2 + 16 + len(email1) * 2)
|
||||
|
||||
msg2.addSemanticTag("firstname", 2, 2 + len(firstname2) * 2)
|
||||
msg2.addSemanticTag("email", 2 + len(firstname2) * 2 + 16, 2 + len(firstname2) * 2 + 16 + len(email2) * 2)
|
||||
|
||||
nwEngine.alignField(symbol.getField())
|
||||
symbol.getField().setFormat(Format.STRING)
|
||||
|
||||
print("Computed Regex : {0}".format(symbol.getRegex()))
|
||||
print("=======")
|
||||
print(symbol.getCells(True))
|
||||
|
||||
computedFields = symbol.getExtendedFields()
|
||||
self.assertTrue(len(computedFields) > 1, "Only one field has been computed which tells us something went wrong.")
|
||||
|
||||
def test_semanticAlignment_simple(self):
|
||||
"""test_semanticAlignment_simple:
|
||||
Test that messages with embedded semantic are efficiently aligned.
|
||||
Format : <random 10 bytes><random username><random 5 ASCII><random email>
|
||||
|
||||
Optimal Needleman & Wunsch Parameters :
|
||||
// Cost definitions for the alignment
|
||||
static const short int MATCH = 5;
|
||||
static const short int SEMANTIC_MATCH = 30;
|
||||
static const short int MISMATCH = -5;
|
||||
static const short int GAP = 0;
|
||||
static const short int BLEN = 10;
|
||||
// Consts for the definition of a mask
|
||||
static const unsigned char END = 2;
|
||||
static const unsigned char DIFFERENT = 1;
|
||||
static const unsigned char EQUAL = 0;
|
||||
"""
|
||||
project = Project(uuid.uuid4(), "Experiment", datetime.now(), "")
|
||||
symbol = Symbol(uuid.uuid4(), "Test", project)
|
||||
|
||||
nbMessage = 500
|
||||
usernames = []
|
||||
emails = []
|
||||
for iMessage in range(0, nbMessage):
|
||||
str_username = self.generateRandomString(4, 10)
|
||||
username = TypeConvertor.stringToNetzobRaw(str_username)
|
||||
usernames.append(str_username)
|
||||
|
||||
email_prefix = self.generateRandomString(4, 10)
|
||||
email_domain = self.generateRandomString(4, 10)
|
||||
email_extension = self.generateRandomString(2, 3)
|
||||
str_email = "{0}@{1}.{2}".format(email_prefix, email_domain, email_extension)
|
||||
emails.append(str_email)
|
||||
email = TypeConvertor.stringToNetzobRaw(str_email)
|
||||
random10Bytes = self.generateRandomBytes(10, 10)
|
||||
random5ASCII = TypeConvertor.stringToNetzobRaw(self.generateRandomString(5, 5))
|
||||
data = "{0}{1}{2}{3}".format(random10Bytes, username, random5ASCII, email)
|
||||
|
||||
message = RawMessage(uuid.uuid4(), None, data)
|
||||
message.addSemanticTag("username", len(random10Bytes), len(random10Bytes) + len(username))
|
||||
message.addSemanticTag("email", len(random10Bytes) + len(username) + len(random5ASCII), len(random10Bytes) + len(username) + len(random5ASCII) + len(email))
|
||||
|
||||
symbol.addMessage(message)
|
||||
|
||||
nwEngine = NeedlemanAndWunsch(8, project, False, None)
|
||||
nwEngine.alignField(symbol.getField())
|
||||
|
||||
symbol.getField().setFormat(Format.STRING)
|
||||
|
||||
print("Number of computed fields : {0}".format(len(symbol.getExtendedFields())))
|
||||
self.assertEqual(4, len(symbol.getExtendedFields()))
|
||||
nbValidMessages = 0
|
||||
|
||||
for message in symbol.getMessages():
|
||||
isValid = symbol.getField().isRegexValidForMessage(message)
|
||||
if isValid:
|
||||
nbValidMessages += 1
|
||||
self.assertTrue(isValid)
|
||||
|
||||
print(symbol.getCells())
|
||||
|
||||
print("Computed regex is valid for {0}/{1} messages.".format(nbValidMessages, len(symbol.getMessages())))
|
||||
|
||||
|
||||
# def test_randomAlignmentsWithTwoCenteredMessages(self):
|
||||
|
||||
# currentProject = Project(uuid.uuid4(), "test_randomAlignmentsWithTwoCenteredMessages", datetime.now(), "")
|
||||
|
||||
# doInternalSlick = currentProject.getConfiguration().getVocabularyInferenceParameter(ProjectConfiguration.VOCABULARY_DO_INTERNAL_SLICK)
|
||||
# defaultFormat = currentProject.getConfiguration().getVocabularyInferenceParameter(ProjectConfiguration.VOCABULARY_GLOBAL_FORMAT)
|
||||
# defaultUnitSize = 8
|
||||
|
||||
# # We generate 1000 random couples of data and try to align them
|
||||
# # Objectives: just test if it executes
|
||||
# nb_data = 2
|
||||
# nb_failed = 0
|
||||
# nb_success = 0
|
||||
# for i_test in range(0, nb_data):
|
||||
|
||||
# common_pattern = self.generateRandomString(30, 40)
|
||||
# # Generate the content of two messages
|
||||
# data1 = TypeConvertor.stringToNetzobRaw(self.generateRandomString(5, 10) + common_pattern + self.generateRandomString(5, 10))
|
||||
# data2 = TypeConvertor.stringToNetzobRaw(self.generateRandomString(5, 10) + common_pattern + self.generateRandomString(5, 10))
|
||||
# # Create the messages
|
||||
# message1 = RawMessage(str(uuid.uuid4()), str(time.time()), data1)
|
||||
# message2 = RawMessage(str(uuid.uuid4()), str(time.time()), data2)
|
||||
# # Create the symbol
|
||||
# symbol = Symbol(str(uuid.uuid4()), "test_randomAlignments#" + str(i_test), currentProject)
|
||||
# symbol.addMessage(message1)
|
||||
# symbol.addMessage(message2)
|
||||
# field = symbol.getField()
|
||||
|
||||
# # Starts the alignment process
|
||||
# alignmentProcess = NeedlemanAndWunsch(defaultUnitSize, currentProject, False, self.emptyAlignmentCB)
|
||||
# alignmentProcess.alignField(field)
|
||||
# print "-----------"+str(TypeConvertor.stringToNetzobRaw(common_pattern))
|
||||
# for message in symbol.getMessages():
|
||||
|
||||
# print message.applyAlignment()
|
||||
|
||||
# if not TypeConvertor.stringToNetzobRaw(common_pattern[:]) in field.getAlignment():
|
||||
# if self.debug is True:
|
||||
# print "Message 1: " + str(data1)
|
||||
# print "Message 2: " + str(data2)
|
||||
# print "Common pattern: " + TypeConvertor.stringToNetzobRaw(common_pattern)
|
||||
# print "Alignment: " + field.getAlignment()
|
||||
# print message1.applyAlignment()
|
||||
# print message2.applyAlignment()
|
||||
# nb_failed += 1
|
||||
# quit()
|
||||
# else:
|
||||
# nb_success += 1
|
||||
# if nb_failed > 0:
|
||||
# print "A number of " + str(nb_failed) + "/" + str(nb_data) + " alignment failed !"
|
||||
# self.assertEqual(0, nb_failed)
|
||||
# self.assertEqual(nb_success, nb_data)
|
||||
|
||||
|
||||
# def test_randomAlignmentsWithTwoPrefixedMessages(self):
|
||||
# workspace = self.getWorkspace()
|
||||
# currentProject = workspace.getProjects()[0]
|
||||
|
||||
# doInternalSlick = currentProject.getConfiguration().getVocabularyInferenceParameter(ProjectConfiguration.VOCABULARY_DO_INTERNAL_SLICK)
|
||||
# defaultFormat = currentProject.getConfiguration().getVocabularyInferenceParameter(ProjectConfiguration.VOCABULARY_GLOBAL_FORMAT)
|
||||
# defaultUnitSize = 8
|
||||
|
||||
# # We generate 1000 random couples of data and try to align them
|
||||
# # Objectives: just test if it executes
|
||||
# nb_data = 1000
|
||||
# nb_failed = 0
|
||||
# nb_success = 0
|
||||
# for i_test in range(0, nb_data):
|
||||
# common_pattern = self.generateRandomString(30, 40)
|
||||
# # Generate the content of two messages
|
||||
# data1 = TypeConvertor.stringToNetzobRaw(common_pattern + self.generateRandomString(5, 100))
|
||||
# data2 = TypeConvertor.stringToNetzobRaw(common_pattern + self.generateRandomString(5, 100))
|
||||
# # Create the messages
|
||||
# message1 = RawMessage(str(uuid.uuid4()), str(time.time()), data1)
|
||||
# message2 = RawMessage(str(uuid.uuid4()), str(time.time()), data2)
|
||||
# # Create the symbol
|
||||
# symbol = Symbol(str(uuid.uuid4()), "test_randomAlignments#" + str(i_test), currentProject)
|
||||
# symbol.addMessage(message1)
|
||||
# symbol.addMessage(message2)
|
||||
# field = symbol.getField()
|
||||
|
||||
# # Starts the alignment process
|
||||
# alignmentProcess = NeedlemanAndWunsch(defaultUnitSize, currentProject, False, self.emptyAlignmentCB)
|
||||
# alignmentProcess.alignField(field)
|
||||
|
||||
# if not TypeConvertor.stringToNetzobRaw(common_pattern[:]) in field.getAlignment():
|
||||
# if self.debug is True:
|
||||
# print "Message 1: " + str(data1)
|
||||
# print "Message 2: " + str(data2)
|
||||
# print "Common pattern: " + TypeConvertor.stringToNetzobRaw(common_pattern)
|
||||
# print "Alignment: " + field.getAlignment()
|
||||
# nb_failed += 1
|
||||
# else:
|
||||
# nb_success += 1
|
||||
# if nb_failed > 0:
|
||||
# print "A number of " + str(nb_failed) + "/" + str(nb_data) + " alignment failed !"
|
||||
# self.assertEqual(0, nb_failed)
|
||||
# self.assertEqual(nb_success, nb_data)
|
||||
|
||||
# def test_randomAlignmentsWithTwoSuffixedMessages(self):
|
||||
# workspace = self.getWorkspace()
|
||||
# currentProject = workspace.getProjects()[0]
|
||||
|
||||
# doInternalSlick = currentProject.getConfiguration().getVocabularyInferenceParameter(ProjectConfiguration.VOCABULARY_DO_INTERNAL_SLICK)
|
||||
# defaultFormat = currentProject.getConfiguration().getVocabularyInferenceParameter(ProjectConfiguration.VOCABULARY_GLOBAL_FORMAT)
|
||||
# defaultUnitSize = 8
|
||||
|
||||
# # We generate 1000 random couples of data and try to align them
|
||||
# # Objectives: just test if it executes
|
||||
# nb_data = 1000
|
||||
# nb_failed = 0
|
||||
# nb_success = 0
|
||||
# for i_test in range(0, nb_data):
|
||||
# common_pattern = self.generateRandomString(30, 40)
|
||||
# # Generate the content of two messages
|
||||
# data1 = TypeConvertor.stringToNetzobRaw(self.generateRandomString(5, 100) + common_pattern)
|
||||
# data2 = TypeConvertor.stringToNetzobRaw(self.generateRandomString(5, 100) + common_pattern)
|
||||
# # Create the messages
|
||||
# message1 = RawMessage(str(uuid.uuid4()), str(time.time()), data1)
|
||||
# message2 = RawMessage(str(uuid.uuid4()), str(time.time()), data2)
|
||||
# # Create the symbol
|
||||
# symbol = Symbol(str(uuid.uuid4()), "test_randomAlignments#" + str(i_test), currentProject)
|
||||
# symbol.addMessage(message1)
|
||||
# symbol.addMessage(message2)
|
||||
# field = symbol.getField()
|
||||
|
||||
# # Starts the alignment process
|
||||
# alignmentProcess = NeedlemanAndWunsch(defaultUnitSize, currentProject, False, self.emptyAlignmentCB)
|
||||
# alignmentProcess.alignField(field)
|
||||
|
||||
# if not TypeConvertor.stringToNetzobRaw(common_pattern[:]) in field.getAlignment():
|
||||
# if self.debug is True:
|
||||
# print "Message 1: " + str(data1)
|
||||
# print "Message 2: " + str(data2)
|
||||
# print "Common pattern: " + TypeConvertor.stringToNetzobRaw(common_pattern)
|
||||
# print "Alignment: " + field.getAlignment()
|
||||
# nb_failed += 1
|
||||
# else:
|
||||
# nb_success += 1
|
||||
# if nb_failed > 0:
|
||||
# print "A number of " + str(nb_failed) + "/" + str(nb_data) + " alignment failed !"
|
||||
# self.assertEqual(0, nb_failed)
|
||||
# self.assertEqual(nb_success, nb_data)
|
||||
@@ -0,0 +1,151 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| 01001110 01100101 01110100 01111010 01101111 01100010 |
|
||||
#| |
|
||||
#| Netzob : Inferring communication protocols |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Copyright (C) 2011-2017 Georges Bossert and Frédéric Guihéry |
|
||||
#| This program is free software: you can redistribute it and/or modify |
|
||||
#| it under the terms of the GNU General Public License as published by |
|
||||
#| the Free Software Foundation, either version 3 of the License, or |
|
||||
#| (at your option) any later version. |
|
||||
#| |
|
||||
#| This program is distributed in the hope that it will be useful, |
|
||||
#| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
#| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
#| GNU General Public License for more details. |
|
||||
#| |
|
||||
#| You should have received a copy of the GNU General Public License |
|
||||
#| along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| @url : http://www.netzob.org |
|
||||
#| @contact : contact@netzob.org |
|
||||
#| @sponsors : Amossys, http://www.amossys.fr |
|
||||
#| Supélec, http://www.rennes.supelec.fr/ren/rd/cidre/ |
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Standard library imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
import uuid
|
||||
import time
|
||||
import random
|
||||
import string
|
||||
import unittest
|
||||
import os
|
||||
import sys
|
||||
#insert in the path the directory where _libNeedleman.pyd is
|
||||
if os.name == 'nt':
|
||||
sys.path.insert(0, 'lib/libNeedleman/')
|
||||
|
||||
try:
|
||||
# Verify that libNeedleman is in the path
|
||||
from netzob import _libNeedleman
|
||||
except:
|
||||
# Else, assume the path is gotten from the 'python setup.py build' command
|
||||
arch = os.uname()[-1]
|
||||
python_version = sys.version[:3]
|
||||
build_lib_path = "../../../../build/lib.linux-" + arch + "-" + python_version
|
||||
sys.path.append(build_lib_path)
|
||||
|
||||
|
||||
sys.path.insert(0, 'src/')
|
||||
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Local Imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
from netzob.Inference.Vocabulary.Alignment.NeedlemanAndWunsch import NeedlemanAndWunsch
|
||||
from netzob.Common.Type.TypeConvertor import TypeConvertor
|
||||
from netzob.Model.RawMessage import RawMessage
|
||||
|
||||
|
||||
class test_NeedlemanInC(unittest.TestCase):
|
||||
|
||||
def generateRandomString(self, min_len, max_len):
|
||||
return ''.join((random.choice(string.letters + string.digits) for _ in range(random.randint(min_len, max_len))))
|
||||
|
||||
def test_deserialisationMessages(self):
|
||||
nbTest = 10
|
||||
alignmentSolution = NeedlemanAndWunsch(8)
|
||||
|
||||
for iTest in range(0, nbTest):
|
||||
messages = []
|
||||
# Generate a random number of message to serialize
|
||||
nbMessage = random.randint(2, 500)
|
||||
for iMessage in range(0, nbMessage):
|
||||
data = TypeConvertor.stringToNetzobRaw(self.generateRandomString(5, 500))
|
||||
message = RawMessage(str(uuid.uuid4()), str(time.time()), data)
|
||||
messages.append(message)
|
||||
|
||||
nbDeserializedTest = alignmentSolution.deserializeMessages(messages)
|
||||
self.assertEqual(nbMessage, nbDeserializedTest)
|
||||
|
||||
def test_AlignementOfMessages(self):
|
||||
alignmentSolution = NeedlemanAndWunsch(4)
|
||||
nbTest = 100
|
||||
|
||||
for iTest in range(0, nbTest):
|
||||
messages = []
|
||||
# Generate a random number of message to serialize
|
||||
nbMessage = random.randint(2, 50)
|
||||
for iMessage in range(0, nbMessage):
|
||||
data = TypeConvertor.stringToNetzobRaw("bonjour" + self.generateRandomString(5, 30) + ", tout va bien ?")
|
||||
message = RawMessage(str(uuid.uuid4()), str(time.time()), data)
|
||||
messages.append(message)
|
||||
|
||||
(alignment, scores) = alignmentSolution.align(False, messages)
|
||||
(score1, score2, score3) = scores
|
||||
(alignmentBis, scoresBis) = alignmentSolution.align(True, messages)
|
||||
(scoreBis1, scoreBis2, scoreBis3) = scoresBis
|
||||
print(alignment)
|
||||
print(alignmentBis)
|
||||
|
||||
self.assertGreaterEqual(scoreBis1, score1)
|
||||
self.assertGreaterEqual(scoreBis1, 90)
|
||||
|
||||
def test_alignmentOfEquivalentMessages(self):
|
||||
alignmentSolution = NeedlemanAndWunsch(8)
|
||||
nbTest = 1000
|
||||
for i_test in range(0, nbTest):
|
||||
common_pattern = self.generateRandomString(30, 40)
|
||||
# Generate the content of two messages
|
||||
data1 = TypeConvertor.stringToNetzobRaw(common_pattern)
|
||||
data2 = TypeConvertor.stringToNetzobRaw(common_pattern)
|
||||
# Create the messages
|
||||
message1 = RawMessage(str(uuid.uuid4()), str(time.time()), data1)
|
||||
message2 = RawMessage(str(uuid.uuid4()), str(time.time()), data2)
|
||||
|
||||
(scores, alignment) = alignmentSolution.alignTwoMessages(False, message1, message2)
|
||||
(score1, score2, score3) = scores
|
||||
self.assertEqual(score1, 100.0)
|
||||
self.assertEqual(score2, 100.0)
|
||||
self.assertEqual(score3, 100.0)
|
||||
|
||||
(scores, alignment) = alignmentSolution.alignTwoMessages(True, message1, message2)
|
||||
(score1, score2, score3) = scores
|
||||
self.assertEqual(score1, 100.0)
|
||||
self.assertEqual(score2, 100.0)
|
||||
self.assertEqual(score3, 100.0)
|
||||
|
||||
def test_alignmentOfAlmostEquivalentMessages(self):
|
||||
alignmentSolution = NeedlemanAndWunsch(8)
|
||||
nbTest = 1000
|
||||
for i_test in range(0, nbTest):
|
||||
common_pattern_before = self.generateRandomString(30, 40)
|
||||
common_pattern_after = self.generateRandomString(30, 40)
|
||||
# Generate the content of two messages
|
||||
data1 = TypeConvertor.stringToNetzobRaw(common_pattern_before + "hercule" + common_pattern_after)
|
||||
data2 = TypeConvertor.stringToNetzobRaw(common_pattern_before + "thomas" + common_pattern_after)
|
||||
# Create the messages
|
||||
message1 = RawMessage(str(uuid.uuid4()), str(time.time()), data1)
|
||||
message2 = RawMessage(str(uuid.uuid4()), str(time.time()), data2)
|
||||
|
||||
(scores, alignment) = alignmentSolution.alignTwoMessages(False, message1, message2)
|
||||
(score1, score2, score3) = scores
|
||||
(scoresBis, alignment2) = alignmentSolution.alignTwoMessages(True, message1, message2)
|
||||
(scoreBis1, scoreBis2, scoreBis3) = scoresBis
|
||||
|
||||
self.assertGreater(scoreBis1, score1)
|
||||
self.assertGreater(scoreBis1, 95)
|
||||
145
netzob-030/test/src/test_netzob/test_Alignment/test_UPGMA.py
Normal file
145
netzob-030/test/src/test_netzob/test_Alignment/test_UPGMA.py
Normal file
@@ -0,0 +1,145 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| 01001110 01100101 01110100 01111010 01101111 01100010 |
|
||||
#| |
|
||||
#| Netzob : Inferring communication protocols |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Copyright (C) 2011-2017 Georges Bossert and Frédéric Guihéry |
|
||||
#| This program is free software: you can redistribute it and/or modify |
|
||||
#| it under the terms of the GNU General Public License as published by |
|
||||
#| the Free Software Foundation, either version 3 of the License, or |
|
||||
#| (at your option) any later version. |
|
||||
#| |
|
||||
#| This program is distributed in the hope that it will be useful, |
|
||||
#| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
#| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
#| GNU General Public License for more details. |
|
||||
#| |
|
||||
#| You should have received a copy of the GNU General Public License |
|
||||
#| along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| @url : http://www.netzob.org |
|
||||
#| @contact : contact@netzob.org |
|
||||
#| @sponsors : Amossys, http://www.amossys.fr |
|
||||
#| Supélec, http://www.rennes.supelec.fr/ren/rd/cidre/ |
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Standard library imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
import uuid
|
||||
import time
|
||||
import random
|
||||
import string
|
||||
import unittest
|
||||
|
||||
from netzob.Common.ExecutionContext import ExecutionContext
|
||||
from netzob.Model.RawMessage import RawMessage
|
||||
from netzob.Common.Symbol import Symbol
|
||||
from netzob.Common.Type.TypeConvertor import TypeConvertor
|
||||
from netzob.Inference.Vocabulary.Alignment.UPGMA import UPGMA
|
||||
from netzob.Common.Type.Format import Format
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Local Imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
|
||||
class test_UPGMA(unittest.TestCase):
|
||||
|
||||
def generateRandomString(self, min_len, max_len):
|
||||
return ''.join((random.choice(string.letters + string.digits) for _ in range(random.randint(min_len, max_len))))
|
||||
|
||||
def test_executingClustering(self):
|
||||
|
||||
# We create 6 messages of 2 group
|
||||
|
||||
# group1
|
||||
originalSymbol1 = Symbol(str(uuid.uuid4()), "TestSymbol", None)
|
||||
message1 = RawMessage(str(uuid.uuid4()), str(time.time()), TypeConvertor.stringToNetzobRaw("bonjour " + self.generateRandomString(20, 30) + " comment vas-tu ?"))
|
||||
originalSymbol1.addMessage(message1)
|
||||
|
||||
originalSymbol2 = Symbol(str(uuid.uuid4()), "TestSymbol2", None)
|
||||
message2 = RawMessage(str(uuid.uuid4()), str(time.time()), TypeConvertor.stringToNetzobRaw("bonjour " + self.generateRandomString(20, 30) + " comment vas-tu ?"))
|
||||
originalSymbol2.addMessage(message2)
|
||||
|
||||
originalSymbol3 = Symbol(str(uuid.uuid4()), "TestSymbol3", None)
|
||||
message3 = RawMessage(str(uuid.uuid4()), str(time.time()), TypeConvertor.stringToNetzobRaw("bonjour " + self.generateRandomString(20, 30) + " comment vas-tu ?"))
|
||||
originalSymbol3.addMessage(message3)
|
||||
|
||||
# group2
|
||||
originalSymbol4 = Symbol(str(uuid.uuid4()), "TestSymbol4", None)
|
||||
message4 = RawMessage(str(uuid.uuid4()), str(time.time()), TypeConvertor.stringToNetzobRaw("salut à toi " + self.generateRandomString(10, 15) + " what's up ?"))
|
||||
originalSymbol4.addMessage(message4)
|
||||
|
||||
originalSymbol5 = Symbol(str(uuid.uuid4()), "TestSymbol5", None)
|
||||
message5 = RawMessage(str(uuid.uuid4()), str(time.time()), TypeConvertor.stringToNetzobRaw("salut à toi " + self.generateRandomString(10, 15) + " what's up ?"))
|
||||
originalSymbol5.addMessage(message5)
|
||||
|
||||
originalSymbol6 = Symbol(str(uuid.uuid4()), "TestSymbol6", None)
|
||||
message6 = RawMessage(str(uuid.uuid4()), str(time.time()), TypeConvertor.stringToNetzobRaw("salut à toi " + self.generateRandomString(10, 15) + " what's up ?"))
|
||||
originalSymbol6.addMessage(message6)
|
||||
|
||||
symbols = [originalSymbol1, originalSymbol2, originalSymbol3, originalSymbol4, originalSymbol5, originalSymbol6]
|
||||
|
||||
# Start the clustering
|
||||
clusteringSolution = UPGMA(None, symbols, True, 100, 90, True, Format.ASCII)
|
||||
result = clusteringSolution.executeClustering()
|
||||
|
||||
for symbol in result:
|
||||
print("Symbol: " + str(symbol.getName()))
|
||||
for m in symbol.getMessages():
|
||||
print(" + " + str(m.getStringData()))
|
||||
|
||||
def test_executingClusteringWithOrphanReduction(self):
|
||||
|
||||
# We create 6 messages of 2 group
|
||||
|
||||
# group1
|
||||
originalSymbol1 = Symbol(str(uuid.uuid4()), "TestSymbol", None)
|
||||
message1 = RawMessage(str(uuid.uuid4()), str(time.time()), TypeConvertor.stringToNetzobRaw("bonjour " + self.generateRandomString(200, 1000)))
|
||||
originalSymbol1.addMessage(message1)
|
||||
|
||||
originalSymbol2 = Symbol(str(uuid.uuid4()), "TestSymbol2", None)
|
||||
message2 = RawMessage(str(uuid.uuid4()), str(time.time()), TypeConvertor.stringToNetzobRaw("bonjour " + self.generateRandomString(200, 1000)))
|
||||
originalSymbol2.addMessage(message2)
|
||||
|
||||
originalSymbol3 = Symbol(str(uuid.uuid4()), "TestSymbol3", None)
|
||||
message3 = RawMessage(str(uuid.uuid4()), str(time.time()), TypeConvertor.stringToNetzobRaw("bonjour " + self.generateRandomString(200, 1000)))
|
||||
originalSymbol3.addMessage(message3)
|
||||
|
||||
# group2
|
||||
originalSymbol4 = Symbol(str(uuid.uuid4()), "TestSymbol4", None)
|
||||
message4 = RawMessage(str(uuid.uuid4()), str(time.time()), TypeConvertor.stringToNetzobRaw("salut " + self.generateRandomString(200, 1000)))
|
||||
originalSymbol4.addMessage(message4)
|
||||
|
||||
originalSymbol5 = Symbol(str(uuid.uuid4()), "TestSymbol5", None)
|
||||
message5 = RawMessage(str(uuid.uuid4()), str(time.time()), TypeConvertor.stringToNetzobRaw("salut " + self.generateRandomString(200, 1000)))
|
||||
originalSymbol5.addMessage(message5)
|
||||
|
||||
originalSymbol6 = Symbol(str(uuid.uuid4()), "TestSymbol6", None)
|
||||
message6 = RawMessage(str(uuid.uuid4()), str(time.time()), TypeConvertor.stringToNetzobRaw("salut " + self.generateRandomString(200, 1000)))
|
||||
originalSymbol6.addMessage(message6)
|
||||
|
||||
symbols = [originalSymbol1, originalSymbol2, originalSymbol3, originalSymbol4, originalSymbol5, originalSymbol6]
|
||||
|
||||
# Start the clustering
|
||||
clusteringSolution = UPGMA(None, symbols, True, 100, 80, True, Format.ASCII)
|
||||
resultBeforeOrphan = clusteringSolution.executeClustering()
|
||||
resultAfterOrphan = clusteringSolution.executeOrphanReduction()
|
||||
|
||||
if (len(resultAfterOrphan) < len(resultBeforeOrphan)):
|
||||
print("Before Orphan Reduction: ")
|
||||
for symbol in resultBeforeOrphan:
|
||||
print("Symbol: " + str(symbol.getName()))
|
||||
for m in symbol.getMessages():
|
||||
print(" + " + str(m.getStringData()))
|
||||
|
||||
print("After Orphan Reduction: ")
|
||||
for symbol in resultAfterOrphan:
|
||||
print("Symbol: " + str(symbol.getName()))
|
||||
for m in symbol.getMessages():
|
||||
print(" + " + str(m.getStringData()))
|
||||
|
||||
self.assertGreaterEqual(len(resultBeforeOrphan), len(resultAfterOrphan))
|
||||
@@ -0,0 +1,98 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| 01001110 01100101 01110100 01111010 01101111 01100010 |
|
||||
#| |
|
||||
#| Netzob : Inferring communication protocols |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Copyright (C) 2011-2017 Georges Bossert and Frédéric Guihéry |
|
||||
#| This program is free software: you can redistribute it and/or modify |
|
||||
#| it under the terms of the GNU General Public License as published by |
|
||||
#| the Free Software Foundation, either version 3 of the License, or |
|
||||
#| (at your option) any later version. |
|
||||
#| |
|
||||
#| This program is distributed in the hope that it will be useful, |
|
||||
#| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
#| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
#| GNU General Public License for more details. |
|
||||
#| |
|
||||
#| You should have received a copy of the GNU General Public License |
|
||||
#| along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| @url : http://www.netzob.org |
|
||||
#| @contact : contact@netzob.org |
|
||||
#| @sponsors : Amossys, http://www.amossys.fr |
|
||||
#| Supélec, http://www.rennes.supelec.fr/ren/rd/cidre/ |
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Standard library imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
import uuid
|
||||
import time
|
||||
import random
|
||||
import string
|
||||
import unittest
|
||||
import os
|
||||
import sys
|
||||
|
||||
# insert in the path the directory where _libNeedleman.pyd is
|
||||
if os.name == 'nt':
|
||||
sys.path.insert(0, 'lib/libNeedleman/')
|
||||
|
||||
try:
|
||||
# Verify that libNeedleman is in the path
|
||||
from netzob import _libNeedleman
|
||||
except:
|
||||
# Else, assume the path is gotten from the 'python setup.py build' command
|
||||
arch = os.uname()[-1]
|
||||
python_version = sys.version[:3]
|
||||
build_lib_path = "../../../../build/lib.linux-" + arch + "-" + python_version
|
||||
sys.path.append(build_lib_path)
|
||||
|
||||
from netzob.Common.ExecutionContext import ExecutionContext
|
||||
from netzob.Model.RawMessage import RawMessage
|
||||
from netzob.Common.Symbol import Symbol
|
||||
from netzob.Common.Type.TypeConvertor import TypeConvertor
|
||||
from netzob.Inference.Vocabulary.Alignment.UPGMA import UPGMA
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Local Imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
|
||||
class test_UPGMAInC(unittest.TestCase):
|
||||
|
||||
def generateRandomString(self, min_len, max_len):
|
||||
return ''.join((random.choice(string.letters + string.digits) for _ in range(random.randint(min_len, max_len))))
|
||||
|
||||
def test_deserialisationGroups(self):
|
||||
print("start")
|
||||
|
||||
symbols = []
|
||||
nbSymbol = random.randint(2, 50)
|
||||
|
||||
for iSymbol in range(0, nbSymbol):
|
||||
# We create 6 messages of 2 group
|
||||
originalSymbol = Symbol(str(uuid.uuid4()), "TestSymbol", None)
|
||||
# group1
|
||||
message1 = RawMessage(str(uuid.uuid4()), str(time.time()), TypeConvertor.stringToNetzobRaw("bonjour " + self.generateRandomString(20, 30) + " comment vas-tu ?"))
|
||||
message2 = RawMessage(str(uuid.uuid4()), str(time.time()), TypeConvertor.stringToNetzobRaw("bonjour " + self.generateRandomString(20, 30) + " comment vas-tu ?"))
|
||||
message3 = RawMessage(str(uuid.uuid4()), str(time.time()), TypeConvertor.stringToNetzobRaw("bonjour " + self.generateRandomString(20, 30) + " comment vas-tu ?"))
|
||||
# group2
|
||||
message4 = RawMessage(str(uuid.uuid4()), str(time.time()), TypeConvertor.stringToNetzobRaw("salut à toi " + self.generateRandomString(10, 15) + " what's up ?"))
|
||||
message5 = RawMessage(str(uuid.uuid4()), str(time.time()), TypeConvertor.stringToNetzobRaw("salut à toi " + self.generateRandomString(10, 15) + " what's up ?"))
|
||||
message6 = RawMessage(str(uuid.uuid4()), str(time.time()), TypeConvertor.stringToNetzobRaw("salut à toi " + self.generateRandomString(10, 15) + " what's up ?"))
|
||||
|
||||
originalSymbol.addMessage(message1)
|
||||
originalSymbol.addMessage(message2)
|
||||
originalSymbol.addMessage(message3)
|
||||
originalSymbol.addMessage(message4)
|
||||
originalSymbol.addMessage(message5)
|
||||
originalSymbol.addMessage(message6)
|
||||
symbols.append(originalSymbol)
|
||||
|
||||
# Start the clustering
|
||||
clusteringSolution = UPGMA(None, [originalSymbol], True, 100, 90, True)
|
||||
result = clusteringSolution.deserializeGroups(symbols)
|
||||
self.assertEqual(result, len(symbols))
|
||||
107
netzob-030/test/src/test_netzob/test_Checksums/test_Checksums.py
Normal file
107
netzob-030/test/src/test_netzob/test_Checksums/test_Checksums.py
Normal file
@@ -0,0 +1,107 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| 01001110 01100101 01110100 01111010 01101111 01100010 |
|
||||
#| |
|
||||
#| Netzob : Inferring communication protocols |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Copyright (C) 2011-2017 Georges Bossert and Frédéric Guihéry |
|
||||
#| This program is free software: you can redistribute it and/or modify |
|
||||
#| it under the terms of the GNU General Public License as published by |
|
||||
#| the Free Software Foundation, either version 3 of the License, or |
|
||||
#| (at your option) any later version. |
|
||||
#| |
|
||||
#| This program is distributed in the hope that it will be useful, |
|
||||
#| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
#| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
#| GNU General Public License for more details. |
|
||||
#| |
|
||||
#| You should have received a copy of the GNU General Public License |
|
||||
#| along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| @url : http://www.netzob.org |
|
||||
#| @contact : contact@netzob.org |
|
||||
#| @sponsors : Amossys, http://www.amossys.fr |
|
||||
#| Supélec, http://www.rennes.supelec.fr/ren/rd/cidre/ |
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Standard library imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
import unittest
|
||||
from netzob.all import *
|
||||
import os
|
||||
|
||||
|
||||
class test_Checksums(unittest.TestCase):
|
||||
|
||||
def parse_file(self, file, checksum_class):
|
||||
file_path = os.path.join("test", "resources", "test_netzob", "test_Checksums", file)
|
||||
fd = open(file_path, 'r')
|
||||
msg = ""
|
||||
given_len = 0
|
||||
for line in fd:
|
||||
if 'Len =' in line:
|
||||
given_len = int(line[6:-1])
|
||||
elif 'Msg =' in line:
|
||||
msg = line[6:-1]
|
||||
elif 'CS =' in line:
|
||||
if len(msg) != given_len:
|
||||
msg = msg[0 : given_len]
|
||||
self.check_res(msg, line[5:-1], checksum_class)
|
||||
msg = ""
|
||||
given_len = 0
|
||||
|
||||
def check_res(self, msg, cs, checksum_class):
|
||||
b = msg.encode()
|
||||
f1 = Field(Raw(b))
|
||||
f2 = Field(checksum_class([f1]))
|
||||
s = Symbol(fields = [f1, f2])
|
||||
tmp = s.specialize()[len(b):]
|
||||
rep = tmp[::-1].hex()
|
||||
self.assertEqual(rep, cs)
|
||||
|
||||
def test_CRC16_implementation(self):
|
||||
file = "CRC16_tests.txt"
|
||||
checksum_class = CRC16
|
||||
self.parse_file(file, checksum_class)
|
||||
|
||||
def test_CRC16DNP_implementation(self):
|
||||
file = "CRC16DNP_tests.txt"
|
||||
checksum_class = CRC16DNP
|
||||
self.parse_file(file, checksum_class)
|
||||
|
||||
def test_CRC16Kermit_implementation(self):
|
||||
file = "CRC16Kermit_tests.txt"
|
||||
checksum_class = CRC16Kermit
|
||||
self.parse_file(file, checksum_class)
|
||||
|
||||
def test_CRC16SICK_implementation(self):
|
||||
file = "CRC16SICK_tests.txt"
|
||||
checksum_class = CRC16SICK
|
||||
self.parse_file(file, checksum_class)
|
||||
|
||||
def test_CRC32_implementation(self):
|
||||
import binascii, zlib
|
||||
|
||||
rand_str = ['42', 'azerty', 'f,efierjee', 'aqwzsxedc',
|
||||
'epgkrtgrtpg', '123456789', 'abcdefghijklmnopqrstuvwxyz', 'f54erf6er4ferfer54f4e56fe',
|
||||
'apc,tjdoped5r9654*ddjv,ror_çggrgt6845zeza2v84eg', 'gr4e56hrtj48ht4trjz84eaz48t48ui94loim45q31cf2qsd81a9fafekferef,9zfezgz4a98f']
|
||||
|
||||
for msg in rand_str:
|
||||
msg = msg.encode()
|
||||
f1 = Field(Raw(msg))
|
||||
f2 = Field(CRC32([f1]))
|
||||
s = Symbol(fields = [f1, f2])
|
||||
tmp = s.specialize()[len(msg):]
|
||||
rep = tmp[::-1].hex()
|
||||
|
||||
cs_ref = hex(binascii.crc32(msg))[2:]
|
||||
cs_ref2 = hex(zlib.crc32(msg))[2:]
|
||||
self.assertEqual(rep, cs_ref)
|
||||
self.assertEqual(rep, cs_ref2)
|
||||
|
||||
def test_CRC_CCITT_implementation(self):
|
||||
file = "CRC_CCITT_tests.txt"
|
||||
checksum_class = CRCCCITT
|
||||
self.parse_file(file, checksum_class)
|
||||
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| 01001110 01100101 01110100 01111010 01101111 01100010 |
|
||||
#| |
|
||||
#| Netzob : Inferring communication protocols |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Copyright (C) 2011-2017 Georges Bossert and Frédéric Guihéry |
|
||||
#| This program is free software: you can redistribute it and/or modify |
|
||||
#| it under the terms of the GNU General Public License as published by |
|
||||
#| the Free Software Foundation, either version 3 of the License, or |
|
||||
#| (at your option) any later version. |
|
||||
#| |
|
||||
#| This program is distributed in the hope that it will be useful, |
|
||||
#| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
#| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
#| GNU General Public License for more details. |
|
||||
#| |
|
||||
#| You should have received a copy of the GNU General Public License |
|
||||
#| along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| @url : http://www.netzob.org |
|
||||
#| @contact : contact@netzob.org |
|
||||
#| @sponsors : Amossys, http://www.amossys.fr |
|
||||
#| Supélec, http://www.rennes.supelec.fr/ren/rd/cidre/ |
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Standard library imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
import unittest
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Local application imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
|
||||
def getSuite():
|
||||
functionsSuite = unittest.TestSuite()
|
||||
return functionsSuite
|
||||
41
netzob-030/test/src/test_netzob/test_Common/suite_Type.py
Normal file
41
netzob-030/test/src/test_netzob/test_Common/suite_Type.py
Normal file
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| 01001110 01100101 01110100 01111010 01101111 01100010 |
|
||||
#| |
|
||||
#| Netzob : Inferring communication protocols |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Copyright (C) 2011-2017 Georges Bossert and Frédéric Guihéry |
|
||||
#| This program is free software: you can redistribute it and/or modify |
|
||||
#| it under the terms of the GNU General Public License as published by |
|
||||
#| the Free Software Foundation, either version 3 of the License, or |
|
||||
#| (at your option) any later version. |
|
||||
#| |
|
||||
#| This program is distributed in the hope that it will be useful, |
|
||||
#| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
#| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
#| GNU General Public License for more details. |
|
||||
#| |
|
||||
#| You should have received a copy of the GNU General Public License |
|
||||
#| along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| @url : http://www.netzob.org |
|
||||
#| @contact : contact@netzob.org |
|
||||
#| @sponsors : Amossys, http://www.amossys.fr |
|
||||
#| Supélec, http://www.rennes.supelec.fr/ren/rd/cidre/ |
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Standard library imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
import unittest
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Local application imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
|
||||
def getSuite():
|
||||
typeSuite = unittest.TestSuite()
|
||||
return typeSuite
|
||||
@@ -0,0 +1,43 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| 01001110 01100101 01110100 01111010 01101111 01100010 |
|
||||
#| |
|
||||
#| Netzob : Inferring communication protocols |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Copyright (C) 2011-2017 Georges Bossert and Frédéric Guihéry |
|
||||
#| This program is free software: you can redistribute it and/or modify |
|
||||
#| it under the terms of the GNU General Public License as published by |
|
||||
#| the Free Software Foundation, either version 3 of the License, or |
|
||||
#| (at your option) any later version. |
|
||||
#| |
|
||||
#| This program is distributed in the hope that it will be useful, |
|
||||
#| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
#| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
#| GNU General Public License for more details. |
|
||||
#| |
|
||||
#| You should have received a copy of the GNU General Public License |
|
||||
#| along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| @url : http://www.netzob.org |
|
||||
#| @contact : contact@netzob.org |
|
||||
#| @sponsors : Amossys, http://www.amossys.fr |
|
||||
#| Supélec, http://www.rennes.supelec.fr/ren/rd/cidre/ |
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Standard library imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
import unittest
|
||||
from netzob.Common.ExecutionContext import ExecutionContext
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Local Imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
|
||||
class test_ExecutionContext(unittest.TestCase):
|
||||
|
||||
def test_getCurrentProcesses(self):
|
||||
current = ExecutionContext.getCurrentProcesses()
|
||||
self.assertGreater(len(current), 5)
|
||||
123
netzob-030/test/src/test_netzob/test_Common/test_Field.py
Normal file
123
netzob-030/test/src/test_netzob/test_Common/test_Field.py
Normal file
@@ -0,0 +1,123 @@
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| 01001110 01100101 01110100 01111010 01101111 01100010 |
|
||||
#| |
|
||||
#| Netzob : Inferring communication protocols |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Copyright (C) 2011-2017 Georges Bossert and Frédéric Guihéry |
|
||||
#| This program is free software: you can redistribute it and/or modify |
|
||||
#| it under the terms of the GNU General Public License as published by |
|
||||
#| the Free Software Foundation, either version 3 of the License, or |
|
||||
#| (at your option) any later version. |
|
||||
#| |
|
||||
#| This program is distributed in the hope that it will be useful, |
|
||||
#| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
#| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
#| GNU General Public License for more details. |
|
||||
#| |
|
||||
#| You should have received a copy of the GNU General Public License |
|
||||
#| along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| @url : http://www.netzob.org |
|
||||
#| @contact : contact@netzob.org |
|
||||
#| @sponsors : Amossys, http://www.amossys.fr |
|
||||
#| Supélec, http://www.rennes.supelec.fr/ren/rd/cidre/ |
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| File contributors : |
|
||||
#| - Georges Bossert <georges.bossert (a) supelec.fr> |
|
||||
#| - Frédéric Guihéry <frederic.guihery (a) amossys.fr> |
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Standard library imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
import unittest
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Local Imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
from netzob.all import *
|
||||
|
||||
|
||||
class test_Field(unittest.TestCase):
|
||||
|
||||
def test_createField(self):
|
||||
f = Field()
|
||||
self.assertNotEqual(f, None)
|
||||
self.assertEqual(f.name, None)
|
||||
|
||||
f = Field(name="Test")
|
||||
self.assertNotEqual(f, None)
|
||||
|
||||
f = Field(Raw(size=(5, 150)), name="Default")
|
||||
self.assertNotEqual(f, None)
|
||||
self.assertEqual(f.name, "Default")
|
||||
|
||||
|
||||
## Encoding (format, unitsize, sign and endianness)
|
||||
def test_format(self):
|
||||
f = Field()
|
||||
f.encodingFunctions.add(TypeEncodingFunction(ASCII))
|
||||
self.assertEqual(len(f.encodingFunctions), 1)
|
||||
|
||||
def test_unitSize(self):
|
||||
f = Field()
|
||||
f.setUnitSize(UnitSize.BIT)
|
||||
self.assertEqual(f.getUnitSize(), UnitSize.BIT)
|
||||
|
||||
def test_sign(self):
|
||||
f = Field()
|
||||
f.setSign(Sign.SIGNED)
|
||||
self.assertEqual(f.getSign(), Sign.SIGNED)
|
||||
|
||||
def test_endianness(self):
|
||||
f = Field()
|
||||
f.setEndianness(Endianness.LITTLE)
|
||||
self.assertEqual(f.getEndianness(), Endianness.LITTLE)
|
||||
|
||||
## Functions (visualization, encoding and transformation)
|
||||
def test_visualizationFunction(self):
|
||||
f = Field()
|
||||
func = TextColorFunction("My function", "red")
|
||||
f.addVisualizationFunction(func)
|
||||
self.assertEqual(getVisualizationFunctions(), [func])
|
||||
|
||||
f.removeVisualizationFunction(func)
|
||||
self.assertEqual(getVisualizationFunctions(), [])
|
||||
|
||||
func2 = TextColorFunction("My other function", "red")
|
||||
f.addVisualizationFunction(func2)
|
||||
f.cleanVisualizationFunctions()
|
||||
self.assertEqual(getVisualizationFunctions(), [])
|
||||
|
||||
def test_encodingFunction(self):
|
||||
f = Field()
|
||||
func = FormatFunction("My function", Format.STRING, UnitSize.BIT, Endianness.LITTLE, Sign.SIGNED)
|
||||
f.addEncodingFunction(func)
|
||||
self.assertEqual(getEncodingFunctions(), [func])
|
||||
|
||||
f.removeEncodingFunction(func)
|
||||
self.assertEqual(getEncodingFunctions(), [])
|
||||
|
||||
func2 = FormatFunction("My other function", Format.STRING, UnitSize.BIT, Endianness.LITTLE, Sign.SIGNED)
|
||||
f.addEncodingFunction(func2)
|
||||
f.cleanEncodingFunctions()
|
||||
self.assertEqual(getEncodingFunctions(), [])
|
||||
|
||||
def test_transformationFunction(self):
|
||||
f = Field()
|
||||
func = Base64Function("My function")
|
||||
f.addTransformationFunction(func)
|
||||
self.assertEqual(getTransformationFunctions(), [func])
|
||||
|
||||
f.removeTransformationFunction(func)
|
||||
self.assertEqual(getTransformationFunctions(), [])
|
||||
|
||||
func2 = Base64Function("My other function")
|
||||
f.addTransformationFunction(func2)
|
||||
f.cleanTransformationFunctions()
|
||||
self.assertEqual(getTransformationFunctions(), [])
|
||||
@@ -0,0 +1,125 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| 01001110 01100101 01110100 01111010 01101111 01100010 |
|
||||
#| |
|
||||
#| Netzob : Inferring communication protocols |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Copyright (C) 2011-2017 Georges Bossert and Frédéric Guihéry |
|
||||
#| This program is free software: you can redistribute it and/or modify |
|
||||
#| it under the terms of the GNU General Public License as published by |
|
||||
#| the Free Software Foundation, either version 3 of the License, or |
|
||||
#| (at your option) any later version. |
|
||||
#| |
|
||||
#| This program is distributed in the hope that it will be useful, |
|
||||
#| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
#| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
#| GNU General Public License for more details. |
|
||||
#| |
|
||||
#| You should have received a copy of the GNU General Public License |
|
||||
#| along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| @url : http://www.netzob.org |
|
||||
#| @contact : contact@netzob.org |
|
||||
#| @sponsors : Amossys, http://www.amossys.fr |
|
||||
#| Supélec, http://www.rennes.supelec.fr/ren/rd/cidre/ |
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
from netzob.Common.Functions.Encoding.FormatFunction import FormatFunction
|
||||
from netzob.Common.Type.Endianness import Endianness
|
||||
from netzob.Common.Type.Format import Format
|
||||
from netzob.Common.Type.Sign import Sign
|
||||
from netzob.Common.Type.TypeConvertor import TypeConvertor
|
||||
from netzob.Common.Type.UnitSize import UnitSize
|
||||
from common.NetzobTestCase import NetzobTestCase
|
||||
|
||||
|
||||
class test_Encoding(NetzobTestCase):
|
||||
|
||||
# UnitSize.NONE
|
||||
def test_HEX(self):
|
||||
ff = FormatFunction("Field Format Encoding", Format.HEX, UnitSize.NONE, Endianness.BIG, Sign.UNSIGNED)
|
||||
res = ff.apply("30313233343536373839")
|
||||
self.assertEqual(res, "30313233343536373839")
|
||||
|
||||
def test_STRING(self):
|
||||
ff = FormatFunction("Field Format Encoding", Format.STRING, UnitSize.NONE, Endianness.BIG, Sign.UNSIGNED)
|
||||
res = ff.apply("30313233343536373839")
|
||||
self.assertEqual(res, "0123456789")
|
||||
|
||||
def test_DECIMAL_4BITS(self):
|
||||
ff = FormatFunction("Field Format Encoding", Format.DECIMAL, UnitSize.BITS4, Endianness.BIG, Sign.UNSIGNED)
|
||||
res = ff.apply("abcdef")
|
||||
self.assertEqual(res, "10 11 12 13 14 15")
|
||||
|
||||
def test_DECIMAL_8BITS(self):
|
||||
ff = FormatFunction("Field Format Encoding", Format.DECIMAL, UnitSize.BITS8, Endianness.BIG, Sign.UNSIGNED)
|
||||
res = ff.apply("abcdef")
|
||||
self.assertEqual(res, "171 205 239")
|
||||
|
||||
def test_OCTAL_4BITS(self):
|
||||
ff = FormatFunction("Field Format Encoding", Format.OCTAL, UnitSize.BITS4, Endianness.BIG, Sign.UNSIGNED)
|
||||
res = ff.apply("abcdef")
|
||||
self.assertEqual(res, "12 13 14 15 16 17")
|
||||
|
||||
def test_OCTAL_8BITS(self):
|
||||
ff = FormatFunction("Field Format Encoding", Format.OCTAL, UnitSize.BITS8, Endianness.BIG, Sign.UNSIGNED)
|
||||
res = ff.apply("abcdef")
|
||||
self.assertEqual(res, "253 315 357")
|
||||
|
||||
def test_BINARY(self):
|
||||
ff = FormatFunction("Field Format Encoding", Format.BINARY, UnitSize.NONE, Endianness.BIG, Sign.UNSIGNED)
|
||||
res = ff.apply("abcdef")
|
||||
self.assertEqual(res, "101010111100110111101111")
|
||||
|
||||
# UnitSize.BITS4
|
||||
def test_HEX_BITS4(self):
|
||||
ff = FormatFunction("Field Format Encoding", Format.HEX, UnitSize.BITS4, Endianness.BIG, Sign.UNSIGNED)
|
||||
res = ff.apply("abcdef")
|
||||
self.assertEqual(res, "a b c d e f")
|
||||
|
||||
def test_STRING_BITS4(self):
|
||||
ff = FormatFunction("Field Format Encoding", Format.STRING, UnitSize.BITS4, Endianness.BIG, Sign.UNSIGNED)
|
||||
res = ff.apply("abcdef")
|
||||
self.assertEqual(res, ". . . . . .")
|
||||
|
||||
def test_DECIMAL_BITS4(self):
|
||||
ff = FormatFunction("Field Format Encoding", Format.DECIMAL, UnitSize.BITS4, Endianness.BIG, Sign.UNSIGNED)
|
||||
res = ff.apply("abcdef")
|
||||
self.assertEqual(res, "10 11 12 13 14 15")
|
||||
|
||||
def test_OCTAL_BITS4(self):
|
||||
ff = FormatFunction("Field Format Encoding", Format.OCTAL, UnitSize.BITS4, Endianness.BIG, Sign.UNSIGNED)
|
||||
res = ff.apply("abcdef")
|
||||
self.assertEqual(res, "12 13 14 15 16 17")
|
||||
|
||||
def test_BINARY_BITS4(self):
|
||||
ff = FormatFunction("Field Format Encoding", Format.BINARY, UnitSize.BITS4, Endianness.BIG, Sign.UNSIGNED)
|
||||
res = ff.apply("abcdef")
|
||||
self.assertEqual(res, "1010 1011 1100 1101 1110 1111")
|
||||
|
||||
# UnitSize.BITS8
|
||||
def test_HEX_BITS8(self):
|
||||
ff = FormatFunction("Field Format Encoding", Format.HEX, UnitSize.BITS8, Endianness.BIG, Sign.UNSIGNED)
|
||||
res = ff.apply("abcdef")
|
||||
self.assertEqual(res, "ab cd ef")
|
||||
|
||||
def test_STRING_BITS8(self):
|
||||
ff = FormatFunction("Field Format Encoding", Format.STRING, UnitSize.BITS8, Endianness.BIG, Sign.UNSIGNED)
|
||||
res = ff.apply("30313233343536373839")
|
||||
self.assertEqual(res, "0 1 2 3 4 5 6 7 8 9")
|
||||
|
||||
def test_DECIMAL_BITS8(self):
|
||||
ff = FormatFunction("Field Format Encoding", Format.DECIMAL, UnitSize.BITS8, Endianness.BIG, Sign.UNSIGNED)
|
||||
res = ff.apply("abcdef")
|
||||
self.assertEqual(res, "171 205 239")
|
||||
|
||||
def test_OCTAL_BITS8(self):
|
||||
ff = FormatFunction("Field Format Encoding", Format.OCTAL, UnitSize.BITS8, Endianness.BIG, Sign.UNSIGNED)
|
||||
res = ff.apply("abcdef")
|
||||
self.assertEqual(res, "253 315 357")
|
||||
|
||||
def test_BINARY_BITS8(self):
|
||||
ff = FormatFunction("Field Format Encoding", Format.BINARY, UnitSize.BITS8, Endianness.BIG, Sign.UNSIGNED)
|
||||
res = ff.apply("abcdef")
|
||||
self.assertEqual(res, "10101011 11001101 11101111")
|
||||
@@ -0,0 +1,40 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| 01001110 01100101 01110100 01111010 01101111 01100010 |
|
||||
#| |
|
||||
#| Netzob : Inferring communication protocols |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Copyright (C) 2011-2017 Georges Bossert and Frédéric Guihéry |
|
||||
#| This program is free software: you can redistribute it and/or modify |
|
||||
#| it under the terms of the GNU General Public License as published by |
|
||||
#| the Free Software Foundation, either version 3 of the License, or |
|
||||
#| (at your option) any later version. |
|
||||
#| |
|
||||
#| This program is distributed in the hope that it will be useful, |
|
||||
#| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
#| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
#| GNU General Public License for more details. |
|
||||
#| |
|
||||
#| You should have received a copy of the GNU General Public License |
|
||||
#| along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| @url : http://www.netzob.org |
|
||||
#| @contact : contact@netzob.org |
|
||||
#| @sponsors : Amossys, http://www.amossys.fr |
|
||||
#| Supélec, http://www.rennes.supelec.fr/ren/rd/cidre/ |
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
from netzob.Common.Functions.Encoding.FormatFunction import FormatFunction
|
||||
from netzob.Common.Type.Endianness import Endianness
|
||||
from netzob.Common.Type.Format import Format
|
||||
from netzob.Common.Type.Sign import Sign
|
||||
from netzob.Common.Type.TypeConvertor import TypeConvertor
|
||||
from netzob.Common.Type.UnitSize import UnitSize
|
||||
from common.NetzobTestCase import NetzobTestCase
|
||||
|
||||
class test_Transformation(NetzobTestCase):
|
||||
|
||||
# TODO
|
||||
def test_TODO(self):
|
||||
pass
|
||||
@@ -0,0 +1,40 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| 01001110 01100101 01110100 01111010 01101111 01100010 |
|
||||
#| |
|
||||
#| Netzob : Inferring communication protocols |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Copyright (C) 2011-2017 Georges Bossert and Frédéric Guihéry |
|
||||
#| This program is free software: you can redistribute it and/or modify |
|
||||
#| it under the terms of the GNU General Public License as published by |
|
||||
#| the Free Software Foundation, either version 3 of the License, or |
|
||||
#| (at your option) any later version. |
|
||||
#| |
|
||||
#| This program is distributed in the hope that it will be useful, |
|
||||
#| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
#| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
#| GNU General Public License for more details. |
|
||||
#| |
|
||||
#| You should have received a copy of the GNU General Public License |
|
||||
#| along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| @url : http://www.netzob.org |
|
||||
#| @contact : contact@netzob.org |
|
||||
#| @sponsors : Amossys, http://www.amossys.fr |
|
||||
#| Supélec, http://www.rennes.supelec.fr/ren/rd/cidre/ |
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
from netzob.Common.Functions.Encoding.FormatFunction import FormatFunction
|
||||
from netzob.Common.Type.Endianness import Endianness
|
||||
from netzob.Common.Type.Format import Format
|
||||
from netzob.Common.Type.Sign import Sign
|
||||
from netzob.Common.Type.TypeConvertor import TypeConvertor
|
||||
from netzob.Common.Type.UnitSize import UnitSize
|
||||
from common.NetzobTestCase import NetzobTestCase
|
||||
|
||||
class test_Visualization(NetzobTestCase):
|
||||
|
||||
# TODO
|
||||
def test_TODO(self):
|
||||
pass
|
||||
@@ -0,0 +1,38 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| 01001110 01100101 01110100 01111010 01101111 01100010 |
|
||||
#| |
|
||||
#| Netzob : Inferring communication protocols |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Copyright (C) 2011-2017 Georges Bossert and Frédéric Guihéry |
|
||||
#| This program is free software: you can redistribute it and/or modify |
|
||||
#| it under the terms of the GNU General Public License as published by |
|
||||
#| the Free Software Foundation, either version 3 of the License, or |
|
||||
#| (at your option) any later version. |
|
||||
#| |
|
||||
#| This program is distributed in the hope that it will be useful, |
|
||||
#| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
#| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
#| GNU General Public License for more details. |
|
||||
#| |
|
||||
#| You should have received a copy of the GNU General Public License |
|
||||
#| along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| @url : http://www.netzob.org |
|
||||
#| @contact : contact@netzob.org |
|
||||
#| @sponsors : Amossys, http://www.amossys.fr |
|
||||
#| Supélec, http://www.rennes.supelec.fr/ren/rd/cidre/ |
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
from netzob.Common.Type.Endianness import Endianness
|
||||
from common.NetzobTestCase import NetzobTestCase
|
||||
|
||||
|
||||
class test_Endianness(NetzobTestCase):
|
||||
|
||||
def test_BIG(self):
|
||||
self.assertEqual(Endianness.BIG, "big-endian")
|
||||
|
||||
def test_LITTLE(self):
|
||||
self.assertEqual(Endianness.LITTLE, "little-endian")
|
||||
@@ -0,0 +1,74 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| 01001110 01100101 01110100 01111010 01101111 01100010 |
|
||||
#| |
|
||||
#| Netzob : Inferring communication protocols |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Copyright (C) 2011-2017 Georges Bossert and Frédéric Guihéry |
|
||||
#| This program is free software: you can redistribute it and/or modify |
|
||||
#| it under the terms of the GNU General Public License as published by |
|
||||
#| the Free Software Foundation, either version 3 of the License, or |
|
||||
#| (at your option) any later version. |
|
||||
#| |
|
||||
#| This program is distributed in the hope that it will be useful, |
|
||||
#| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
#| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
#| GNU General Public License for more details. |
|
||||
#| |
|
||||
#| You should have received a copy of the GNU General Public License |
|
||||
#| along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| @url : http://www.netzob.org |
|
||||
#| @contact : contact@netzob.org |
|
||||
#| @sponsors : Amossys, http://www.amossys.fr |
|
||||
#| Supélec, http://www.rennes.supelec.fr/ren/rd/cidre/ |
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
#+----------------------------------------------
|
||||
#| Global Imports
|
||||
#+----------------------------------------------
|
||||
import unittest
|
||||
import random
|
||||
import base64
|
||||
|
||||
#+----------------------------------------------
|
||||
#| Local Imports
|
||||
#+----------------------------------------------
|
||||
from netzob.Common.Type.TypeIdentifier import TypeIdentifier
|
||||
from netzob.Common.Type.TypeConvertor import TypeConvertor
|
||||
from netzob.Common.Type.Format import Format
|
||||
from common.NetzobTestCase import NetzobTestCase
|
||||
|
||||
|
||||
class test_TypeIdentifier(NetzobTestCase):
|
||||
|
||||
def test_getTypesNum(self):
|
||||
number = random.randint(0, 10000)
|
||||
typeIdentifier = TypeIdentifier()
|
||||
self.assertIn(Format.DECIMAL, typeIdentifier.getTypes(number))
|
||||
|
||||
def test_getTypesAlpha(self):
|
||||
alphabet = list(map(chr, list(range(97, 123))))
|
||||
alpha = alphabet[random.randint(0, len(alphabet) - 1)]
|
||||
typeIdentifier = TypeIdentifier()
|
||||
self.assertIn(Format.ALPHA, typeIdentifier.getTypes(alpha))
|
||||
|
||||
def test_getTypesAscii(self):
|
||||
alphabet = list(map(chr, list(range(97, 123))))
|
||||
alpha = alphabet[random.randint(0, len(alphabet) - 1)]
|
||||
typeIdentifier = TypeIdentifier()
|
||||
self.assertIn(Format.ASCII, typeIdentifier.getTypes(alpha))
|
||||
|
||||
def test_getTypesBase64(self):
|
||||
string = "Vive Netzob !"
|
||||
base64String = base64.encodestring(string)
|
||||
typeIdentifier = TypeIdentifier()
|
||||
self.assertIn(Format.BASE64_ENC, typeIdentifier.getTypes(base64String))
|
||||
|
||||
def test_getTypesBinary(self):
|
||||
alphabet = list(map(chr, list(range(97, 123))))
|
||||
alpha = alphabet[random.randint(0, len(alphabet) - 1)]
|
||||
typeIdentifier = TypeIdentifier()
|
||||
hexOfNumber = str(hex(ord(alpha)))[2:]
|
||||
self.assertIn(Format.BINARY, typeIdentifier.getTypes(hexOfNumber))
|
||||
30
netzob-030/test/src/test_netzob/test_Export/__init__.py
Normal file
30
netzob-030/test/src/test_netzob/test_Export/__init__.py
Normal file
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| 01001110 01100101 01110100 01111010 01101111 01100010 |
|
||||
#| |
|
||||
#| Netzob : Inferring communication protocols |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Copyright (C) 2011-2014 Georges Bossert and Frédéric Guihéry |
|
||||
#| This program is free software: you can redistribute it and/or modify |
|
||||
#| it under the terms of the GNU General Public License as published by |
|
||||
#| the Free Software Foundation, either version 3 of the License, or |
|
||||
#| (at your option) any later version. |
|
||||
#| |
|
||||
#| This program is distributed in the hope that it will be useful, |
|
||||
#| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
#| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
#| GNU General Public License for more details. |
|
||||
#| |
|
||||
#| You should have received a copy of the GNU General Public License |
|
||||
#| along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| @url : http://www.netzob.org |
|
||||
#| @contact : contact@netzob.org |
|
||||
#| @sponsors : Amossys, http://www.amossys.fr |
|
||||
#| Supélec, http://www.rennes.supelec.fr/ren/rd/cidre/ |
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
# List subpackages to import with the current one
|
||||
# see docs.python.org/2/tutorial/modules.html
|
||||
@@ -0,0 +1,82 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| 01001110 01100101 01110100 01111010 01101111 01100010 |
|
||||
#| |
|
||||
#| Netzob : Inferring communication protocols |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Copyright (C) 2011-2014 Georges Bossert and Frédéric Guihéry |
|
||||
#| This program is free software: you can redistribute it and/or modify |
|
||||
#| it under the terms of the GNU General Public License as published by |
|
||||
#| the Free Software Foundation, either version 3 of the License, or |
|
||||
#| (at your option) any later version. |
|
||||
#| |
|
||||
#| This program is distributed in the hope that it will be useful, |
|
||||
#| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
#| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
#| GNU General Public License for more details. |
|
||||
#| |
|
||||
#| You should have received a copy of the GNU General Public License |
|
||||
#| along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| @url : http://www.netzob.org |
|
||||
#| @contact : contact@netzob.org |
|
||||
#| @sponsors : Amossys, http://www.amossys.fr |
|
||||
#| Supélec, http://www.rennes.supelec.fr/ren/rd/cidre/ |
|
||||
#+---------------------------------------------------------------------------+
|
||||
# +---------------------------------------------------------------------------+
|
||||
# | File contributors : |
|
||||
# | - Sumit Acharya <sumit.acharya@uni-ulm.de> |
|
||||
# | - Stephan Kleber <stephan.kleber@uni-ulm.de> |
|
||||
# +---------------------------------------------------------------------------+
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Standard library imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
import unittest
|
||||
import os
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Local Imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
from common.NetzobTestCase import NetzobTestCase
|
||||
from netzob.Common.Models.Vocabulary.Symbol import Symbol
|
||||
from netzob.Common.Models.Vocabulary.Messages.RawMessage import RawMessage
|
||||
from netzob.Inference.Vocabulary.Format import Format
|
||||
from netzob.Export.ScapyExporter.ScapyExporter import ScapyExporter
|
||||
|
||||
class test_ScapyExporter(NetzobTestCase):
|
||||
|
||||
def test_exportToScapy(self):
|
||||
# Test if exportToScapy function in ScapyExporter is working correctly.
|
||||
# Test if created file runs without error
|
||||
# Verify the content of the exported file is as expected, including size info.
|
||||
# check for both iterable and non-iterable symbols
|
||||
m1=RawMessage("\x09\x70\x95\xcc\xef")
|
||||
m2=RawMessage("\x0a\x70\x03\x8f\x23\x5f")
|
||||
m3=RawMessage("\x09\x70\x31\xa0")
|
||||
m4=RawMessage("\x0a\xd6\xb5\x5b")
|
||||
messages = [m1, m2, m3, m4]
|
||||
symbols = Symbol(messages=messages)
|
||||
with self.assertRaises(TypeError):
|
||||
iter(symbols)
|
||||
self.assertEqual(ScapyExporter().exportToScapy(symbols,'test1.py','ProtocolName'),None)
|
||||
self.assertEqual(os.system("python test1.py"), 0)
|
||||
import test1
|
||||
self.assertEqual(test1.ProtocolName_Symbol().fields_desc[0].name,'Field')
|
||||
self.assertEqual(test1.ProtocolName_Symbol().fields_desc[0].default,None)
|
||||
self.assertEqual(test1.ProtocolName_Symbol().fields_desc[0].cls,(0,None)) # size
|
||||
with self.assertRaises(AttributeError): test1.ProtocolName_Symbol1().fields_desc[0].name
|
||||
os.remove('test1.py')
|
||||
|
||||
symbl = Format.clusterByAlignment(messages, minEquivalence=50, internalSlick=True)
|
||||
self.assertEqual(type(symbl),list)
|
||||
self.assertEqual(ScapyExporter().exportToScapy(symbl,'test2.py','ProtocolName'),None)
|
||||
self.assertEqual(os.system("python test2.py"), 0)
|
||||
import test2
|
||||
self.assertEqual(test2.ProtocolName_Symbol0().fields_desc[0].name,'Field00')
|
||||
self.assertEqual(test2.ProtocolName_Symbol0().fields_desc[0].cls,(0,32)) # size
|
||||
self.assertEqual(test2.ProtocolName_Symbol1().fields_desc[1].default,'p')
|
||||
self.assertEqual(test2.ProtocolName_Symbol1().Field01,'p')
|
||||
self.assertEqual(len(test2.ProtocolName_Symbol1().fields_desc),3)
|
||||
os.remove('test2.py')
|
||||
103
netzob-030/test/src/test_netzob/test_Hashes/test_Hashes.py
Normal file
103
netzob-030/test/src/test_netzob/test_Hashes/test_Hashes.py
Normal file
@@ -0,0 +1,103 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| 01001110 01100101 01110100 01111010 01101111 01100010 |
|
||||
#| |
|
||||
#| Netzob : Inferring communication protocols |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Copyright (C) 2011-2017 Georges Bossert and Frédéric Guihéry |
|
||||
#| This program is free software: you can redistribute it and/or modify |
|
||||
#| it under the terms of the GNU General Public License as published by |
|
||||
#| the Free Software Foundation, either version 3 of the License, or |
|
||||
#| (at your option) any later version. |
|
||||
#| |
|
||||
#| This program is distributed in the hope that it will be useful, |
|
||||
#| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
#| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
#| GNU General Public License for more details. |
|
||||
#| |
|
||||
#| You should have received a copy of the GNU General Public License |
|
||||
#| along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| @url : http://www.netzob.org |
|
||||
#| @contact : contact@netzob.org |
|
||||
#| @sponsors : Amossys, http://www.amossys.fr |
|
||||
#| Supélec, http://www.rennes.supelec.fr/ren/rd/cidre/ |
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Standard library imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
import unittest
|
||||
from netzob.all import *
|
||||
import os
|
||||
|
||||
|
||||
class test_Hashes(unittest.TestCase):
|
||||
|
||||
def parse_cavs_file(self, file, hash_class):
|
||||
file_path = os.path.join("test", "resources", "test_netzob", "test_Hashes", file)
|
||||
fd = open(file_path, 'r')
|
||||
msg = ""
|
||||
given_len = 0
|
||||
for line in fd:
|
||||
if 'Len =' in line:
|
||||
given_len = int(line[6:-1])
|
||||
elif 'Msg =' in line:
|
||||
msg = line[6:-1]
|
||||
elif 'MD =' in line:
|
||||
if len(msg) != given_len:
|
||||
msg = msg[0 : given_len]
|
||||
if 'MD5' in file:
|
||||
msg = msg.encode().hex()
|
||||
self.check_res(msg, line[5:-1], hash_class)
|
||||
msg = ""
|
||||
given_len = 0
|
||||
|
||||
def check_res(self, msg, md, hash_class):
|
||||
b = bytes.fromhex(msg)
|
||||
f1 = Field(Raw(b))
|
||||
f2 = Field(hash_class([f1]))
|
||||
s = Symbol(fields = [f1, f2])
|
||||
rep = s.specialize().hex()
|
||||
self.assertEqual(rep, (msg + md))
|
||||
|
||||
def test_MD5_implementation(self):
|
||||
file_1 = "MD5_test_suite.txt"
|
||||
hash_class = MD5
|
||||
self.parse_cavs_file(file_1, hash_class)
|
||||
|
||||
def test_SHA1_implementation(self):
|
||||
file_1 = "SHA1ShortMsg.rsp"
|
||||
file_2 = "SHA1LongMsg.rsp"
|
||||
hash_class = SHA1
|
||||
self.parse_cavs_file(file_1, hash_class)
|
||||
self.parse_cavs_file(file_2, hash_class)
|
||||
|
||||
def test_SHA2_224_implementation(self):
|
||||
file_1 = "SHA224ShortMsg.rsp"
|
||||
file_2 = "SHA224LongMsg.rsp"
|
||||
hash_class = SHA2_224
|
||||
self.parse_cavs_file(file_1, hash_class)
|
||||
self.parse_cavs_file(file_2, hash_class)
|
||||
|
||||
def test_SHA2_256_implementation(self):
|
||||
file_1 = "SHA256ShortMsg.rsp"
|
||||
file_2 = "SHA256LongMsg.rsp"
|
||||
hash_class = SHA2_256
|
||||
self.parse_cavs_file(file_1, hash_class)
|
||||
self.parse_cavs_file(file_2, hash_class)
|
||||
|
||||
def test_SHA2_384_implementation(self):
|
||||
file_1 = "SHA384ShortMsg.rsp"
|
||||
file_2 = "SHA384LongMsg.rsp"
|
||||
hash_class = SHA2_384
|
||||
self.parse_cavs_file(file_1, hash_class)
|
||||
self.parse_cavs_file(file_2, hash_class)
|
||||
|
||||
def test_SHA2_512_implementation(self):
|
||||
file_1 = "SHA512ShortMsg.rsp"
|
||||
file_2 = "SHA512LongMsg.rsp"
|
||||
hash_class = SHA2_512
|
||||
self.parse_cavs_file(file_1, hash_class)
|
||||
self.parse_cavs_file(file_2, hash_class)
|
||||
103
netzob-030/test/src/test_netzob/test_Hmacs/test_Hmacs.py
Normal file
103
netzob-030/test/src/test_netzob/test_Hmacs/test_Hmacs.py
Normal file
@@ -0,0 +1,103 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| 01001110 01100101 01110100 01111010 01101111 01100010 |
|
||||
#| |
|
||||
#| Netzob : Inferring communication protocols |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Copyright (C) 2011-2017 Georges Bossert and Frédéric Guihéry |
|
||||
#| This program is free software: you can redistribute it and/or modify |
|
||||
#| it under the terms of the GNU General Public License as published by |
|
||||
#| the Free Software Foundation, either version 3 of the License, or |
|
||||
#| (at your option) any later version. |
|
||||
#| |
|
||||
#| This program is distributed in the hope that it will be useful, |
|
||||
#| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
#| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
#| GNU General Public License for more details. |
|
||||
#| |
|
||||
#| You should have received a copy of the GNU General Public License |
|
||||
#| along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| @url : http://www.netzob.org |
|
||||
#| @contact : contact@netzob.org |
|
||||
#| @sponsors : Amossys, http://www.amossys.fr |
|
||||
#| Supélec, http://www.rennes.supelec.fr/ren/rd/cidre/ |
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Standard library imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
import unittest
|
||||
from netzob.all import *
|
||||
import os
|
||||
|
||||
# About the test vector file (HMAC.rsp):
|
||||
# the choice of the algorithm is defined by the starting length of the Mac (described as '[L=XX]' in the test file)
|
||||
# [L=20] stand for SHA1
|
||||
# [L=28] stand for SHA2-224
|
||||
# [L=32] stand for SHA2-256
|
||||
# [L=48] stand for SHA2-384
|
||||
# [L=64] stand for SHA2-512
|
||||
|
||||
class test_Hmacs(unittest.TestCase):
|
||||
|
||||
file = "HMAC.rsp"
|
||||
|
||||
def parse_file(self, mac_len_start, hmac_class):
|
||||
file_path = os.path.join("test", "resources", "test_netzob", "test_Hmacs", self.file)
|
||||
fd = open(file_path, 'r')
|
||||
msg = ""
|
||||
key = ""
|
||||
mac_len = 0
|
||||
for line in fd:
|
||||
if line.find('[L='+str(mac_len_start)+']') != -1: # mean start of the algorithm section
|
||||
break
|
||||
for line in fd:
|
||||
if line.find('[L=') != -1: # mean end of the algorithm section
|
||||
break
|
||||
elif 'Tlen =' in line:
|
||||
mac_len = int(line[7:-1]) * 2
|
||||
elif 'Key =' in line:
|
||||
key = line[6:-1]
|
||||
elif 'Msg =' in line:
|
||||
msg = line[6:-1]
|
||||
elif 'Mac =' in line:
|
||||
self.check_res(key, msg, line[6:-1], hmac_class, mac_len)
|
||||
msg = ""
|
||||
key = ""
|
||||
|
||||
def check_res(self, key, msg, mac, hmac_class, mac_len):
|
||||
b = bytes.fromhex(msg)
|
||||
k = bytes.fromhex(key)
|
||||
f1 = Field(Raw(b))
|
||||
f2 = Field(hmac_class([f1], key=k))
|
||||
s = Symbol(fields = [f1, f2])
|
||||
tmp = s.specialize()[len(b):]
|
||||
rep = tmp.hex()[:mac_len]
|
||||
self.assertEqual(rep, mac)
|
||||
|
||||
def test_SHA1_implementation(self):
|
||||
mac_len_start = 20
|
||||
hmac_class = HMAC_SHA1
|
||||
self.parse_file(mac_len_start, hmac_class)
|
||||
|
||||
def test_SHA2_224_implementation(self):
|
||||
mac_len_start = 28
|
||||
hmac_class = HMAC_SHA2_224
|
||||
self.parse_file(mac_len_start, hmac_class)
|
||||
|
||||
def test_SHA2_256_implementation(self):
|
||||
mac_len_start = 32
|
||||
hmac_class = HMAC_SHA2_256
|
||||
self.parse_file(mac_len_start, hmac_class)
|
||||
|
||||
def test_SHA2_384_implementation(self):
|
||||
mac_len_start = 48
|
||||
hmac_class = HMAC_SHA2_384
|
||||
self.parse_file(mac_len_start, hmac_class)
|
||||
|
||||
def test_SHA2_512_implementation(self):
|
||||
mac_len_start = 64
|
||||
hmac_class = HMAC_SHA2_512
|
||||
self.parse_file(mac_len_start, hmac_class)
|
||||
@@ -0,0 +1,43 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| 01001110 01100101 01110100 01111010 01101111 01100010 |
|
||||
#| |
|
||||
#| Netzob : Inferring communication protocols |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Copyright (C) 2011-2017 Georges Bossert and Frédéric Guihéry |
|
||||
#| This program is free software: you can redistribute it and/or modify |
|
||||
#| it under the terms of the GNU General Public License as published by |
|
||||
#| the Free Software Foundation, either version 3 of the License, or |
|
||||
#| (at your option) any later version. |
|
||||
#| |
|
||||
#| This program is distributed in the hope that it will be useful, |
|
||||
#| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
#| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
#| GNU General Public License for more details. |
|
||||
#| |
|
||||
#| You should have received a copy of the GNU General Public License |
|
||||
#| along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| @url : http://www.netzob.org |
|
||||
#| @contact : contact@netzob.org |
|
||||
#| @sponsors : Amossys, http://www.amossys.fr |
|
||||
#| Supélec, http://www.rennes.supelec.fr/ren/rd/cidre/ |
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Standard library imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
import unittest
|
||||
from netzob.Common.ExecutionContext import ExecutionContext
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Local Imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
|
||||
class test_ExecutionContext(unittest.TestCase):
|
||||
|
||||
def test_getCurrentProcesses(self):
|
||||
current = ExecutionContext.getCurrentProcesses()
|
||||
self.assertGreater(len(current), 5)
|
||||
83
netzob-030/test/src/test_netzob/test_Tutorials/test_ICMP.py
Normal file
83
netzob-030/test/src/test_netzob/test_Tutorials/test_ICMP.py
Normal file
@@ -0,0 +1,83 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| 01001110 01100101 01110100 01111010 01101111 01100010 |
|
||||
#| |
|
||||
#| Netzob : Inferring communication protocols |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Copyright (C) 2011-2017 Georges Bossert and Frédéric Guihéry |
|
||||
#| This program is free software: you can redistribute it and/or modify |
|
||||
#| it under the terms of the GNU General Public License as published by |
|
||||
#| the Free Software Foundation, either version 3 of the License, or |
|
||||
#| (at your option) any later version. |
|
||||
#| |
|
||||
#| This program is distributed in the hope that it will be useful, |
|
||||
#| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
#| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
#| GNU General Public License for more details. |
|
||||
#| |
|
||||
#| You should have received a copy of the GNU General Public License |
|
||||
#| along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| @url : http://www.netzob.org |
|
||||
#| @contact : contact@netzob.org |
|
||||
#| @sponsors : Amossys, http://www.amossys.fr |
|
||||
#| Supélec, http://www.rennes.supelec.fr/ren/rd/cidre/ |
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Standard library imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
import logging
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Local Imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
from common.NetzobTestCase import NetzobTestCase
|
||||
from netzob.all import *
|
||||
|
||||
|
||||
class test_ICMP(NetzobTestCase):
|
||||
|
||||
def test_generateICMP(self):
|
||||
"""test_generateICMP:
|
||||
"""
|
||||
logging.debug("Test : generate some ICMP Echo Request.")
|
||||
|
||||
# Build header : 3 fields
|
||||
pingHeader = Field(name="Header")
|
||||
|
||||
pingHeaders = [
|
||||
Field(name="Type"),
|
||||
Field(name="Code"),
|
||||
Field(name="Checksum")
|
||||
]
|
||||
pingHeader.children = pingHeaders
|
||||
pingHeader.domain.learnable = False
|
||||
|
||||
# Create a payload with a 1 single field
|
||||
pingPayload = Field(name="Payload")
|
||||
|
||||
# field 1 : type - 1 byte
|
||||
pingHeaders[0].domain = Raw(nbBytes=1)
|
||||
pingHeaders[0].domain.learnable = False
|
||||
|
||||
# field 2 : code - 1 byte
|
||||
pingHeaders[1].domain = Raw(nbBytes=1)
|
||||
pingHeaders[1].domain.learnable = False
|
||||
|
||||
# field 3 : checksum - 2 bytes
|
||||
pingHeaders[2].domain = [Raw(CRC16(pingHeader + pingPayload), size=16)]
|
||||
#pingHeaders[2].domain = Raw(nbBytes=2)
|
||||
pingHeaders[2].domain.learnable = False
|
||||
|
||||
|
||||
# field 4 : we put an ascii of 10 to 50 chars in the payload
|
||||
pingPayload.domain = ASCII(nbChars=(10, 50))
|
||||
pingPayload.domain.learnable = False
|
||||
|
||||
ping = Symbol([pingHeader, pingPayload])
|
||||
|
||||
ping.messages = [RawMessage(ping.specialize()) for i in range(0, 20)]
|
||||
cells = ping.getCells()
|
||||
print(cells)
|
||||
@@ -0,0 +1,79 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| 01001110 01100101 01110100 01111010 01101111 01100010 |
|
||||
#| |
|
||||
#| Netzob : Inferring communication protocols |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Copyright (C) 2011-2017 Georges Bossert and Frédéric Guihéry |
|
||||
#| This program is free software: you can redistribute it and/or modify |
|
||||
#| it under the terms of the GNU General Public License as published by |
|
||||
#| the Free Software Foundation, either version 3 of the License, or |
|
||||
#| (at your option) any later version. |
|
||||
#| |
|
||||
#| This program is distributed in the hope that it will be useful, |
|
||||
#| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
#| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
#| GNU General Public License for more details. |
|
||||
#| |
|
||||
#| You should have received a copy of the GNU General Public License |
|
||||
#| along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| @url : http://www.netzob.org |
|
||||
#| @contact : contact@netzob.org |
|
||||
#| @sponsors : Amossys, http://www.amossys.fr |
|
||||
#| Supélec, http://www.rennes.supelec.fr/ren/rd/cidre/ |
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Standard library imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
import logging
|
||||
import os
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Local Imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
from common.NetzobTestCase import NetzobTestCase
|
||||
from netzob.all import *
|
||||
|
||||
|
||||
class test_ImportPCAP(NetzobTestCase):
|
||||
|
||||
def test_createSymbolWithPCAPMessages(self):
|
||||
"""Tests (and illustrates) how to import messages
|
||||
from a PCAP and store them in a dedicated symbol"""
|
||||
|
||||
pcapFile = os.path.join("test", "resources", "pcaps", "botnet_irc_bot.pcap")
|
||||
symbol = Symbol(messages=list(PCAPImporter.readFile(pcapFile).values()))
|
||||
self.assertTrue(len(symbol.messages) == 17)
|
||||
|
||||
def test_importPCAPApplicativeLayer(self):
|
||||
"""Test (and illustrates) how to import messages
|
||||
out of a pcap. In this test, we only consider the payload
|
||||
of the applicative layer (L5) while headers of L5 and below layers
|
||||
will be stored as properties (e.g. metadata).
|
||||
|
||||
"""
|
||||
logging.debug("Test : Import messages from the applicative layer of a PCAP.")
|
||||
|
||||
pcapFile = os.path.join("test", "resources", "pcaps", "botnet_irc_bot.pcap")
|
||||
messages = PCAPImporter.readFile(pcapFile)
|
||||
logging.debug(messages)
|
||||
self.assertTrue(len(messages) == 17)
|
||||
|
||||
def test_importPCAPApplicativeLayerWithFilter(self):
|
||||
"""Test (and illustrates) how to import messages
|
||||
out of a pcap prefiltered with BPF filter.
|
||||
|
||||
"""
|
||||
logging.debug("Test : Import messages from a PCAP with a specified BPF filter.")
|
||||
|
||||
pcapFile = os.path.join("test", "resources", "pcaps", "botnet_irc_bot.pcap")
|
||||
messages = PCAPImporter.readFile(pcapFile, bpfFilter="tcp dst port 6667")
|
||||
logging.debug(messages)
|
||||
self.assertTrue(len(messages) == 8)
|
||||
|
||||
messages = PCAPImporter.readFile(pcapFile, bpfFilter="tcp src port 6667")
|
||||
logging.debug(messages)
|
||||
self.assertTrue(len(messages) == 9)
|
||||
@@ -0,0 +1,100 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| 01001110 01100101 01110100 01111010 01101111 01100010 |
|
||||
#| |
|
||||
#| Netzob : Inferring communication protocols |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Copyright (C) 2011-2017 Georges Bossert and Frédéric Guihéry |
|
||||
#| This program is free software: you can redistribute it and/or modify |
|
||||
#| it under the terms of the GNU General Public License as published by |
|
||||
#| the Free Software Foundation, either version 3 of the License, or |
|
||||
#| (at your option) any later version. |
|
||||
#| |
|
||||
#| This program is distributed in the hope that it will be useful, |
|
||||
#| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
#| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
#| GNU General Public License for more details. |
|
||||
#| |
|
||||
#| You should have received a copy of the GNU General Public License |
|
||||
#| along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| @url : http://www.netzob.org |
|
||||
#| @contact : contact@netzob.org |
|
||||
#| @sponsors : Amossys, http://www.amossys.fr |
|
||||
#| Supélec, http://www.rennes.supelec.fr/ren/rd/cidre/ |
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Standard library imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
import logging
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Local Imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
from common.NetzobTestCase import NetzobTestCase
|
||||
from netzob.all import *
|
||||
import binascii
|
||||
|
||||
|
||||
class test_ManualFieldStatic(NetzobTestCase):
|
||||
|
||||
def test_analyze(self):
|
||||
logging.info("Test : manual slicing of a field")
|
||||
|
||||
# Step1 : import messages from PCAP
|
||||
samples = ["00ff1f000000", "00fe1f000000", "00fe1f000000", "00fe1f000000", "00ff1f000000", "00ff1f000000", "00ff0f000000", "00fe2f000000"]
|
||||
# Create a message for each data ...
|
||||
messages = [RawMessage(data=binascii.unhexlify(sample)) for sample in samples]
|
||||
|
||||
# ... and attach them to a unique symbol
|
||||
symbol = Symbol(messages=messages)
|
||||
|
||||
# lets consider this as hexastring
|
||||
symbol.encodingFunctions.add(TypeEncodingFunction(HexaString))
|
||||
|
||||
# display symbol (and so its messages)
|
||||
logging.info(symbol)
|
||||
# 00ff1f000000
|
||||
# 00fe1f000000
|
||||
# 00fe1f000000
|
||||
# 00fe1f000000
|
||||
# 00ff1f000000
|
||||
# 00ff1f000000
|
||||
# 00ff0f000000
|
||||
# 00fe2f000000
|
||||
|
||||
Format.splitStatic(symbol, unitSize=UnitSize.SIZE_8, mergeAdjacentStaticFields=False, mergeAdjacentDynamicFields=False)
|
||||
logging.info(symbol)
|
||||
# 00 | ff | 1f | 00 | 00 | 00
|
||||
# 00 | fe | 1f | 00 | 00 | 00
|
||||
# 00 | fe | 1f | 00 | 00 | 00
|
||||
# 00 | fe | 1f | 00 | 00 | 00
|
||||
# 00 | ff | 1f | 00 | 00 | 00
|
||||
# 00 | ff | 1f | 00 | 00 | 00
|
||||
# 00 | ff | 0f | 00 | 00 | 00
|
||||
# 00 | fe | 2f | 00 | 00 | 00
|
||||
|
||||
Format.mergeFields(symbol.children[1], symbol.children[2])
|
||||
logging.info(symbol)
|
||||
# 00 | ff1f | 00 | 00 | 00
|
||||
# 00 | fe1f | 00 | 00 | 00
|
||||
# 00 | fe1f | 00 | 00 | 00
|
||||
# 00 | fe1f | 00 | 00 | 00
|
||||
# 00 | ff1f | 00 | 00 | 00
|
||||
# 00 | ff1f | 00 | 00 | 00
|
||||
# 00 | ff0f | 00 | 00 | 00
|
||||
# 00 | fe2f | 00 | 00 | 00
|
||||
|
||||
Format.mergeFields(symbol.children[2], symbol.children[3])
|
||||
logging.info(symbol)
|
||||
# 00 | ff1f | 0000 | 00
|
||||
# 00 | fe1f | 0000 | 00
|
||||
# 00 | fe1f | 0000 | 00
|
||||
# 00 | fe1f | 0000 | 00
|
||||
# 00 | ff1f | 0000 | 00
|
||||
# 00 | ff1f | 0000 | 00
|
||||
# 00 | ff0f | 0000 | 00
|
||||
# 00 | fe2f | 0000 | 00
|
||||
|
||||
logging.info(symbol._str_debug())
|
||||
@@ -0,0 +1,111 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| 01001110 01100101 01110100 01111010 01101111 01100010 |
|
||||
#| |
|
||||
#| Netzob : Inferring communication protocols |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Copyright (C) 2011-2017 Georges Bossert and Frédéric Guihéry |
|
||||
#| This program is free software: you can redistribute it and/or modify |
|
||||
#| it under the terms of the GNU General Public License as published by |
|
||||
#| the Free Software Foundation, either version 3 of the License, or |
|
||||
#| (at your option) any later version. |
|
||||
#| |
|
||||
#| This program is distributed in the hope that it will be useful, |
|
||||
#| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
#| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
#| GNU General Public License for more details. |
|
||||
#| |
|
||||
#| You should have received a copy of the GNU General Public License |
|
||||
#| along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| @url : http://www.netzob.org |
|
||||
#| @contact : contact@netzob.org |
|
||||
#| @sponsors : Amossys, http://www.amossys.fr |
|
||||
#| Supélec, http://www.rennes.supelec.fr/ren/rd/cidre/ |
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Standard library imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
import logging
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Local Imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
from common.NetzobTestCase import NetzobTestCase
|
||||
from netzob.all import *
|
||||
import binascii
|
||||
|
||||
|
||||
class test_StaticFieldSlicing(NetzobTestCase):
|
||||
|
||||
def test_analyze(self):
|
||||
logging.info("Test : static slicing of a field")
|
||||
|
||||
# Step1 : import messages from PCAP
|
||||
samples = ["00ff1f000000", "00fe1f000000", "00fe1f000000", "00fe1f000000", "00ff1f000000", "00ff1f000000", "00ff0f000000", "00fe2f000000"]
|
||||
# Create a message for each data ...
|
||||
messages = [RawMessage(data=binascii.unhexlify(sample)) for sample in samples]
|
||||
|
||||
# ... and attach them to a unique symbol
|
||||
symbol = Symbol(messages=messages)
|
||||
|
||||
# lets consider this as hexastring
|
||||
symbol.encodingFunctions.add(TypeEncodingFunction(HexaString))
|
||||
|
||||
# display symbol (and so its messages)
|
||||
logging.info(symbol)
|
||||
# 00ff1f000000
|
||||
# 00fe1f000000
|
||||
# 00fe1f000000
|
||||
# 00fe1f000000
|
||||
# 00ff1f000000
|
||||
# 00ff1f000000
|
||||
# 00ff0f000000
|
||||
# 00fe2f000000
|
||||
|
||||
# lets slice data
|
||||
Format.splitStatic(symbol)
|
||||
|
||||
logging.info(symbol)
|
||||
# 00 | ff1f | 000000
|
||||
# 00 | fe1f | 000000
|
||||
# 00 | fe1f | 000000
|
||||
# 00 | fe1f | 000000
|
||||
# 00 | ff1f | 000000
|
||||
# 00 | ff1f | 000000
|
||||
# 00 | ff0f | 000000
|
||||
# 00 | fe2f | 000000
|
||||
|
||||
Format.splitStatic(symbol, unitSize=UnitSize.SIZE_8, mergeAdjacentStaticFields=False, mergeAdjacentDynamicFields=False)
|
||||
logging.info(symbol)
|
||||
# 00 | ff | 1f | 00 | 00 | 00
|
||||
# 00 | fe | 1f | 00 | 00 | 00
|
||||
# 00 | fe | 1f | 00 | 00 | 00
|
||||
# 00 | fe | 1f | 00 | 00 | 00
|
||||
# 00 | ff | 1f | 00 | 00 | 00
|
||||
# 00 | ff | 1f | 00 | 00 | 00
|
||||
# 00 | ff | 0f | 00 | 00 | 00
|
||||
# 00 | fe | 2f | 00 | 00 | 00
|
||||
|
||||
Format.splitStatic(symbol, unitSize=UnitSize.SIZE_16, mergeAdjacentStaticFields=False, mergeAdjacentDynamicFields=False)
|
||||
logging.info(symbol)
|
||||
# 00ff | 1f00 | 0000
|
||||
# 00fe | 1f00 | 0000
|
||||
# 00fe | 1f00 | 0000
|
||||
# 00fe | 1f00 | 0000
|
||||
# 00ff | 1f00 | 0000
|
||||
# 00ff | 1f00 | 0000
|
||||
# 00ff | 0f00 | 0000
|
||||
# 00fe | 2f00 | 0000
|
||||
|
||||
Format.splitStatic(symbol, unitSize=UnitSize.SIZE_16, mergeAdjacentStaticFields=False, mergeAdjacentDynamicFields=True)
|
||||
logging.info(symbol)
|
||||
# 00ff1f00 | 0000
|
||||
# 00fe1f00 | 0000
|
||||
# 00fe1f00 | 0000
|
||||
# 00fe1f00 | 0000
|
||||
# 00ff1f00 | 0000
|
||||
# 00ff1f00 | 0000
|
||||
# 00ff0f00 | 0000
|
||||
# 00fe2f00 | 0000
|
||||
@@ -0,0 +1,386 @@
|
||||
#-*- coding: utf-8 -*-
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| 01001110 01100101 01110100 01111010 01101111 01100010 |
|
||||
#| |
|
||||
#| Netzob : Inferring communication protocols |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Copyright (C) 2011-2017 Georges Bossert and Frédéric Guihéry |
|
||||
#| This program is free software: you can redistribute it and/or modify |
|
||||
#| it under the terms of the GNU General Public License as published by |
|
||||
#| the Free Software Foundation, either version 3 of the License, or |
|
||||
#| (at your option) any later version. |
|
||||
#| |
|
||||
#| This program is distributed in the hope that it will be useful, |
|
||||
#| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
#| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
#| GNU General Public License for more details. |
|
||||
#| |
|
||||
#| You should have received a copy of the GNU General Public License |
|
||||
#| along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| @url : http://www.netzob.org |
|
||||
#| @contact : contact@netzob.org |
|
||||
#| @sponsors : Amossys, http://www.amossys.fr |
|
||||
#| Supélec, http://www.rennes.supelec.fr/ren/rd/cidre/ |
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| File contributors : |
|
||||
#| - Georges Bossert <georges.bossert (a) supelec.fr> |
|
||||
#| - Frédéric Guihéry <frederic.guihery (a) amossys.fr> |
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
from common.NetzobTestCase import NetzobTestCase
|
||||
import binascii
|
||||
from netzob.all import *
|
||||
import logging
|
||||
|
||||
|
||||
class test_USBMouseProtocol(NetzobTestCase):
|
||||
|
||||
def test_inferUSBMouseProtocol(self):
|
||||
"""This method illustrates the very short script which
|
||||
gives some insights on the over USB protocol used
|
||||
by a traditionnal mouse."""
|
||||
|
||||
# Put samples in an array
|
||||
samples = [
|
||||
"00ff1f000000",
|
||||
"00fe1f000000",
|
||||
"00fe1f000000",
|
||||
"00fe1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff0f000000",
|
||||
"00fe2f000000",
|
||||
"00fe1f000000",
|
||||
"00ff0f000000",
|
||||
"000010000000",
|
||||
"00fe1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff0f000000",
|
||||
"00ff1f000000",
|
||||
"000010000000",
|
||||
"00ff0f000000",
|
||||
"000010000000",
|
||||
"00ff1f000000",
|
||||
"00ff0f000000",
|
||||
"00ff1f000000",
|
||||
"00fe0f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff0f000000",
|
||||
"00fe1f000000",
|
||||
"00fe2f000000",
|
||||
"00fe1f000000",
|
||||
"00fe1f000000",
|
||||
"00fe1f000000",
|
||||
"000010000000",
|
||||
"00ff0f000000",
|
||||
"000010000000",
|
||||
"00fe0f000000",
|
||||
"00ff1f000000",
|
||||
"00fe1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff0f000000",
|
||||
"000010000000",
|
||||
"00fe1f000000",
|
||||
"00ff2f000000",
|
||||
"00fe1f000000",
|
||||
"00fe1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00fe1f000000",
|
||||
"00fe2f000000",
|
||||
"00fd2f000000",
|
||||
"00fe2f000000",
|
||||
"00fe1f000000",
|
||||
"00ff1f000000",
|
||||
"000010000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff0f000000",
|
||||
"000010000000",
|
||||
"00fe1f000000",
|
||||
"00ff0f000000",
|
||||
"00fe2f000000",
|
||||
"00fe2f000000",
|
||||
"00fd2f000000",
|
||||
"00ff2f000000",
|
||||
"00ff1f000000",
|
||||
"00fe0f000000",
|
||||
"000010000000",
|
||||
"00ff1f000000",
|
||||
"00fe1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00fe1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff2f000000",
|
||||
"00ff0f000000",
|
||||
"00fe1f000000",
|
||||
"00fe2f000000",
|
||||
"00ff1f000000",
|
||||
"00fe1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00fe1f000000",
|
||||
"00fe1f000000",
|
||||
"00fe1f000000",
|
||||
"00fe2f000000",
|
||||
"00ff1f000000",
|
||||
"00fe1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00fe1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff0f000000",
|
||||
"000010000000",
|
||||
"00fe1f000000",
|
||||
"000010000000",
|
||||
"00fe1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff0f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00fe2f000000",
|
||||
"00fe1f000000",
|
||||
"00fe2f000000",
|
||||
"00fe1f000000",
|
||||
"00ff1f000000",
|
||||
"00fe1f000000",
|
||||
"00ff1f000000",
|
||||
"00fe1f000000",
|
||||
"00fe2f000000",
|
||||
"00ff1f000000",
|
||||
"00fe1f000000",
|
||||
"00fe1f000000",
|
||||
"00ff0f000000",
|
||||
"00fe2f000000",
|
||||
"00fe1f000000",
|
||||
"00fe1f000000",
|
||||
"00fe2f000000",
|
||||
"00fe1f000000",
|
||||
"00fe2f000000",
|
||||
"00fe2f000000",
|
||||
"00fd2f000000",
|
||||
"00fe1f000000",
|
||||
"00ff1f000000",
|
||||
"00fe1f000000",
|
||||
"00fe1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00fe0f000000",
|
||||
"00fe1f000000",
|
||||
"00fe2f000000",
|
||||
"00fd1f000000",
|
||||
"00fe1f000000",
|
||||
"00fe1f000000",
|
||||
"00fe1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff0f000000",
|
||||
"00ff1f000000",
|
||||
"00ff0f000000",
|
||||
"00ff1f000000",
|
||||
"00ff0f000000",
|
||||
"00ff1f000000",
|
||||
"00ff0f000000",
|
||||
"00ff1f000000",
|
||||
"00fe1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff0f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00fe1f000000",
|
||||
"00fe2f000000",
|
||||
"00fd1f000000",
|
||||
"00fe2f000000",
|
||||
"00fd1f000000",
|
||||
"00fe1f000000",
|
||||
"00fe2f000000",
|
||||
"00ff0f000000",
|
||||
"00fe1f000000",
|
||||
"00fe2f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff0f000000",
|
||||
"00fe1f000000",
|
||||
"00ff1f000000",
|
||||
"00fe1f000000",
|
||||
"00fe2f000000",
|
||||
"00ff1f000000",
|
||||
"00fe1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00fe1f000000",
|
||||
"00fe1f000000",
|
||||
"00ff2f000000",
|
||||
"00fe1f000000",
|
||||
"00fe1f000000",
|
||||
"00fe2f000000",
|
||||
"00fe1f000000",
|
||||
"00fe2f000000",
|
||||
"00ff1f000000",
|
||||
"00fe1f000000",
|
||||
"00fe1f000000",
|
||||
"00fe2f000000",
|
||||
"00ff2f000000",
|
||||
"00fe1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff2f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"000020000000",
|
||||
"00fe1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"000010000000",
|
||||
"00fe1f000000",
|
||||
"00ff0f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00fe1f000000",
|
||||
"00fe2f000000",
|
||||
"00ff1f000000",
|
||||
"00fe2f000000",
|
||||
"00fe1f000000",
|
||||
"00fe2f000000",
|
||||
"00ff2f000000",
|
||||
"00fe1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00fe1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff2f000000",
|
||||
"00ff1f000000",
|
||||
"00fd1f000000",
|
||||
"00fe2f000000",
|
||||
"00ff1f000000",
|
||||
"00ff0f000000",
|
||||
"00ff1f000000",
|
||||
"00fe1f000000",
|
||||
"000010000000",
|
||||
"00ff1f000000",
|
||||
"00ff2f000000",
|
||||
"00fe2f000000",
|
||||
"00fe1f000000",
|
||||
"00ff2f000000",
|
||||
"00fe1f000000",
|
||||
"00ff1f000000",
|
||||
"00fe2f000000",
|
||||
"00ff1f000000",
|
||||
"00fe1f000000",
|
||||
"00fe1f000000",
|
||||
"00ff2f000000",
|
||||
"00fe1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff0f000000",
|
||||
"00fe1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00fe1f000000",
|
||||
"00ff1f000000",
|
||||
"00fe1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00fe1f000000",
|
||||
"00fe1f000000",
|
||||
"00fe2f000000",
|
||||
"00fc2f000000",
|
||||
"00fe1f000000",
|
||||
"00fd2f000000",
|
||||
"00fe1f000000",
|
||||
"00ff1f000000",
|
||||
"00fe1f000000",
|
||||
"00ff1f000000",
|
||||
"00fe0f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00fe1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00fe1f000000",
|
||||
"000010000000",
|
||||
"00fe1f000000",
|
||||
"00fe1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff0f000000",
|
||||
"00ff1f000000",
|
||||
"00ff0f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00fd2f000000",
|
||||
"00fe1f000000",
|
||||
"00fe1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff0f000000",
|
||||
"00ff1f000000",
|
||||
"00fe1f000000",
|
||||
"00fc2f000000",
|
||||
"00fb2f000000",
|
||||
"00fb2f000000",
|
||||
"00fa4f000000",
|
||||
"00f92f000000",
|
||||
"00fa3f000000",
|
||||
"00fe1f000000",
|
||||
"000010000000",
|
||||
"00ff1f000000",
|
||||
"00fd3f000000",
|
||||
"00fd3f000000",
|
||||
"00fe2f000000",
|
||||
"00fd2f000000",
|
||||
"00ff2f000000",
|
||||
"00fe0f000000",
|
||||
"000010000000",
|
||||
"000010000000",
|
||||
"00ff1f000000",
|
||||
"000010000000",
|
||||
"00ff1f000000",
|
||||
"00ff2f000000",
|
||||
"000010000000",
|
||||
"00fe1f000000",
|
||||
"000020000000",
|
||||
"00ff1f000000",
|
||||
"00ff1f000000",
|
||||
"00ff2f000000",
|
||||
"00fe1f000000",
|
||||
"00ff2f000000"
|
||||
]
|
||||
|
||||
# Create a message for each data
|
||||
messages = [RawMessage(data=binascii.unhexlify(sample)) for sample in samples]
|
||||
|
||||
# Create a symbol to represent all the messages
|
||||
initialSymbol = Symbol(messages=messages)
|
||||
|
||||
# Split following the value
|
||||
Format.splitStatic(initialSymbol, mergeAdjacentDynamicFields=False)
|
||||
|
||||
initialSymbol.addEncodingFunction(TypeEncodingFunction(HexaString))
|
||||
|
||||
logging.debug(initialSymbol)
|
||||
0
netzob-030/test/src/test_netzob/test_UI/__init__.py
Normal file
0
netzob-030/test/src/test_netzob/test_UI/__init__.py
Normal file
47
netzob-030/test/src/test_netzob/test_UI/test_UI.py
Normal file
47
netzob-030/test/src/test_netzob/test_UI/test_UI.py
Normal file
@@ -0,0 +1,47 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| 01001110 01100101 01110100 01111010 01101111 01100010 |
|
||||
#| |
|
||||
#| Netzob : Inferring communication protocols |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Copyright (C) 2011-2017 Georges Bossert and Frédéric Guihéry |
|
||||
#| This program is free software: you can redistribute it and/or modify |
|
||||
#| it under the terms of the GNU General Public License as published by |
|
||||
#| the Free Software Foundation, either version 3 of the License, or |
|
||||
#| (at your option) any later version. |
|
||||
#| |
|
||||
#| This program is distributed in the hope that it will be useful, |
|
||||
#| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
#| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
#| GNU General Public License for more details. |
|
||||
#| |
|
||||
#| You should have received a copy of the GNU General Public License |
|
||||
#| along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| @url : http://www.netzob.org |
|
||||
#| @contact : contact@netzob.org |
|
||||
#| @sponsors : Amossys, http://www.amossys.fr |
|
||||
#| Supélec, http://www.rennes.supelec.fr/ren/rd/cidre/ |
|
||||
#+---------------------------------------------------------------------------+
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Standard library imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
import ldtp
|
||||
|
||||
#+---------------------------------------------------------------------------+
|
||||
#| Local Imports
|
||||
#+---------------------------------------------------------------------------+
|
||||
from common.NetzobTestCase import NetzobTestCase
|
||||
|
||||
|
||||
class test_UI(NetzobTestCase):
|
||||
|
||||
def test_startUI(self):
|
||||
ldtp.launchapp("./netzob")
|
||||
|
||||
selectWorkspaceFrame = "SelectWorkspace"
|
||||
ldtp.waittillguiexist(selectWorkspaceFrame, guiTimeOut=30)
|
||||
ldtp.click(selectWorkspaceFrame, "btnCancel")
|
||||
ldtp.waittillguinotexist(selectWorkspaceFrame)
|
||||
136
netzob-030/test/src/test_netzob/test_public_api.py
Normal file
136
netzob-030/test/src/test_netzob/test_public_api.py
Normal file
@@ -0,0 +1,136 @@
|
||||
# !/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# +---------------------------------------------------------------------------+
|
||||
# | 01001110 01100101 01110100 01111010 01101111 01100010 |
|
||||
# | |
|
||||
# | Netzob : Inferring communication protocols |
|
||||
# +---------------------------------------------------------------------------+
|
||||
# | Copyright (C) 2011-2017 Georges Bossert and Frédéric Guihéry |
|
||||
# | This program is free software: you can redistribute it and/or modify |
|
||||
# | it under the terms of the GNU General Public License as published by |
|
||||
# | the Free Software Foundation, either version 3 of the License, or |
|
||||
# | (at your option) any later version. |
|
||||
# | |
|
||||
# | This program is distributed in the hope that it will be useful, |
|
||||
# | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
# | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
# | GNU General Public License for more details. |
|
||||
# | |
|
||||
# | You should have received a copy of the GNU General Public License |
|
||||
# | along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
# +---------------------------------------------------------------------------+
|
||||
# | @url : http://www.netzob.org |
|
||||
# | @contact : contact@netzob.org |
|
||||
# | @sponsors : Amossys, http://www.amossys.fr |
|
||||
# | Supélec, http://www.rennes.supelec.fr/ren/rd/cidre/ |
|
||||
# +---------------------------------------------------------------------------+
|
||||
|
||||
# +---------------------------------------------------------------------------+
|
||||
# | Standard library imports
|
||||
# +---------------------------------------------------------------------------+
|
||||
import inspect
|
||||
import ast
|
||||
import unittest
|
||||
|
||||
# +---------------------------------------------------------------------------+
|
||||
# | Local application imports
|
||||
# +---------------------------------------------------------------------------+
|
||||
from netzob.all import *
|
||||
from netzob.Model.Grammar.Transitions.AbstractTransition import AbstractTransition
|
||||
from netzob.Model.Grammar.States.AbstractState import AbstractState
|
||||
from netzob.Simulator.AbstractChannel import AbstractChannel
|
||||
from netzob.Model.Vocabulary.Domain.Variables.Leafs.AbstractChecksum import AbstractChecksum
|
||||
from netzob.Model.Vocabulary.Domain.Variables.Leafs.AbstractHash import AbstractHash
|
||||
from netzob.Model.Vocabulary.Domain.Variables.Leafs.AbstractHMAC import AbstractHMAC
|
||||
from netzob.Fuzzing.Mutators.DomainMutator import DomainMutator
|
||||
|
||||
|
||||
def get_decorators(cls):
|
||||
target = cls
|
||||
decorators = {}
|
||||
|
||||
def visit_FunctionDef(node):
|
||||
decorators[node.name] = []
|
||||
for n in node.decorator_list:
|
||||
name = ''
|
||||
if isinstance(n, ast.Call):
|
||||
name = n.func.attr if isinstance(n.func, ast.Attribute) else n.func.id
|
||||
else:
|
||||
name = n.attr if isinstance(n, ast.Attribute) else n.id
|
||||
|
||||
decorators[node.name].append(name)
|
||||
|
||||
node_iter = ast.NodeVisitor()
|
||||
node_iter.visit_FunctionDef = visit_FunctionDef
|
||||
node_iter.visit(ast.parse(inspect.getsource(target)))
|
||||
return decorators
|
||||
|
||||
|
||||
class test_public_api(unittest.TestCase):
|
||||
|
||||
def test_annotations(self):
|
||||
is_failure = False
|
||||
log_failures = []
|
||||
log_annotations = []
|
||||
|
||||
# One-line used to produce the list: grep -nir public_api src/netzob/| awk -F":" '{ print $1}' |uniq|grep -v .pyc|awk -F".py" '{ print $1}' |awk -F"/" '{print $NF}' | sort |xargs echo
|
||||
public_classes = [
|
||||
AbstractChannel, AbstractChecksum, AbstractField, AbstractHash, AbstractHMAC, AbstractionLayer, AbstractState, AbstractTransition, AbstractType, Actor, Agg, Alt, Automata, BitArray, CloseChannelTransition, Data, DebugChannel, DomainMutator, EmptySymbol, CustomEthernetChannel, Field, Preset, HexaString, Integer, IPChannel, IPv4, Memory, OpenChannelTransition, Opt, Padding, Protocol, Raw, RawEthernetChannel, CustomIPChannel, Repeat, Size, SSLClient, State, String, Symbol, TCPClient, TCPServer, Timestamp, Transition, UDPClient, UDPServer, UnknownSymbol, Value
|
||||
]
|
||||
|
||||
for public_class in public_classes:
|
||||
decorated_members = get_decorators(public_class)
|
||||
|
||||
# First: find all public API methods
|
||||
public_api_members = []
|
||||
for member, decorators in decorated_members.items():
|
||||
for decorator in decorators:
|
||||
if decorator == "public_api":
|
||||
public_api_members.append(member)
|
||||
break
|
||||
|
||||
# Then: verify existence of type annotation for each public API
|
||||
interesting_members = inspect.getmembers(public_class, inspect.isfunction)
|
||||
for (method_name, method_object) in interesting_members:
|
||||
if method_name in public_api_members:
|
||||
if callable(method_object):
|
||||
signature = inspect.signature(method_object)
|
||||
|
||||
for param_name, param in signature.parameters.items():
|
||||
if param_name != 'self':
|
||||
if param.annotation == inspect.Parameter.empty:
|
||||
is_failure = True
|
||||
log_failures.append("In class '{}', method '{}', parameter '{}' has no type annotation".format(public_class.__name__, method_name, param_name))
|
||||
else:
|
||||
log_annotations.append("In class '{}', method '{}', parameter '{}' has type annotation: '{}'".format(public_class.__name__, method_name, param_name, param.annotation))
|
||||
|
||||
if signature.return_annotation == inspect.Parameter.empty:
|
||||
is_failure = True
|
||||
log_failures.append("In class '{}', method '{}', return value has no type annotation".format(public_class.__name__, method_name))
|
||||
else:
|
||||
log_annotations.append("In class '{}', method '{}', return value has type annotation: '{}'".format(public_class.__name__, method_name, signature.return_annotation))
|
||||
|
||||
# For public properties, just verify that they have a proper documentation
|
||||
interesting_members = inspect.getmembers(public_class, inspect.isdatadescriptor)
|
||||
for (method_name, method_object) in interesting_members:
|
||||
if method_name in public_api_members:
|
||||
if method_object.__doc__ is None:
|
||||
is_failure = True
|
||||
log_failures.append("In class '{}', property '{}' has no doc".format(public_class.__name__, method_name))
|
||||
|
||||
expected_log_annotations = [
|
||||
"In class 'Symbol', method 'specialize', parameter 'presets' has type annotation: 'typing.Dict[typing.Union[str, netzob.Model.Vocabulary.Field.Field], typing.Union[bitarray.bitarray, bytes, netzob.Model.Vocabulary.Types.AbstractType.AbstractType]]'",
|
||||
"In class 'Symbol', method 'specialize', parameter 'fuzz' has type annotation: '<class 'netzob.Fuzzing.Fuzz.Fuzz'>'",
|
||||
"In class 'Symbol', method 'specialize', parameter 'memory' has type annotation: '<class 'netzob.Model.Vocabulary.Domain.Variables.Memory.Memory'>'"
|
||||
]
|
||||
|
||||
#self.assertTrue(log_annotations == expected_log_annotations)
|
||||
|
||||
#print("List of parameter type annotations:\n [+] {}".format("\n [+] ".join(log_annotations)))
|
||||
#print(repr(log_annotations))
|
||||
|
||||
if is_failure is True:
|
||||
# TODO: remove comment
|
||||
#self.fail("Type annotation verification failure. Failures:\n [+] {}".format("\n [+] ".join(log_failures)))
|
||||
print("Type annotation verification failure. Failures:\n [+] {}".format("\n [+] ".join(log_failures)))
|
||||
Reference in New Issue
Block a user