-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
72 lines (60 loc) · 2.19 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python3
"""
test.py
This script uses Scapy to send test packets on the virtual network interface (snet0)
to exercise the enhanced filtering rules:
1. IP Filter: Drops TCP packets with source IP 192.168.1.1.
2. UDP Filter: Drops UDP packets.
3. MAC Filter: Drops packets with source MAC 00:11:22:33:44:55.
4. Valid Packet: A TCP packet with valid parameters that should be accepted.
"""
from scapy.all import Ether, IP, TCP, UDP, sendp
import time
INTERFACE = "snet0"
def test_ip_filter():
print("[Test IP Filter] Sending TCP packet with source IP 192.168.1.1 (should be dropped)")
packet = (
Ether() /
IP(src="192.168.1.1", dst="192.168.1.200") /
TCP(sport=12345, dport=80)
)
sendp(packet, iface=INTERFACE, verbose=True)
time.sleep(1)
def test_udp_filter():
print("[Test UDP Filter] Sending UDP packet with source IP 192.168.1.100 (should be dropped due to UDP filtering)")
packet = (
Ether() /
IP(src="192.168.1.100", dst="192.168.1.200") /
UDP(sport=12345, dport=53)
)
sendp(packet, iface=INTERFACE, verbose=True)
time.sleep(1)
def test_mac_filter():
print("[Test MAC Filter] Sending TCP packet with source MAC 00:11:22:33:44:55 (should be dropped)")
packet = (
Ether(src="00:11:22:33:44:55") /
IP(src="192.168.1.100", dst="192.168.1.200") /
TCP(sport=12345, dport=80)
)
sendp(packet, iface=INTERFACE, verbose=True)
time.sleep(1)
def test_valid_packet():
print("[Test Valid Packet] Sending TCP packet with valid parameters (should be accepted)")
packet = (
Ether(src="00:aa:bb:cc:dd:ee") /
IP(src="192.168.1.100", dst="192.168.1.200") /
TCP(sport=12345, dport=80)
)
sendp(packet, iface=INTERFACE, verbose=True)
time.sleep(1)
def main():
print("Starting packet simulation tests on interface:", INTERFACE)
print("-------------------------------------------------------------\n")
test_ip_filter()
test_udp_filter()
test_mac_filter()
test_valid_packet()
print("\nPacket simulation tests completed.")
print("Please check kernel logs using: dmesg | tail -n 30")
if __name__ == "__main__":
main()