networking, updated

SMB (with NTLM)

Server Message Block is Windows file sharing, and much more: named pipes for remote administration (RPC), printer sharing, and the transport for NTLM and Kerberos logins. It is the protocol behind most lateral movement in Windows networks.

OSI layer
7 Application
Carried in
TCP (also QUIC on 443/udp)
Ports
445/tcp, 139/tcp (over NetBIOS, legacy)
Specs
MS-SMB2, MS-NLMP
Wireshark filter
smb2 || smb || ntlmssp
Encrypted
no

Packet structure

Every SMB2/3 message starts with this 64-byte header, followed by a command-specific body:

SMB2/3 header (sync)64 bytes

Select a field to see what it does.

MS-SMB2 2.2.1. Always 64 bytes, little-endian. Over TCP 445 a 4-byte Direct TCP length header comes first. The async variant replaces Reserved + Tree ID with an 8-byte Async ID.

Over port 445 each message is prefixed with a 4-byte length (Direct TCP transport). Over 139 the same 4 bytes are a NetBIOS session header. With SMB 3 encryption, a 52-byte transform header (0xFD 'SMB') replaces the clear header and everything after it is encrypted.

How it works

sequenceDiagram
    participant C as Client
    participant S as Server :445
    C->>S: NEGOTIATE (dialects 2.0.2 to 3.1.1)
    S->>C: NEGOTIATE response (dialect, signing required?, GSS token)
    C->>S: SESSION_SETUP (NTLM NEGOTIATE or Kerberos AP-REQ)
    S->>C: SESSION_SETUP (NTLM CHALLENGE, STATUS_MORE_PROCESSING_REQUIRED)
    C->>S: SESSION_SETUP (NTLM AUTHENTICATE)
    S->>C: SESSION_SETUP response (success, Session ID)
    C->>S: TREE_CONNECT \\server\share
    S->>C: Tree ID
    C->>S: CREATE / READ / WRITE / IOCTL / CLOSE
  1. Negotiate: the client lists the dialects it speaks; the server picks one and says whether signing is required. SMB 3.1.1 protects this step with a pre-authentication hash.
  2. Session setup: authentication through SPNEGO, which picks Kerberos if the client has a ticket for the server name, otherwise NTLM.
  3. Tree connect: connect to a share. IPC$ is special: it gives access to named pipes such as \srvsvc, \samr, \lsarpc, \svcctl and \winreg, which carry DCE/RPC calls for remote administration.
  4. File operations: CREATE returns a file handle, then READ, WRITE, QUERY_INFO, CLOSE.

NTLM inside SMB

NTLM is a challenge-response login in three messages, carried in the SESSION_SETUP security blob (the same messages appear in HTTP, LDAP, RDP and others):

MessageDirectionContent
NEGOTIATE (type 1)Client → serverSupported features (flags)
CHALLENGE (type 2)Server → client8-byte random server challenge, target info (domain, host names, timestamp)
AUTHENTICATE (type 3)Client → serverUser name, domain, workstation and the response, computed from the challenge and the user’s NT hash

The server cannot check the response itself for a domain account: it forwards it to a domain controller (Netlogon). The password never crosses the wire, but the response is enough to crack it offline or to relay it.

In Wireshark

FilterShows
smb2SMB2/3
smbSMB1 (should be empty)
smb2.cmd == 1Session setups (logins)
ntlmssp.messagetype == 3NTLM AUTHENTICATE: user, domain, workstation
ntlmssp.auth.usernameAdd as a column to list who logs in
smb2.nt_status == 0xc000006dFailed logins (spraying shows many)
smb2.cmd == 3Tree connects (which shares, e.g. ADMIN$, C$)
smb2.filename contains "svcctl"Service control pipe (PsExec-style remote execution)
smb2.flags.signature == 0 && smb2.cmd > 1Unsigned messages after login
smb2.cmd == 5 && smb2.filenameOpened files and pipes

File › Export Objects › SMB extracts transferred files. With the user’s password (or NT hash) configured under NTLMSSP preferences, Wireshark decrypts SMB 3 encrypted sessions.

What normal looks like: clients talk SMB to file servers and domain controllers (SYSVOL, NETLOGON for group policy). Workstation-to-workstation SMB, connections to ADMIN$ or C$, or a new service created over \svcctl are typical lateral movement. SMB to the internet should not exist (leaks NTLM hashes).

Security notes

References

§ home
~/knubertus/home/
1,1 Top