# tacacs — Stateful TCP 49 Router CLI Auth & Command Audits (`tacacs`)

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

- **Full Protocol Name:** Terminal Access Controller Access-Control System Plus
- **Keyword:** `tacacs`
- **OSI Layer & Transport:** Layer 7 · TCP 49
- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6
- **Standards:** RFC 8907
- **Wireshark Display Filter:** `tacplus`
- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 -> TCP 49 -> TACACS+`

## Overview

Router CLI command auditing over TCP `49` — pro tip: `seq` on a `tacacs` line sets the 8-bit TACACS+ `seq_no` (`1, 2, 3...`) without stomping on the underlying 32-bit TCP sequence tracker!

TACACS+ (`tacacs`, RFC 8907) handles administrative login authentication (`authen`), per-command CLI authorization (`author`), and command audit accounting (`acct`) for routers, switches, and firewalls over **TCP port `49`**. Unlike RADIUS (which combines authentication and authorization over UDP), TACACS+ separates all three AAA functions over reliable TCP.

FrameAssembly builds the 12-byte RFC 8907 TACACS+ header (`version 0xc0`, `type`, `seq_no`, `flags`, `session_id`, and `length`) alongside user and command data, while automatically keeping TCP sequence and acknowledgment numbers in sync.

## Minimal Quickstart (`tacacs_quickstart.frasm`)

```frameassembly
host core_rtr   { ip 10.10.0.1 }
host tacacs_srv { ip 10.10.0.49 }

compile {
    core_rtr -> tacacs_srv tacacs authen seq 1 sessionid 0x8001 user "netadmin" data "tty0" wait 2ms
    core_rtr <- tacacs_srv tacacs authen seq 2 sessionid 0x8001 data "Password: "
}
```

### Automatic Wire Calculations

- Defaults to TCP destination port `49` (`psh ack`), TACACS+ version `0xc0`, and calculates the 32-bit payload `length` field automatically.
- Treats `seq` (`0..255`) on a `tacacs` line as the 1-byte TACACS+ `seq_no` (`1` client start, `2` server reply, `3` client continue) without breaking the outer 32-bit TCP sequence number.
- Shares TCP sequence and acknowledgment tracking with `tcp` handshake packets on port `49`.

## Practical Lab Example: Full TCP 49 Handshake + TACACS+ Admin Login & Command Accounting (`tacacs_admin_session.frasm`)

Opens a TCP port 49 session from a spine router to a TACACS+ server, completes an authentication prompt/reply pair, and sends a command accounting record.

```frameassembly
host spine_rtr  { ip 172.20.0.1 }
host tacacs_aaa { ip 172.20.0.49 }

compile {
    // 1. TCP 3-way handshake on port 49
    spine_rtr -> tacacs_aaa tcp syn srcport 51049 dstport 49 win 65535 mss 1460 wait 1ms
    spine_rtr <- tacacs_aaa tcp syn ack win 65535 mss 1460 wait 1ms
    spine_rtr -> tacacs_aaa tcp ack wait 1ms
    // 2. TACACS+ Authentication conversation (odd seq = router, even seq = server)
    spine_rtr -> tacacs_aaa tacacs authen seq 1 flags 1 sessionid 0x44001122 user "secops" data "vty0" wait 2ms
    spine_rtr <- tacacs_aaa tacacs authen seq 2 flags 1 sessionid 0x44001122 data "Password: " wait 5ms
    spine_rtr -> tacacs_aaa tacacs authen seq 3 flags 1 sessionid 0x44001122 user "secops" data "LabPass!" wait 2ms
    // 3. Command authorization & accounting
    spine_rtr -> tacacs_aaa tacacs author seq 1 flags 1 sessionid 0x44001123 user "secops" data "cmd=configure" wait 2ms
    spine_rtr -> tacacs_aaa tacacs acct seq 1 flags 1 sessionid 0x44001124 user "secops" data "task_id=42"
}
```

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

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

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

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

## All `tacacs` Keywords & Header Options

Packet line pattern: `src_host -> dst_host tacacs [authen | author | acct | type <authen|author|acct>] [seq <0..255>] [flags <0..255>] [sessionid <number>] [user "<text>"] [data "<text>"]`

| Keyword / Option | Accepted Value | Default | Effect on Packet |
| --- | --- | --- | --- |
| `authen \| author \| acct \| type <authen\|author\|acct>` | TACACS+ AAA packet type | `authen (0x01)` | Selects TACACS+ Type `0x01` Authentication (`authen`), `0x02` Authorization (`author`), or `0x03` Accounting (`acct`). |
| `seq <0..255>` | 1-byte TACACS+ sequence number (0..255) | `1` | Sets the 8-bit TACACS+ `seq_no` header field (clients send odd numbers `1, 3, 5`; servers reply with even numbers `2, 4, 6`). |
| `flags <0..255>` | 1-byte bitmask (0..255) | `0` | Sets TACACS+ header flags (`0x01` Unencrypted cleartext lab mode, `0x04` Single-Connection mode). |
| `sessionid <number>` | 32-bit session identifier (decimal or 0x hex) | `1` | Sets the 4-byte TACACS+ `session_id` grouping messages in one AAA exchange. |
| `user "<text>" \| data "<text>"` | Quoted text | `Empty` | Populates the username and port/prompt/command payload fields inside the TACACS+ body. |

## Cross-Layer Options Valid with `tacacs`

| 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 49` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |
| ``acknum <number> [win\|window <0..65535>] [urgent <0..65535>]` (`seq` before `tacacs` sets TCP `seq`; `seq` after `tacacs` or `seqno` sets 8-bit TACACS+ `seq_no`)` | 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

### Protocol Keyword Is tacacs (No Plus Sign)

- **Avoid:** `core_rtr -> tacacs_srv tacacs+ authen user "admin"`
- **Valid v3.2.2 Syntax:** `core_rtr -> tacacs_srv tacacs authen user "admin"`

Built-in protocol names only use letters and digits (`a-z0-9`), so TACACS+ is written `tacacs`.

### seq Sets the 1-Byte TACACS+ Sequence Number

- **Avoid:** `core_rtr -> tacacs_srv tacacs authen seq 1000`
- **Valid v3.2.2 Syntax:** `core_rtr -> tacacs_srv tacacs authen seq 1`

On `tacacs` packets, `seq` sets the 8-bit TACACS+ `seq_no` (`0..255`), while FrameAssembly advances the outer 32-bit TCP sequence number automatically.
