# snmp3 — Real SHA-256 + AES-128 Encrypted USM Traps & Polls (`snmp3`)

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

- **Full Protocol Name:** Simple Network Management Protocol v3 with USM Auth & Privacy
- **Keyword:** `snmp3`
- **OSI Layer & Transport:** Layer 7 · UDP 162 (trap/inform/report) / UDP 161 (get/getbulk)
- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6
- **Standards:** RFC 3414, RFC 3826, RFC 7860
- **Wireshark Display Filter:** `snmp`
- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 -> UDP 162 (trap/inform/report) / UDP 161 (get/getbulk) -> SNMPv3 USM (authPriv)`

## Overview

Zero fake placeholder bytes here: `snmp3` runs full RFC 3414/7860 `Ku -> Kul` key localization against `engineid`, encrypts the `ScopedPDU` with AES-128-CFB or DES, and signs the live HMAC so Wireshark and `snmptrapd` decrypt it on the first try.

Simple Network Management Protocol v3 (`snmp3`, RFC 3414 / RFC 3826 / RFC 7860) secures network monitoring with the User-based Security Model (**USM**). Unlike mock packet generators that emit zeroed dummy bytes, FrameAssembly executes **full cryptographic key localization (`Ku -> Kul`)** against `msgAuthoritativeEngineID` (`engineid`), computes live truncated **HMAC (`md5`, `sha`, `sha256`, `sha384`, `sha512`)** over the entire SNMPv3 message, and encrypts the ASN.1 `ScopedPDU` using **AES-128-CFB (`priv aes`)** or **CBC-DES (`priv des`)**.

That means you can enter your exact `user`, `auth`, and `priv` passphrases into **Wireshark -> Preferences -> Protocols -> SNMP -> Users Table** (or Checkmk / `snmptrapd`) and decrypt every FrameAssembly-generated `.pcap` on the first try.

## Minimal Quickstart (`snmp3_quickstart.frasm`)

```frameassembly
host poller { ip 10.40.1.10 }
host router { ip 10.40.1.1 }

compile {
    poller -> router snmp3 get user "secops" engineid "80001f888001020304" engineboots 3 enginetime 1200 auth sha256 "AuthPassPhrase99!" priv aes "PrivPassPhrase99!" reqid 101 oid 1.3.6.1.2.1.1.1.0 wait 2ms
    poller <- router snmp3 response user "secops" engineid "80001f888001020304" engineboots 3 enginetime 1200 auth sha256 "AuthPassPhrase99!" priv aes "PrivPassPhrase99!" reqid 101 varbind 1.3.6.1.2.1.1.1.0 string "Core-RTR OS 17.9"
}
```

### Automatic Wire Calculations

- Derives `msgFlags` automatically from provided credentials: `noAuthNoPriv` (neither set), `authNoPriv` (`auth` only), or `authPriv` (`auth` + `priv`, setting `0x03`, plus `0x04` Reportable on requests/informs).
- Runs RFC 3414 / RFC 7860 password-to-key (`Ku`, 1 MiB expansion) and engine-localized (`Kul`) derivation for `md5`, `sha` (SHA-1), `sha256`, `sha384`, and `sha512`.
- Encrypts the `ScopedPDU` with `aes` (AES-128-CFB using `engineboots || enginetime || salt` IV per RFC 3826) or `des`, then writes the exact HMAC digest into `msgAuthenticationParameters`.

## Practical Lab Example: Full RFC 3414 Engine Discovery (`report`) + SHA-256/AES-128 `authPriv` Poll & Trap (`snmp3_usm_discovery_and_authpriv.frasm`)

Walks through RFC 3414 USM engine discovery (`usmStatsUnknownEngineIDs.0`), authenticated/encrypted `get` + `response` on UDP 161, and an `authPriv` encrypted `snmp3 trap` on UDP 162.

```frameassembly
host zabbix_srv { ip 172.18.10.50 }
host core_rtr   { ip 172.18.10.1 }

compile {
    // 1. Unauthenticated USM EngineID discovery probe -> Agent replies with Report PDU
    zabbix_srv -> core_rtr snmp3 get user "" reqid 100 wait 1ms
    zabbix_srv <- core_rtr snmp3 report user "" engineid "80001f8880aabbccdd" engineboots 5 enginetime 8420 reqid 100 varbind 1.3.6.1.6.3.15.1.1.4.0 counter32 1 wait 3ms
    // 2. Encrypted authPriv (HMAC-SHA-256 + AES-128-CFB) GET & RESPONSE on UDP 161
    zabbix_srv -> core_rtr snmp3 get user "nms-v3-prod" engineid "80001f8880aabbccdd" engineboots 5 enginetime 8420 auth sha256 "StrongAuthKey2026!" priv aes "StrongPrivKey2026!" reqid 101 oid 1.3.6.1.2.1.1.5.0 wait 2ms
    zabbix_srv <- core_rtr snmp3 response user "nms-v3-prod" engineid "80001f8880aabbccdd" engineboots 5 enginetime 8420 auth sha256 "StrongAuthKey2026!" priv aes "StrongPrivKey2026!" reqid 101 varbind 1.3.6.1.2.1.1.5.0 string "core-rtr-fra1.internal" wait 5ms
    // 3. Encrypted authPriv SNMPv3 Trap on UDP 162 (authoritative sender = core_rtr)
    core_rtr -> zabbix_srv snmp3 trap user "nms-v3-prod" engineid "80001f8880aabbccdd" engineboots 5 enginetime 8425 auth sha256 "StrongAuthKey2026!" priv aes "StrongPrivKey2026!" sysuptime 842500 varbind 1.3.6.1.6.3.1.1.4.1.0 oidval 1.3.6.1.6.3.1.1.5.4 varbind 1.3.6.1.2.1.2.2.1.2.1 string "HundredGigE0/0/0/1"
}
```

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

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

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

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

## All `snmp3` Keywords & Header Options

Packet line pattern: `src_host -> dst_host snmp3 [trap | inform | report | get | getnext | getbulk | set | response] [user "<text>"] [engineid "<even_hex>"] [engineboots <number>] [enginetime <number>] [contextname "<text>"] [auth <md5|sha|sha256|sha384|sha512> "<password>"] [priv <des|aes> "<password>"] [reqid <number>] [nonrepeaters <number>] [maxrepetitions <number>] [sysuptime <number>] [oid <oid>] [varbind <oid> <type_val> ...]`

| Keyword / Option | Accepted Value | Default | Effect on Packet |
| --- | --- | --- | --- |
| `trap \| inform \| report \| get \| getnext \| getbulk \| set \| response` | SNMPv3 ScopedPDU type keyword | `trap (UDP 162)` | Selects the inner BER PDU tag inside the plaintext or encrypted `ScopedPDU`. |
| `user "<text>"` | Double-quoted USM securityName | `"initial"` | Sets `msgUserName` in the USM security parameters header. |
| `engineid "<even_hex>"` | Even-length ASCII hex string (e.g. "80001f880431") | `"80001f888000000001"` | Sets `msgAuthoritativeEngineID` and `contextEngineID` and localizes `Ku -> Kul` USM keys. |
| `engineboots <number> \| enginetime <number>` | Whole number | `engineboots 1, enginetime 100` | Sets `msgAuthoritativeEngineBoots` and `msgAuthoritativeEngineTime` (also used in the AES-128-CFB IV). |
| `contextname "<text>"` | Quoted text | `"" (default context)` | Sets `contextName` inside the `ScopedPDU` (e.g. `"vlan-10"` per-VLAN bridge MIB contexts). |
| `auth md5 \| sha \| sha256 \| sha384 \| sha512 "<password>"` | HMAC algorithm keyword + passphrase string | `Omitted (noAuthNoPriv)` | Enables USM authentication (`authNoPriv` or `authPriv`) and writes the live RFC 3414 / RFC 7860 HMAC digest. |
| `priv des \| aes "<password>"` | `des` (CBC-DES) or `aes` (AES-128-CFB) + passphrase | `Omitted` | Encrypts the `ScopedPDU` (`authPriv`, requires `auth`) and populates the 8-byte `msgPrivacyParameters` salt/IV. |
| `reqid <number> \| nonrepeaters <number> \| maxrepetitions <number> \| sysuptime <number> \| oid <oid>` | ScopedPDU request/bulk/trap fields | `reqid 1, nonrepeaters 0, maxrepetitions 10` | Sets inner `ScopedPDU` request ID, `getbulk` bounds, prepended `sysUpTime.0` varbind, or `NULL`-valued query OID. |
| `varbind <oid> string "<text>" \| int <number> \| oidval <oid> \| ipval <ipv4> \| counter32 <number> \| gauge32 <number> \| timeticks <number> \| counter64 <number> \| null \| nullval` | Repeatable SMIv2 OID + typed value keyword | `Omitted` | Appends `VarBind` entries (`string`, `int`, `oidval`, `ipval`, `counter32`, `gauge32`, `timeticks`, `counter64`, `null` \| `nullval`) prior to encryption. |

## Cross-Layer Options Valid with `snmp3`

| 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 162 (trap/inform/report) / UDP 161 (get/getbulk)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |

## Common Mistakes & Quick Fixes

### engineid Must Be Non-Empty Even-Length Hex Octets

- **Avoid:** `poller -> router snmp3 get user "ops" engineid "router-01"`
- **Valid v3.2.2 Syntax:** `poller -> router snmp3 get user "ops" engineid "80001f8804726f75746572"`

`engineid` must contain a non-empty even number of hexadecimal characters (`0-9a-fA-F`, with optional colons or spaces). Omit `engineid` on initial discovery probes rather than passing `engineid ""`.

### SHA-1 Is Spelled sha (Not sha1)

- **Avoid:** `poller -> router snmp3 get user "ops" auth sha1 "SecretPass123!"`
- **Valid v3.2.2 Syntax:** `poller -> router snmp3 get user "ops" auth sha "SecretPass123!"`

Accepted USM HMAC keywords are `md5`, `sha` (RFC 3414 HMAC-SHA-1-96), `sha256`, `sha384`, and `sha512` (RFC 7860).
