# redis — Stateful TCP 6379 RESP Arrays & Unauth Cache Probes (`redis`)

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

- **Full Protocol Name:** Redis Serialization Protocol Cache & Broker
- **Keyword:** `redis`
- **OSI Layer & Transport:** Layer 7 · TCP 6379
- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6
- **Standards:** Redis RESP2 / RESP3
- **Wireshark Display Filter:** `redis || tcp.port == 6379`
- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 -> TCP 6379 -> Redis (RESP)`

## Overview

An exposed Redis port `6379` on a cloud subnet gets owned in about 90 seconds — `redis` formats exact RESP bulk-string arrays (`cmd "CONFIG" args "GET dir"`) to verify NDR east-west alerts.

Redis and Valkey communicate over **TCP port `6379`** using the **Redis Serialization Protocol (RESP)**, where client commands are formatted as length-prefixed multibulk arrays (`*3
$3
SET
...`) and server replies use type prefixes (`+` simple string, `-` error, `:` integer, `$` bulk string). Exposed unauthenticated Redis instances (`CONFIG SET dir`, `SLAVEOF`, `EVAL`) are a top cloud/container attack vector.

FrameAssembly computes every `*N` array count and `$len` byte-length prefix automatically for `get`, `set`, or arbitrary `cmd` (`"AUTH"`, `"INFO"`, `"CONFIG"`) requests, as well as typed `replytype` server responses.

## Minimal Quickstart (`redis_quickstart.frasm`)

```frameassembly
host api_pod   { ip 10.44.1.12 }
host redis_primary { ip 10.44.2.10 }

compile {
    api_pod -> redis_primary tcp syn srcport 51637 dstport 6379 wait 1ms
    api_pod <- redis_primary tcp syn ack wait 1ms
    api_pod -> redis_primary tcp ack wait 1ms
    api_pod -> redis_primary redis set key "session:4821" value "active" wait 1ms
    api_pod <- redis_primary redis replytype "ok" value "OK"
}
```

### Automatic Wire Calculations

- Defaults to TCP destination port `6379` (`psh ack`) and formats exact `*N
$<len>
...` RESP multibulk wire arrays.
- Emits `+OK
` (`replytype "ok"`), `-ERR ...
` (`replytype "err"`), `:<num>
` (`replytype "integer"`), or `$<len>
<value>
` (`replytype "bulk"`) on server responses.
- Tracks TCP sequence numbers automatically across commands and replies.

## Practical Lab Example: Blocked Unauthenticated `CONFIG` Probe (`-NOAUTH`) + Authenticated Cache Read/Write (`redis_security_audit.frasm`)

Tests an unauthenticated command rejected with `-NOAUTH Authentication required.`, followed by `AUTH`, `SET`, and bulk `GET`.

```frameassembly
host app_worker { ip 172.16.44.20 }
host cache_node { ip 172.16.44.63 }

compile {
    app_worker -> cache_node tcp syn srcport 52637 dstport 6379 win 65535 mss 1460 wait 1ms
    app_worker <- cache_node tcp syn ack win 65535 mss 1460 wait 1ms
    app_worker -> cache_node tcp ack wait 1ms
    // 1. Unauthenticated probe rejected with RESP error (-)
    app_worker -> cache_node redis cmd "INFO" wait 1ms
    app_worker <- cache_node redis replytype "err" value "NOAUTH Authentication required." wait 3ms
    // 2. Authenticate + SET + GET
    app_worker -> cache_node redis cmd "AUTH" args "LabCacheToken2026" wait 1ms
    app_worker <- cache_node redis replytype "ok" value "OK" wait 1ms
    app_worker -> cache_node redis set key "ratelimit:198.51.100.9" value "42" wait 1ms
    app_worker <- cache_node redis replytype "ok" value "OK" wait 1ms
    app_worker -> cache_node redis get key "ratelimit:198.51.100.9" wait 1ms
    app_worker <- cache_node redis replytype "bulk" value "42"
}
```

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

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

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

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

## All `redis` Keywords & Header Options

Packet line pattern: `src_host -> dst_host redis [get | set | cmd "<text>"] [key "<text>"] [args "<text>"] [value "<text>"] [replytype "<ok|err|integer|bulk>"]`

| Keyword / Option | Accepted Value | Default | Effect on Packet |
| --- | --- | --- | --- |
| `get \| set \| cmd "<text>"` | Redis command (`get`, `set`, or quoted command such as `"AUTH"`, `"PING"`, `"DEL"`) | `get` | Sets the first bulk string element of the RESP command array. |
| `key "<text>" \| value "<text>" \| args "<text>"` | Quoted key, value, or extra arguments | `key "mykey" on get/set` | Populates subsequent `$len\r\n...` elements in requests or payload text in server replies. |
| `replytype "<ok\|err\|integer\|bulk>"` | RESP reply type selector | `Omitted on client requests` | Switches the packet to a server reply using `+`, `-`, `:`, or `$` RESP framing. |

## Cross-Layer Options Valid with `redis`

| 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 6379` | 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

### Use replytype on Server Replies So Redis Does Not Emit Another Client Command

- **Avoid:** `api_pod <- redis_primary redis value "OK"`
- **Valid v3.2.2 Syntax:** `api_pod <- redis_primary redis replytype "ok" value "OK"`

Adding `replytype` (`"ok"`, `"err"`, `"integer"`, or `"bulk"`) tells FrameAssembly to format a server RESP reply rather than a client `*N` command array.
