smb

package
v0.0.0-...-f4b48e8 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2018 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CommandNegotiate uint16 = iota
	CommandSessionSetup
	CommandLogoff
	CommandTreeConnect
	CommandTreeDisconnect
	CommandCreate
	CommandClose
	CommandFlush
	CommandRead
	CommandWrite
	CommandLock
	CommandIOCtl
	CommandCancel
	CommandEcho
	CommandQueryDirectory
	CommandChangeNotify
	CommandQueryInfo
	CommandSetInfo
	CommandOplockBreak
)
View Source
const (
	SecurityModeSigningEnabled uint16
	SecurityModeSigningRequired
)
View Source
const (
	ShareTypeDisk byte
	ShareTypePipe
	ShareTypePrint
)
View Source
const (
	ShareFlagManualCaching            uint32 = 0x00000000
	ShareFlagAutoCaching              uint32 = 0x00000010
	ShareFlagVDOCaching               uint32 = 0x00000020
	ShareFlagNoCaching                uint32 = 0x00000030
	ShareFlagDFS                      uint32 = 0x00000001
	ShareFlagDFSRoot                  uint32 = 0x00000002
	ShareFlagRestriceExclusiveOpens   uint32 = 0x00000100
	ShareFlagForceSharedDelete        uint32 = 0x00000200
	ShareFlagAllowNamespaceCaching    uint32 = 0x00000400
	ShareFlagAccessBasedDirectoryEnum uint32 = 0x00000800
	ShareFlagForceLevelIIOplock       uint32 = 0x00001000
	ShareFlagEnableHashV1             uint32 = 0x00002000
	ShareFlagEnableHashV2             uint32 = 0x00004000
	ShareFlagEncryptData              uint32 = 0x00008000
)
View Source
const (
	ShareCapDFS                    uint32 = 0x00000008
	ShareCapContinuousAvailability uint32 = 0x00000010
	ShareCapScaleout               uint32 = 0x00000020
	ShareCapCluster                uint32 = 0x00000040
	ShareCapAsymmetric             uint32 = 0x00000080
)
View Source
const (
	Smb2OplockLevelNone      uint8 = 0x00
	Smb2OplockLevelII        uint8 = 0x01
	Smb2OplockLevelExclusive uint8 = 0x08
	Smb2OplockLevelBatch     uint8 = 0x09
	Smb2OplockLevelLease     uint8 = 0xFF
)

RequestedOplockLevel

View Source
const (
	Anonymous uint32 = iota
	Identification
	Impersonation
	Delegate
)

ImpersonationLeve

View Source
const (
	FileReadData         uint32 = 0x00000001
	FileWriteData        uint32 = 0x00000002
	FileAppendData       uint32 = 0x00000004
	FileReadEa           uint32 = 0x00000008
	FileWriteEa          uint32 = 0x00000010
	FileDeleteChild      uint32 = 0x00000040
	FileExecute          uint32 = 0x00000020
	FileReadAttributes   uint32 = 0x00000080
	FileWriteAttributes  uint32 = 0x00000100
	Delete               uint32 = 0x00010000
	ReadControl          uint32 = 0x00020000
	WriteDac             uint32 = 0x00040000
	WriteOwner           uint32 = 0x00080000
	Synchronize          uint32 = 0x00100000
	AccessSystemSecurity uint32 = 0x01000000
	MaxinumAllowed       uint32 = 0x02000000
	GenericAll           uint32 = 0x10000000
	GenericExecute       uint32 = 0x20000000
	GenericWrite         uint32 = 0x40000000
	GenericRead          uint32 = 0x80000000
)

DesiredAccess

View Source
const (
	FileAttributeArchive           uint32 = 0x00000020
	FileAttributeCompressed        uint32 = 0x00000800
	FileAttributeDirectory         uint32 = 0x00000010
	FileAttributeEncrypted         uint32 = 0x00004000
	FileAttributeHidden            uint32 = 0x00000002
	FileAttributeNormal            uint32 = 0x00000080
	FileAttributeNotContentIndexed uint32 = 0x00002000
	FileAttributeOffline           uint32 = 0x00001000
	FileAttributeReadonly          uint32 = 0x00000001
	FileAttributeReparsePoint      uint32 = 0x00000400
	FileAttributeSparseFile        uint32 = 0x00000200
	FileAttributeSystem            uint32 = 0x00000004
	FileAttributeTemporary         uint32 = 0x00000100
	FileAttributeIntegrityStream   uint32 = 0x00008000
	FileAttributeNoScrubData       uint32 = 0x00020000
)

FileAttributes

View Source
const (
	FileShareRead   uint32 = 0x00000001
	FileShareWrite  uint32 = 0x00000002
	FileShareDelete uint32 = 0x00000003
)

ShareAccess

View Source
const (
	FileSupersede uint32 = iota
	FileOpen
	FileCreate
	FileOpenIf
	FileOverwrite
	FileOverwriteIf
)

CreateDisposition

View Source
const (
	FileDirectoryFile           uint32 = 0x00000001
	FileWriteThrough            uint32 = 0x00000002
	FileSequentialOnly          uint32 = 0x00000004
	FileNoIntermediateBuffering uint32 = 0x00000008
	FileSynchronousIoAlert      uint32 = 0x00000010
	FileSynchronousIoNonalert   uint32 = 0x00000020
	FileNonDirectoryFile        uint32 = 0x00000040
	FileCompleteIfOplocked      uint32 = 0x00000100
	FileNoEaKnowledge           uint32 = 0x00000200
	FileRandomAccess            uint32 = 0x00000800
	FileDeleteOnClose           uint32 = 0x00001000
	FileOpenByFileId            uint32 = 0x00002000
	FileOpenForBackupIntent     uint32 = 0x00004000
	FileNoCompression           uint32 = 0x00008000
	FileOpenRemoteInstance      uint32 = 0x00000400
	FileOpenRequireingOplock    uint32 = 0x00010000
	FileDisallowExclusive       uint32 = 0x00020000
	FileReserveOpfilter         uint32 = 0x00100000
	FileOpenReparsePoint        uint32 = 0x00200000
	FileOpenNoRecall            uint32 = 0x00400000
	FileOpenForFreeSpaceQuery   uint32 = 0x00800000
)

CreateOptions

View Source
const (
	Smb2ChannelNone uint32 = iota
	Smb2ChannelRdmaV1
	Smb2ChannelRdmaV1Invalidate
)

Channel

View Source
const DialectSmb2_ALL = 0x02FF
View Source
const DialectSmb_2_0_2 = 0x0202
View Source
const DialectSmb_2_1 = 0x0210
View Source
const DialectSmb_3_0 = 0x0300
View Source
const DialectSmb_3_0_2 = 0x0302
View Source
const DialectSmb_3_1_1 = 0x0311
View Source
const ProtocolSmb = "\xFFSMB"
View Source
const ProtocolSmb2 = "\xFESMB"
View Source
const StatusInvalidParameter = 0xc000000d
View Source
const StatusLogonFailure = 0xc000006d
View Source
const StatusMoreProcessingRequired = 0xc0000016
View Source
const StatusOk = 0x00000000
View Source
const StatusUserSessionDeleted = 0xc0000203

Variables

View Source
var CommandStr = map[uint16]string{
	CommandNegotiate:      "Negotiate",
	CommandSessionSetup:   "SessionSetup",
	CommandLogoff:         "Logoff",
	CommandTreeConnect:    "TreeConnect",
	CommandTreeDisconnect: "TreeDisconnect",
	CommandCreate:         "Create",
	CommandClose:          "Close",
	CommandFlush:          "Flush",
	CommandRead:           "Read",
	CommandWrite:          "Write",
	CommandLock:           "Lock",
	CommandIOCtl:          "IOCtl",
	CommandCancel:         "Cancel",
	CommandEcho:           "Echo",
	CommandQueryDirectory: "QueryDirectory",
	CommandChangeNotify:   "ChangeNotify",
	CommandQueryInfo:      "QueryInfo",
	CommandSetInfo:        "SetInfo",
	CommandOplockBreak:    "OplockBreak",
}
View Source
var StatusMap = map[uint32]string{
	StatusOk:                     "OK",
	StatusMoreProcessingRequired: "More Processing Required",
	StatusInvalidParameter:       "Invalid Parameter",
	StatusLogonFailure:           "Logon failed",
	StatusUserSessionDeleted:     "User session deleted",
}

Functions

This section is empty.

Types

type CancelReq

type CancelReq struct {
	Header
	StructureSize uint16
	Reserved      uint16
}

cancel request

type ChangeNotifyReq

type ChangeNotifyReq struct {
	Header
	StructureSize      uint16
	Flags              uint16
	OutputBufferLength uint32
	FileID
	CompletionFilter uint32
	Reserved         uint32
}

change notify request&response

type ChangeNotifyRes

type ChangeNotifyRes struct {
	Header
	StructureSize      uint16
	OutputBufferOffset uint16
	OutputBufferLength uint32
	Buffer             []byte
}

type CloseReq

type CloseReq struct {
	Header
	StructureSize uint16
	Flags         uint16
	Reserved      uint32
	FileID        `smb:"fixed:16"`
}

close file request&response

type CloseRes

type CloseRes struct {
	Header
	StructureSize  uint16
	Flags          uint16
	Reserved       uint32
	CreationTime   uint64
	LastAccessTime uint64
	LastWriteTime  uint64
	ChangeTime     uint64
	AllocationSize uint64
	EndofFile      uint64
	FileAttributes uint32
}

type CreateReq

type CreateReq struct {
	Header
	StructureSize        uint16
	SecurityFlags        uint8
	RequestedOplockLevel uint8
	ImpersonationLevel   uint32
	SmbCreateFlags       uint64
	Reserved             uint64
	DesiredAccess        uint32
	FileAttributes       uint32
	ShareAccess          uint32
	CreateDisposition    uint32
	CreateOptions        uint32
	NameOffset           uint16
	NameLength           uint16
	CreateContextsOffset uint32
	CreateContextsLength uint32
	Buffer               []byte
}

create file request&response

type CreateRes

type CreateRes struct {
	Header
	StructureSize        uint16
	OplockLevel          uint8
	Flags                uint8
	CreateAction         uint32
	CreationTime         uint64
	LastAccessTime       uint64
	LastWriteTime        uint64
	ChangeTime           uint64
	AllocationSize       uint64
	EndofFile            uint64
	FileAttributes       uint32
	Reserved2            uint32
	FileID               `smb:"fixed:16"`
	CreateContextsOffset uint32 `smb:"offset:Contexts"`
	CreateContextsLength uint32 `smb:"len:Contexts"`
	Contexts             []byte
}

type EchoReq

type EchoReq struct {
	Header
	StructureSize uint16
	Reserved      uint16
}

echo request&response

type EchoRes

type EchoRes struct {
	Header
	StructureSize uint16
	Reserved      uint16
}

type FileID

type FileID struct {
	Persistent []byte `smb:"fixed:8"`
	Volatile   []byte `smb:"fixed:8"`
}

type FlushReq

type FlushReq struct {
	Header
	StructureSize uint16
	Reserved1     uint16
	Reserved2     uint32
	FileID
}

flush file request&response

type FlushRes

type FlushRes struct {
	Header
	StructureSize uint16
	Reserved      uint16
}
type Header struct {
	ProtocolID    []byte `smb:"fixed:4"`
	StructureSize uint16
	CreditCharge  uint16
	Status        uint32
	Command       uint16
	Credits       uint16
	Flags         uint32
	NextCommand   uint32
	MessageID     uint64
	Reserved      uint32
	TreeID        uint32
	SessionID     uint64
	Signature     []byte `smb:"fixed:16"`
}

type IoctlReq

type IoctlReq struct {
	Header
	StructureSize uint16
	Reserved      uint16
	CtlCode       uint32
	FileID
	InputOffset       uint32
	InputCount        uint32
	MaxInputResponse  uint32
	OutputOffset      uint32
	OutputCount       uint32
	MaxOutputResponse uint32
	Flags             uint32
	Reserved2         uint32
	Buffer            []byte
}

ioctl request&response

type IoctlRes

type IoctlRes struct {
	Header
	StructureSize uint16
	Reserved      uint16
	CtlCode       uint32
	FileID
	InputOffset  uint32
	InputCount   uint32
	OutputOffset uint32
	OutputCount  uint32
	Flags        uint32
	Reserved2    uint32
	Buffer       []byte
}

type LeaseBreakAck

type LeaseBreakAck struct {
	Header
	StructureSize uint16
	Reserved      uint16
	Flags         uint32
	LeaseKey      []byte `smb:"fixed:16"`
	LeaseState    uint32
	LeaseDuration uint64
}

type LeaseBreakNotification

type LeaseBreakNotification struct {
	Header
	StructureSize     uint16
	NewEpoch          uint16
	Flags             uint32
	LeaseKey          []byte `smb:"fixed:16"`
	CurrentLeaseState uint32
}

type LeaseBreakRes

type LeaseBreakRes struct {
	Header
	StructureSize uint16
	Reserved      uint16
	Flags         uint32
	LeaseKey      []byte `smb:"fixed:16"`
	LeaseState    uint32
	LeaseDuration uint64
}

type LockElement

type LockElement struct {
	Offset   uint64
	Length   uint64
	Flags    uint32
	Reserved uint32
}

type LockReq

type LockReq struct {
	Header
	StructureSize uint16
	LockCount     uint16 `smb:"count:Locks"`
	LockSequence  uint32 `LSN: 4bit; LockSequenceIndex: 28bit`
	FileID
	Locks []LockElement
}

lock request&response

type LockRes

type LockRes struct {
	Header
	StructureSize uint16
	Reserved      uint16
}

type LogoffReq

type LogoffReq struct {
	Header
	StructureSize uint16
	Reserved      uint16
}

logoff request&response

type LogoffRes

type LogoffRes struct {
	Header
	StructureSize uint16
	Reserved      uint16
}

type NegotiateContext

type NegotiateContext struct {
	ContentType uint16
	DataLen     uint16 `smb:"len:Data"`
	Reserved    uint32
	Data        []byte
}

type NegotiateReq

type NegotiateReq struct {
	Header
	StructureSize   uint16
	DialectCount    uint16 `smb:"count:Dialects"`
	SecurityMode    uint16
	Reserved        uint16
	Capabilities    uint32
	ClientGuid      []byte `smb:"fixed:16"`
	ClientStartTime uint64
	Dialects        []uint16
}

type NegotiateReqExt

type NegotiateReqExt struct {
	Header
	StructureSize          uint16
	DialectCount           uint16 `smb:"count:Dialects"`
	SecurityMode           uint16
	Reserved               uint16
	Capabilities           uint32
	ClientGuid             []byte `smb:"fixed:16"`
	NegotiateContextOffset uint16 `smb:"offset:NegotiateContextList"`
	NegotiateContextCount  uint8  `smb:"count:NegotiateContextList"`
	Reserved2              uint8
	Dialects               []uint16
	//used for 8 byte aligned
	Padding              []byte
	NegotiateContextList []NegotiateContext
}

if dialects contain 0x0311, use it

type NegotiateRes

type NegotiateRes struct {
	Header
	StructureSize        uint16
	SecurityMode         uint16
	DialectRevision      uint16
	Reserved             uint16
	ServerGuid           []byte `smb:"fixed:16"`
	Capabilities         uint32
	MaxTransactSize      uint32
	MaxReadSize          uint32
	MaxWriteSize         uint32
	SystemTime           uint64
	ServerStartTime      uint64
	SecurityBufferOffset uint16 `smb:"offset:SecurityBlob"`
	SecurityBufferLength uint16 `smb:"len:SecurityBlob"`
	Reserved2            uint32
	SecurityBlob         *gss.NegTokenInit
}

func NewNegotiateRes

func NewNegotiateRes() NegotiateRes

type OplockBreakAck

type OplockBreakAck struct {
	Header
	StructureSize uint16
	OplockLevel   uint8
	Reserved      uint8
	Reserved2     uint32
	FileID
}

oplock break ack by client

type OplockBreakNotification

type OplockBreakNotification struct {
	Header
	StructureSize uint16
	OplockLevel   uint8
	Reserved      uint8
	Reserved2     uint32
	FileID
}

oplock break notify by server

type OplockBreakRes

type OplockBreakRes struct {
	Header
	StructureSize uint16
	OplockLevel   uint8
	Reserved      uint8
	Reserved2     uint32
	FileID
}

oplock break res by server

type Options

type Options struct {
	Host        string
	Port        int
	Workstation string
	Domain      string
	User        string
	Password    string
	Hash        string
}

type QueryDirectoryReq

type QueryDirectoryReq struct {
	Header
	StructureSize        uint16
	FileInformationClass uint8
	Flags                uint8
	FileIndex            uint32
	FileID
	FileNameOffset     uint16
	FileNameLength     uint16
	OutputBufferLength uint32
	Pattern            []byte
}

query directory request&response

type QueryDirectoryRes

type QueryDirectoryRes struct {
	Header
	StructureSize      uint16
	OutputBufferOffset uint16
	OutputBufferLength uint32
	Buffer             []byte
}

type QueryInfoReq

type QueryInfoReq struct {
	Header
	StructureSize         uint16
	InfoType              uint8
	FileInfoClass         uint8
	OutputBufferLength    uint32
	InputBufferOffset     uint16
	Reserved              uint16
	InputBufferLength     uint32
	AdditionalInformation uint32
	Flags                 uint32
	FileID
	InputBuffer []byte
}

query info request&response

type QueryInfoRes

type QueryInfoRes struct {
	Header
	StructureSize      uint16
	OutputBufferOffset uint16
	OutputBufferLength uint32
	Buffer             []byte
}

type ReadReq

type ReadReq struct {
	Header
	StructureSize         uint16
	Padding               uint8
	Flags                 uint8
	Length                uint32
	Offset                uint64
	FileID                `smb:"fixed:16"`
	MinimumCount          uint32
	Channel               uint32
	RemainingBytes        uint32
	ReadChannelInfoOffset uint16 `smb:"offset:ChannelInfo"`
	ReadChannelInfoLength uint16 `smb:"len:ChannelInfo"`
	ChannelInfo           []byte
}

read file request&response

type ReadRes

type ReadRes struct {
	Header
	StructureSize uint16
	DataOffset    uint8 `smb:"offset:Data"`
	Reserved      uint8
	DataLength    uint32 `smb:"len:Data"`
	DataRemaining uint32
	Reserved2     uint32
	Data          []byte
}

type Session

type Session struct {
	IsSigningRequired bool
	IsAuthenticated   bool

	FileId FileID
	// contains filtered or unexported fields
}

func NewSession

func NewSession(opt Options, debug bool) (s *Session, err error)

func (*Session) Close

func (s *Session) Close()

func (*Session) CloseFile

func (s *Session) CloseFile(tree string) error

func (*Session) Debug

func (s *Session) Debug(msg string, err error)

func (*Session) Logoff

func (s *Session) Logoff() error

func (*Session) NegotiateProtocol

func (s *Session) NegotiateProtocol() error

func (*Session) NewCloseReq

func (s *Session) NewCloseReq(tree string) (CloseReq, error)

func (*Session) NewCreateReq

func (s *Session) NewCreateReq(tree string, name string) (CreateReq, error)

open a new file or directory using create

func (*Session) NewLogoffReq

func (s *Session) NewLogoffReq() (LogoffReq, error)

func (*Session) NewNegotiateReq

func (s *Session) NewNegotiateReq() NegotiateReq

func (*Session) NewReadReq

func (s *Session) NewReadReq(tree string) (ReadReq, error)

func (*Session) NewSessionSetup1Req

func (s *Session) NewSessionSetup1Req() (SessionSetup1Req, error)

func (*Session) NewSessionSetup2Req

func (s *Session) NewSessionSetup2Req() (SessionSetup2Req, error)

func (*Session) NewTreeConnectReq

func (s *Session) NewTreeConnectReq(name string) (TreeConnectReq, error)

NewTreeConnectReq creates a new TreeConnect message and accepts the share name as input.

func (*Session) NewTreeDisconnectReq

func (s *Session) NewTreeDisconnectReq(treeId uint32) (TreeDisconnectReq, error)

func (*Session) OpenFile

func (s *Session) OpenFile(tree, name string) error

func (*Session) ReadFile

func (s *Session) ReadFile(tree string) error

func (*Session) TreeConnect

func (s *Session) TreeConnect(name string) error

func (*Session) TreeDisconnect

func (s *Session) TreeDisconnect(name string) error

type SessionSetup1Req

type SessionSetup1Req struct {
	Header
	StructureSize        uint16
	Flags                byte
	SecurityMode         byte
	Capabilities         uint32
	Channel              uint32
	SecurityBufferOffset uint16 `smb:"offset:SecurityBlob"`
	SecurityBufferLength uint16 `smb:"len:SecurityBlob"`
	PreviousSessionID    uint64
	SecurityBlob         *gss.NegTokenInit
}

type SessionSetup1Res

type SessionSetup1Res struct {
	Header
	StructureSize        uint16
	Flags                uint16
	SecurityBufferOffset uint16 `smb:"offset:SecurityBlob"`
	SecurityBufferLength uint16 `smb:"len:SecurityBlob"`
	SecurityBlob         *gss.NegTokenResp
}

func NewSessionSetup1Res

func NewSessionSetup1Res() (SessionSetup1Res, error)

type SessionSetup2Req

type SessionSetup2Req struct {
	Header
	StructureSize        uint16
	Flags                byte
	SecurityMode         byte
	Capabilities         uint32
	Channel              uint32
	SecurityBufferOffset uint16 `smb:"offset:SecurityBlob"`
	SecurityBufferLength uint16 `smb:"len:SecurityBlob"`
	PreviousSessionID    uint64
	SecurityBlob         *gss.NegTokenResp
}

type SessionSetup2Res

type SessionSetup2Res struct {
	Header
	StructureSize        uint16
	Flags                uint16
	SecurityBufferOffset uint16 `smb:"offset:SecurityBlob"`
	SecurityBufferLength uint16 `smb:"len:SecurityBlob"`
	SecurityBlob         *gss.NegTokenResp
}

func NewSessionSetup2Res

func NewSessionSetup2Res() (SessionSetup2Res, error)

type SetInfoReq

type SetInfoReq struct {
	Header
	StructureSize         uint16
	InfoType              uint8
	FileInfoClass         uint8
	BufferLength          uint32
	BufferOffset          uint16
	Reserved              uint16
	AdditionalInformation uint32
	FileID
	Buffer []byte
}

set info request&response

type SetInfoRes

type SetInfoRes struct {
	Header
	StructureSize uint16
}

type TreeConnectReq

type TreeConnectReq struct {
	Header
	StructureSize uint16
	Reserved      uint16
	PathOffset    uint16 `smb:"offset:Path"`
	PathLength    uint16 `smb:"len:Path"`
	Path          []byte
}

type TreeConnectRes

type TreeConnectRes struct {
	Header
	StructureSize uint16
	ShareType     byte
	Reserved      byte
	ShareFlags    uint32
	Capabilities  uint32
	MaximalAccess uint32
}

type TreeDisconnectReq

type TreeDisconnectReq struct {
	Header
	StructureSize uint16
	Reserved      uint16
}

type TreeDisconnectRes

type TreeDisconnectRes struct {
	Header
	StructureSize uint16
	Reserved      uint16
}

type WriteReq

type WriteReq struct {
	Header
	StructureSize uint16
	DataOffset    uint16
	Length        uint32
	Offset        uint64
	FileID
	Channel                uint32
	RemainingBytes         uint32
	WriteChannelInfoOffset uint16
	WriteChannelInfoLength uint16
	Flags                  uint32
	ChannelInfo            []byte
}

write file request&response

type WriteRes

type WriteRes struct {
	Header
	StructureSize          uint16
	Reserved               uint16
	Count                  uint32
	Remaining              uint32
	WriteChannelInfoOffset uint16
	WriteChannelInfoLength uint16
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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