# Cursed Packets Cookbook: Weird Frames, Middlebox Lies & Reproducers

> **FrameAssembly v3.2.2** · Workflow Guide 08 · Canonical URL: https://frameassembly-lang.dev/docs/cursed-packets-cookbook

Four copy-paste packet war stories for catching forged middlebox TCP resets, 802.1ad QinQ native-VLAN leaks, IDS stream-reassembler edge cases, and offline OT coil writes.

## Key Takeaways

- Isolate forged inline middlebox TCP resets by comparing the origin server SYN-ACK TTL (`52`) against the sudden RST TTL (`251`) and IPID (`0x0000`).
- Standard OS network stacks will not emit double-tagged QinQ frames, overlapping TCP sequence offsets, or custom hop-limit jumps — `.frasm` writes exact wire bytes directly to `.pcap`.
- Every recipe compiles to `.pcap` or `.pcapng` with valid Ethernet/IP/TCP/CRC checksums for Wireshark, Suricata, Zeek, and `tcpreplay`.

## 1. Inline Middlebox TCP Reset Detection (TTL & IPID Discrepancy)

When a TLS connection terminates 400 microseconds after `ClientHello` — faster than round-trip propagation to the origin server — an adjacent inline DPI firewall or proxy is typically injecting a forged `RST+ACK`.

In Wireshark, compare the origin server (`upstream_api`) `SYN-ACK` at `ttl 52` (twelve router hops away) against the sudden `RST+ACK` arriving with `ttl 251`, `ipid 0x0000`, and `win 0`. This 5-frame `.frasm` reproducer builds a deterministic regression capture:

### `middlebox_rst_autopsy.frasm`

```frameassembly
// Reproduce TTL jump (52 -> 251) when an inline DPI middlebox resets TLS SNI
host client_host  { ip 10.42.10.99   mac 00:1b:21:aa:bb:01 }
host upstream_api { ip 198.51.100.42 mac 00:1c:73:00:00:01 }

compile {
    // Origin server sits 12 router hops away (64 - 12 = TTL 52)
    client_host -> upstream_api tcp syn srcport 54321 dstport 443 ttl 64 win 65535 mss 1460 wscale 7 sackperm wait 14ms
    client_host <- upstream_api tcp syn ack ttl 52 ipid 0x4a21 win 65535 mss 1460 wscale 7 sackperm wait 1ms
    client_host -> upstream_api tcp ack ttl 64 wait 1ms

    // TLS ClientHello triggers an inline middlebox reset 400us later
    client_host -> upstream_api tls clienthello sni "git.corp-internal.example" ciphersuite 0x1301 alpn "h2" ttl 64 wait 400us
    client_host <- upstream_api tcp rst ack ttl 251 ipid 0x0000 win 0
}
```

```bash
# Compile and inspect the sudden TTL jump (52 -> 251) in tshark
frameassembly middlebox_rst_autopsy.frasm
tshark -r middlebox_rst_autopsy.pcap -T fields -e frame.number -e frame.time_relative -e ip.ttl -e ip.id -e tcp.flags.str
```

> **Wireshark Filter for Suspect Resets:** Filter on `tcp.flags.reset == 1 && ip.id == 0` (or check whether `ip.ttl` jumps by 60+ mid-stream compared to the initial `SYN-ACK`).

## 2. Unsolicited LLDP Discovery & Native-VLAN 802.1ad QinQ Tag Popping

Unmanaged endpoints often broadcast firmware and management details over `lldp` while sharing access ports. If a switch trunk leaves VLAN 1 untagged as its native VLAN, an outer `0x88a8` tag (`qinq 1 innervlan 20`) can be stripped on the first trunk hop and forward the inner tag into VLAN 20.

Because client OS NIC drivers strip VLAN headers before user space, validating switch port-security and double-tag drop policies normally requires dedicated hardware. Here is the 3-frame `.frasm` audit:

### `qinq_printer_hop.frasm`

```frameassembly
// Step 1: Unsolicited LLDP advertisement · Step 2: Outer VLAN 1 -> Inner VLAN 20 probe
host access_endpoint { ip 10.1.1.250 mac 00:11:0a:99:88:77 }
host core_trunk_sw   { mac 00:1c:73:aa:00:01 }
host finance_db      { ip 10.1.20.54 mac 00:50:56:bb:20:54 }

compile {
    // Unsolicited LLDP multicast to 01:80:c2:00:00:0e
    access_endpoint -> core_trunk_sw lldp chassisid "access-port-3f" portid "eth0" ttl 120 sysname "prn-3f-east.local" sysdesc "Embedded JetDirect; management enabled" wait 2ms

    // Double-tagged 802.1ad S-VLAN 1 + 802.1Q C-VLAN 20 SYN probe toward Postgres
    access_endpoint -> finance_db qinq 1 innervlan 20 tcp syn srcport 60123 dstport 5432 win 64240 mss 1460 wait 2ms
    access_endpoint -> finance_db vlan 20 icmp echorequest id 0x1020 seq 1 payload "native-vlan1-audit"
}
```

## 3. Overlapping TCP `seq` Retransmits (First-Seen vs. Last-Seen)

FrameAssembly tracks 4-tuple `seq` and `acknum` automatically across every TCP frame. When testing IDS stream reassemblers, passing an explicit `seq` value overrides the sequence counter on that frame and re-anchors subsequent segments.

Send two `PSH+ACK` segments at the exact same `seq 1001` (`wait 500us` apart) with different HTTP URIs and TTLs to verify whether Suricata, Zeek, or an inline proxy inspects the first-seen or last-seen segment:

### `seq_retransmit_puzzle.frasm`

```frameassembly
// Stream-reassembler validation: two HTTP segments at TCP seq 1001
host test_client { ip 172.16.50.15 }
host inline_ids  { ip 172.16.50.80 }

compile {
    test_client -> inline_ids tcp syn srcport 51999 dstport 80 win 65535 mss 1460 wait 1ms
    test_client <- inline_ids tcp syn ack win 65535 mss 1460 wait 1ms
    test_client -> inline_ids tcp ack wait 1ms

    // Segment A at seq 1001 with short TTL 3
    test_client -> inline_ids http get uri "/index.html" hosthdr "app.lab.local" seq 1001 ttl 3 wait 500us

    // Segment B 500us later at the same seq 1001 with full TTL 64
    test_client -> inline_ids http get uri "/admin/debug-vars" hosthdr "app.lab.local" seq 1001 ttl 64
}
```

```bash
# Inspect reassembly behavior offline in Suricata and Zeek
frameassembly seq_retransmit_puzzle.frasm
suricata -r seq_retransmit_puzzle.pcap -k none -l ./suricata-retransmit
zeek -C -r seq_retransmit_puzzle.pcap
```

## 4. Offline OT Firewall & NDR Audit: Modbus Coil Writes & DNP3 Direct Operate

Validating OT firewall policies and industrial NDR detections for unauthorized Modbus coil writes (`0x05`) or DNP3 Direct Operate commands should never require sending write frames toward live substation RTUs or plant PLCs.

Compile a deterministic 6-frame `.pcap` with valid TCP port 502 sequence tracking and computed IEEE 1815 DNP3 per-chunk CRC-16 checksums, then replay or ingest it against your sensor offline:

### `ot_midnight_coil.frasm`

```frameassembly
// Offline OT conduit test: permitted FC 03 read -> blocked FC 05 write -> DNP3 CROB
host eng_workstation { ip 192.168.120.99 }
host substation_plc  { ip 192.168.120.10 }

compile {
    eng_workstation -> substation_plc tcp syn srcport 50502 dstport 502 win 64240 mss 1460 vlan 120 wait 1ms
    eng_workstation <- substation_plc tcp syn ack win 64240 mss 1460 vlan 120 wait 1ms
    eng_workstation -> substation_plc tcp ack vlan 120 wait 1ms

    // 1. Permitted SCADA poll (FC 03 Read Holding Registers)
    eng_workstation -> substation_plc modbus readholdingregisters txid 10 unitid 1 addr 40001 count 2 vlan 120 wait 2ms

    // 2. Unauthorized FC 05 Write Single Coil (expected to trigger OT policy block/alert)
    eng_workstation -> substation_plc modbus writesinglecoil txid 11 unitid 1 addr 1 value 0xff00 vlan 120 wait 3ms

    // 3. DNP3 Direct Operate over UDP 20000 (computes IEEE 1815 CRC-16 chunks automatically)
    eng_workstation -> substation_plc transport udp dnp3 directoperate src 3 dst 10 group 12 variation 1 vlan 120
}
```

| Anomaly / Pattern | Wireshark Display Filter | `.frasm` Modifier |
| --- | --- | --- |
| Forged middlebox TCP reset | `tcp.flags.reset == 1 && ip.ttl > 200` | `tcp rst ack ttl 251 ipid 0x0000 win 0` |
| 802.1ad QinQ double-VLAN hop | `vlan.etype == 0x88a8` | `qinq 1 innervlan 20` |
| Duplicate / overlapping TCP `seq` | `tcp.analysis.retransmission` | Explicit `seq 1001` on two consecutive frames (`ttl 3` vs `ttl 64`) |
| Unauthorized OT coil / breaker write | `modbus.func_code == 5 \|\| dnp3.al.func == 5` | `modbus writesinglecoil value 0xff00` / `dnp3 directoperate` |
