From aff272654557360b986f6a48d679ccdf02d68de2 Mon Sep 17 00:00:00 2001 From: originalsouth Date: Tue, 21 Nov 2023 11:26:15 +0100 Subject: [PATCH] Fix/2037 kat nmap normalizer (#2038) --- boefjes/boefjes/plugins/kat_nmap/normalize.py | 4 +- boefjes/tests/examples/raw/nmap_mispoes.xml | 39 +++++++++++++++++++ boefjes/tests/test_nmap.py | 20 ++++++++++ 3 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 boefjes/tests/examples/raw/nmap_mispoes.xml diff --git a/boefjes/boefjes/plugins/kat_nmap/normalize.py b/boefjes/boefjes/plugins/kat_nmap/normalize.py index 63812596ebf..e6393297370 100644 --- a/boefjes/boefjes/plugins/kat_nmap/normalize.py +++ b/boefjes/boefjes/plugins/kat_nmap/normalize.py @@ -44,9 +44,7 @@ def get_ip_ports_and_service(host: NmapHost, network: Network, netblock: Referen yield ip_port service_name = service.service - if port == 80: - service_name = "http" - if port == 443: + if service_name == "http" and service.tunnel == "ssl": service_name = "https" port_service = Service(name=service_name) diff --git a/boefjes/tests/examples/raw/nmap_mispoes.xml b/boefjes/tests/examples/raw/nmap_mispoes.xml new file mode 100644 index 00000000000..61b143ca602 --- /dev/null +++ b/boefjes/tests/examples/raw/nmap_mispoes.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + +cpe:/a:openbsd:openssh:8.4p1cpe:/o:linux:linux_kernel +cpe:/a:isc:bind:9.16.44cpe:/o:linux:linux_kernel +cpe:/a:igor_sysoev:nginx:1.18.0 +cpe:/a:igor_sysoev:nginx:1.18.0 +cpe:/a:mysql:mysql + + + + + + diff --git a/boefjes/tests/test_nmap.py b/boefjes/tests/test_nmap.py index e4a16cf41a7..64996a32277 100644 --- a/boefjes/tests/test_nmap.py +++ b/boefjes/tests/test_nmap.py @@ -1,6 +1,10 @@ from unittest import TestCase +from boefjes.job_handler import serialize_ooi from boefjes.plugins.kat_nmap.main import Protocol, build_nmap_arguments +from boefjes.plugins.kat_nmap.normalize import run +from octopoes.models.ooi.network import IPAddressV4, Network +from tests.loading import get_boefje_meta, get_dummy_data, get_normalizer_meta class NmapTest(TestCase): @@ -163,3 +167,19 @@ def test_nmap_arguments_udp_top250_ipv6(self): ], args, ) + + def test_normalizer(self): + input_ooi = IPAddressV4(network=Network(name="internet").reference, address="134.209.85.72") + boefje_meta = get_boefje_meta(input_ooi=input_ooi.reference) + boefje_meta.arguments["input"] = serialize_ooi(input_ooi) + output = list(run(get_normalizer_meta(boefje_meta), get_dummy_data("raw/nmap_mispoes.xml"))) + self.assertEqual(17, len(output)) + for i, out in enumerate(output[:-1]): + if out.object_type == "IPPort" and output[i + 1].object_type == "Service": + if out.port == 80: + self.assertEqual("http", output[i + 1].name) + elif out.port == 443: + self.assertEqual("https", output[i + 1].name) + else: + self.assertNotEqual("http", output[i + 1].name) + self.assertNotEqual("https", output[i + 1].name)