smbpacket

package
v0.0.0-...-c8c792b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 19, 2019 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package smbpacket facilitates serialization and deserialization of SMB packets.

Index

Constants

View Source
const (
	// ServerToClient indicates that the packet is a response from the server.
	ServerToClient = 0x00000001 // SMB2_FLAGS_SERVER_TO_REDIR

	// Async indicates that the packet is in asynchronous form.
	Async = 0x00000002 // SMB2_FLAGS_ASYNC_COMMAND

	// Related indicates that the packet is a related operation that belongs
	// to a compounded request or response chain.
	Related = 0x00000004 // SMB2_FLAGS_RELATED_OPERATIONS

	// Signed indicates that the packet has been signed.
	Signed = 0x00000008 // SMB2_FLAGS_SIGNED

	// PriorityMask is a mask for the I/O priority bits of the packet.
	//
	// This flag is only valid in the SMB 3.1.1 dialect.
	PriorityMask = 0x00000070 // SMB2_FLAGS_PRIORITY_MASK

	// DFS indicates that the packet is part of a DFS operation.
	DFS = 0x10000000 // SMB2_FLAGS_DFS_OPERATIONS

	// Replay indicates that the packet is being replayed after a
	// transport failure.
	Replay = 0x20000000 // SMB2_FLAGS_REPLAY_OPERATION
)

SMB packet processing flags.

View Source
const HeaderSize = 64

HeaderSize is the number of bytes used by SMB request and response packet headers.

Variables

View Source
var FlagNames = FlagFormat{
	ServerToClient: "ServerToClient",
	Async:          "Async",
	Related:        "Related",
	Signed:         "Signed",
	PriorityMask:   "PriorityMask",
	DFS:            "DFS",
	Replay:         "Replay",
}

FlagNames maps individual flags to their Go-style names.

View Source
var FlagProtoNames = FlagFormat{
	ServerToClient: "SMB2_FLAGS_SERVER_TO_REDIR",
	Async:          "SMB2_FLAGS_ASYNC_COMMAND",
	Related:        "SMB2_FLAGS_RELATED_OPERATIONS",
	Signed:         "SMB2_FLAGS_SIGNED",
	PriorityMask:   "SMB2_FLAGS_PRIORITY_MASK",
	DFS:            "SMB2_FLAGS_DFS_OPERATIONS",
	Replay:         "SMB2_FLAGS_REPLAY_OPERATION",
}

FlagProtoNames maps individual flags to their names as defined by the SMB protocol specification.

View Source
var SMB2 = Protocol{0xFE, 'S', 'M', 'B'}

SMB2 is the SMB version 2 and 3 protocol packet identifier.

Functions

This section is empty.

Types

type FlagFormat

type FlagFormat map[Flags]string

FlagFormat describes a set of names for SMB packet flags.

type Flags

type Flags uint32

Flags declares a set of processing flags for an SMB packet.

func (Flags) Format

func (f Flags) Format(sep string, format FlagFormat) string

Format returns a string representation of the packet flags using the given separator and format.

func (Flags) Match

func (f Flags) Match(c Flags) bool

Match reports whether f contains all of the packet flags specified by c.

func (Flags) String

func (f Flags) String() string

String returns a string representation of the packet flags.

type Protocol

type Protocol [4]byte

Protocol is an SMB packet protocol identifier in network byte order.

type Request

type Request []byte

Request interprets a slice of bytes as an SMB request packet.

func (Request) Data

func (r Request) Data() []byte

Data returns the request data that follows the header.

func (Request) Header

func (r Request) Header() RequestHeader

Header returns the request header of r.

type RequestHeader

type RequestHeader []byte

RequestHeader interprets a slice of bytes as an SMB request packet header.

https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/fb188936-5050-48d3-b350-dc43059638a4

https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/ea4560b7-90da-4803-82b5-344754b92a79

func (RequestHeader) AsyncID

func (h RequestHeader) AsyncID() uint64

AsyncID returns the asynchronous ID of the request.

This field is only valid for asynchronous requests.

func (RequestHeader) ChannelSequence

func (h RequestHeader) ChannelSequence() uint16

ChannelSequence returns the channel sequence of the request. It indicates a channel change to the server.

This field is only valid in the SMB 3.x dialects.

func (RequestHeader) Command

func (h RequestHeader) Command() smbcommand.Code

Command returns the command code of the request.

func (RequestHeader) CreditCharge

func (h RequestHeader) CreditCharge() uint16

CreditCharge returns the credit charge of the request. This represents the cost of the packet.

This field is not valid in the SMB 2.0.2 dialect. It is valid in all other dialects.

func (RequestHeader) CreditRequest

func (h RequestHeader) CreditRequest() uint16

CreditRequest returns the number of credits requested in the request.

func (RequestHeader) Flags

func (h RequestHeader) Flags() Flags

Flags returns the processing flags for the request.

func (RequestHeader) MessageID

func (h RequestHeader) MessageID() uint64

MessageID returns the message ID of the request.

func (RequestHeader) NextCommand

func (h RequestHeader) NextCommand() uint32

NextCommand returns the byte offset of the next request in the message, if there is one. Returns zero if there are no more requests. The offset is relative to the start of h.

func (RequestHeader) Protocol

func (h RequestHeader) Protocol() Protocol

Protocol returns the protocol ID of the packet.

func (RequestHeader) SessionID

func (h RequestHeader) SessionID() uint64

SessionID returns the session ID of the request.

func (RequestHeader) SetAsyncID

func (h RequestHeader) SetAsyncID(async uint64)

SetAsyncID sets the asynchronous ID of the request.

This field is only valid for asynchronous requests.

func (RequestHeader) SetChannelSequence

func (h RequestHeader) SetChannelSequence(sequence uint16)

SetChannelSequence sets the channel sequence of the request. It indicates a channel change to the server.

This field is only valid in the SMB 3.x dialects.

func (RequestHeader) SetCommand

func (h RequestHeader) SetCommand(command smbcommand.Code)

SetCommand sets the command code of the request.

func (RequestHeader) SetCreditCharge

func (h RequestHeader) SetCreditCharge(charge uint16)

SetCreditCharge sets the credit charge of the request. This represents the cost of the packet.

This field is not valid in the SMB 2.0.2 dialect. It is valid in all other dialects.

func (RequestHeader) SetCreditRequest

func (h RequestHeader) SetCreditRequest(credits uint16)

SetCreditRequest sets the number of credits requested in the request.

func (RequestHeader) SetFlags

func (h RequestHeader) SetFlags(f Flags)

SetFlags sets the processing flags for the request.

func (RequestHeader) SetMessageID

func (h RequestHeader) SetMessageID(message uint64)

SetMessageID sets the message ID of the request.

func (RequestHeader) SetNextCommand

func (h RequestHeader) SetNextCommand(offset uint32)

SetNextCommand sets the byte offset of the next request in the message.

func (RequestHeader) SetProtocol

func (h RequestHeader) SetProtocol(p Protocol)

SetProtocol sets the protocol ID of the packet.

func (RequestHeader) SetSessionID

func (h RequestHeader) SetSessionID(tree uint32)

SetSessionID sets the session ID of the request.

func (RequestHeader) SetSignature

func (h RequestHeader) SetSignature(s Signature)

SetSignature sets the cryptographic signature of the request.

func (RequestHeader) SetSize

func (h RequestHeader) SetSize(size uint16)

SetSize sets the structure size of the header.

func (RequestHeader) SetTreeID

func (h RequestHeader) SetTreeID(tree uint32)

SetTreeID sets the tree ID of the request.

This field is only valid for synchronous requests.

func (RequestHeader) Signature

func (h RequestHeader) Signature() Signature

Signature returns the cryptographic signature of the request.

func (RequestHeader) Size

func (h RequestHeader) Size() uint16

Size returns the structure size of the header.

func (RequestHeader) Status

func (h RequestHeader) Status() uint32

Status returns the status from the request.

This field is only valid in the SMB 2.0.2 and 2.1 dialects. It must be 0.

func (RequestHeader) TreeID

func (h RequestHeader) TreeID() uint32

TreeID returns the tree ID of the request.

This field is only valid for synchronous requests.

func (RequestHeader) Valid

func (h RequestHeader) Valid() bool

Valid returns true if the header is valid.

type Response

type Response []byte

Response interprets a slice of bytes of an SMB response packet.

func (Response) Data

func (r Response) Data() []byte

Data returns the response data that follows the header.

func (Response) Header

func (r Response) Header() ResponseHeader

Header returns the response header of r.

type ResponseHeader

type ResponseHeader []byte

ResponseHeader interprets a slice of bytes as an SMB response packet header.

https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/fb188936-5050-48d3-b350-dc43059638a4

https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/ea4560b7-90da-4803-82b5-344754b92a79

func (ResponseHeader) AsyncID

func (h ResponseHeader) AsyncID() uint64

AsyncID returns the asynchronous ID of the response.

This field is only valid for asynchronous responses.

func (ResponseHeader) Command

func (h ResponseHeader) Command() smbcommand.Code

Command returns the command code of the response.

func (ResponseHeader) CreditCharge

func (h ResponseHeader) CreditCharge() uint16

CreditCharge returns the credit charge of the response. This represents the cost of the packet.

This field is not valid in the SMB 2.0.2 dialect. It is valid in all other dialects.

func (ResponseHeader) CreditResponse

func (h ResponseHeader) CreditResponse() uint16

CreditResponse returns the number of credits granted in the response.

func (ResponseHeader) Flags

func (h ResponseHeader) Flags() Flags

Flags returns the processing flags for the response.

func (ResponseHeader) MessageID

func (h ResponseHeader) MessageID() uint64

MessageID returns the message ID of the response.

func (ResponseHeader) NextCommand

func (h ResponseHeader) NextCommand() uint32

NextCommand returns the byte offset of the next response in the message, if there is one. It returns zero if there are no more responses. The offset is relative to the start of h.

func (ResponseHeader) Protocol

func (h ResponseHeader) Protocol() Protocol

Protocol returns the protocol ID of the packet.

func (ResponseHeader) SessionID

func (h ResponseHeader) SessionID() uint64

SessionID returns the session ID of the response.

func (ResponseHeader) SetAsyncID

func (h ResponseHeader) SetAsyncID(async uint64)

SetAsyncID sets the asynchronous ID of the response.

This field is only valid for asynchronous responses.

func (ResponseHeader) SetCommand

func (h ResponseHeader) SetCommand(command smbcommand.Code)

SetCommand sets the command code of the response.

func (ResponseHeader) SetCreditCharge

func (h ResponseHeader) SetCreditCharge(charge uint16)

SetCreditCharge sets the credit charge of the response. This represents the cost of the packet.

This field is not valid in the SMB 2.0.2 dialect. It is valid in all other dialects.

func (ResponseHeader) SetCreditResponse

func (h ResponseHeader) SetCreditResponse(credits uint16)

SetCreditResponse sets the number of credits granted in the response.

func (ResponseHeader) SetFlags

func (h ResponseHeader) SetFlags(f Flags)

SetFlags sets the processing flags for the response.

func (ResponseHeader) SetMessageID

func (h ResponseHeader) SetMessageID(message uint64)

SetMessageID sets the message ID of the response.

func (ResponseHeader) SetNextCommand

func (h ResponseHeader) SetNextCommand(offset uint32)

SetNextCommand sets the byte offset of the next response in the message.

func (ResponseHeader) SetProtocol

func (h ResponseHeader) SetProtocol(p Protocol)

SetProtocol sets the protocol ID of the packet.

func (ResponseHeader) SetSessionID

func (h ResponseHeader) SetSessionID(tree uint32)

SetSessionID sets the session ID of the response.

func (ResponseHeader) SetSignature

func (h ResponseHeader) SetSignature(s Signature)

SetSignature sets the cryptographic signature of the response.

func (ResponseHeader) SetSize

func (h ResponseHeader) SetSize(size uint16)

SetSize sets the structure size of the header.

func (ResponseHeader) SetStatus

func (h ResponseHeader) SetStatus(status uint32)

SetStatus sets the status of the response. It indicates the success or failure of the command.

func (ResponseHeader) SetTreeID

func (h ResponseHeader) SetTreeID(tree uint32)

SetTreeID sets the tree ID of the response.

This field is only valid for synchronous responses.

func (ResponseHeader) Signature

func (h ResponseHeader) Signature() Signature

Signature returns the cryptographic signature of the response.

func (ResponseHeader) Size

func (h ResponseHeader) Size() uint16

Size returns the structure size of the header.

func (ResponseHeader) Status

func (h ResponseHeader) Status() uint32

Status returns the status from the response. It indicates the success or failure of the command.

func (ResponseHeader) TreeID

func (h ResponseHeader) TreeID() uint32

TreeID returns the tree ID of the response.

This field is only valid for synchronous responses.

func (ResponseHeader) Valid

func (h ResponseHeader) Valid() bool

Valid returns true if the header is valid.

type Signature

type Signature [16]byte

Signature is an SMB packet signature.

func (Signature) Marshal

func (s Signature) Marshal(v []byte)

Marshal copies 16 bytes of signature data into v.

func (*Signature) Unmarshal

func (s *Signature) Unmarshal(v []byte)

Unmarshal copies the first 16 bytes of v into s.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL