Library smb2

Implements the Server Message Block (SMB) protocol version 2 and 3.

The implementation extends smb.lua to support SMB dialects 2.0.2, 2.1, 3.0, 3.0.2 and 3.1.1. This is a work in progress and not all commands are implemented yet. Features/functionality will be added as the scripts get updated. I tried to be consistent with the current implementation of smb.lua but some fields may have changed name or don't exist anymore.

Author:

  • Paulino Calderon <paulino@calderonpale.com>

Copyright © Same as Nmap--See https://nmap.org/book/man-legal.html

Source: https://svn.nmap.org/nmap/nselib/smb2.lua

Functions

dialect_name (dialect)

Converts a supported SMB 2 dialect code to dialect name https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/fac3655a-7eb5-4337-b0ab-244bbcd014e8

dialects ()

Returns the list of supported SMB 2 dialects https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/fac3655a-7eb5-4337-b0ab-244bbcd014e8

negotiate_v2 (smb, overrides)

Sends SMB2_COM_NEGOTIATE command for a SMB2/SMB3 connection. All supported dialects are offered. Use table overrides['Dialects'] to exclude some dialects or to force a specific dialect. Use function smb2.dialects to obtain the list of supported dialects. Use function smb2.dialect_name to check whether a given dialect is supported.

smb2_encode_header_sync (smb, command, overrides)

Creates a SMB2 SYNC header packet.

smb2_read (smb, read_data)

Reads the next SMB2 packet from the socket, and parses it into the header and data. Netbios handling based taken from smb.lua.

smb2_send (smb, header, data, overrides)

Sends a SMB2 packet

Functions

dialect_name (dialect)

Converts a supported SMB 2 dialect code to dialect name https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/fac3655a-7eb5-4337-b0ab-244bbcd014e8

Parameters

dialect
SMB 2 dialect revision code

Return value:

string representing the dialect (or nil). Example: 0x202 -> "2.0.2"
dialects ()

Returns the list of supported SMB 2 dialects https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/fac3655a-7eb5-4337-b0ab-244bbcd014e8

Return value:

list of 16-bit numerical revision codes (0x202, 0x210, ...)
negotiate_v2 (smb, overrides)

Sends SMB2_COM_NEGOTIATE command for a SMB2/SMB3 connection. All supported dialects are offered. Use table overrides['Dialects'] to exclude some dialects or to force a specific dialect. Use function smb2.dialects to obtain the list of supported dialects. Use function smb2.dialect_name to check whether a given dialect is supported.

Packet structure: https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/e14db7ff-763a-4263-8b10-0c3944f52fc5

Parameters

smb
The associated SMB connection object.
overrides
Overrides table.

Return value:

(status, dialect) If status is true, the negotiated dialect is returned as the second value. Otherwise if status is false, the error message is returned.

See also:

smb2_encode_header_sync (smb, command, overrides)

Creates a SMB2 SYNC header packet.

SMB2 Packet Header - SYNC:

Parameters

smb
The SMB object associated with the connection.
command
The SMB2 command to execute.
overrides
Overrides table.

Return value:

header The encoded SMB2 SYNC header.
smb2_read (smb, read_data)

Reads the next SMB2 packet from the socket, and parses it into the header and data. Netbios handling based taken from smb.lua.

Parameters

smb
The SMB object associated with the connection
read_data
[optional] Return data section. Set to false if you only need the header. Default: true

Return value:

(status, header, data) If status is true, the header, and data are all the raw arrays of bytes. If status is false, header contains an error message and data is undefined.
smb2_send (smb, header, data, overrides)

Sends a SMB2 packet

Parameters

smb
The SMB object associated with the connection
header
The header encoded with smb_encode_sync_header.
data
The data.
overrides
Overrides table.

Return values:

  1. Boolean Status.
  2. An error message if status is false.