# scorpiox-scorpioplayer-smb-v3-file-client

**SCORPIO PLAYER 2027** row 47: pure C99, zero-dependency, **read-only** SMB 3.0/3.0.2/3.1.1
client (`spsmb3c_`). Built from the row-45 v2 client framing (vendored by copy), extended to
the 3.x dialects: negotiate contexts (3.1.1), pre-auth integrity (SHA-512), AES-CMAC (3.0/3.0.2)
and AES-GMAC (3.1.1) signing, AES-128-CCM/GCM encryption (`TRANSFORM_HEADER`), and
`FSCTL_VALIDATE_NEGOTIATE_INFO`. Also the row-54 `sprch_handler` (`"SMB2"`) and the #26
`spffa_backend` (`"smb2"`). Every failure names its NTSTATUS.

| Key | Value |
|---|---|
| Exports | 34 (`spsmb3c_*`, see `exports.json` == `nm -D` == the PE export table) |
| Test | `make test` = 188 unit + 60-file fuzz replay + 34-symbol exports-check, all offline |
| ASAN | `make asan` (clang, ASAN+UBSAN, leak-detect) — clean |
| Windows | `make win` (mingw) → `.dll`/`.exe`, KERNEL32 + msvcrt + WS2_32 only |
| Console | `scorpiox-scorpioplayer-smb-v3-file-client.console` — 97/97 on Linux `.so` **and** Windows `.dll` (on .204) |
| dist | `dist.scorpiox.net/dlls/scorpiox-scorpioplayer-smb-v3-file-client/verified/1.0.0` + `latest` |

## The 3.x encryption contract

- **Dialects**: 2.0.2/2.1 (the v2 shapes) + 3.0/3.0.2/3.1.1. `SPSMB3C_DIALECTS=2|3|311|30|300|302`
  picks the offer set (default: 3.1.1 first, then 3.0.2/3.0/2.1).
- **Pre-auth integrity (3.1.1)**: a SHA-512 chain over every negotiate/session frame; the final
  SUCCESS SESSION_SETUP reply stays out (MS-SMB2 3.1.4.2). The signing/cipher keys derive from it.
- **Signing**: AES-CMAC (2.1/3.0/3.0.2) or AES-GMAC (3.1.1). The 3.1.1 KDF labels carry TWO
  trailing NULs (`SMBSigningKey\0\0`, `SMBC2SCipherKey\0\0`, `SMBS2CCipherKey\0\0`) — Samba's
  `data_blob_string_const_null` + the SP800-108 separator, measured.
- **Encryption (`TRANSFORM_HEADER`, MS-SMB2 2.2.41)**: AES-128-GCM at 3.1.1 (random 12-byte
  nonce), AES-128-CCM at 3.0/3.0.2 (11-byte random nonce in the 16-byte SMB2Nonce field).
  Header 52 bytes: tag rides the Signature field, ciphertext = body only, AAD = header[20..52],
  `OriginalMessageSize` = the plaintext size. We encrypt ONLY when the server demands it:
  the session `ENCRYPT_DATA` flag (SessionFlags 0x2) or the share's SSE ShareFlag 0x8000 —
  never because "we can decrypt" (smbd drops the first unsolicited encrypted frame, measured).
  A read never charges more than ONE credit (Samba kills the connection when CreditCharge
  exceeds the granted balance), so a read is capped at 64 KiB per call and the caller loops.

## Oracles (the proof, 2026-10-01)

1. **Samba smbd 4.15 loopback** (ports 1446 SMB3_11 / 1447-1448 SMB3_00):
   `shares / ls / stat / cat / sha / ranges / session` green at 3.1.1 GMAC on the plaintext
   `MEDIA` share, and on `MEDIAE` (`smb encrypt = required`) the TRANSFORM_HEADER frames ride
   BOTH directions with `sha256 == disk` through the encrypted session. Named credentials
   (`smbfuser`) — a guest logon cannot TREE_CONNECT on the SSE-configured smbd.
2. **The in-process fake** (`sp3c_fake.c`, the row-44 wire shapes + 3.x modes): the full matrix
   in-process — 3.1.1 GCM + 3.0/3.0.2 CCM × session ENCRYPT_DATA + per-tree SSE + the
   no-cipher refusal — every combination green in `make test`, offline.
3. **The fake is itself wire-proven**: the row-44 server it mirrors passed smbclient + the
   Linux kernel CIFS mount; the row-45 client passed Samba + impacket.

## Defects found on the way (the record)

- The 3.1.1 TRANSFORM_HEADER layout was rewritten to the Samba/smbprotocol shape (tag in the
  Signature field, ciphertext-only tail, random nonces) — the first shape decrypted nothing.
- The 3.1.1 cipher-key labels need the two-trailing-NUL form (see above).
- `sp3c_fake_handle_frame` denied its own successfully decrypted frames: the recursive
  inner-frame call reset `saw_encrypted` and re-fired the plaintext-refusal rule
  (`st.decrypting` now guards both) — every post-auth frame on an encrypting session failed
  ACCESS_DENIED until this.
- `test_large_reads` was never called from `main` — the "1 MiB in one READ" assertion was dead;
  the shipped contract is the 64 KiB one-credit cap with the caller looping.

## CLI

```
build/spsmb3c shares HOST[:PORT] [DOMAIN USER PASS]
build/spsmb3c ls|lsh HOST[:PORT] SHARE[/SUB] [DOMAIN USER PASS]   # lsh = hidden entries too
build/spsmb3c stat|cat|sha HOST[:PORT] SHARE/PATH [DOMAIN USER PASS]
build/spsmb3c ranges HOST[:PORT] SHARE/PATH N SEED [DOMAIN USER PASS]
build/spsmb3c bench HOST[:PORT] SHARE/PATH [bytes] [DOMAIN USER PASS]
build/spsmb3c fake TREE.json shares|ls SHARE|cat|sha SHARE/PATH   # offline, the fake server
```
