# Edit & Anonymize a `.pcap` File (IPs, VLANs & Payloads)

> **FrameAssembly v3.2.2** · Workflow Guide 02 · Canonical URL: https://frameassembly-lang.dev/docs/edit-and-anonymize-pcap

Reverse captures into plain `.frasm` text, edit or redact customer IPs and internal hostnames with find-and-replace, and rebuild clean checksums.

## Key Takeaways

- `frameassembly reverse` converts `.pcap` and `.pcapng` captures into editable `.frasm` text across all 81 protocols.
- Swap an IP once inside `host1`, and every packet in that flow updates its IP header and L4 pseudo-header checksum.
- Unlike hex editors or `tcprewrite`, changing Layer 7 text (`qname`, `sni`, `hosthdr`) recalculates outer lengths and TCP `seq` numbers automatically.

## 1. Why Hex Editors & `tcprewrite` Betray You

Vendor TAC wants a packet capture of your broken auth flow — except your raw `.pcap` is stuffed with internal `10.x` subnets, MAC OUIs, SNMP community strings, and `"payroll.corp.internal"` inside DNS and TLS SNI.

`tcprewrite` can swap outer Layer 3 IPs, right up until you notice your internal hostnames are still sitting in plaintext inside Layer 7 payloads. Hex-edit those strings and you immediately wreck IP total lengths, TCP sequence offsets, and transport checksums. Going `.pcap -> .frasm -> .pcap` fixes the whole stack at once.

## 2. The 3-Step Loop: `reverse` -> Edit Text -> Rebuild

Point `frameassembly reverse` at any `.pcap` or `.pcapng` (or drop the file onto the browser Playground — zero bytes ever leave your tab). FrameAssembly dissects every frame, groups endpoints into `host1`, `host2`, ..., preserves inter-packet `wait` gaps, and writes clean `.frasm` text.

Run find-and-replace in your favorite editor, then build a fresh, checksum-clean `.pcap`.

### `sanitized_case.frasm`

```frameassembly
// Reversed capture after scrubbing production IPs and internal hostnames
host host1 { ip 10.254.1.10 mac 02:00:00:00:00:01 }
host host2 { ip 10.254.1.53 mac 02:00:00:00:00:02 }
host host3 { ip 10.254.2.80 mac 02:00:00:00:00:03 }

compile {
    host1 -> host2 dns query txid 0x8821 qname "app.sanitized-example.test" qtype "A" vlan 100 wait 2ms
    host1 <- host2 dns response txid 0x8821 qname "app.sanitized-example.test" qtype "A" rdata "10.254.2.80" ansttl 300 vlan 100 wait 4ms
    host1 -> host3 tcp syn srcport 54320 dstport 443 win 65535 mss 1460 vlan 100 wait 1ms
    host1 <- host3 tcp syn ack win 65535 mss 1460 vlan 100 wait 1ms
    host1 -> host3 tcp ack vlan 100 wait 1ms
    host1 -> host3 tls clienthello sni "app.sanitized-example.test" alpn "h2" vlan 100
}
```

```bash
# 1. Reverse customer_incident.pcap -> sanitized_case.frasm
frameassembly reverse customer_incident.pcap sanitized_case.frasm

# 2. Scrub IPs, VLANs, or hostnames in any editor, then preview the packet table
frameassembly show sanitized_case.frasm

# 3. Rebuild -> clean .pcap with recalculated lengths and checksums
frameassembly sanitized_case.frasm sanitized_case.pcap
```

### What Changed Between customer_incident.pcap and sanitized_case.pcap

Changing a 21-byte internal hostname ("payroll.corp.internal") to a 26-byte redacted hostname ("app.sanitized-example.test") grows every DNS & TLS frame by +5 bytes — and recompiling fixes every outer length and checksum automatically:

```diff
--- reversed_raw.frasm (from customer_incident.pcap)
+++ sanitized_case.frasm (ready for vendor TAC)
- host host1 { ip 10.24.8.19  mac 00:50:56:9a:41:0c }
+ host host1 { ip 10.254.1.10 mac 02:00:00:00:00:01 }
  compile {
-     host1 -> host2 dns query txid 0x8821 qname "payroll.corp.internal" qtype "A" wait 2ms
+     host1 -> host2 dns query txid 0x8821 qname "app.sanitized-example.test" qtype "A" vlan 100 wait 2ms
-     host1 -> host3 tls clienthello sni "payroll.corp.internal" alpn "h2"
+     host1 -> host3 tls clienthello sni "app.sanitized-example.test" alpn "h2" vlan 100
  }
```

- Ethernet II vendor OUI MACs replaced with locally administered 02:00:00:00:00:0x + 802.1Q VLAN 100 inserted (+4 B)
- DNS QNAME labels + UDP length + IPv4 Total Length + IPv4/UDP checksums recalculated for +5 B hostname delta
- TLS Record length, Handshake length, Server Name extension length, and TCP pseudo-header checksum updated cleanly

## 3. Edits That Used to Take 80 Lines of Python

Once a binary trace is `.frasm` text, surgery is just text editing:

| What You Want | What You Edit in `.frasm` | What the Compiler Fixes for You |
| --- | --- | --- |
| Scrub customer subnets | Swap `ip` and `mac` inside `host1`, `host2`, ... | Ethernet MACs, IPv4/IPv6 headers, and TCP/UDP/ICMPv6 pseudo-header checksums |
| Insert or strip VLAN / QinQ tags | Add, tweak, or delete `vlan 200` or `qinq 500 innervlan 20` | Outer EtherTypes (`0x8100` / `0x88a8`) and wire frame byte lengths |
| Wipe hostnames or secrets | Edit `qname`, `sni`, `hosthdr`, `uri`, `community`, or `user` | L7 TLV/header lengths, IP total length, and downstream TCP `seq` / `acknum` |
| Stretch or compress timing | Change `wait 500us` to `wait 50ms` | Cumulative `.pcap` / `.pcapng` timestamps on every subsequent frame |
| Preserve unknown payloads | Leave or edit `hexpayload "..."` | Keeps custom or proprietary wire bytes byte-for-byte intact |

> **IPsec ESP Reverse Note (`esp` <-> `ipsec`):** When reversing IP protocol 50 traffic, `reverse` emits `esp` preserving `spi`, `seq`, and encrypted payload bytes cleanly.

## 4. `frameassembly reverse` Fidelity & Boundary Matrix

Understanding what `frameassembly reverse` converts into editable fields and what stays as raw bytes keeps TAC redaction predictable:

| Input Frame / Container Class | frameassembly reverse Output Behavior | Recompile Round-Trip Guarantee |
| --- | --- | --- |
| Container & Link-Layer Normalization | Reads classic/nanosecond `.pcap` and `.pcapng` (`SHB`/`IDB`/`EPB`/`SPB`); normalizes `ETHERNET`, `RAW`, `IPV4`, `IPV6`, `LINUX_SLL`, `LINUX_SLL2`, `NULL`, and `LOOP` into Ethernet II; strips trailing 60/64B zero-padding and 4B FCS. | Clean Ethernet II output (`LINKTYPE_ETHERNET`) with preserved nanosecond inter-packet `wait` deltas. |
| Cleartext & Structured L2–L7 Protocols (80 builders) | Converts packets into `host1`, `host2`, ... + lowercase `.frasm` protocol fields (`dns qname`, `tls clienthello sni`, `http`, `bgp`, `modbus`, `dnp3`, `snmp1`/`snmp2`, `snmp3` `noAuthNoPriv`), verified byte-for-byte on round-trip. | Editing variable-length strings or adding `vlan`/`qinq` recalculates L7 TLV lengths, IPv4/UDP lengths, downstream TCP `seq`/`acknum`, and all checksums. |
| IPsec ESP (IP Protocol 50) | Emits `esp` (`spi`, `seq`, `iv`, `icv` / encrypted payload) rather than the `ipsec` shorthand. | Preserves SPI, sequence number, and ciphertext while recalculating outer IP headers if `hostN` IPs are redacted. |
| Encrypted `snmp3` (`authPriv` / keyed `authNoPriv`) & Unknown Payloads | Falls back cleanly to `udp` / `tcp` with lossless `hexpayload "..."` because USM decryption requires external keys. | Byte-exact payload preservation on recompile while still allowing outer MAC, VLAN, IP, and port redaction. |

## 5. Choosing the Right PCAP Scrubber (`frameassembly reverse` vs. `tcprewrite` & TraceWrangler)

Different capture-scrubbing jobs call for different tools. Use `tcprewrite`, `TraceWrangler`, or `editcap` when slicing or remapping multi-gigabyte captures in bulk; reach for `frameassembly reverse` when you need to edit Layer 7 strings, VLAN/QinQ tags, or trim an incident trace down to a clean TAC reproducer:

| Tool | Best For | Layer 7 Hostname & String Edits | Trade-Offs |
| --- | --- | --- | --- |
| `frameassembly reverse` (`.frasm`) | Scrubbing 5–500 packet TAC reproducers, editing L2–L7 fields (`qname`, `sni`, `hosthdr`, `vlan`), and checking captures into Git. | Recalculates DNS/TLS/HTTP lengths, IPv4/UDP lengths, TCP `seq`/`acknum`, and checksums on recompile. | Converts the capture into plain text; for multi-GB captures, filter the relevant conversation with `tshark` or `editcap` first. |
| `tcprewrite` (`tcpreplay` suite) | Fast bulk L2 MAC, VLAN, and L3 IP/CIDR remapping across large `.pcap` files from the Linux CLI. | Does not rewrite variable-length Layer 7 strings (`sni`, `qname`, `hosthdr`) or shift downstream TCP `seq` numbers. | Great for fast subnet NAT before `tcpreplay`; leaves internal hostnames exposed inside L7 payloads. |
| TraceWrangler (Windows GUI) | Batch-anonymizing IPv4/IPv6 subnets, MAC OUIs, and DHCP/DNS options across large multi-file Windows captures. | Strong automated anonymization profiles, but does not turn packets into human-editable L2–L7 text lines. | Windows desktop workflow (or Wine); less suited for hand-crafting or diffing custom protocol edge cases in Git. |
| `editcap` & `tshark` (Wireshark CLI) | Slicing time windows, deduplicating frames, stripping packet bytes (`-s`), or filtering a noisy capture down to one flow. | Filters or truncates payloads (`-s 96`) rather than replacing hostnames while keeping L7 sessions intact. | Ideal first step (`tshark -r big.pcap -Y "ip.addr==..." -w slim.pcap`) right before `frameassembly reverse`. |
