smb2

package
v0.0.0-...-e973567 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FILE_ATTRIBUTE_READONLY              = 0x00000001
	FILE_ATTRIBUTE_HIDDEN                = 0x00000002
	FILE_ATTRIBUTE_SYSTEM                = 0x00000004
	FILE_ATTRIBUTE_DIRECTORY             = 0x00000010
	FILE_ATTRIBUTE_ARCHIVE               = 0x00000020
	FILE_ATTRIBUTE_NORMAL                = 0x00000080
	FILE_ATTRIBUTE_TEMPORARY             = 0x00000100
	FILE_ATTRIBUTE_SPARSE_FILE           = 0x00000200
	FILE_ATTRIBUTE_REPARSE_POINT         = 0x00000400
	FILE_ATTRIBUTE_COMPRESSED            = 0x00000800
	FILE_ATTRIBUTE_OFFLINE               = 0x00001000
	FILE_ATTRIBUTE_NOT_CONTENT_INDEXED   = 0x00002000
	FILE_ATTRIBUTE_ENCRYPTED             = 0x00004000
	FILE_ATTRIBUTE_INTEGRITY_STREAM      = 0x00008000
	FILE_ATTRIBUTE_NO_SCRUB_DATA         = 0x00020000
	FILE_ATTRIBUTE_RECALL_ON_OPEN        = 0x00040000
	FILE_ATTRIBUTE_PINNED                = 0x00080000
	FILE_ATTRIBUTE_UNPINNED              = 0x00100000
	FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS = 0x00400000
)

https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/ca28ec38-f155-4768-81d6-4bfeb8586fc9 FileAttributes属性

View Source
const (
	SMB2_OPLOCK_LEVEL_NONE      = 0x00
	SMB2_OPLOCK_LEVEL_II        = 0x01
	SMB2_OPLOCK_LEVEL_EXCLUSIVE = 0x08
	SMB2_OPLOCK_LEVEL_BATCH     = 0x09
	SMB2_OPLOCK_LEVEL_LEASE     = 0xFF
)

RequestedOplockLevel属性

View Source
const (
	Anonymous      = 0x00000000
	Identification = 0x00000001
	Impersonation  = 0x00000002
	Delegate       = 0x00000003
)

ImpersonationLevel属性

View Source
const (
	FILE_SUPERSEDE           = 0x00000000
	FILE_OPEN                = 0x00000001
	FILE_CREATE              = 0x00000002
	FILE_OPEN_IF             = 0x00000003
	FILE_OVERWRITE           = 0x00000004
	FILE_OVERWRITE_IF        = 0x00000005
	FILE_ACTION_ADDED_STREAM = 0x00000006
)

AccessMask、CreateDisposition属性

View Source
const (
	FILE_SHARE_READ   = 0x00000001
	FILE_SHARE_WRITE  = 0x00000002
	FILE_SHARE_DELETE = 0x00000004
)

ShareAccess属性

View Source
const (
	FILE_DIRECTORY_FILE            = 0x00000001
	FILE_WRITE_THROUGH             = 0x00000002
	FILE_SEQUENTIAL_ONLY           = 0x00000004
	FILE_NO_INTERMEDIATE_BUFFERING = 0x00000008
	FILE_SYNCHRONOUS_IO_ALERT      = 0x00000010
	FILE_SYNCHRONOUS_IO_NONALERT   = 0x00000020
	FILE_NON_DIRECTORY_FILE        = 0x00000040
	FILE_COMPLETE_IF_OPLOCKED      = 0x00000100
	FILE_NO_EA_KNOWLEDGE           = 0x00000200
	FILE_RANDOM_ACCESS             = 0x00000800
	FILE_DELETE_ON_CLOSE           = 0x00001000
	FILE_OPEN_BY_FILE_ID           = 0x00002000
	FILE_OPEN_FOR_BACKUP_INTENT    = 0x00004000
	FILE_NO_COMPRESSION            = 0x00008000
	FILE_OPEN_REMOTE_INSTANCE      = 0x00000400
	FILE_OPEN_REQUIRING_OPLOCK     = 0x00010000
	FILE_DISALLOW_EXCLUSIVE        = 0x00020000
	FILE_RESERVE_OPFILTER          = 0x00100000
	FILE_OPEN_REPARSE_POINT        = 0x00200000
	FILE_OPEN_NO_RECALL            = 0x00400000
	FILE_OPEN_FOR_FREE_SPACE_QUERY = 0x00800000
)

CreateOptionss属性

View Source
const (
	FILE_READ_DATA         = 0x00000001
	FILE_WRITE_DATA        = 0x00000002
	FILE_APPEND_DATA       = 0x00000004
	FILE_READ_EA           = 0x00000008
	FILE_WRITE_EA          = 0x00000010
	FILE_DELETE_CHILD      = 0x00000040
	FILE_EXECUTE           = 0x00000020
	FILE_READ_ATTRIBUTES   = 0x00000080
	FILE_WRITE_ATTRIBUTES  = 0x00000100
	DELETE                 = 0x00010000
	READ_CONTROL           = 0x00020000
	WRITE_DAC              = 0x00040000
	WRITE_OWNER            = 0x00080000
	SYNCHRONIZE            = 0x00100000
	ACCESS_SYSTEM_SECURITY = 0x01000000
	MAXIMUM_ALLOWED        = 0x02000000
	GENERIC_ALL            = 0x10000000
	GENERIC_EXECUTE        = 0x20000000
	GENERIC_WRITE          = 0x40000000
	GENERIC_READ           = 0x80000000
)

https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/77b36d0f-6016-458a-a7a0-0f4a72ae1534 DesiredAccess属性

View Source
const (
	FSCTL_DFS_GET_REFERRALS            = 0x00060194
	FSCTL_PIPE_PEEK                    = 0x0011400C
	FSCTL_PIPE_WAIT                    = 0x00110018
	FSCTL_PIPE_TRANSCEIVE              = 0x0011C017
	FSCTL_SRV_COPYCHUNK                = 0x001440F2
	FSCTL_SRV_ENUMERATE_SNAPSHOTS      = 0x00144064
	FSCTL_SRV_REQUEST_RESUME_KEY       = 0x00140078
	FSCTL_SRV_READ_HASH                = 0x001441bb
	FSCTL_SRV_COPYCHUNK_WRITE          = 0x001480F2
	FSCTL_LMR_REQUEST_RESILIENCY       = 0x001401D4
	FSCTL_QUERY_NETWORK_INTERFACE_INFO = 0x001401FC
	FSCTL_SET_REPARSE_POINT            = 0x000900A4
	FSCTL_DFS_GET_REFERRALS_EX         = 0x000601B0
	FSCTL_FILE_LEVEL_TRIM              = 0x00098208
	FSCTL_VALIDATE_NEGOTIATE_INFO      = 0x00140204
)

Function属性

View Source
const (
	SMB2_0_IOCTL_IS_IOCTL = 0x00000000
	SMB2_0_IOCTL_IS_FSCTL = 0x00000001
)

Flags属性

View Source
const (
	SMB2_CHANNEL_NONE               = 0x00000000
	SMB2_CHANNEL_RDMA_V1            = 0x00000001
	SMB2_CHANNEL_RDMA_V1_INVALIDATE = 0x00000002
	SMB2_CHANNEL_RDMA_TRANSFORM     = 0x00000003
)

Channel属性

Variables

This section is empty.

Functions

func NewNegotiateResponse

func NewNegotiateResponse() smb.SMB2NegotiateResponseStruct

协商版本响应初始化

func NewSMB2Packet

func NewSMB2Packet() smb.SMB2PacketStruct

func NewSessionSetupResponse

func NewSessionSetupResponse() (smb.SMB2SessionSetupResponseStruct, error)

质询响应初始化

Types

type Client

type Client struct {
	common.Client
}

func NewSession

func NewSession(opt common.ClientOptions, debug bool) (client *Client, err error)

SMB2连接封装

func (*Client) Close

func (c *Client) Close()

func (*Client) ConnectAndBindNamedPipes

func (c *Client) ConnectAndBindNamedPipes(pipename string) (stdinpipe, stdoutpipe, stderrpipe []byte, err error)

拿到stdin、out、err句柄

func (*Client) ConnectAndWriteStdInPipes

func (c *Client) ConnectAndWriteStdInPipes(pipename string) (treeid uint32, pipehandle []byte, err error)

连接并绑定命名管道,并拿到管道句柄

func (*Client) CreatePipeRequest

func (c *Client) CreatePipeRequest(treeId uint32, pipename string) (fileId []byte, err error)

打开管道

func (*Client) CreateRequest

func (c *Client) CreateRequest(treeId uint32, filename string, r CreateRequestStruct) (fileId []byte, err error)

func (*Client) NegotiateProtocol

func (c *Client) NegotiateProtocol() (err error)

func (*Client) NewCreateRequest

func (c *Client) NewCreateRequest(treeId uint32, filename string, r CreateRequestStruct) CreateRequestStruct

创建文件请求

func (*Client) NewFSCTLPIPEWAITRequest

func (c *Client) NewFSCTLPIPEWAITRequest(pipename string) FSCTLPIPEWAITRequestStruct

func (*Client) NewIOCTLRequest

func (c *Client) NewIOCTLRequest(treeId uint32) IOCTLRequestStruct

func (*Client) NewNegotiateRequest

func (c *Client) NewNegotiateRequest() smb.SMB2NegotiateRequestStruct

协商版本请求初始化

func (*Client) NewReadRequest

func (c *Client) NewReadRequest(treeId uint32, fileId []byte) ReadRequestStruct

func (*Client) NewSessionSetup2Request

func (c *Client) NewSessionSetup2Request() (smb.SMB2SessionSetup2RequestStruct, error)

认证请求初始化

func (*Client) NewSessionSetupRequest

func (c *Client) NewSessionSetupRequest() (smb.SMB2SessionSetupRequestStruct, error)

质询请求初始化

func (*Client) NewTreeConnectRequest

func (c *Client) NewTreeConnectRequest(name string) (TreeConnectRequestStruct, error)

func (*Client) NewTreeDisconnectRequest

func (c *Client) NewTreeDisconnectRequest(treeId uint32) (TreeDisconnectRequestStruct, error)

func (*Client) NewWriteRequest

func (c *Client) NewWriteRequest(treeId uint32, fileId []byte, buf interface{}) WriteRequestStruct

写入请求

func (*Client) ReadRequest

func (c *Client) ReadRequest(treeId uint32, fileId []byte) (info []byte, err error)

func (*Client) TreeConnect

func (c *Client) TreeConnect(name string) (treeId uint32, err error)

树连接

func (*Client) TreeDisconnect

func (c *Client) TreeDisconnect(name string) error

断开树连接

func (*Client) WritePipeRequest

func (c *Client) WritePipeRequest(treeId uint32, buffer, fileId []byte) error

写入管道数据

func (*Client) WriteRequest

func (c *Client) WriteRequest(treeId uint32, filepath, filename string, fileId []byte) (err error)

需要传入树id

type CreateRequestStruct

type CreateRequestStruct struct {
	smb.SMB2PacketStruct
	StructureSize        uint16
	SecurityFlags        uint8  //1字节,保留字段,不得使用
	OpLock               uint8  //1字节,对应文档RequestedOplockLevel字段
	ImpersonationLevel   uint32 //4字节,模拟等级
	CreateFlags          []byte `smb:"fixed:8"` //8字节,保留字段,不得使用
	Reserved             []byte `smb:"fixed:8"`
	AccessMask           uint32 //4字节,访问权限
	FileAttributes       uint32 //4字节,文件属性
	ShareAccess          uint32 //4字节,共享模式
	CreateDisposition    uint32
	CreateOptions        uint32
	FilenameBufferOffset uint16 `smb:"offset:Filename"`
	FilenameBufferLength uint16 `smb:"len:Filename"`
	CreateContextsOffset uint32
	CreateContextsLength uint32
	Filename             []byte `smb:"unicode"`
}

https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/e8fb45c1-a03d-44ca-b7ae-47385cfd7997 创建请求结构

type CreateResponseStruct

type CreateResponseStruct struct {
	smb.SMB2PacketStruct
	StructureSize        uint16
	Oplock               uint8 //1字节,对应文档RequestedOplockLevel字段
	ResponseFlags        uint8
	CreateAction         uint32
	CreationTime         []byte `smb:"fixed:8"` //8字节,创建时间
	LastAccessTime       []byte `smb:"fixed:8"` //8字节
	LastWriteTime        []byte `smb:"fixed:8"` //8字节
	LastChangeTime       []byte `smb:"fixed:8"` //8字节
	AllocationSize       []byte `smb:"fixed:8"` //8字节,文件大小
	EndofFile            []byte `smb:"fixed:8"` //8字节
	FileAttributes       uint32
	Reserved2            uint32 `smb:"fixed:4"`
	FileId               []byte `smb:"fixed:16"` //16字节,文件句柄
	CreateContextsOffset uint32
	CreateContextsLength uint32
}

https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/d166aa9e-0b53-410e-b35e-3933d8131927 创建请求响应结构

func NewCreateResponse

func NewCreateResponse() CreateResponseStruct

创建请求响应

type FSCTLPIPEWAITRequestStruct

type FSCTLPIPEWAITRequestStruct struct {
	Timeout          uint64 // 毫秒单位
	NameLength       uint32
	TimeoutSpecified uint8 // 一个布尔值,指定是否忽略Timeout参数
	Padding          uint8
	Name             []byte // 命名管道名称的Unicode字符串,名称不得包含“\pipe\”
}

https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/f030a3b9-539c-4c7b-a893-86b795b9b711 请求服务器等待连接

type IOCTLRequestStruct

type IOCTLRequestStruct struct {
	smb.SMB2PacketStruct
	StructureSize     uint16
	Reserved          uint16
	Function          uint32
	GUIDHandle        []byte `smb:"fixed:16"`
	InputOffset       uint32 `smb:"offset:Buffer"`
	InputCount        uint32 `smb:"len:Buffer"`
	MaxInputResponse  uint32
	OutputOffset      uint32
	OutputCount       uint32
	MaxOutputResponse uint32
	Flags             uint32
	Reserved2         uint32
	Buffer            interface{}
}

https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/5c03c9d6-15de-48a2-9835-8fb37f8a79d8

type IOCTLResponseStruct

type IOCTLResponseStruct struct {
	smb.SMB2PacketStruct
	StructureSize uint16
	Reserved      uint16
	Function      uint32
	GUIDHandle    []byte `smb:"fixed:16"`
	BlobOffset    uint32
	BlobLength    uint32
	BlobOffset2   uint32
	BlobLength2   uint32
	Flags         uint32
	Reserved2     uint32
}

https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/f70eccb6-e1be-4db8-9c47-9ac86ef18dbb

func NewIOCTLResponse

func NewIOCTLResponse() IOCTLResponseStruct

type ReadRequestStruct

type ReadRequestStruct struct {
	smb.SMB2PacketStruct
	StructureSize  uint16 //2字节,必须设置49/0x0031
	Padding        uint8
	Flags          uint8
	ReadLength     uint32
	FileOffset     []byte `smb:"fixed:8"`  //8字节
	FileId         []byte `smb:"fixed:16"` //8字节
	MinCount       uint32
	Channel        uint32
	RemainingBytes uint32
	BlobOffset     uint16
	BlobLength     uint16 `smb:"len:Buffer"`
	Buffer         []byte
	Reserved       uint8
}

https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/320f04f3-1b28-45cd-aaa1-9e5aed810dca

type ReadResponseStruct

type ReadResponseStruct struct {
	smb.SMB2PacketStruct
	StructureSize uint16
	DataOffset    uint32 `smb:"fixed:4"`
	Reserved      uint32 `smb:"fixed:4"`
	BlobOffset    uint8
	Reserved2     uint8
	BlobLength    uint32
}

https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/3e3d2f2c-0e2f-41ea-ad07-fbca6ffdfd90

type ReadResponseStruct2

type ReadResponseStruct2 struct {
	smb.SMB2PacketStruct
	StructureSize uint16
	BlobOffset    uint8
	Reserved      uint8
	BlobLength    uint32
	ReadRemaining uint32
	Reserved2     uint32
	Info          []byte `smb:"count:BlobLength"` //写入的数据
}

func NewReadResponse

func NewReadResponse() ReadResponseStruct2

type TreeConnectRequestStruct

type TreeConnectRequestStruct struct {
	smb.SMB2PacketStruct
	StructureSize uint16
	Reserved      uint16 //2字节,smb3.x使用,其他忽略
	PathOffset    uint16 `smb:"offset:Path"`
	PathLength    uint16 `smb:"len:Path"`
	Path          []byte
}

https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/832d2130-22e8-4afb-aafd-b30bb0901798 树连接请求结构

type TreeConnectResponseStruct

type TreeConnectResponseStruct struct {
	smb.SMB2PacketStruct
	StructureSize uint16
	ShareType     uint8 //1字节,访问共享类型
	Reserved      uint8 //1字节
	ShareFlags    uint32
	Capabilities  uint32
	MaximalAccess uint32
}

https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/dd34e26c-a75e-47fa-aab2-6efc27502e96 树连接响应结构

func NewTreeConnectResponse

func NewTreeConnectResponse() TreeConnectResponseStruct

type TreeDisconnectRequestStruct

type TreeDisconnectRequestStruct struct {
	smb.SMB2PacketStruct
	StructureSize uint16 //2字节,客户端必须设为4,表示请求大小
	Reserved      uint16
}

https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/8a622ecb-ffee-41b9-b4c4-83ff2d3aba1b 断开树连接请求结构

type TreeDisconnectResponseStruct

type TreeDisconnectResponseStruct struct {
	smb.SMB2PacketStruct
	StructureSize uint16
	Reserved      uint16
}

https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/aeac92de-8db3-48f8-a8b7-bfee28b9fd9e 断开树连接响应结构

func NewTreeDisconnectResponse

func NewTreeDisconnectResponse() TreeDisconnectResponseStruct

type WriteRequestStruct

type WriteRequestStruct struct {
	smb.SMB2PacketStruct
	StructureSize          uint16
	DataOffset             uint16 `smb:"offset:Buffer"`
	WriteLength            uint32 `smb:"len:Buffer"`
	FileOffset             uint64
	FileId                 []byte `smb:"fixed:16"` //16字节,服务端返回句柄
	Channel                uint32
	RemainingBytes         uint32
	WriteChannelInfoOffset uint16
	WriteChannelInfoLength uint16
	WriteFlags             uint32
	Buffer                 interface{} //写入的数据
}

https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/e7046961-3318-4350-be2a-a8d69bb59ce8

type WriteResponseStruct

type WriteResponseStruct struct {
	smb.SMB2PacketStruct
	StructureSize          uint16
	Reserved               uint16
	WriteCount             uint32
	WriteRemaining         uint32
	WriteChannelInfoOffset uint16
	WriteChannelInfoLength uint16
}

https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/7b80a339-f4d3-4575-8ce2-70a06f24f133

func NewWriteResponse

func NewWriteResponse() WriteResponseStruct

写入请求响应

Jump to

Keyboard shortcuts

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