header
import "github.com/TheManticoreProject/Manticore/network/smb/smb_v20/message/header"
Index
- Constants
- Variables
- type Header
- func NewHeader() *Header
- func (h *Header) AddFlags(value flags.Flags)
- func (h *Header) GetAsyncId() types.UINT64
- func (h *Header) GetCommand() codes.CommandCode
- func (h *Header) GetMessageId() types.UINT64
- func (h *Header) GetSessionId() types.UINT64
- func (h *Header) GetTreeId() types.ULONG
- func (h *Header) HasValidProtocolId() bool
- func (h *Header) IsAsync() bool
- func (h *Header) IsRequest() bool
- func (h *Header) IsResponse() bool
- func (h *Header) Marshal() ([]byte, error)
- func (h *Header) SetAsyncId(asyncId types.UINT64)
- func (h *Header) SetCommand(command codes.CommandCode)
- func (h *Header) SetFlags(value flags.Flags)
- func (h *Header) SetMessageId(messageId types.UINT64)
- func (h *Header) SetSessionId(sessionId types.UINT64)
- func (h *Header) SetTreeId(treeId types.ULONG)
- func (h *Header) Unmarshal(data []byte) (int, error)
Constants
const (
// SMB2_HEADER_SIZE is the fixed wire size, in bytes, of an SMB2 packet header.
SMB2_HEADER_SIZE = 64
// SMB2_HEADER_STRUCTURE_SIZE is the value the StructureSize field MUST carry.
SMB2_HEADER_STRUCTURE_SIZE = 64
// SMB2_SIGNATURE_SIZE is the size, in bytes, of the header Signature field.
SMB2_SIGNATURE_SIZE = 16
)
Variables
SMB2ProtocolId is the 4-byte protocol identifier prefixing every SMB2 message: 0xFE ‘S’ ‘M’ ‘B’ (0x424D53FE in little-endian). It distinguishes SMB2 from the SMB 1.0 marker 0xFF ‘S’ ‘M’ ‘B’.
var SMB2ProtocolId = [4]byte{0xFE, 'S', 'M', 'B'}
type Header
Header represents the fixed 64-byte SMB2 packet header.
The header has two forms, selected by the SMB2_FLAGS_ASYNC_COMMAND bit in Flags: the SYNC form carries Reserved(4) + TreeId(4) at offsets 32..39, while the ASYNC form carries a single AsyncId(8) in the same span. Both forms are represented by this single struct; Marshal/Unmarshal select the layout from the Flags field.
type Header struct {
// ProtocolId (4 bytes): MUST be 0xFE 'S' 'M' 'B'.
ProtocolId [4]byte
// StructureSize (2 bytes): MUST be set to 64.
StructureSize types.USHORT
// CreditCharge (2 bytes): In the SMB 2.0.2 dialect this field MUST be 0 and
// ignored on receipt. In later dialects it indicates the number of credits
// the request consumes.
CreditCharge types.USHORT
// Status (4 bytes): The (ChannelSequence,Reserved)/Status union. In the
// SMB 2.0.2 and SMB 2.1 dialects this is the Status field in both requests
// (client sets 0) and responses. In the SMB 3.x family it is reinterpreted
// as ChannelSequence(2)+Reserved(2) in a request; that reinterpretation is
// deferred to the SMB 3.x implementation.
Status types.ULONG
// Command (2 bytes): The command code of this packet.
Command codes.CommandCode
// Credit (2 bytes): CreditRequest on a request / CreditResponse on a response.
Credit types.USHORT
// Flags (4 bytes): Indicates how to process the operation.
Flags flags.Flags
// NextCommand (4 bytes): Offset, in bytes, from the start of this header to
// the next 8-byte-aligned header in a compounded message, or 0 if this is
// the last (or only) command.
NextCommand types.ULONG
// MessageId (8 bytes): Uniquely identifies a request/response pair across all
// messages on the same transport connection.
MessageId types.UINT64
// Reserved (4 bytes): SYNC form only; SHOULD be 0. Overlaps AsyncId in the
// ASYNC form.
Reserved types.ULONG
// TreeId (4 bytes): SYNC form only; identifies the tree connect for the
// command. Overlaps AsyncId in the ASYNC form.
TreeId types.ULONG
// AsyncId (8 bytes): ASYNC form only; identifies an operation being processed
// asynchronously. Overlaps Reserved+TreeId in the SYNC form.
AsyncId types.UINT64
// SessionId (8 bytes): Uniquely identifies the established session for the
// command. MUST be 0 for an SMB2 NEGOTIATE.
SessionId types.UINT64
// Signature (16 bytes): The message signature if SMB2_FLAGS_SIGNED is set;
// otherwise all zero.
Signature [SMB2_SIGNATURE_SIZE]byte
}
func NewHeader
func NewHeader() *Header
NewHeader creates a new SMB2 SYNC Header with default values: the SMB2 protocol identifier and StructureSize set to 64.
Returns:
- *Header: A pointer to the newly created SMB2 Header.
func (*Header) AddFlags
func (h *Header) AddFlags(value flags.Flags)
AddFlags sets the given flag bits without clearing the others.
func (*Header) GetAsyncId
func (h *Header) GetAsyncId() types.UINT64
GetAsyncId returns the 64-bit AsyncId (ASYNC form).
func (*Header) GetCommand
func (h *Header) GetCommand() codes.CommandCode
GetCommand returns the command code.
func (*Header) GetMessageId
func (h *Header) GetMessageId() types.UINT64
GetMessageId returns the 64-bit MessageId.
func (*Header) GetSessionId
func (h *Header) GetSessionId() types.UINT64
GetSessionId returns the 64-bit SessionId.
func (*Header) GetTreeId
func (h *Header) GetTreeId() types.ULONG
GetTreeId returns the 32-bit TreeId (SYNC form).
func (*Header) HasValidProtocolId
func (h *Header) HasValidProtocolId() bool
HasValidProtocolId reports whether the ProtocolId field holds the SMB2 marker 0xFE ‘S’ ‘M’ ‘B’.
func (*Header) IsAsync
func (h *Header) IsAsync() bool
IsAsync reports whether the header uses the ASYNC form (SMB2_FLAGS_ASYNC_COMMAND set).
func (*Header) IsRequest
func (h *Header) IsRequest() bool
IsRequest reports whether the message is a request.
func (*Header) IsResponse
func (h *Header) IsResponse() bool
IsResponse reports whether the message is a response (SMB2_FLAGS_SERVER_TO_REDIR set).
func (*Header) Marshal
func (h *Header) Marshal() ([]byte, error)
Marshal serializes the SMB2 Header into a 64-byte slice using little-endian byte order. The Reserved+TreeId vs AsyncId span at offsets 32..39 is chosen from the SMB2_FLAGS_ASYNC_COMMAND bit in Flags.
Returns:
- []byte: The serialized header (always 64 bytes on success).
- error: Any error encountered during serialization.
func (*Header) SetAsyncId
func (h *Header) SetAsyncId(asyncId types.UINT64)
SetAsyncId sets the 64-bit AsyncId (ASYNC form).
func (*Header) SetCommand
func (h *Header) SetCommand(command codes.CommandCode)
SetCommand sets the command code.
func (*Header) SetFlags
func (h *Header) SetFlags(value flags.Flags)
SetFlags sets the 32-bit Flags field.
func (*Header) SetMessageId
func (h *Header) SetMessageId(messageId types.UINT64)
SetMessageId sets the 64-bit MessageId.
func (*Header) SetSessionId
func (h *Header) SetSessionId(sessionId types.UINT64)
SetSessionId sets the 64-bit SessionId.
func (*Header) SetTreeId
func (h *Header) SetTreeId(treeId types.ULONG)
SetTreeId sets the 32-bit TreeId (SYNC form).
func (*Header) Unmarshal
func (h *Header) Unmarshal(data []byte) (int, error)
Unmarshal deserializes a 64-byte SMB2 Header from the input byte slice using little-endian byte order. The offsets 32..39 are decoded as AsyncId when SMB2_FLAGS_ASYNC_COMMAND is set in the parsed Flags, and as Reserved+TreeId otherwise.
Parameters:
- data: The byte slice containing the serialized SMB2 header.
Returns:
- int: The number of bytes read (64 on success).
- error: An error if the input is shorter than 64 bytes.