Quiz Entry - updated: 2026.11.26
How can you test an IDS rule with scapy and tcpreplay, without a real attack?
Use scapy to craft a packet that contains the content the rule looks for and save it as a pcap, then use tcpreplay to inject that pcap onto the interface Suricata is watching.
# scapy: build Ethernet / IP / TCP with the payload, write it to a file
pkt = Ether()/IP(dst="192.168.1.12")/TCP()/"evilliveshere"
wrpcap("ids-testing.pcap", pkt)
# replay the capture onto the monitored interface at 10 MB/s
sudo tcpreplay -i ens3 -M 10 ids-testing.pcap
- scapy is a Python tool for building, sending and dissecting packets layer by layer; the
/operator stacks layers. - tcpreplay sends previously captured traffic back onto a network interface (
-i), at a chosen speed (-Min Mbps).
The packet never needs to reach a real server. Suricata sees it on the wire, matches content:"evilliveshere", and the alert appears in Kibana. The same technique is how you test a rule against real attack traffic safely: record it once, then replay it whenever you change the rule. Later in the lab it is used to replay recorded malware traffic.
Go deeper:
Scapy usage guide — stacking layers with
/and writing pcaps withwrpcap().tcpreplay man page — every replay option, including
-iand the-Mrate limit.Tcpreplay — why IDS/IPS vendors replay captured traffic for repeatable tests.