# telnet — Port 23 IAC Option Negotiations & Login Alarms (`telnet`)

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

- **Full Protocol Name:** Telnet Cleartext Terminal & IAC Negotiation
- **Keyword:** `telnet`
- **OSI Layer & Transport:** Layer 7 · TCP 23
- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6
- **Standards:** RFC 854, RFC 855
- **Wireshark Display Filter:** `telnet`
- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 -> TCP 23 -> Telnet`

## Overview

If TCP `23` fires on a modern network, either someone powered on a museum switch or a red teamer is having a great afternoon. `telnet` emits authentic `0xff` IAC `will`/`do` bytes plus cleartext prompts.

Telnet (`telnet`, RFC 854 / RFC 855) sends terminal sessions and `0xff` Interpret-As-Command (**IAC**) option triplets (`WILL`, `WONT`, `DO`, `DONT`) in cleartext over **TCP port `23`**. Because credentials and commands travel unencrypted, detecting unexpected Telnet connections is a mandatory compliance check in PCI-DSS, NIST 800-53, CIS Benchmarks, and IEC 62443 OT networks.

FrameAssembly encodes `0xff` IAC negotiation triplets (`do`, `dont`, `will`, `wont`) alongside ASCII terminal prompts and CLI commands (`data`) so you can verify IDS and NAC cleartext-management alerts safely without enabling Telnet on a real switch.

## Minimal Quickstart (`telnet_quickstart.frasm`)

```frameassembly
host audit_pc  { ip 10.10.10.50 }
host legacy_sw { ip 10.10.10.2 }

compile {
    audit_pc -> legacy_sw tcp syn srcport 51023 dstport 23 wait 1ms
    audit_pc <- legacy_sw tcp syn ack wait 1ms
    audit_pc -> legacy_sw tcp ack wait 1ms
    audit_pc <- legacy_sw telnet will 1 do 24 data "User Access Verification\r\nUsername: " wait 3ms
    audit_pc -> legacy_sw telnet do 1 wont 24 data "operator\r\n"
}
```

### Automatic Wire Calculations

- Defaults to TCP destination port `23` (`psh ack`) and tracks TCP sequence numbers automatically.
- Prefixes every `will` (`251`), `wont` (`252`), `do` (`253`), and `dont` (`254`) option with the `0xff` IAC escape byte.
- Appends `data` text immediately after any IAC negotiation bytes in the same TCP segment.

## Practical Lab Example: Legacy OT RTU Telnet Login Detection Scenario (`telnet_cleartext_audit.frasm`)

Models a TCP 23 connection to a legacy serial-to-Ethernet terminal server, negotiating Echo/Suppress-Go-Ahead options and sending a `show running-config` command.

```frameassembly
host eng_laptop { ip 192.168.50.15 }
host rtu_gw     { ip 192.168.50.200 }

compile {
    eng_laptop -> rtu_gw tcp syn srcport 50123 dstport 23 win 65535 mss 1460 wait 1ms
    eng_laptop <- rtu_gw tcp syn ack win 65535 mss 1460 wait 1ms
    eng_laptop -> rtu_gw tcp ack wait 1ms
    eng_laptop <- rtu_gw telnet will 1 do 24 wait 2ms
    eng_laptop <- rtu_gw telnet will 3 data "RTU-GW01 login: " wait 5ms
    eng_laptop -> rtu_gw telnet do 1 wont 24 wait 2ms
    eng_laptop -> rtu_gw telnet do 3 data "maint\r\n" wait 3ms
    eng_laptop <- rtu_gw telnet data "Password: " wait 5ms
    eng_laptop -> rtu_gw telnet data "show version\r\n"
}
```

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

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

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

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

## All `telnet` Keywords & Header Options

Packet line pattern: `src_host -> dst_host telnet [do <0..255>] [dont <0..255>] [will <0..255>] [wont <0..255>] [option <0..255>] [data "<text>"]`

| Keyword / Option | Accepted Value | Default | Effect on Packet |
| --- | --- | --- | --- |
| `do <0..255> \| dont <0..255> \| will <0..255> \| wont <0..255>` | Telnet option code (`1` Echo, `3` Suppress Go Ahead, `24` Terminal Type, `31` Window Size) | `Omitted` | Emits the 3-byte `0xff <CMD> <OPT>` IAC negotiation triplet. |
| `option <0..255>` | 1-byte option number | `Omitted` | Specifies an auxiliary Telnet option code. |
| `data "<text>"` | Quoted terminal text (supports `\r\n`) | `Empty` | Writes NVT ASCII terminal characters into the Telnet segment. |

## Cross-Layer Options Valid with `telnet`

| 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), TCP 23` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |
| `seq <number> \| acknum <number> \| win\|window <0..65535> \| urgent <0..65535> \| syn \| ack \| psh \| fin \| rst \| urg \| ece \| cwr` | TCP sequence/ack numbers, window size, flags & RFC 7323 options | `psh ack, win 65535, automatic TCP seq/acknum` | Overrides automatic TCP sequence tracking, flags, or RFC 7323 options (`mss`, `wscale`, `sackperm`, `tsval`, `tsecr`). |

## Common Mistakes & Quick Fixes

### Include \r\n Line Endings in Interactive Commands

- **Valid v3.2.2 Syntax:** `eng_laptop -> rtu_gw telnet data "show ip interface brief\r\n"`

RFC 854 Network Virtual Terminal (NVT) lines end with CR-LF (`\r\n`), which IDS command signatures often check for.

### One Option Per IAC Verb Per Packet Line

- **Avoid:** `eng_laptop <- rtu_gw telnet will 1 will 3`
- **Valid v3.2.2 Syntax:** `eng_laptop <- rtu_gw telnet will 1 do 24`

Each IAC verb (`will`, `wont`, `do`, `dont`) may appear once on a packet line. Combine different verbs on one segment (`will 1 do 24`) or send a second `will 3` on the next Telnet segment.
