SMB Cheat Sheet

Overview

  • SMB (Server Message Block) is a network file sharing protocol used for providing shared access to files, printers, and serial ports. It operates at the Application Layer (Layer 7) of the OSI model.

Common Uses

  • Accessing files and networks shares on remote servers.
  • Printing to shared printers on the network.
  • Interprocess communication between programs on the same server.

Common SMB Message Types

SMB Message TypeDescriptionPurpose
SMB_COM_READRequest to read a file from the server.Used to retrieve the contents of a file.
SMB_COM_WRITERequest to write data to a file on the server.Used to modify an existing file or create a new one.
SMB_COM_CREATERequest to create a new file or directory.Used for creating new resources in shared folders.
SMB_COM_DELETERequest to delete a file or directory.Used to remove files or folders from the server.
SMB_COM_TRANSACTIONPerform a transaction over the SMB session.Used for complex operations that require multiple steps.

SMB Packet Structure

FieldSize (bytes)Description
Protocol ID2Always set to 0xFF534D42 (‘SMB’)
Command1Indicates the type of SMB command being issued
Error Code2Error code indicating the result of the SMB command
Flags2Flags indicating various options (e.g., case sensitivity)
PID High2High word of the process ID
UID2User ID assigned when a connection is established
MID2Multiplexer ID for tracking requests
Word Count1Number of words in the parameter block
Parameter BlockVariableParameters specific to the command being requested
Data BlockVariableContains the data associated with the request (file contents, etc.)

Common SMB Ports

PortDescription
445Direct SMB over TCP without NetBIOS encapsulation.
139SMB over NetBIOS, commonly used for legacy systems.

Security Considerations

  • SMB Signing: Provides integrity and authenticity for SMB communications.
  • SMB Encryption: Protects data in transit to prevent eavesdropping and tampering.
  • Guest Access: Should be disabled to prevent unauthorized access to shared resources.

Common Commands for SMB Scanning and Enumeration

CommandDescription
nmap -p 445 --script=smb-os-discovery <target>Discover the operating system on a target SMB server.
nbtscan -r <target>Scans for NetBIOS services and shares on target IPs.
enum4linux -a <target>Enumerates SMB shares, users, and groups from a target.

This cheat sheet provides a quick reference for understanding and utilizing the SMB protocol, including its structure, common commands, and security considerations.