# Layer 7 Mail, Identity, Storage, Databases & Brokers

> **FrameAssembly v3.2.2** · Category 07 (Layer 7 · 14 Protocols) · Canonical URL: https://frameassembly-lang.dev/docs/protocols/categories/l7-mail-auth-storage-db

East-west lateral movement detections, Active Directory segmentation audits, database activity monitors, and IoT message-broker parsers all rely on intricate binary and stateful wire encodings: ASN.1 DER Kerberos tickets, ASN.1 BER LDAPv3 search trees, NetBIOS-prefixed UTF-16LE SMB2 shares, ONC RPC record-marked NFSv4 compounds, and length-tagged SQL/MQTT frames.

FrameAssembly builds all 14 enterprise mail (`smtp`, `imap`, `pop3`), directory/identity (`kerberos`, `ldap`), file-share (`smb`, `nfs`), cache/database (`redis`, `memcached`, `mysql`, `postgres`), and broker (`mqtt`, `coap`, `amqp`) protocols offline—with zero risk of locking out production Active Directory accounts or touching live databases.

## Category Wire & Endpoint Rules

- **ASN.1 DER/BER Directory & Ticket Framing:** `kerberos` encodes `pvno=5` ASN.1 DER (`etype 18` AES256 or `etype 23` RC4-HMAC; `transport tcp` adds the 4-byte RFC 4120 record mark) and `ldap` encodes ASN.1 BER `LDAPMessage` sequences.
- **SMB2 UTF-16LE & ONC RPC Record Marking:** `smb` prepends the 4-byte NetBIOS length + 64-byte `0xfeSMB` header with UTF-16LE `share`/`filename` strings; `nfs` prepends the RFC 5531 TCP Last-Fragment record mark (omitted on `transport udp`).
- **Native SQL & Cache WireFraming:** `postgres` emits v3.0 `0x00030000` startup and tagged `Q`/`C`/`Z`/`E` messages; `mysql` emits 24-bit little-endian lengths; `redis` emits RESP multibulk arrays; `memcached` includes the 8-byte UDP header by default.
- **IoT Broker Variable Lengths & CoAP Options:** `mqtt` computes variable-byte Remaining Length headers (`qos 0..2`, `retain`), `amqp` appends `0xce` frame-end markers, and `coap` delta-encodes `uripath` options.

## Multi-Protocol Example: Kerberos TGS, LDAP SPN Search, SMB2 Share, Postgres SQL & MQTT QoS 1 (`identity_storage_db_broker.frasm`)

Combines a UDP 88 Kerberos TGS-REQ, a stateful TCP 389 LDAPv3 SPN search, a TCP 445 SMB2 TreeConnect, a TCP 5432 PostgreSQL v3.0 query cycle, and a TCP 1883 MQTT QoS 1 telemetry publish.

```frameassembly
host app_node { ip 10.70.10.15 }
host svc_host { ip 10.70.20.30 }

compile {
    app_node -> svc_host kerberos tgsreq realm "CORP.INTERNAL" cname "svc-web" sname "postgres/db01.corp.internal" etype 18 wait 2ms
    app_node -> svc_host tcp syn srcport 54110 dstport 389 win 65535 mss 1460 wait 1ms
    app_node <- svc_host tcp syn ack win 65535 mss 1460 wait 1ms
    app_node -> svc_host tcp ack wait 1ms
    app_node -> svc_host ldap searchreq msgid 2 basedn "dc=corp,dc=internal" filter "(servicePrincipalName=postgres/*)" wait 2ms
    app_node <- svc_host ldap searchdone msgid 2 resultcode 0 wait 2ms
    app_node -> svc_host tcp syn srcport 54111 dstport 5432 win 65535 mss 1460 wait 1ms
    app_node <- svc_host tcp syn ack win 65535 mss 1460 wait 1ms
    app_node -> svc_host tcp ack wait 1ms
    app_node -> svc_host postgres startup user "app_ro" db "inventory" wait 1ms
    app_node <- svc_host postgres authok wait 1ms
    app_node -> svc_host postgres query sql "SELECT count(*) FROM orders;" wait 2ms
    app_node <- svc_host postgres commandcomplete wait 1ms
    app_node <- svc_host postgres readyforquery
}
```

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

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

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

# 4. Verify dissected protocol fields in tshark
tshark -r identity_storage_db_broker.pcap -Y "kerberos || ldap || pgsql"
```

- **Wireshark Display Filter:** `kerberos || ldap || pgsql`

## Protocols in Category 07 (14 Native Builders)

| # | Keyword | Protocol | Default Port / Proto | Endpoint Rule | Wireshark Filter | Spec URL |
| --- | --- | --- | --- | --- | --- | --- |
| 62 | `smtp` | Simple Mail Transfer Protocol | `TCP 25 (or dstport 587 Submission)` | Dual-Stack IPv4/IPv6 | `smtp` | https://frameassembly-lang.dev/docs/protocols/smtp |
| 63 | `imap` | Internet Message Access Protocol IMAP4rev1 | `TCP 143` | Dual-Stack IPv4/IPv6 | `imap` | https://frameassembly-lang.dev/docs/protocols/imap |
| 64 | `pop3` | Post Office Protocol Version 3 | `TCP 110` | Dual-Stack IPv4/IPv6 | `pop` | https://frameassembly-lang.dev/docs/protocols/pop3 |
| 65 | `kerberos` | Kerberos Network Authentication Service v5 (Active Directory) | `UDP 88 (or TCP 88 via transport tcp)` | Dual-Stack IPv4/IPv6 | `kerberos` | https://frameassembly-lang.dev/docs/protocols/kerberos |
| 66 | `ldap` | Lightweight Directory Access Protocol v3 (ASN.1 BER) | `TCP 389` | Dual-Stack IPv4/IPv6 | `ldap` | https://frameassembly-lang.dev/docs/protocols/ldap |
| 67 | `smb` | Server Message Block SMB2 & SMB3 File Sharing | `TCP 445` | Dual-Stack IPv4/IPv6 | `smb2` | https://frameassembly-lang.dev/docs/protocols/smb |
| 68 | `nfs` | Network File System over ONC RPC | `TCP 2049 (or UDP 2049 via transport udp)` | Dual-Stack IPv4/IPv6 | `nfs \|\| rpc` | https://frameassembly-lang.dev/docs/protocols/nfs |
| 69 | `redis` | Redis Serialization Protocol Cache & Broker | `TCP 6379` | Dual-Stack IPv4/IPv6 | `redis \|\| tcp.port == 6379` | https://frameassembly-lang.dev/docs/protocols/redis |
| 70 | `memcached` | Memcached ASCII & Binary Cache Protocol | `UDP 11211 (or TCP 11211 via transport tcp)` | Dual-Stack IPv4/IPv6 | `memcache` | https://frameassembly-lang.dev/docs/protocols/memcached |
| 71 | `mysql` | MySQL & MariaDB Wire Protocol v10 | `TCP 3306` | Dual-Stack IPv4/IPv6 | `mysql` | https://frameassembly-lang.dev/docs/protocols/mysql |
| 72 | `postgres` | PostgreSQL Frontend/Backend Wire Protocol v3.0 | `TCP 5432` | Dual-Stack IPv4/IPv6 | `pgsql` | https://frameassembly-lang.dev/docs/protocols/postgres |
| 73 | `mqtt` | Message Queuing Telemetry Transport (IoT & IIoT) | `TCP 1883` | Dual-Stack IPv4/IPv6 | `mqtt` | https://frameassembly-lang.dev/docs/protocols/mqtt |
| 74 | `coap` | Constrained Application Protocol | `UDP 5683` | Dual-Stack IPv4/IPv6 | `coap` | https://frameassembly-lang.dev/docs/protocols/coap |
| 75 | `amqp` | Advanced Message Queuing Protocol (RabbitMQ) | `TCP 5672` | Dual-Stack IPv4/IPv6 | `amqp` | https://frameassembly-lang.dev/docs/protocols/amqp |
