# tftp — UDP 69 Config Read/Write Requests & Block Transfers (`tftp`)

> **FrameAssembly v3.2.2** · Protocol 54 of 81 · Canonical URL: https://frameassembly-lang.dev/docs/protocols/tftp

- **Full Protocol Name:** Trivial File Transfer Protocol
- **Keyword:** `tftp`
- **OSI Layer & Transport:** Layer 7 · UDP 69
- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6
- **Standards:** RFC 1350
- **Wireshark Display Filter:** `tftp`
- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 -> UDP 69 -> TFTP`

## Overview

Zero passwords, UDP `69`, and still the fastest way network gear leaks `"startup-config"` — `tftp` scripts `rrq -> data -> ack` block transfers and error codes in seconds.

Trivial File Transfer Protocol (`tftp`, RFC 1350) transfers VoIP phone firmware, PXE network bootloaders, and legacy router/switch `running-config` files over **UDP port `69`** without authentication. Because attackers frequently abuse TFTP to pull cleartext switch configurations (`copy running-config tftp:`) or stage tools inside OT networks, TFTP monitoring is a staple IDS and NAC control.

FrameAssembly encodes all five RFC 1350 opcodes: Read Request (`rrq`, Opcode `1`), Write Request (`wrq`, Opcode `2`), numbered Data blocks (`data`, Opcode `3`), Block Acknowledgments (`ack`, Opcode `4`), and Error packets (`error` / `err`, Opcode `5`).

## Minimal Quickstart (`tftp_quickstart.frasm`)

```frameassembly
host voip_phone { ip 10.20.30.112 }
host tftp_srv   { ip 10.20.30.10 }

compile {
    voip_phone -> tftp_srv tftp rrq filename "SIPDefault.cnf" mode "octet" wait 2ms
    voip_phone <- tftp_srv tftp data block 1 payload "[device]\nproxy=10.20.30.5\n" wait 1ms
    voip_phone -> tftp_srv tftp ack block 1
}
```

### Automatic Wire Calculations

- Defaults UDP destination port to `69` and writes NUL-terminated (`0x00`) `filename` and transfer `mode` (`"octet"` or `"netascii"`) strings on `rrq`/`wrq`.
- Encodes 2-byte big-endian Opcode + 2-byte `block` number on `data` (`3`) and `ack` (`4`) packets.
- Formats Opcode `5` (`error` / `err`) with 2-byte `errcode` and NUL-terminated `errmsg`.

## Practical Lab Example: PXE Bootloader Download + Missing Config File Error (`tftp_pxe_boot.frasm`)

Requests `pxelinux.0` in binary `"octet"` mode, transfers Block 1 with TFTP `ack`, and then requests a missing board config returning RFC 1350 Error Code `1`.

```frameassembly
host pxe_host { ip 172.16.50.101 }
host boot_srv { ip 172.16.50.10 }

compile {
    // 1. Successful Read Request (RRQ) + Block 1 transfer
    pxe_host -> boot_srv tftp rrq filename "pxelinux.0" mode "octet" wait 2ms
    pxe_host <- boot_srv tftp data block 1 hexpayload "7f454c46020101000000000000000000" wait 1ms
    pxe_host -> boot_srv tftp ack block 1 wait 4ms
    // 2. Missing profile returns TFTP Error (Opcode 5, Error Code 1 = File not found)
    pxe_host -> boot_srv tftp rrq filename "pxelinux.cfg/default" mode "octet" wait 2ms
    pxe_host <- boot_srv tftp error errcode 1 errmsg "File not found"
}
```

```bash
# 1. Eyeball relative timestamps, ports & wire lengths in your terminal
frameassembly show tftp_pxe_boot.frasm

# 2. Compile .frasm -> classic .pcap (tcpdump/tcpreplay/Suricata) or nanosecond .pcapng
frameassembly tftp_pxe_boot.frasm tftp_pxe_boot.pcap
frameassembly tftp_pxe_boot.frasm tftp_pxe_boot.pcapng

# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture
frameassembly reverse tftp_pxe_boot.pcap tftp_pxe_boot_edited.frasm

# 4. Verify dissected protocol fields in tshark
tshark -r tftp_pxe_boot.pcap
```

## All `tftp` Keywords & Header Options

Packet line pattern: `src_host -> dst_host tftp [rrq | wrq | data | ack | error | err] [filename "<text>"] [mode "<text>"] [block <0..65535>] [errcode <0..65535>] [errmsg "<text>"]`

| Keyword / Option | Accepted Value | Default | Effect on Packet |
| --- | --- | --- | --- |
| `rrq \| wrq \| data \| ack \| error \| err` | TFTP opcode keyword | `rrq (Opcode 1)` | Selects Opcode `1` Read Request (`rrq`), `2` Write Request (`wrq`), `3` Data (`data`), `4` Acknowledgment (`ack`), or `5` Error (`error` / `err`). |
| `filename "<text>" \| mode "<text>"` | Quoted filename and mode (`"octet"` or `"netascii"`) | `filename "boot.bin", mode "octet"` | Writes NUL-terminated filename and transfer mode strings in `rrq` and `wrq` packets. |
| `block <0..65535>` | 16-bit block number | `1` | Sets the 2-byte Block Number in `data` and `ack` packets (`0` acknowledges a `wrq`). |
| `errcode <0..65535> \| errmsg "<text>"` | RFC 1350 error code (`1` File not found, `2` Access violation) + message | `errcode 1, errmsg "File not found"` | Populates the error code and NUL-terminated error string in `error` / `err` packets. |

## Cross-Layer Options Valid with `tftp`

| Option | Range / Format | Default | Effect |
| --- | --- | --- | --- |
| `wait <number><ns\|us\|ms\|s\|m>` | Time gap (ns, us, ms, s, m) | `10ms` | Advances the packet timestamp clock after sending this packet and before the next packet (`wait 0ns` sends back-to-back). |
| `payload "<text>" \| hexpayload "<hex>"` | Quoted text or hex bytes (choose one) | `Omitted` | Appends or overrides raw payload bytes (`"deadbeef"` or `"de:ad:be:ef"`) and updates packet lengths and checksums. |
| `srcmac <mac> \| dstmac <mac> \| ethertype <0..65535>` | Colon/hyphen/Cisco MAC · EtherType u16 (e.g. 0x0800) | `Host MAC / RFC multicast MAC / auto EtherType` | Overrides the 14-byte Ethernet II source MAC, destination MAC, or 16-bit EtherType for this single packet. |
| `vlan <0..4095> [pcp <0..7>] [dei <0\|1>]` | VLAN ID 0..4095, PCP 0..7, DEI 0..1 | `Untagged` | Wraps the packet in an IEEE 802.1Q VLAN tag (`0x8100`) with optional 802.1p QoS priority. |
| `qinq <0..4095> [innervlan <0..4095>]` | Outer S-VLAN 0..4095, Inner C-VLAN 0..4095 | `Untagged (innervlan 1 when qinq is set)` | Double-tags the packet with outer IEEE 802.1ad S-Tag (`0x88a8`) plus inner IEEE 802.1Q C-Tag (`0x8100`). |
| `mpls <0..1048575> [label <0..1048575>] [exp\|tc <0..7>] [bos <0\|1>] [mplsttl <0..255>]` | Label 0..1048575, exp/tc 0..7, bos 0..1, ttl 0..255 | `Unlabeled (at most 1 mpls tag per packet)` | Inserts a 32-bit MPLS label header (`0x8847`) ahead of the Layer 3 header. |
| `ttl <0..255> [dscp <0..63>] [ecn <0..3>]` | TTL/Hop Limit 0..255, DSCP 0..63, ECN 0..3 | `ttl 64, dscp 0, ecn 0` | Sets IPv4 TTL or IPv6 Hop Limit plus DiffServ (DSCP) and ECN QoS markings. |
| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>]` | IPv4 ID, DF/MF flags, fragment offset 0..8191 | `ipid 1, flags 0, fragoffset 0` | Sets IPv4 Identification, Do-Not-Fragment (`df`), More-Fragments (`mf`), and fragment offset (ignored over IPv6). |
| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (ignored when running over IPv4 hosts). |
| `srcport <0..65535> \| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 69` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |

## Common Mistakes & Quick Fixes

### ack Inside a tftp Packet Emits TFTP Opcode 4 (Not TCP ACK)

- **Valid v3.2.2 Syntax:** `voip_phone -> tftp_srv tftp ack block 1`

On a `tftp` line, `ack` builds the 4-byte UDP TFTP Block Acknowledgment (`0x0004` + 2-byte `block`), whereas TCP flags are not allowed on UDP protocols.

### Quote Filenames Containing Dots, Slashes, or Hyphens

- **Avoid:** `voip_phone -> tftp_srv tftp rrq filename router-confg.cfg`
- **Valid v3.2.2 Syntax:** `voip_phone -> tftp_srv tftp rrq filename "router-confg.cfg"`

Always wrap file paths and names in double quotes (`"router-confg.cfg"`).
