diff --git a/test/src/all.py b/test/src/all.py index 96f9062..0a6bd61 100644 --- a/test/src/all.py +++ b/test/src/all.py @@ -18,7 +18,7 @@ import importlib import os # Export / other tests -from .core import test_all +from .core import test_all # noqa: F401 DEFAULT_TESTS = [ "arp", @@ -26,11 +26,12 @@ DEFAULT_TESTS = [ "http", "icmpv4", "icmpv6", - "ip46", + "ip", "rpc", "smb", "ssh", "stun", + "tcp", ] ENABLED_TESTS = DEFAULT_TESTS diff --git a/test/src/core.py b/test/src/core.py index a08e4d0..87f0844 100644 --- a/test/src/core.py +++ b/test/src/core.py @@ -36,6 +36,7 @@ LOG = setup_logs() TESTS = [] ERRORS = [] + # decorator to automatically add a function to tests def test(f): global ERRORS, TESTS diff --git a/test/src/tests/ip.py b/test/src/tests/ip.py new file mode 100644 index 0000000..f87fb75 --- /dev/null +++ b/test/src/tests/ip.py @@ -0,0 +1,50 @@ +# This file is part of masscanned. +# Copyright 2021 - The IVRE project +# +# Masscanned 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. +# +# Masscanned 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 Masscanned. If not, see . + +from scapy.layers.inet import IP, ICMP +from scapy.layers.l2 import Ether +from scapy.sendrecv import srp1 + +from ..conf import IPV4_ADDR, MAC_ADDR +from ..core import test, check_ip_checksum + + +@test +def test_ipv4_req(): + ##### IP ##### + ip_req = Ether(dst=MAC_ADDR) / IP(dst=IPV4_ADDR, id=0x1337) / ICMP(type=8, code=0) + ip_repl = srp1(ip_req, timeout=1) + assert ip_repl is not None, "expecting answer, got nothing" + check_ip_checksum(ip_repl) + assert IP in ip_repl, "no IP layer in response" + ip_repl = ip_repl[IP] + assert ip_repl.id == 0, "IP identification unexpected" + + +@test +def test_eth_req_other_mac(): + #### ETH #### + ip_req = Ether(dst="00:00:00:11:11:11") / IP(dst=IPV4_ADDR) / ICMP(type=8, code=0) + ip_repl = srp1(ip_req, timeout=1) + assert ip_repl is None, "responding to other MAC addresses" + + +@test +def test_ipv4_req_other_ip(): + ##### IP ##### + ip_req = Ether(dst=MAC_ADDR) / IP(dst="1.2.3.4") / ICMP(type=8, code=0) + ip_repl = srp1(ip_req, timeout=1) + assert ip_repl is None, "responding to other IP addresses" diff --git a/test/src/tests/ip46.py b/test/src/tests/tcp.py similarity index 88% rename from test/src/tests/ip46.py rename to test/src/tests/tcp.py index 62f3912..1b0d00e 100644 --- a/test/src/tests/ip46.py +++ b/test/src/tests/tcp.py @@ -14,7 +14,7 @@ # You should have received a copy of the GNU General Public License # along with Masscanned. If not, see . -from scapy.layers.inet import IP, ICMP, TCP +from scapy.layers.inet import IP, TCP from scapy.layers.inet6 import IPv6 from scapy.layers.l2 import Ether from scapy.packet import Raw @@ -25,34 +25,6 @@ from ..conf import IPV4_ADDR, IPV6_ADDR, MAC_ADDR from ..core import test, check_ip_checksum, check_ipv6_checksum -@test -def test_ipv4_req(): - ##### IP ##### - ip_req = Ether(dst=MAC_ADDR) / IP(dst=IPV4_ADDR, id=0x1337) / ICMP(type=8, code=0) - ip_repl = srp1(ip_req, timeout=1) - assert ip_repl is not None, "expecting answer, got nothing" - check_ip_checksum(ip_repl) - assert IP in ip_repl, "no IP layer in response" - ip_repl = ip_repl[IP] - assert ip_repl.id == 0, "IP identification unexpected" - - -@test -def test_eth_req_other_mac(): - #### ETH #### - ip_req = Ether(dst="00:00:00:11:11:11") / IP(dst=IPV4_ADDR) / ICMP(type=8, code=0) - ip_repl = srp1(ip_req, timeout=1) - assert ip_repl is None, "responding to other MAC addresses" - - -@test -def test_ipv4_req_other_ip(): - ##### IP ##### - ip_req = Ether(dst=MAC_ADDR) / IP(dst="1.2.3.4") / ICMP(type=8, code=0) - ip_repl = srp1(ip_req, timeout=1) - assert ip_repl is None, "responding to other IP addresses" - - @test def test_tcp_syn(): ##### SYN-ACK #####