Documentation
¶
Index ¶
- Constants
- type Header
- func (h *Header) GetMID() types.USHORT
- func (h *Header) GetPID() types.ULONG
- func (h *Header) GetTID() types.USHORT
- func (h *Header) GetUID() types.USHORT
- func (h *Header) IsRequest() bool
- func (h *Header) IsResponse() bool
- func (h *Header) Marshal() ([]byte, error)
- func (h *Header) SetFlags(value uint8)
- func (h *Header) SetFlags2(value uint16)
- func (h *Header) SetMID(mid types.USHORT)
- func (h *Header) SetPID(pid types.ULONG)
- func (h *Header) SetTID(tid types.USHORT)
- func (h *Header) SetUID(uid types.USHORT)
- func (h *Header) Unmarshal(data []byte) (int, error)
Constants ¶
const (
SMB_HEADER_SIZE = 32
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Header ¶
type Header struct {
// Protocol (4 bytes): This field MUST contain the 4-byte literal string '\xFF', 'S', 'M', 'B',
// with the letters represented by their respective ASCII values in the order shown. In the earliest
// available SMB documentation, this field is defined as a one byte message type (0xFF) followed by
// a three byte server type identifier.
Protocol [4]byte
// Command (1 byte): A one-byte command code. Defined SMB command codes are listed in section 2.2.2.1.
Command codes.CommandCode
// Status (4 bytes): A 32-bit field used to communicate error messages from the server to the client.
Status types.ULONG
// Flags (1 byte): An 8-bit field of 1-bit flags describing various features in effect for the message.
Flags flags.Flags
// Flags2 (2 bytes): A 16-bit field of 1-bit flags that represent various features in effect for the message.
// Unspecified bits are reserved and MUST be zero.
Flags2 flags2.Flags2
// PID (2 bytes): A 32-bit field that represents the process identifier (PID).
PIDHigh types.USHORT
// SecurityFeatures (8 bytes): This 8-byte field has three possible interpretations.
SecurityFeatures securityfeatures.SecurityFeatures
// Reserved (2 bytes): This field is reserved and SHOULD be set to 0x0000.
Reserved types.USHORT
// TID (2 bytes): A tree identifier (TID).
TID types.USHORT
// PIDLow (2 bytes): A 32-bit field that represents the process identifier (PID).
PIDLow types.USHORT
// UID (2 bytes): A user identifier (UID).
UID types.USHORT
// MID (2 bytes): A multiplex identifier (MID).
MID types.USHORT
}
Header represents the header structure for SMB packets Source: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-cifs/69a29f73-de0c-45a6-a1aa-8ceeea42217f
func NewHeader ¶
func NewHeader() *Header
NewHeader creates a new SMB Header with default values and initializes the SecurityFeatures field with a Reserved security features object.
Returns:
- *Header: A pointer to the newly created SMB Header
func NewHeaderWithSecurityFeaturesConnectionLess ¶
func NewHeaderWithSecurityFeaturesConnectionLess() *Header
NewHeaderWithSecurityFeaturesConnectionLess creates a new SMB Header with default values and initializes the SecurityFeatures field with a ConnectionlessTransport security features object.
Returns:
- *Header: A pointer to the newly created SMB Header
func NewHeaderWithSecurityFeaturesSecuritySignature ¶
func NewHeaderWithSecurityFeaturesSecuritySignature() *Header
NewHeaderWithSecurityFeaturesSecuritySignature creates a new SMB Header with default values and initializes the SecurityFeatures field with a SecuritySignature security features object.
Returns:
- *Header: A pointer to the newly created SMB Header
func (*Header) GetMID ¶
GetMID returns the multiplex identifier (MID) value
Returns:
- types.USHORT: The multiplex identifier (MID) value
func (*Header) GetPID ¶
GetPID returns the full 32-bit process identifier (PID) value combining PIDHigh and PIDLow
Returns:
- types.ULONG: The full 32-bit process identifier (PID) value
func (*Header) GetTID ¶
GetTID returns the tree identifier (TID) value
Returns:
- types.USHORT: The tree identifier (TID) value
func (*Header) GetUID ¶
GetUID returns the user identifier (UID) value
Returns:
- types.USHORT: The user identifier (UID) value
func (*Header) IsRequest ¶
IsRequest returns true if the header is a request, false otherwise.
Returns:
- bool: True if the header is a request, false otherwise
func (*Header) IsResponse ¶
IsResponse returns true if the header is a response, false otherwise.
Returns:
- bool: True if the header is a response, false otherwise
func (*Header) Marshal ¶
Marshal serializes the SMB Header structure into a byte slice. It converts all header fields into their binary representation using little-endian byte order. The resulting byte slice will be exactly 32 bytes (SMB_HEADER_SIZE) long, containing all header fields in the order specified by the SMB protocol.
Returns:
- []byte: The serialized header as a byte slice
- error: Any error encountered during serialization, or nil if successful
func (*Header) SetFlags ¶
SetFlags sets the flags field in the SMB Header. The flags field is an 8-bit field of 1-bit flags describing various features in effect for the message.
Parameters:
- flags: The byte value to set as flags
func (*Header) SetFlags2 ¶
SetFlags2 sets the flags2 field in the SMB Header. The flags2 field is a 16-bit field of 1-bit flags that represent various features in effect for the message.
Parameters:
- flags2: The uint16 value to set as flags2
func (*Header) SetMID ¶
SetMID sets the multiplex identifier (MID) value
Parameters:
- mid: The new multiplex identifier (MID) value
func (*Header) SetPID ¶
SetPID sets both PIDHigh and PIDLow from a 32-bit process identifier (PID)
Parameters:
- pid: The new 32-bit process identifier (PID) value
func (*Header) SetTID ¶
SetTID sets the tree identifier (TID) value
Parameters:
- tid: The new tree identifier (TID) value
func (*Header) SetUID ¶
SetUID sets the user identifier (UID) value
Parameters:
- uid: The new user identifier (UID) value
func (*Header) Unmarshal ¶
Unmarshal deserializes a byte slice into the SMB Header structure. It reads the binary representation of the header fields from the input byte slice using little-endian byte order. This method determines the appropriate security features type based on the header flags and unmarshals accordingly.
Parameters:
- data: The byte slice containing the serialized SMB header
Returns:
- int: The number of bytes read from the input byte slice
- error: Any error encountered during deserialization, or nil if successful