smb

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2024 License: MIT Imports: 27 Imported by: 4

Documentation

Overview

Copyright (c) 2016 Hiroshi Ioka. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright

notice, this list of conditions and the following disclaimer.

  • Redistributions in binary form must reproduce the above

copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Copyright (c) 2016 Hiroshi Ioka. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright

notice, this list of conditions and the following disclaimer.

  • Redistributions in binary form must reproduce the above

copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

MIT License

Copyright (c) 2017 stacktitan Copyright (c) 2023 Jimmy Fjällid for extensions beyond login for SMB 2.1

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

MIT License

Copyright (c) 2017 stacktitan Copyright (c) 2023 Jimmy Fjällid for extensions beyond login for SMB 2.1

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Copyright (c) 2016 Hiroshi Ioka. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright

notice, this list of conditions and the following disclaimer.

  • Redistributions in binary form must reproduce the above

copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Index

Constants

View Source
const (
	StatusOk                     = 0x00000000
	StatusPending                = 0x00000103
	StatusBufferOverflow         = 0x80000005
	StatusNoMoreFiles            = 0x80000006
	StatusInfoLengthMismatch     = 0xc0000004
	StatusInvalidParameter       = 0xc000000d
	StatusNoSuchFile             = 0xc000000f
	StatusEndOfFile              = 0xc0000011
	StatusMoreProcessingRequired = 0xc0000016
	StatusAccessDenied           = 0xc0000022
	StatusObjectNameInvalid      = 0xc0000033
	StatusObjectNameNotFound     = 0xc0000034
	StatusObjectNameCollision    = 0xc0000035
	StatusObjectPathNotFound     = 0xc000003A
	StatusLogonFailure           = 0xc000006d
	StatusAccountRestriction     = 0xc000006e
	StatusPasswordExpired        = 0xc0000071
	StatusAccountDisabled        = 0xc0000072
	StatusBadNetworkName         = 0xc00000cc
	StatusUserSessionDeleted     = 0xc0000203
	StatusPasswordMustChange     = 0xc0000224
	StatusAccountLockedOut       = 0xc0000234
)
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 (
	SMB2_FLAGS_SERVER_TO_REDIR    uint32 = 0x00000001
	SMB2_FLAGS_ASYNC_COMMAND      uint32 = 0x00000002
	SMB2_FLAGS_RELATED_OPERATIONS uint32 = 0x00000004
	SMB2_FLAGS_SIGNED             uint32 = 0x00000008
	SMB2_FLAGS_PRIORITY_MASK      uint32 = 0x00000070
	SMB2_FLAGS_DFS_OPERATIONS     uint32 = 0x10000000
	SMB2_FLAGS_REPLAY_OPERATIONS  uint32 = 0x20000000
)

MS-SMB2 2.2.1.1 Flags

View Source
const (
	SecurityModeSigningDisabled uint16 = iota
	SecurityModeSigningEnabled
	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 (
	GlobalCapDFS               uint32 = 0x00000001
	GlobalCapLeasing           uint32 = 0x00000002
	GlobalCapLargeMTU          uint32 = 0x00000004
	GlobalCapMultiChannel      uint32 = 0x00000008
	GlobalCapPersistentHandles uint32 = 0x00000010
	GlobalCapDirectoryLeasing  uint32 = 0x00000020
	GlobalCapEncryption        uint32 = 0x00000040
)
View Source
const (
	OpLockLevelNone      byte = 0x00
	OpLockLevelII        byte = 0x01
	OpLockLevelExclusive byte = 0x08
	OpLockLevelBatch     byte = 0x09
	OpLockLevelLease     byte = 0xff
)
View Source
const (
	ImpersonationLevelAnonymous      uint32 = 0x00000000
	ImpersonationLevelIdentification uint32 = 0x00000001
	ImpersonationLevelImpersonation  uint32 = 0x00000002
	ImpersonationLevelDelegate       uint32 = 0x00000003
)
View Source
const (
	PreauthIntegrityCapabilities uint16 = 0x0001
	EncryptionCapabilities       uint16 = 0x0002
	CompressionCapabilities      uint16 = 0x0003
	NetNameNegotiateContextId    uint16 = 0x0005
	TransportCapabilities        uint16 = 0x0006
	RDMATranformCapabilities     uint16 = 0x0007
	SigningCapabilities          uint16 = 0x0008
)

MS-SMB2 Section 2.2.3.1 Context Type

View Source
const (
	AES128CCM uint16 = 0x0001
	AES128GCM uint16 = 0x0002
	AES256CCM uint16 = 0x0003
	AES256GCM uint16 = 0x0004
)

MS-SMB2 Section 2.2.3.1.2 Ciphers

View Source
const (
	HMAC_SHA256 uint16 = 0x0000
	AES_CMAC    uint16 = 0x0001
	AES_GMAC    uint16 = 0x0002
)

MS-SMB2 Section 2.2.3.1.7 SigningAlgorithms

View Source
const (
	SessionFlagIsGuest     uint16 = 0x0001
	SessionFlagIsNull      uint16 = 0x0002
	SessionFlagEncryptData uint16 = 0x0004
)

MS-SMB2 Section 2.2.6 Session setup flags

View Source
const (
	FAccMaskFileReadData         uint32 = 0x00000001
	FAccMaskFileWriteData        uint32 = 0x00000002
	FAccMaskFileAppendData       uint32 = 0x00000004
	FAccMaskFileReadEA           uint32 = 0x00000008
	FAccMaskFileWriteEA          uint32 = 0x00000010
	FAccMaskFileDeleteChild      uint32 = 0x00000040
	FAccMaskFileExecute          uint32 = 0x00000020
	FAccMaskFileReadAttributes   uint32 = 0x00000080
	FAccMaskFileWriteAttributes  uint32 = 0x00000100
	FAccMaskDelete               uint32 = 0x00010000
	FAccMaskReadControl          uint32 = 0x00020000
	FAccMaskWriteDac             uint32 = 0x00040000
	FAccMaskWriteOwner           uint32 = 0x00080000
	FAccMaskSynchronize          uint32 = 0x00100000
	FAccMaskAccessSystemSecurity uint32 = 0x01000000
	FAccMaskMaximumAllowed       uint32 = 0x02000000
	FAccMaskGenericAll           uint32 = 0x10000000
	FAccMaskGenericExecute       uint32 = 0x20000000
	FAccMaskGenericWrite         uint32 = 0x40000000
	FAccMaskGenericRead          uint32 = 0x80000000
)

File, Pipe, Printer access masks

View Source
const (
	DAccMaskFileListDirectory    uint32 = 0x00000001
	DAccMaskFileAddFile          uint32 = 0x00000002
	DAccMaskFileAddSubDirectory  uint32 = 0x00000004
	DAccMaskFileReadEA           uint32 = 0x00000008
	DAccMaskFileWriteEA          uint32 = 0x00000010
	DAccMaskFileTraverse         uint32 = 0x00000020
	DAccMaskFileDeleteChild      uint32 = 0x00000040
	DAccMaskFileReadAttributes   uint32 = 0x00000080
	DAccMaskFileWriteAttributes  uint32 = 0x00000100
	DAccMaskDelete               uint32 = 0x00010000
	DAccMaskReadControl          uint32 = 0x00020000
	DAccMaskWriteDac             uint32 = 0x00040000
	DAccMaskWriteOwner           uint32 = 0x00080000
	DAccMaskSynchronize          uint32 = 0x00100000
	DAccMaskAccessSystemSecurity uint32 = 0x01000000
	DAccMaskMaximumAllowed       uint32 = 0x02000000
	DAccMaskGenericAll           uint32 = 0x10000000
	DAccMaskGenericExecute       uint32 = 0x20000000
	DAccMaskGenericWrite         uint32 = 0x40000000
	DAccMaskGenericRead          uint32 = 0x80000000
)

Directory access masks

View Source
const (
	FileAttrReadonly           uint32 = 0x00000001
	FileAttrHidden             uint32 = 0x00000002
	FileAttrSystem             uint32 = 0x00000004
	FileAttrDirectory          uint32 = 0x00000010
	FileAttrAchive             uint32 = 0x00000020
	FileAttrNormal             uint32 = 0x00000080
	FileAttrTemporary          uint32 = 0x00000100
	FileAttrSparseFile         uint32 = 0x00000200
	FileAttrReparsePoint       uint32 = 0x00000400 // Junction
	FileAttrCompressed         uint32 = 0x00000800
	FileAttrOffline            uint32 = 0x00001000
	FileAttrNotContentIndexed  uint32 = 0x00002000
	FileAttrEncrypted          uint32 = 0x00004000
	FileAttrIntegrityStream    uint32 = 0x00008000
	FileAttrNoScrubData        uint32 = 0x00020000
	FileAttrRecallOnOpen       uint32 = 0x00040000
	FileAttrPinned             uint32 = 0x00080000
	FileAttrUnPinned           uint32 = 0x00100000
	FileAttrRecallOnDataAccess uint32 = 0x00400000
)

File attributes

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

Share access

View Source
const (
	FileSupersede   uint32 = iota // If the file already exists, supersede it. Otherwise, create the file. This value SHOULD NOT be used for a printer object.
	FileOpen                      // If the file already exists, return success; otherwise, fail the operation MUST NOT be used for a printer object.
	FileCreate                    // If the file already exists, fail the operation; otherwise, create the file.
	FileOpenIf                    // Open the file if it already exists; otherwise, create the file. This value SHOULD NOT be used for a printer object.
	FileOverwrite                 // Overwrite the file if it already exists; otherwise, fail the operation. MUST NOT be used for a printer object.
	FileOverwriteIf               // Overwrite the file if it already exists; otherwise, create the file. This value SHOULD NOT be used for a printer object.
)

File Create Disposition

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
	FileOpenRequiringOpLock     uint32 = 0x00010000
	FileDisallowExclusive       uint32 = 0x00020000
	FileReserveOpFilter         uint32 = 0x00100000
	FileOpenReparsePoint        uint32 = 0x00200000
	FileOpenNoRecall            uint32 = 0x00400000
	FileOpenForFreeSpaceQuery   uint32 = 0x00800000
)

File Create Options

View Source
const (
	FileSuperseded uint32 = iota
	FileOpened
	FileCreated
	FileOverwritten
)

File CreateActions

View Source
const (
	RestartScans      byte = 0x01
	ReturnSingleEntry byte = 0x02
	IndexSpecified    byte = 0x04
	Reopen            byte = 0x10
)

Query Directory Flags

View Source
const (
	FsctlDfsGetRefferrals uint32 = 0x00060194
	FsctlPipePeek         uint32 = 0x0011400c
	FsctlPipeWait         uint32 = 0x00110018
	// ...
	FsctlPipeTransceive uint32 = 0x0011C017
)

IOCTL Functions / CtlCode

View Source
const (
	FsctlStatusPipeDisconnected      uint32 = 0xC00000B0 //The specified named pipe is in the disconnected state.
	FsctlStatusInvalidPipeState      uint32 = 0xC00000AD //The named pipe is not in the connected state or not in the full-duplex message mode.
	FsctlStatusPipeBusy              uint32 = 0xC00000AE //The named pipe contains unread data.
	FsctlStatusInvalidUserBuffer     uint32 = 0xC00000E8 //An exception was raised while accessing a user buffer.
	FsctlStatusInsufficientResources uint32 = 0xC000009A //There were insufficient resources to complete the operation.
	FsctlStatusInvalidDeviceRequest  uint32 = 0xC0000010 //The type of the handle is not a pipe.
	FsctlStatusBufferOverflow        uint32 = 0x80000005 //The data was too large to fit into
)

MS-FSCC Status codes

View Source
const (
	OInfoFile       byte = 0x01
	OInfoFilesystem byte = 0x02
	OInfoSecurity   byte = 0x03
	OInfoQuota      byte = 0x04
)

MS-SMB2 Section 2.2.39 Info Type

View Source
const (
	OwnerSecurityInformation     uint32 = 0x00000001 // The client is setting the owner in the security descriptor of the file or named pipe.
	GroupSecurityInformation     uint32 = 0x00000002 // The client is setting the group in the security descriptor of the file or named pipe.
	DACLSecurityInformation      uint32 = 0x00000004 // The client is setting the discretionary access control list in the security descriptor of the file or named pipe.
	SACLSecurityInformation      uint32 = 0x00000008 // The client is setting the system access control list in the security descriptor of the file or named pipe.
	LabelSecurityInformation     uint32 = 0x00000010 // The client is setting the integrity label in the security descriptor of the file or named pipe.
	AttributeSecurityInformation uint32 = 0x00000020 // The client is setting the resource attribute in the security descriptor of the file or named pipe.
	ScopeSecurityInformation     uint32 = 0x00000040 // The client is setting the central access policy of the resource in the security descriptor of the file or named pipe.
	BackupSecurityInformation    uint32 = 0x00010000 // The client is setting the backup operation information in the security descriptor of the file or named pipe
)

MS-SMB2 Section 2.2.39 AdditionalInformation

View Source
const (
	FileDirectoryInformation           byte = 0x01 // Query
	FileFullDirectoryInformation       byte = 0x02 // Query
	FileBothDirectoryInformation       byte = 0x03 // Query
	FileBasicInformation               byte = 0x04 // Query, Set
	FileStandardInformation            byte = 0x05 // Query
	FileInternalInformation            byte = 0x06 // Query
	FileEaInformation                  byte = 0x07 // Query
	FileAccessInformation              byte = 0x08 // Query
	FileNameInformation                byte = 0x09 // LOCAL
	FileRenameInformation              byte = 0x0a // Set
	FileLinkInformation                byte = 0x0b // Set
	FileNamesInformation               byte = 0x0c // Query
	FileDispositionInformation         byte = 0x0d // Set
	FilePositionInformation            byte = 0x0e // Query, Set
	FileFullEaInformation              byte = 0x0f // Query, Set
	FileModeInformation                byte = 0x10 // Query, Set
	FileAlignmentInformation           byte = 0x11 // Query
	FileAllInformation                 byte = 0x12 // Query
	FileAllocationInformation          byte = 0x13 // Set
	FileEndOfFileInformation           byte = 0x14 // Set
	FileAlternateNameInformation       byte = 0x15 // Query
	FileStreamInformation              byte = 0x16 // Query
	FilePipeInformation                byte = 0x17 // Query, Set
	FilePipeLocalInformation           byte = 0x18 // Query
	FilePipeRemoteInformation          byte = 0x19 // Query
	FileMailslotQueryInformation       byte = 0x1a // LOCAL
	FileMailslotSetInformation         byte = 0x1b // LOCAL
	FileCompressionInformation         byte = 0x1c // Query
	FileObjectIdInformation            byte = 0x1d // LOCAL
	FileMoveClusterInformation         byte = 0x1f //
	FileQuotaInformation               byte = 0x20 // Query, Set
	FileReparsePointInformation        byte = 0x21 // LOCAL
	FileNetworkOpenInformation         byte = 0x22 // Query
	FileAttributeTagInformation        byte = 0x23 // Query
	FileTrackingInformation            byte = 0x24 // LOCAL
	FileIdBothDirectoryInformation     byte = 0x25 // Query
	FileIdFullDirectoryInformation     byte = 0x26 // Query
	FileValidDataLengthInformation     byte = 0x27 // Set
	FileShortNameInformation           byte = 0x28 // Set
	FileSfioReserveInformation         byte = 0x2c // LOCAL
	FileSfioVolumeInformation          byte = 0x2d
	FileHardLinkInformation            byte = 0x2e // LOCAL
	FileNormalizedNameInformation      byte = 0x30 // Query
	FileIdGlobalTxDirectoryInformation byte = 0x32 // LOCAL
	FileStandardLinkInformation        byte = 0x36 // LOCAL
	FileIdInformation                  byte = 0x3b // Query
	FileIdExtdDirectoryInformation     byte = 0x3c // Query

)

MS-FSCC Section 2.4 File Information Class

View Source
const DialectSmb2_ALL uint16 = 0x02FF
View Source
const DialectSmb_2_0_2 uint16 = 0x0202
View Source
const DialectSmb_2_1 uint16 = 0x0210
View Source
const DialectSmb_3_0 uint16 = 0x0300
View Source
const DialectSmb_3_0_2 uint16 = 0x0302
View Source
const DialectSmb_3_1_1 uint16 = 0x0311
View Source
const (
	IoctlIsFsctl uint32 = 0x00000001
)

IOCTL Flags

View Source
const ProtocolSmb = "\xFFSMB"
View Source
const ProtocolSmb2 = "\xFESMB"
View Source
const ProtocolTransformHdr = "\xFDSMB"
View Source
const SHA512 = 0x001
View Source
const (
	SMB1CommandNegotiate byte = 0x72
)

Variables

View Source
var ErrorNotDir = fmt.Errorf("Not a directory")

Custom error not part of SMB

View Source
var FsctlStatusMap = map[uint32]error{
	FsctlStatusPipeDisconnected:      fmt.Errorf("FSCTL_STATUS_PIPE_DISCONNECTED"),
	FsctlStatusInvalidPipeState:      fmt.Errorf("FSCTL_STATUS_INVALID_PIPE_STATE"),
	FsctlStatusPipeBusy:              fmt.Errorf("FSCTL_STATUS_PIPE_BUSY"),
	FsctlStatusInvalidUserBuffer:     fmt.Errorf("FSCTL_STATUS_INVALID_USER_BUFFER"),
	FsctlStatusInsufficientResources: fmt.Errorf("FSCTL_STATUS_INSUFFICIENT_RESOURCES"),
	FsctlStatusInvalidDeviceRequest:  fmt.Errorf("FSCTL_STATUS_INVALID_DEVICE_REQUEST"),
	FsctlStatusBufferOverflow:        fmt.Errorf("FSCTL_STATUS_BUFFER_OVERFLOW"),
}
View Source
var StatusMap = map[uint32]error{
	StatusOk:                     fmt.Errorf("OK"),
	StatusPending:                fmt.Errorf("Status Pending"),
	StatusBufferOverflow:         fmt.Errorf("Response buffer overflow"),
	StatusNoMoreFiles:            fmt.Errorf("No more files"),
	StatusInfoLengthMismatch:     fmt.Errorf("Insuffient size of response buffer"),
	StatusInvalidParameter:       fmt.Errorf("Invalid Parameter"),
	StatusNoSuchFile:             fmt.Errorf("No such file"),
	StatusEndOfFile:              fmt.Errorf("The end-of-file marker has been reached"),
	StatusMoreProcessingRequired: fmt.Errorf("More Processing Required"),
	StatusAccessDenied:           fmt.Errorf("Access denied!"),
	StatusObjectNameInvalid:      fmt.Errorf("The object name is invalid for the target filesystem"),
	StatusObjectNameNotFound:     fmt.Errorf("Requested file does not exist"),
	StatusObjectNameCollision:    fmt.Errorf("File or directory already exists"),
	StatusObjectPathNotFound:     fmt.Errorf("The path to the specified directory was not found"),
	StatusLogonFailure:           fmt.Errorf("Logon failed"),
	StatusAccountRestriction:     fmt.Errorf("Account restriction"),
	StatusPasswordExpired:        fmt.Errorf("Password expired!"),
	StatusAccountDisabled:        fmt.Errorf("Account disabled!"),
	StatusBadNetworkName:         fmt.Errorf("Bad network name"),
	StatusUserSessionDeleted:     fmt.Errorf("User session deleted"),
	StatusPasswordMustChange:     fmt.Errorf("User is required to change password at next logon"),
	StatusAccountLockedOut:       fmt.Errorf("User account has been locked!"),
}

Functions

This section is empty.

Types

type CloseReq

type CloseReq struct {
	Header
	StructureSize uint16 // Must be set to 24
	Flags         uint16 // Can only be 0x0000 or 0x0001
	Reserved      uint32
	FileId        []byte `smb:"fixed:16"` // 16 bytes length
}

type CloseRes

type CloseRes struct {
	Header
	StructureSize  uint16 // Must be 60
	Flags          uint16 // Can only be 0x0000 or 0x0001
	Reserved       uint32
	CreationTime   uint64
	LastAccessTime uint64
	LastWriteTime  uint64
	ChangeTime     uint64
	AllocationSize uint64
	EndOfFile      uint64
	FileAttributes uint32
}

type Connection

type Connection struct {
	*Session
	// contains filtered or unexported fields
}

func NewConnection

func NewConnection(opt Options) (c *Connection, err error)

func NewRelayConnection added in v0.3.0

func NewRelayConnection(opt Options) (c *Connection, err error)

func (*Connection) Close

func (c *Connection) Close()

func (*Connection) DeleteDir added in v0.3.5

func (s *Connection) DeleteDir(share string, dirpath string) (err error)

func (*Connection) DeleteFile added in v0.2.0

func (s *Connection) DeleteFile(share string, filepath string) (err error)

func (*Connection) GetAuthUsername added in v0.2.4

func (c *Connection) GetAuthUsername() string

func (*Connection) GetTargetInfo added in v0.3.2

func (c *Connection) GetTargetInfo() *TargetInfo

func (*Connection) ListDirectory

func (s *Connection) ListDirectory(share, dir, pattern string) (files []SharedFile, err error)

Assumes a tree connect is already performed

func (*Connection) ListRecurseDirectory

func (s *Connection) ListRecurseDirectory(share, dir, pattern string) (files []SharedFile, err error)

Assumes a tree connect is already performed

func (*Connection) ListShare

func (s *Connection) ListShare(share, dir string, recurse bool) (files []SharedFile, err error)

func (*Connection) Logoff added in v0.3.8

func (c *Connection) Logoff() error

func (*Connection) Mkdir added in v0.3.5

func (s *Connection) Mkdir(share string, path string) (err error)

Create a new directory

func (*Connection) MkdirAll added in v0.3.5

func (s *Connection) MkdirAll(share string, path string) (err error)

Creates a directory named path along with any necessary parent directories If the directory specified by path already exists, the return value is nil

func (*Connection) NegotiateProtocol

func (c *Connection) NegotiateProtocol() error

func (*Connection) NewSessionSetup1Req

func (s *Connection) NewSessionSetup1Req(spnegoClient *spnegoClient) (req SessionSetup1Req, err error)

func (*Connection) NewSessionSetup2Req

func (s *Connection) NewSessionSetup2Req(client *spnegoClient, msg *SessionSetup1Res) (SessionSetup2Req, error)

func (*Connection) OpenFile

func (s *Connection) OpenFile(tree string, filepath string) (file *File, err error)

func (*Connection) OpenFileExt added in v0.2.0

func (s *Connection) OpenFileExt(tree string, filepath string, opts *CreateReqOpts) (file *File, err error)

func (*Connection) PutFile

func (s *Connection) PutFile(share string, filepath string, offset uint64, callback func([]byte) (int, error)) (err error)

func (*Connection) RetrieveFile

func (s *Connection) RetrieveFile(share string, filepath string, offset uint64, callback func([]byte) (int, error)) (err error)

func (*Connection) SessionSetup

func (c *Connection) SessionSetup() error

func (*Connection) SetInitiator added in v0.3.8

func (c *Connection) SetInitiator(initiator Initiator) error

Update the Initiator used for authentication. Calling this function when already logged in will kill the existing session.

func (*Connection) TreeConnect

func (c *Connection) TreeConnect(name string) error

func (*Connection) TreeDisconnect

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

func (*Connection) WriteIoCtlReq

func (s *Connection) WriteIoCtlReq(req *IoCtlReq) (res IoCtlRes, err error)

type CreateReq

type CreateReq struct {
	Header
	StructureSize        uint16 // Must always be 57 regardless of Buffer size
	SecurityFlags        byte   // Must always be 0
	RequestedOplockLevel byte
	ImpersonationLevel   uint32
	SmbCreateFlags       uint64 // Must always be 0
	Reserved             uint64 // Must always be 0
	DesiredAccess        uint32
	FileAttributes       uint32
	ShareAccess          uint32
	CreateDisposition    uint32
	CreateOptions        uint32
	NameOffset           uint16
	NameLength           uint16
	CreateContextsOffset uint32
	CreateContextsLength uint32
	Buffer               []byte // Min length is 1
}

type CreateReqOpts added in v0.2.0

type CreateReqOpts struct {
	OpLockLevel        byte
	ImpersonationLevel uint32
	DesiredAccess      uint32
	FileAttr           uint32
	ShareAccess        uint32
	CreateDisp         uint32
	CreateOpts         uint32
}

func NewCreateReqOpts added in v0.2.0

func NewCreateReqOpts() *CreateReqOpts

type CreateRes

type CreateRes struct {
	Header
	StructureSize        uint16 // Must be 89
	OplockLevel          byte
	Flags                byte
	CreateAction         uint32
	CreationTime         uint64 //Filetime
	LastAccessTime       uint64 //Filetime
	LastWriteTime        uint64 //Filetime
	ChangeTime           uint64 //Filetime
	AllocationSize       uint64
	EndOfFile            uint64
	FileAttributes       uint32
	Reserved2            uint32 // Must be 0
	FileId               []byte `smb:"fixed:16"` // 16 bytes length
	CreateContextsOffset uint32 `smb:"offset:Buffer"`
	CreateContextsLength uint32 `smb:"len:Buffer"`
	Buffer               []byte
}

type EncryptionContext

type EncryptionContext struct {
	CipherCount uint16 `smb:"count:Ciphers"`
	Ciphers     []uint16
}

type File

type File struct {
	*Connection
	FileMetadata
	// contains filtered or unexported fields
}

func (*File) CloseFile

func (f *File) CloseFile() error

func (*File) IsDir added in v0.3.5

func (f *File) IsDir() bool

func (*File) NewIoCTLReq

func (f *File) NewIoCTLReq(operation uint32, data []byte) (*IoCtlReq, error)

func (*File) QueryDirectory

func (f *File) QueryDirectory(pattern string, flags byte, fileIndex uint32, bufferSize uint32) (sf []SharedFile, err error)

func (*File) ReadFile

func (f *File) ReadFile(b []byte, offset uint64) (n int, err error)

func (*File) WriteFile

func (f *File) WriteFile(data []byte, offset uint64) (n int, err error)

type FileBothDirectoryInformationStruct

type FileBothDirectoryInformationStruct struct {
	NextEntryOffset uint32
	FileIndex       uint32
	CreationTime    uint64
	LastAccessTime  uint64
	LastWriteTime   uint64
	ChangeTime      uint64
	EndOfFile       uint64
	AllocationSize  uint64
	FileAttributes  uint32
	FileNameLength  uint32 `smb:"len:FileName"`
	EaSize          uint32
	ShortNameLength byte
	Reserved        byte
	ShortName       []byte `smb:"fixed:24"`
	FileName        []byte
}

type FileMetadata added in v0.2.0

type FileMetadata struct {
	CreateAction   uint32
	CreationTime   uint64 //Filetime
	LastAccessTime uint64 //Filetime
	LastWriteTime  uint64 //Filetime
	ChangeTime     uint64 //Filetime
	Attributes     uint32
	EndOfFile      uint64
}

type Filetime

type Filetime struct {
	DwLowDateTime  uint32
	DwHighDateTime uint32
}
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 // In async requests Reserved and TreeId are replaced by AsyncID
	TreeID        uint32
	SessionID     uint64
	Signature     []byte `smb:"fixed:16"`
}

type Initiator

type Initiator interface {
	// contains filtered or unexported methods
}

type IoCtlReq

type IoCtlReq struct {
	Header                   // 64 bytes
	StructureSize     uint16 // Must be 57
	Reserved          uint16 // Must be 0
	CtlCode           uint32
	FileId            []byte `smb:"fixed:16"`
	InputOffset       uint32 `smb:"offset:Buffer"`
	InputCount        uint32 `smb:"len:Buffer"`
	MaxInputResponse  uint32
	OutputOffset      uint32 //`smb:"offset:Buffer"` // Must be 0
	OutputCount       uint32 //`smb:"len:Buffer"` // Must be 0
	MaxOutputResponse uint32 // Max response size. Test 4280
	Flags             uint32
	Reserved2         uint32 // Must be 0
	Buffer            []byte
}

NOTE Might be problematic and not work with multiple offset tags for same buffer?

type IoCtlRes

type IoCtlRes struct {
	Header
	StructureSize uint16 // Must be 49
	Reserved      uint16 // Must be 0
	CtlCode       uint32
	FileId        []byte `smb:"fixed:16"`
	InputOffset   uint32 `smb:"offset:Buffer"`
	InputCount    uint32 `smb:"len:Buffer"`
	OutputOffset  uint32 `smb:"offset:Buffer"` // Must be 0
	OutputCount   uint32 `smb:"len:Buffer"`    // Must be 0
	Flags         uint32
	Reserved2     uint32 // Must be 0
	Buffer        []byte
}

type LogoffReq added in v0.3.8

type LogoffReq struct {
	Header
	StructureSize uint16
	Reserved      uint16
}

type LogoffRes added in v0.3.8

type LogoffRes struct {
	Header
	StructureSize uint16
	Reserved      uint16
}

func NewLogoffRes added in v0.3.8

func NewLogoffRes() LogoffRes

type NTLMInitiator

type NTLMInitiator struct {
	User               string
	Password           string
	Hash               []byte
	Domain             string
	LocalUser          bool
	NullSession        bool
	Workstation        string
	TargetSPN          string
	DisableSigning     bool
	EncryptionDisabled bool
	// contains filtered or unexported fields
}

NTLMInitiator implements session setup through NTLMv2. It does not support NTLMv1. It is possible to use hash instead of password.

type NegContext

type NegContext struct {
	ContextType uint16
	DataLength  uint16 `smb:"len:Data"`
	Reserved    uint32
	Data        []byte
	Padd        []byte `smb:"align:8"`
}

For SMB 3.1.1 MS-SMB2 Section 2.2.3.1

type NegotiateReq

type NegotiateReq struct {
	Header
	StructureSize          uint16
	DialectCount           uint16 `smb:"count:Dialects"`
	SecurityMode           uint16
	Reserved               uint16
	Capabilities           uint32
	ClientGuid             []byte `smb:"fixed:16"`
	NegotiateContextOffset uint32 `smb:"offset:ContextList"`
	NegotiateContextCount  uint16 `smb:"count:ContextList"`
	Reserved2              uint16
	Dialects               []uint16
	Padding                []byte `smb:"align:8"`
	ContextList            []NegContext
}

MS-SMB2 Section 2.2.3

func (*NegotiateReq) MarshalBinary added in v0.2.0

func (self *NegotiateReq) MarshalBinary(meta *encoder.Metadata) ([]byte, error)

func (*NegotiateReq) UnmarshalBinary added in v0.2.0

func (self *NegotiateReq) UnmarshalBinary(buf []byte, meta *encoder.Metadata) error

type NegotiateRes

type NegotiateRes struct {
	Header
	StructureSize         uint16
	SecurityMode          uint16
	DialectRevision       uint16
	NegotiateContextCount uint16 `smb:"count:ContextList"`
	ServerGuid            []byte `smb:"fixed:16"`
	Capabilities          uint32
	// MaxTransactSize is the maximum size, in bytes, of the buffer sent by the
	// client in SetInfo, or sent by the server in the response to QueryInfo,
	// QueryDirectory, and ChangeNotify requests
	MaxTransactSize        uint32 // Max buffer size
	MaxReadSize            uint32 // Max value for Length of Read request the server will accept
	MaxWriteSize           uint32 // Max value for Length of Write request the server will accept
	SystemTime             uint64
	ServerStartTime        uint64
	SecurityBufferOffset   uint16 `smb:"offset:SecurityBlob"`
	SecurityBufferLength   uint16 `smb:"len:SecurityBlob"`
	NegotiateContextOffset uint32 `smb:"offset:ContextList"`
	SecurityBlob           *gss.NegTokenInit
	Padding                []byte `smb:"align:8"`
	ContextList            []NegContext
}

MS-SMB2 Section 2.2.4

func NewNegotiateRes

func NewNegotiateRes() NegotiateRes

type Options

type Options struct {
	Host                  string
	Port                  int
	Workstation           string
	Domain                string
	User                  string
	Password              string
	Hash                  string
	DisableSigning        bool
	RequireMessageSigning bool
	DisableEncryption     bool
	ForceSMB2             bool
	Initiator             Initiator
	DialTimeout           time.Duration
	ProxyDialer           proxy.Dialer
	RelayPort             int
	ManualLogin           bool
}

type PreauthIntegrityContext

type PreauthIntegrityContext struct {
	HashAlgorithmCount uint16 `smb:"count:HashAlgorithms"`
	SaltLength         uint16 `smb:"len:Salt"`
	HashAlgorithms     []uint16
	Salt               []byte
	Padd               []byte `smb:"align:8"`
}

type QueryDirectoryReq

type QueryDirectoryReq struct {
	Header
	StructureSize        uint16 // Must always be 33 regardless of Buffer size
	FileInformationClass byte
	Flags                byte
	FileIndex            uint32
	FileID               []byte `smb:"fixed:16"`
	FileNameOffset       uint16 `smb:"offset:Buffer"`
	FileNameLength       uint16 `smb:"len:Buffer"`
	OutputBufferLength   uint32
	Buffer               []byte
}

type QueryDirectoryRes

type QueryDirectoryRes struct {
	Header
	StructureSize      uint16 // Must always be 9
	OutputBufferOffset uint16 `smb:"offset:Buffer"`
	OutputBufferLength uint32 `smb:"len:Buffer"`
	Buffer             []byte
}

type ReadReq

type ReadReq struct {
	Header
	StructureSize         uint16 // Must always be 49 regardless of Buffer size
	Padding               byte   // Set to 0
	Flags                 byte   // Must be 0 for smb 2.1
	Length                uint32
	Offset                uint64
	FileId                []byte `smb:"fixed:16"`
	MinimumCount          uint32 // How many bytes to at least read for successful operation
	Channel               uint32 // Must be 0 for smb 2.1
	RemainingBytes        uint32 // 0 for smb 2.1
	ReadChannelInfoOffset uint16 // 0 for smb 2.1
	ReadChannelInfoLength uint16 // 0 for smb 2.1
	Buffer                []byte // 0 length for smb 2.1
}

type ReadRes

type ReadRes struct {
	Header
	StructureSize uint16 // Must be 17
	DataOffset    byte   `smb:"offset:Buffer"`
	Reserved      byte
	DataLength    uint32 `smb:"len:Buffer"`
	DataRemaining uint32
	Reserved2     uint32 // Must be 0 for smb 2.1
	Buffer        []byte
}

type SMB1Dialect added in v0.3.3

type SMB1Dialect struct {
	BufferFormat  uint8  // Must be 0x2
	DialectString string // Null-terminated string
}

type SMB1Header added in v0.3.0

type SMB1Header struct {
	Protocol         []byte `smb:"fixed:4"` // Must contain 0xff, S, M, B
	Command          uint8
	Status           uint32
	Flags            uint8
	Flags2           uint16
	PIDHigh          uint16
	SecurityFeatures []byte `smb:"fixed:8"`
	Reserved         uint16
	TID              uint16
	PIDLow           uint16
	UID              uint16
	MID              uint16
}

MS-CIFS 2.2.3.1 SMB Header

type SMB1NegotiateReq added in v0.3.3

type SMB1NegotiateReq struct {
	Header    SMB1Header
	WordCount uint8
	ByteCount uint16
	Dialects  []SMB1Dialect
}

func (*SMB1NegotiateReq) MarshalBinary added in v0.3.3

func (self *SMB1NegotiateReq) MarshalBinary(meta *encoder.Metadata) ([]byte, error)

func (*SMB1NegotiateReq) UnmarshalBinary added in v0.3.3

func (self *SMB1NegotiateReq) UnmarshalBinary(buf []byte, meta *encoder.Metadata) error

type Session

type Session struct {
	// contains filtered or unexported fields
}

func (*Session) GetSessionKey added in v0.4.0

func (s *Session) GetSessionKey() []byte

func (*Session) IsAuthenticated

func (s *Session) IsAuthenticated() bool

func (*Session) IsSigningRequired

func (s *Session) IsSigningRequired() bool

func (*Session) NewCloseReq

func (s *Session) NewCloseReq(share string, fileId []byte) (CloseReq, error)

func (*Session) NewCreateReq

func (s *Session) NewCreateReq(share, name string,
	opLockLevel byte,
	impersonationLevel uint32,
	desiredAccess uint32,
	fileAttr uint32,
	shareAccess uint32,
	createDisp uint32,
	createOpts uint32) (CreateReq, error)

func (*Session) NewLogoffReq added in v0.3.8

func (s *Session) NewLogoffReq() LogoffReq

func (*Session) NewNegotiateReq

func (s *Session) NewNegotiateReq() (req NegotiateReq, err error)

func (*Session) NewQueryDirectoryReq

func (s *Session) NewQueryDirectoryReq(share, pattern string, fileId []byte,
	fileInformationClass byte,
	flags byte,
	fileIndex uint32,
	outputBufferLength uint32,
) (QueryDirectoryReq, error)

func (*Session) NewReadReq

func (s *Session) NewReadReq(share string, fileid []byte,
	length uint32,
	offset uint64,
	minRead uint32,
) (ReadReq, error)

func (*Session) NewSMB1NegotiateReq added in v0.3.3

func (s *Session) NewSMB1NegotiateReq() (req SMB1NegotiateReq, err error)

func (*Session) NewSetInfoReq added in v0.2.0

func (s *Session) NewSetInfoReq(share string, fileId []byte) (SetInfoReq, 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) NewWriteReq

func (s *Session) NewWriteReq(share string, fileid []byte,
	offset uint64,
	data []byte,
) (WriteReq, 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
}

func NewSessionSetup1Req added in v0.3.0

func NewSessionSetup1Req() SessionSetup1Req

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 SessionSetupReq added in v0.3.0

type SessionSetupReq 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         []byte
}

Useful with a generic struct when we don't know if this is a Negotiate or Auth message

type SessionSetupRes added in v0.3.0

type SessionSetupRes struct {
	Header
	StructureSize        uint16
	Flags                uint16
	SecurityBufferOffset uint16 `smb:"offset:SecurityBlob"`
	SecurityBufferLength uint16 `smb:"len:SecurityBlob"`
	SecurityBlob         []byte
}

Useful with a generic struct when we wan't to respond with LOGON FAILURE and an empty SecurityBlob

type SetInfoReq added in v0.2.0

type SetInfoReq struct {
	Header
	StructureSize         uint16 // Must always be 33 regardless of Buffer size
	InfoType              byte
	FileInfoClass         byte
	BufferLength          uint32 `smb:"len:Buffer"`    // The length of the data being written, in bytes. Can be zero bytes.
	BufferOffset          uint16 `smb:"offset:Buffer"` // 0x70. The offset, in bytes, from the beginning of the SMB2 header to the data being written.
	Reserved              uint16
	AdditionalInformation uint32
	FileId                []byte `smb:"fixed:16"`
	Buffer                []byte // 0 length for smb 2.1
}

type SetInfoRes added in v0.2.0

type SetInfoRes struct {
	Header
	StructureSize uint16 // Must be 2
}

type SharedFile

type SharedFile struct {
	Name           string
	FullPath       string
	IsDir          bool
	Size           uint64
	IsHidden       bool
	IsReadOnly     bool
	IsJunction     bool
	CreationTime   uint64
	LastAccessTime uint64
	LastWriteTime  uint64
	ChangeTime     uint64
}

type SigningContext

type SigningContext struct {
	SigningAlgorithmCount uint16 `smb:"count:SigningAlgorithms"`
	SigningAlgorithms     []uint16
}

MS-SMB2 2.2.3.1.7 SMB2_SIGNING_CAPABILITIES

type TargetInfo added in v0.3.2

type TargetInfo struct {
	DnsComputerName  string
	DnsDomainName    string
	NBComputerName   string
	NBDomainName     string
	OS               uint64
	GuessedOSVersion string
}

Information extracted from the SessionSetup handshake

type TransformHeader

type TransformHeader struct {
	ProtcolID           uint32
	Signature           []byte `smb:"fixed:16"`
	Nonce               []byte `smb:"fixed:16"` // 11 bytes nonce + 5 bytes reversed if CCM, 12 bytes nonce + 4 bytes reversed if GCM
	OriginalMessageSize uint32
	Reserved            uint16
	Flags               uint16 //SMB 3.1.1
	SessionId           uint64
}

func NewTransformHeader

func NewTransformHeader() TransformHeader

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
}

func NewTreeConnectRes

func NewTreeConnectRes() (TreeConnectRes, error)

type TreeDisconnectReq

type TreeDisconnectReq struct {
	Header
	StructureSize uint16
	Reserved      uint16
}

type TreeDisconnectRes

type TreeDisconnectRes struct {
	Header
	StructureSize uint16
	Reserved      uint16
}

func NewTreeDisconnectRes

func NewTreeDisconnectRes() (TreeDisconnectRes, error)

type WriteReq

type WriteReq struct {
	Header
	StructureSize          uint16 // Must always be 49 regardless of Buffer size
	DataOffset             uint16 `smb:"offset:Buffer"` // 0x70. The offset, in bytes, from the beginning of the SMB2 header to the data being written.
	Length                 uint32 `smb:"len:Buffer"`    // The length of the data being written, in bytes. Can be zero bytes.
	Offset                 uint64 // The offset, in bytes, of where to write the data in the destination file. For pipes it must be 0.
	FileId                 []byte `smb:"fixed:16"`
	Channel                uint32 // Must be 0 for smb 2.1
	RemainingBytes         uint32 // Not used in smb 2.1
	WriteChannelInfoOffset uint16 // Not used in smb 2.1
	WriteChannelInfoLength uint16 // Not used in smb 2.1
	Flags                  uint32 // How to process the write operation. Can be 0.
	Buffer                 []byte // 0 length for smb 2.1
}

type WriteRes

type WriteRes struct {
	Header
	StructureSize          uint16 // Must be 17
	Reserved               uint16 // Must not be used
	Count                  uint32 // The number of bytes written
	Remaining              uint32 // Must not be used
	WriteChannelInfoOffset uint16 // Must not be used
	WriteChannelInfoLength uint16 // Must not be used
}

Directories

Path Synopsis
crypto
ccm
MIT License
MIT License
cmac
MIT License
MIT License
msrrp
MIT License
MIT License

Jump to

Keyboard shortcuts

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