smb

package
v0.0.0-...-64a4400 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2021 License: Apache-2.0, ISC, MIT Imports: 16 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 (
	SMB2_CAP_DFS                = 0x00000001 // Distributed Filesystem
	SMB2_CAP_LEASING            = 0x00000002 // Leasing Support
	SMB2_CAP_LARGE_MTU          = 0x00000004 // Muti-credit support
	SMB2_CAP_MULTI_CHANNEL      = 0x00000008 // Multi-channel support
	SMB2_CAP_PERSISTENT_HANDLES = 0x00000010 // Persistent handles
	SMB2_CAP_DIRECTORY_LEASING  = 0x00000020 // Directory leasing
	SMB2_CAP_ENCRYPTION         = 0x00000040 // Encryption support
)

See [MS-SMB2] Sect. 2.2.4 These are the flags for the Capabilties field, and are use for determining the SMBCapabilties booleans (below).

View Source
const DialectSmb2_ALL = 0x02FF
View Source
const DialectSmb_1_0 = "\x02NT LM 0.12\x00"
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 (
	SmbHeaderV1Length = 32
)
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 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 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 HeaderLog

type HeaderLog struct {
	// ProtocolID identifies the SMB protocol version (e.g. ProtocolSmb ==
	// "\xFFSMB")
	ProtocolID []byte `json:"protocol_id"`

	// Status is the server's status; e.g. NTSTATUS
	// (https://msdn.microsoft.com/en-us/library/cc704588.aspx).
	Status uint32 `json:"status"`

	// Command is the command identifier.
	Command uint16 `json:"command"`

	// Credits is the number of credits granted to the client.
	Credits uint16 `json:"credits"`

	// Flags is the flags for the request (see
	// https://msdn.microsoft.com/en-us/library/cc246529.aspx)
	Flags uint32 `json:"flags"`
}

HeaderLog contains the relevant parts of the header that is included with each packet.

type HeaderV1

type HeaderV1 struct {
	ProtocolID       []byte `smb:"fixed:4"`
	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
}

type LoggedSession

type LoggedSession struct {
	Session
	Log *SMBLog
}

LoggedSession wraps the Session struct, and holds a Log struct alongside it to track its progress.

func (*LoggedSession) LoggedNegotiateProtocol

func (ls *LoggedSession) LoggedNegotiateProtocol(setup bool) error

LoggedNegotiateProtocol performs the same operations as Session.NegotiateProtocol() up to the point where user credentials would be required, and logs the server's responses. If setup is false, stop after reading the response to Negotiate. If setup is true, send a SessionSetup1 request.

Note: This supports SMB2 only.

func (*LoggedSession) LoggedNegotiateProtocolv1

func (ls *LoggedSession) LoggedNegotiateProtocolv1(setup bool) error

Temporary placeholder to detect SMB v1 by sending a simple v1 header with an invalid command; the response with be an error code, but with a v1 ProtocolID TODO: Parse the unmarshaled results.

func (*LoggedSession) LoggedSessionSetupV1

func (ls *LoggedSession) LoggedSessionSetupV1() (err error)

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 NegotiateReqV1

type NegotiateReqV1 struct {
	HeaderV1
	WordCount uint8
	ByteCount uint16  // hardcoded to 14
	Dialects  []uint8 `smb:"fixed:12"`
}

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 NegotiateResV1

type NegotiateResV1 struct {
	HeaderV1
	WordCount       uint8
	DialectIndex    uint16
	SecurityMode    uint8
	MaxMpxCount     uint16
	MaxNumberVcs    uint16
	MaxBufferSize   uint32
	MaxRawSize      uint32
	SessionKey      uint32
	Capabilities    uint32
	SystemTime      uint64
	ServerTimezon   uint16
	ChallengeLength uint8
	ByteCount       uint16 `smb:"len:VarData"`
	VarData         []byte
}

type NegotiationLog

type NegotiationLog struct {
	HeaderLog

	// SecurityMode is the server's security mode (e.g. signing
	// enabled/required).
	SecurityMode uint16 `json:"security_mode"`

	// DialectRevision is the SMB2 dialect number; 0x2FF is the wildcard.
	DialectRevision uint16 `json:"dialect_revision"`

	// ServerGuid is the server's globally unique identifier.
	ServerGuid []byte `json:"server_guid"`

	// Capabilities specifies protocol capabilities for the server.
	Capabilities uint32 `json:"capabilities"`

	// SystemTime is the time (in seconds since Unix epoch) the server received
	// the negotiation request.
	SystemTime uint32 `json:"system_time"`

	// ServerStartTime is the time (in seconds since the Unix epoch) the server started.
	ServerStartTime uint32 `json:"server_start_time"`

	// AuthenticationTypes is a list of OBJECT IDENTIFIERs (in dotted-decimal
	// format) identifying authentication modes that the server supports.
	AuthenticationTypes []string `json:"authentication_types,omitempty"`
}

NegotiationLog contains the relevant parts of the negotiation response packet. See https://msdn.microsoft.com/en-us/library/cc246561.aspx.

type Options

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

type SMBCapabilities

type SMBCapabilities struct {
	DFSSupport bool `json:"smb_dfs_support"`
	Leasing    bool `json:"smb_leasing_support,omitempty"`           // Valid for >2.0.2
	LargeMTU   bool `json:"smb_multicredit_support,omitempty"`       // Valid for >2.0.2
	MultiChan  bool `json:"smb_multichan_support,omitempty"`         // Valid for >2.1
	Persist    bool `json:"smb_persistent_handle_support,omitempty"` // Valid for >2.1
	DirLeasing bool `json:"smb_directory_leasing_support,omitempty"` // Valid for >2.1
	Encryption bool `json:"smb_encryption_support,omitempty"`        // Only for 3.0, 3.0.2
}

type SMBLog

type SMBLog struct {
	// SupportV1 is true if the server's protocol ID indicates support for
	// version 1.
	SupportV1 bool `json:"smbv1_support"`

	Version *SMBVersions `json:"smb_version,omitempty"`

	// If present, represent the NativeOS, NTLM, and GroupName fields of SMBv1 Session Setup Negotiation
	// An empty string for these values indicate the data was not available
	NativeOs  string `json:"native_os"`
	NTLM      string `json:"ntlm"`
	GroupName string `json:"group_name"`

	// While the NegotiationLogs and SessionSetupLog each have their own
	// Capabilties field, we are ignoring the SessionsSetupLog capability
	// when decoding, and only representing the server capabilties based
	// on what is present in the NegotiationLog capability bitmask field,
	// which is why this capability decode is presented at this level
	// in the results.
	//
	// This is based on Sect. 2.2.4 from the [MS-SMB2] document, which states:
	// "The Capabilities field specifies protocol capabilities for the server."
	Capabilities *SMBCapabilities `json:"smb_capabilities,omitempty"`

	// HasNTLM is true if the server supports the NTLM authentication method.
	HasNTLM bool `json:"has_ntlm"`

	// NegotiationLog, if present, contains the server's response to the
	// negotiation request.
	NegotiationLog *NegotiationLog `json:"negotiation_log,omitempty"`

	// SessionSetupLog, if present, contains the server's response to the
	// session setup request.
	SessionSetupLog *SessionSetupLog `json:"session_setup_log,omitempty"`
}

SMBLog logs the relevant information about the session.

func GetSMBLog

func GetSMBLog(conn net.Conn, session bool, v1 bool, debug bool) (smbLog *SMBLog, err error)

GetSMBLog() determines the Protocol version and dialect, and optionally negotiates a session.

type SMBVersions

type SMBVersions struct {
	Major     uint8  `json:"major"`
	Minor     uint8  `json:"minor"`
	Revision  uint8  `json:"revision"`
	VerString string `json:"version_string"`
}

Parse the SMB version and dialect; version string will be of the form: Major.Minor.Revision.

'Revisions' are set to 0 if not specified (e.g. 2.1 is 2.1.0) The following versions/dialects are known: SMB 1.0.0 SMB 2.0.2 SMB 2.1.0 SMB 3.0.0 SMB 3.0.2 SMB 3.1.1

type Session

type Session struct {
	IsSigningRequired bool
	IsAuthenticated   bool
	// 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) Debug

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

func (*Session) NegotiateProtocol

func (s *Session) NegotiateProtocol() error

func (*Session) NewNegotiateReq

func (s *Session) NewNegotiateReq() NegotiateReq

func (*Session) NewNegotiateReqV1

func (s *Session) NewNegotiateReqV1() NegotiateReqV1

func (*Session) NewSessionSetup1Req

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

func (*Session) NewSessionSetup2Req

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

func (*Session) NewSessionSetupV1Req

func (s *Session) NewSessionSetupV1Req() SessionSetupV1Req

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) 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 SessionSetupLog

type SessionSetupLog struct {
	HeaderLog

	// SetupFlags is the gives additional information on the session.
	SetupFlags uint16 `json:"setup_flags"`

	// TargetName is the target name from the challenge packet
	TargetName string `json:"target_name"`

	// NegotiateFlags are the flags from the challenge packet
	NegotiateFlags uint32 `json:"negotiate_flags"`
}

SessionSetupLog contains the relevant parts of the first session setup response packet. See https://msdn.microsoft.com/en-us/library/cc246564.aspx

type SessionSetupV1Req

type SessionSetupV1Req struct {
	HeaderV1
	WordCount             uint8
	AndCommand            uint8
	Reserved1             uint8
	AndOffset             uint16
	MaxBuffer             uint16
	MaxMPXCount           uint16
	VCNumber              uint16
	SessionKey            uint32
	OEMPasswordLength     uint16
	UnicodePasswordLength uint16
	Reserved2             uint32
	Capabilities          uint32
	ByteCount             uint16
	VarData               []byte
}

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)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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