Well the answer was in the linked post Samba SMB Encryption - How safe is it?. More concretely, the microsoft article linked within: Encryption in SMB 3.0: A protocol perspective.
I couldn't really read it before as I was quite out of context. Only after finding out about the existence of password-based cryptography (which lead to password-authenticated key agreement) from tags suggestions in my initial question did it start to make sense.
Quote:
Cryptographic keys
Ko = SMB3KDF (Ki, Label, Context)
SMB3KDF()
is defined as the KDF algorithm in Counter Mode, as
specified in [SP800-108] section 5.1, with 'r' value of 32 and 'L'
value of 128, and HMAC-SHA256 as the PRF.
- Ki – Key derivation key, used as an input to the KDF. For SMB 3.0, Ki
is the SessionKey.
- Label – the purpose of this derived key, encoded as string and length
for SMB 3.0.
- Context – the context information of this derived key, encoded as
string and length for SMB 3.0.
- L – An integer that specifies the length of the derived keying
material Ko, L is 128 bits for SMB 3.0 cryptographic keys. Note that L
is a constant since all SMB 3.0 keys are 16 bytes in length
(SigningKey, EncryptionKey, DecryptionKey, and ApplicationKey).
- Ko – Keying material output from the KDF, a binary string of length L,
where Ko is the leftmost L bits of KDF result.
ServerInKey (ClientToServer) = SMB3KDF (SessionKey, "SMB2AESCCM\0",
"ServerIn \0")
EncryptionKey(Client) = DecryptionKey(Server) = ServerInKey(ClientToServer)
ServerOutKey (ServerToClient) = SMB3KDF ( SessionKey, "SMB2AESCCM\0",
"ServerOut\0")
EncryptionKey(Server) = DecryptionKey(Client) = ServerOutKey(ServerToClient)
The server and client generate the encryption keys upon session
establishment of the primary channel. If the server is configured for
encryption (...) the server generates the EncryptionKey and DecryptionKey (...), the client must also generate its encryption
and decryption keys.
(...)
Note: These cryptographic keys are all derived from the SessionKey. As
a result, SMB 3.0 signing and encryption is as secure as the session
key. Not only must this key be unique and very random, but also it
needs be kept secret.
There's a lot more information in the article, but the KDF algorithm part answered my question. KDF stands for Key Derivation Function. The SessionKey is used to derive it.
For the sake of thoroughness, there's a few places information can be found about the SessionKey, first of which is more microsoft documentation: SessionKey Generation
Virtual circuit session keys (SessionKeys) are generated on CIFS servers.
The definition for CIFS linked:
Common Internet File System (CIFS): The "NT LM 0.12" / NT LAN Manager dialect of the Server Message Block (SMB) Protocol, as implemented in Windows NT.
Alternatively, there's an encryption overview from the samba wiki which states:
The encryption key and algorithm to use for the connection is determined by one of the following methods:
- Kerberos (...)
- NTLM (NT LAN Manager) authentication. When NTLM authentication is used, the session key is derived from the shared secret, which is the user or machine account password in the database. The choice of cryptographic algorithms are essentially hardwired into the NTLM protocol, and are not really able to be configured.
- SCHANNEL (...) It uses the shared machine account password as the secret between the client and server
So the sessionkey is either derived from the credentials directly, or negotiated with the server by using communications encrypted using those credentials (hard to tell exactly without digging into the specifications).
In short, the information that is present on both the client and the server. The information the man in the middle has no knowledge of.
The samba wireshark decryption guide on the samba wiki may also be helpful, as well as How SMB signing works from the infosec SE.