From 9117721cbccaa1ff73fcff92bb49b91c6ecf31d8 Mon Sep 17 00:00:00 2001 From: Alice Akaki Date: Thu, 7 Nov 2024 17:12:46 -0400 Subject: [PATCH] test: add test for vlan.id Ticket: #1065 --- tests/detect-vlan-id/README.md | 3 ++ tests/detect-vlan-id/input.pcap | Bin 0 -> 94 bytes tests/detect-vlan-id/test.rules | 9 +++++ tests/detect-vlan-id/test.yaml | 56 ++++++++++++++++++++++++++++++ tests/detect-vlan-id/writepcap.py | 17 +++++++++ 5 files changed, 85 insertions(+) create mode 100644 tests/detect-vlan-id/README.md create mode 100644 tests/detect-vlan-id/input.pcap create mode 100644 tests/detect-vlan-id/test.rules create mode 100644 tests/detect-vlan-id/test.yaml create mode 100644 tests/detect-vlan-id/writepcap.py diff --git a/tests/detect-vlan-id/README.md b/tests/detect-vlan-id/README.md new file mode 100644 index 000000000..bb496914b --- /dev/null +++ b/tests/detect-vlan-id/README.md @@ -0,0 +1,3 @@ +Test for checking the working of vlan.id keyword by creating rules and matching a crafted packet against them. The packet is an ICMP packet with 3 different VLAN ids [200,300,400]. + +PCAP created with scapy 2.5.0. diff --git a/tests/detect-vlan-id/input.pcap b/tests/detect-vlan-id/input.pcap new file mode 100644 index 0000000000000000000000000000000000000000..35ee79b95ee4d0e807dad33c74a1e6fde07226a7 GIT binary patch literal 94 zcmca|c+)~A1{MYw`2U}Qff2}guC1Hi`InQy49EsyB`^>KgGL616O9avIzT*ugTa-7 YK?bD7fwAN^BM>kF0SCi(pg9Z-0C{c@&;S4c literal 0 HcmV?d00001 diff --git a/tests/detect-vlan-id/test.rules b/tests/detect-vlan-id/test.rules new file mode 100644 index 000000000..b88286efa --- /dev/null +++ b/tests/detect-vlan-id/test.rules @@ -0,0 +1,9 @@ +alert ip any any -> any any (msg:"Vlan ID is equal to 200 with specific layer"; vlan.id:200,0; sid:1;) +alert ip any any -> any any (msg:"One Vlan ID is equal to 300"; vlan.id:300; sid:2;) +alert ip any any -> any any (msg:"Last Vlan ID is equal to 400"; vlan.id:400,-1; sid:3;) +alert ip any any -> any any (msg:"Vlan ID is equal to 300 with specific layer"; vlan.id:0x12C,1; sid:4;) +alert ip any any -> any any (msg:"Vlan ID at layer 1 is not equal to 200"; vlan.id:!200,1; sid:5;) +alert ip any any -> any any (msg:"There is no VLAN ID equal to 500"; vlan.id:!500; sid:6;) +alert ip any any -> any any (msg:"VLAN ID at layer 2 is between 100 and 600"; vlan.id:100-600,2; sid:7;) +alert ip any any -> any any (msg:"VLAN ID at layer 1 is less than 400"; vlan.id:<400,1; sid:8;) +alert ip any any -> any any (msg:"One Vlan ID is greater than or equal to 200"; vlan.id:>=0xC8; sid:9;) \ No newline at end of file diff --git a/tests/detect-vlan-id/test.yaml b/tests/detect-vlan-id/test.yaml new file mode 100644 index 000000000..911393ca6 --- /dev/null +++ b/tests/detect-vlan-id/test.yaml @@ -0,0 +1,56 @@ +requires: + min-version: 8 + +args: +- -k none + +checks: +- filter: + count: 1 + match: + event_type: alert + vlan[0]: 200 + alert.signature_id: 1 +- filter: + count: 1 + match: + event_type: alert + vlan[1]: 300 + alert.signature_id: 2 +- filter: + count: 1 + match: + event_type: alert + vlan[2]: 400 + alert.signature_id: 3 +- filter: + count: 1 + match: + event_type: alert + vlan[1]: 300 + alert.signature_id: 4 +- filter: + count: 1 + match: + event_type: alert + alert.signature_id: 5 +- filter: + count: 1 + match: + event_type: alert + alert.signature_id: 6 +- filter: + count: 1 + match: + event_type: alert + alert.signature_id: 7 +- filter: + count: 1 + match: + event_type: alert + alert.signature_id: 8 +- filter: + count: 1 + match: + event_type: alert + alert.signature_id: 9 \ No newline at end of file diff --git a/tests/detect-vlan-id/writepcap.py b/tests/detect-vlan-id/writepcap.py new file mode 100644 index 000000000..c0e3663f5 --- /dev/null +++ b/tests/detect-vlan-id/writepcap.py @@ -0,0 +1,17 @@ +#! /usr/bin/env python3 +from scapy.all import * + +CLIENT_MAC = "11:11:11:11:11:11" +SERVER_MAC = "22:22:22:22:22:22" + +CLIENT_IP = "1.1.1.1" +SERVER_IP = "2.2.2.2" + +request = (Ether(src=CLIENT_MAC, dst=SERVER_MAC) / + Dot1Q(vlan=200) / + Dot1Q(vlan=300) / + Dot1Q(vlan=400) / + IP(src=CLIENT_IP, dst=SERVER_IP) / + ICMP(type=8)) + +wrpcap("input.pcap", request, append=False) \ No newline at end of file