smb

package
v0.0.0-...-ccdda2f Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const FlagUnicode uint16 = 0x8000

FlagUnicode indicates that the data in the SMB packet is encoded in Unicode.

Variables

This section is empty.

Functions

This section is empty.

Types

type Capability

type Capability uint32

Capability represents the capabilities of an SMB packet

const (
	// CapabilityNTStatus indicates support for NT error codes
	CapabilityNTStatus Capability = 0x00000001

	// CapabilityRPCRemoteAPIs indicates support for remote RPC
	CapabilityRPCRemoteAPIs Capability = 0x00000002

	// CapabilityUnicode indicates support for Unicode strings
	CapabilityUnicode Capability = 0x00000004

	// CapabilityLargeFiles indicates support for large files
	CapabilityLargeFiles Capability = 0x00000008

	// CapabilityExtendedSecurity indicates support for extended security
	CapabilityExtendedSecurity Capability = 0x80000000
)

type CloseRequest

type CloseRequest struct {
	WordCount        uint8
	FID              uint16
	LastWriteTime    uint64
	Reserved         uint16
	NameLength       uint16
	ByteCount        uint16
	Flags            uint16
	FileName         string
	CloseContextData []byte
}

This structure represents a request to close a file in the Server Message Block (SMB) protocol. It has the following fields:

WordCount: an 8-bit integer indicating the number of 16-bit words in the request.
FID: a 16-bit integer identifying the file to close.
LastWriteTime: a 64-bit integer representing the last write time of the file.
Reserved: a 32-bit integer reserved for future use.
ByteCount: a 16-bit integer that indicates the total number of bytes in the CloseRequest structure. This includes the length of both the fixed-length and variable-length fields of the structure. The ByteCount field is used by the SMB protocol to determine the end of the CloseRequest structure in a packet. It allows the receiver of the packet to parse the CloseRequest structure correctly, even if the structure includes variable-length fields with different lengths in different packets.
NameLength: an 8-bit integer indicating the length of the FileName field in bytes.
Flags: a 16-bit integer that contains various flags that control the behavior of the CloseRequest command. The exact meaning and use of these flags varies depending on the specific version of the SMB protocol in use. In the CloseRequestParse function, the Flags field is used to determine if the FileName field is encoded in Unicode or ASCII format.
FileName: a variable-length string containing the name of the file to close.
CreateContextData: a variable-length byte slice containing additional data for the request.

func CloseRequestParse

func CloseRequestParse(data []byte) (*CloseRequest, error)

func (*CloseRequest) Marshal

func (c *CloseRequest) Marshal() ([]byte, error)

type Command

type Command uint16

Command represents an SMB command

const (
	// CommandNegotiate indicates a negotiate command
	CommandNegotiate Command = 0x72

	// CommandSessionSetup indicates a session setup command
	CommandSessionSetup Command = 0x73

	// CommandTreeConnect indicates a tree connect command
	CommandTreeConnect Command = 0x75

	// CommandCreate indicates a create command
	CommandCreate Command = 0x6D

	// CommandClose indicates a close command
	CommandClose Command = 0x6E

	// CommandWrite indicates a write command
	CommandWrite Command = 0x2B

	// CommandRead indicates a read command
	CommandRead Command = 0x2E

	// CommandTreeDisconnect indicates a tree disconnect command
	CommandTreeDisconnect Command = 0x71

	// CommandLogoff indicates a logoff command
	CommandLogoff Command = 0x74
)

type CreateRequest

type CreateRequest struct {
	WordCount          uint8
	NameLength         uint8
	Flags              uint32
	RootDirectoryFID   uint32
	DesiredAccess      uint32
	AllocationSize     uint64
	ExtFileAttributes  uint32
	ShareAccess        uint32
	CreateDisposition  uint32
	CreateOptions      uint32
	ImpersonationLevel uint32
	SecurityFlags      uint8
	ByteCount          uint16
	FileName           string
	CreateContextData  []byte
}

func CreateRequestParse

func CreateRequestParse(data []byte) (*CreateRequest, error)

type DeleteRequest

type DeleteRequest struct {
	WordCount         uint8
	SearchAttributes  uint16
	NameLength        uint8
	Flags             uint16
	FileName          string
	DeleteContextData []byte
}

WordCount: an 8-bit integer indicating the number of 16-bit words in the request. SearchAttributes: a 16-bit integer containing flags specifying the search attributes for the file to delete. NameLength: an 8-bit integer indicating the length of the FileName field in bytes. Flags: a 16-bit integer containing flags that modify the request. FileName: a variable-length string containing the name of the file to delete. DeleteContextData: a variable-length byte slice containing additional data for the request.

func DeleteRequestParse

func DeleteRequestParse(data []byte) (*DeleteRequest, error)

type Dialect

type Dialect uint16

Dialect represents an SMB dialect

const (
	// DialectUnknown indicates an unknown dialect
	DialectUnknown Dialect = 0

	// DialectSMB202 indicates the SMB 2.0.2 dialect
	DialectSMB202 Dialect = 0x0202

	// DialectSMB210 indicates the SMB 2.1 dialect
	DialectSMB210 Dialect = 0x0210

	// DialectSMB300 indicates the SMB 3.0 dialect
	DialectSMB300 Dialect = 0x0300

	// DialectSMB302 indicates the SMB 3.0.2 dialect
	DialectSMB302 Dialect = 0x0302

	// DialectSMB311 indicates the SMB 3.1.1 dialect
	DialectSMB311 Dialect = 0x0311
)

type Dialects

type Dialects []Dialect

Dialects represents a list of SMB dialects

func (*Dialects) Read

func (d *Dialects) Read(r io.Reader) (int, error)

Read implements the io.Reader interface

type ErrorClass

type ErrorClass uint8

ErrorClass represents an SMB error class

const (
	// ErrorClassSuccess indicates a successful operation
	ErrorClassSuccess ErrorClass = 0

	// ErrorClassDOS indicates a DOS error
	ErrorClassDOS ErrorClass = 0x01

	// ErrorClassServer indicates a server error
	ErrorClassServer ErrorClass = 0x02

	// ErrorClassHardware indicates a hardware error
	ErrorClassHardware ErrorClass = 0x03

	// ErrorClassProto indicates a protocol error
	ErrorClassProto ErrorClass = 0x04
)

type ErrorResponse

type ErrorResponse struct {
	ErrorClass    ErrorClass
	Reserved      uint8
	ErrorCode     uint32
	ErrorReserved uint32
	ErrorString   string
}

ErrorResponse represents an SMB error response

type FlushRequest

type FlushRequest struct {
	WordCount         uint8
	FID               uint16
	Reserved          uint16
	Flags             uint16
	NameLength        uint8
	FileName          string
	CreateContextData []byte
}

FlushRequest structure represents a request to flush the buffers of a file in the Server Message Block (SMB) protocol. It has the following fields:

WordCount: an 8-bit integer indicating the number of 16-bit words in the request.
FID: a 16-bit integer identifying the file to flush.
Reserved: a 16-bit integer reserved for future use.
Flags: a 16-bit integer containing flags that modify the request.
NameLength: an 8-bit integer indicating the length of the FileName field in bytes.
FileName: a variable-length string containing the name of the file to flush.
CreateContextData: a variable-length byte slice containing additional data for the request.

func FlushRequestParse

func FlushRequestParse(data []byte) (*FlushRequest, error)
type Header struct {
	ProtocolID  [4]byte
	Command     Command
	Status      Status
	Flags       uint32
	Flags2      uint32
	Reserved    uint32
	TreeID      uint32
	ProcessID   uint16
	UserID      uint16
	MultiplexID uint16
	Data        []byte
}

Header represents an SMB header

func HeaderParse

func HeaderParse(data []byte) (*Header, error)

HeaderParse parses an SMB packet header from a byte slice

func (*Header) Marshal

func (h *Header) Marshal() ([]byte, error)

Marshal serializes an SMB header into a byte slice

type Marshaller

type Marshaller interface {
	Marshal() ([]byte, error)
}

func ParseData

func ParseData(command Command, data []byte) (Marshaller, error)

ParseData parses the data section of an SMB packet

type NegotiateRequest

type NegotiateRequest struct {
	Dialects Dialects
}

NegotiateRequest represents an SMB negotiate request

func NegotiateRequestParse

func NegotiateRequestParse(data []byte) (*NegotiateRequest, error)

NegotiateRequestParse parses an SMB negotiate request

func (*NegotiateRequest) Marshal

func (r *NegotiateRequest) Marshal() ([]byte, error)

type NegotiateResponse

type NegotiateResponse struct {
	Dialect             Dialect
	SecurityMode        SecurityMode
	MaxBufferSize       uint32
	MaxMpxCount         uint16
	Capabilities        Capability
	SystemTime          time.Time
	ServerTimeZone      int16
	Challenge           [8]byte
	DomainName          string
	ServerName          string
	EncryptionKeyLength uint16
}

NegotiateResponse represents an SMB negotiate response

func (*NegotiateResponse) Marshal

func (r *NegotiateResponse) Marshal() ([]byte, error)

Marshal serializes an SMB negotiate response into a byte slice

type Packet

type Packet struct {
	Header Header
	Data   Marshaller
}

Packet represents an SMB packet

func PacketParse

func PacketParse(data []byte) (*Packet, error)

PacketParse parses an SMB packet from a byte slice

func (*Packet) Marshal

func (p *Packet) Marshal() ([]byte, error)

Marshal serializes an SMB packet into a byte slice

type QueryInfoRequest

type QueryInfoRequest struct {
	WordCount        uint8
	InformationLevel uint16
	Reserved         uint8
	NameLength       uint8
	Flags            uint16
	FileName         string
	QueryContextData []byte
}

WordCount: an 8-bit integer indicating the number of 16-bit words in the request. InformationLevel: a 16-bit integer specifying the type of information to query. Reserved: an 8-bit integer reserved for future use. NameLength: an 8-bit integer indicating the length of the FileName field in bytes. Flags: a 16-bit integer containing flags that modify the request. FileName: a variable-length string containing the name of the file to query. QueryContextData: a variable-length byte slice containing additional data for the request.

func QueryInfoRequestParse

func QueryInfoRequestParse(data []byte) (*QueryInfoRequest, error)

type ReadRequest

type ReadRequest struct {
	WordCount       uint8
	FID             uint16
	Offset          uint64
	MaxCount        uint16
	MinCount        uint16
	Remaining       uint32
	HighOffset      uint32
	Reserved        uint32
	Flags           uint16
	NameLength      uint8
	FileName        string
	ReadContextData []byte
}

WordCount: an 8-bit integer indicating the number of 16-bit words in the request. FID: a 16-bit integer identifying the file to read from. Offset: a 64-bit integer specifying the offset in the file to read from. MaxCount: a 16-bit integer indicating the maximum number of bytes to read from the file. MinCount: a 16-bit integer indicating the minimum number of bytes to read from the file. Remaining: a 32-bit integer indicating the number of bytes remaining to be read from the file. HighOffset: a 32-bit integer specifying the high 32 bits of the file offset. Reserved: a 32-bit integer reserved for future use. Flags: a 16-bit integer containing flags that modify the request. NameLength: an 8-bit integer indicating the length of the FileName field in bytes. FileName: a variable-length string containing the name of the file to read from. ReadContextData: a variable-length byte slice containing additional data for the request.

func ReadRequestParse

func ReadRequestParse(data []byte) (*ReadRequest, error)

type RenameRequest

type RenameRequest struct {
	WordCount         uint8
	SearchAttributes  uint16
	OldNameLength     uint8
	NewNameLength     uint8
	Flags             uint16
	OldFileName       string
	NewFileName       string
	RenameContextData []byte
}

WordCount: an 8-bit integer indicating the number of 16-bit words in the request. SearchAttributes: a 16-bit integer containing flags specifying the search attributes for the file to rename. OldNameLength: an 8-bit integer indicating the length of the OldFileName field in bytes. NewNameLength: an 8-bit integer indicating the length of the NewFileName field in bytes. Flags: a 16-bit integer containing flags that modify the request. OldFileName: a variable-length string containing the current name of the file to rename. NewFileName: a variable-length string containing the new name of the file. RenameContextData: a variable-length byte slice containing additional data for the request.

func RenameRequestParse

func RenameRequestParse(data []byte) (*RenameRequest, error)

type SecurityMode

type SecurityMode uint8

SecurityMode represents the security mode of an SMB packet

const (
	// SecurityModeUserLevel indicates user-level security
	SecurityModeUserLevel SecurityMode = 0x01

	// SecurityModeEncryptPasswords indicates encrypted password support
	SecurityModeEncryptPasswords SecurityMode = 0x02

	// SecurityModeSignaturesEnabled indicates signature support
	SecurityModeSignaturesEnabled SecurityMode = 0x04

	// SecurityModeSignaturesRequired indicates signature support
	SecurityModeSignaturesRequired SecurityMode = 0x08
)

type SessionSetupRequest

type SessionSetupRequest struct {
	WordCount       uint8
	AndXCommand     Command
	AndXReserved    uint8
	AndXOffset      uint16
	MaxBufferSize   uint16
	MaxMpxCount     uint16
	VCNumber        uint16
	SessionKey      uint32
	SecurityBlobLen uint16
	Reserved        uint16
	Capabilities    uint32
	SecurityBlob    []byte
}

SessionSetupRequest represents an SMB session setup request The WordCount field specifies the number of words in the request, where a word is a 16-bit field. The AndXCommand field is used to chain multiple SMB commands together into a single request. The AndXReserved field is reserved for future use and should be set to zero. The AndXOffset field specifies the offset, in bytes, from the start of the SMB header to the next SMB command in the chain. The MaxBufferSize field specifies the maximum size, in bytes, of the buffer that the client can use for the request. The MaxMpxCount field specifies the maximum number of pending multiplexed requests that the client can have. The VCNumber field specifies the virtual circuit (VC) number that the client is using for the request. The SessionKey field is a 32-bit value that is used to identify the session. The SecurityBlobLen field specifies the length, in bytes, of the security blob. The Reserved field is reserved for future use and should be set to zero. The Capabilities field specifies the capabilities of the client, such as support for Unicode strings and large files. The SecurityBlob field contains the security blob, which is used to authenticate the client.

func SessionSetupRequestParse

func SessionSetupRequestParse(data []byte) (*SessionSetupRequest, error)

SessionSetupRequestParse parses an SMB session setup request

type SetInfoRequest

type SetInfoRequest struct {
	WordCount        uint8
	InformationLevel uint16
	Reserved         uint8
	NameLength       uint8
	Flags            uint16
	FileName         string
	SetContextData   []byte
}

WordCount: an 8-bit integer indicating the number of 16-bit words in the request. InformationLevel: a 16-bit integer specifying the type of information to set. Reserved: an 8-bit integer reserved for future use. NameLength: an 8-bit integer indicating the length of the FileName field in bytes. Flags: a 16-bit integer containing flags that modify the request. FileName: a variable-length string containing the name of the file to set. SetContextData: a variable-length byte slice containing additional data for the request.

func SetInfoRequestParse

func SetInfoRequestParse(data []byte) (*SetInfoRequest, error)

type Status

type Status uint32

Status represents an SMB status code

const (
	// StatusSuccess indicates a successful operation
	StatusSuccess Status = 0x00000000

	// StatusInvalidParameter indicates an invalid parameter
	StatusInvalidParameter Status = 0x00000057

	// StatusAccessDenied indicates access was denied
	StatusAccessDenied Status = 0x00000005

	// StatusIncorrectPassword indicates an incorrect password
	StatusIncorrectPassword Status = 0x00000056

	// StatusBadNetworkName indicates a bad network name
	StatusBadNetworkName Status = 0x000004B3

	// StatusPathNotFound indicates a path was not found
	StatusPathNotFound Status = 0x00000003

	// StatusInvalidHandle indicates an invalid handle
	StatusInvalidHandle Status = 0x00000006

	// StatusFileExists indicates a file already exists
	StatusFileExists Status = 0x00000050

	// StatusInvalidDevice indicates an invalid device
	StatusInvalidDevice Status = 0x00000047

	// StatusInvalidNetworkResponse indicates an invalid network response
	StatusInvalidNetworkResponse Status = 0x000004B2

	// StatusNotSupported indicates a request is not supported
	StatusNotSupported Status = 0x00000032

	// StatusObjectNameInvalid indicates an invalid object name
	StatusObjectNameInvalid Status = 0x00000033

	// StatusObjectNameNotFound indicates an object name was not found
	StatusObjectNameNotFound Status = 0x00000034

	// StatusObjectNameCollision indicates an object name collision
	StatusObjectNameCollision Status = 0x00000035
)

type TreeConnectRequest

type TreeConnectRequest struct {
	Path     string
	Password string
	Service  string
}

Path: The path of the share to connect to. Password: The password for the share, if any. Service: The service associated with the share.

func TreeConnectRequestParse

func TreeConnectRequestParse(data []byte) (*TreeConnectRequest, error)

TreeConnectRequestParse parses an SMB tree connect request

type TreeDisconnectRequest

type TreeDisconnectRequest struct {
	WordCount uint8
	ByteCount uint16
}

func TreeDisconnectRequestParse

func TreeDisconnectRequestParse(data []byte) (*TreeDisconnectRequest, error)

type WriteRequest

type WriteRequest struct {
	WordCount        uint8
	FID              uint16
	Offset           uint64
	Remaining        uint32
	DataLength       uint16
	DataOffset       uint16
	HighOffset       uint32
	Reserved         uint32
	Flags            uint16
	NameLength       uint8
	FileName         string
	WriteContextData []byte
	DataToWrite      []byte
}

This structure represents a request to write data to a file in the Server Message Block (SMB) protocol. It has the following fields:

WordCount: an 8-bit integer indicating the number of 16-bit words in the request.
FID: a 16-bit integer identifying the file to write to.
Offset: a 64-bit integer specifying the offset in the file to write to.
Remaining: a 32-bit integer indicating the number of bytes remaining to be written to the file.
DataLength: a 16-bit integer indicating the length of the DataToWrite field in bytes.
DataOffset: a 16-bit integer specifying the offset in the packet where the DataToWrite field begins.
HighOffset: a 32-bit integer specifying the high 32 bits of the file offset.
Reserved: a 32-bit integer reserved for future use.
Flags: a 16-bit integer containing flags that modify the request.
NameLength: an 8-bit integer indicating the length of the FileName field in bytes.
FileName: a variable-length string containing the name of the file to write to.
WriteContextData: a variable-length byte slice containing additional data for the request.
DataToWrite: a variable-length byte slice containing the data to write to the file.

func WriteRequestParse

func WriteRequestParse(data []byte) (*WriteRequest, error)

Jump to

Keyboard shortcuts

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