Generated from Manticore v1.1.6 • 388 packages. View on pkg.go.dev

nbt

import "github.com/TheManticoreProject/Manticore/network/netbios/nbt"

Index

Constants

const (
    // DefaultCalledName is the wildcard NetBIOS server name that modern SMB
    // servers answer to regardless of their configured machine name.
    DefaultCalledName = "*SMBSERVER"

    // NetBIOSSuffixWorkstation and NetBIOSSuffixServer are the one-byte service
    // suffixes appended to the 16th byte of a NetBIOS name: the calling name is
    // the workstation service (0x00) and the called name is the server service
    // (0x20).
    NetBIOSSuffixWorkstation byte = 0x00
    NetBIOSSuffixServer      byte = 0x20
)

type NBTTransport

NBTTransport implements the Transport interface for NetBIOS over TCP Source: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-cifs/45170055-a0cd-4910-9228-801d5bf7ac84

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

func NewNBTTransport

func NewNBTTransport() *NBTTransport

NewNBTTransport creates a new NetBIOS over TCP transport with the RFC 1002 session-establishment handshake enabled and the CALLED name defaulting to the “*SMBSERVER” wildcard.

func NewNBTTransportFromConn

func NewNBTTransportFromConn(conn net.Conn) *NBTTransport

NewNBTTransportFromConn wraps an already-established connection — typically one returned by net.Listener.Accept — as a NetBIOS over TCP transport. Connect MUST NOT be called on the result; the accept-side handshake is performed by AcceptSession instead of by Connect.

func (*NBTTransport) AcceptSession

func (n *NBTTransport) AcceptSession(acceptedNames []string) (called, calling string, err error)

AcceptSession completes the RFC 1002 4.3 session-establishment handshake on an accepted connection, the server-side counterpart of EstablishSession: it reads the SESSION REQUEST (0x81), decodes the CALLED and CALLING names it carries, and answers either a POSITIVE SESSION RESPONSE (0x82) or a NEGATIVE SESSION RESPONSE (0x83).

The CALLED name is accepted when acceptedNames is empty (any name is served), when it matches one of acceptedNames case-insensitively, or when it is a wildcard such as the “*SMBSERVER” convention that clients use before they know a host’s real machine name. A name that matches none of these is refused with NEGATIVE_SESSION_NOT_LISTENING_ON_CALLED_NAME, mirroring what EstablishSession expects to receive and retry against.

Parameters:

  • acceptedNames: the CALLED names this endpoint answers to; empty accepts any

Returns:

  • called: the CALLED name the client asked for
  • calling: the CALLING name the client identified itself with
  • err: non-nil if the handshake did not complete, in which case the caller should close the connection

func (*NBTTransport) Close

func (n *NBTTransport) Close() error

Close terminates the NetBIOS over TCP connection

func (*NBTTransport) Connect

func (n *NBTTransport) Connect(ipaddr net.IP, port int) error

Connect establishes a NetBIOS over TCP connection and, unless the handshake has been disabled, performs the RFC 1002 session-establishment handshake.

func (*NBTTransport) EstablishSession

func (n *NBTTransport) EstablishSession(calledName, callingName string) error

EstablishSession performs the RFC 1002 4.3 session-establishment handshake on the current connection: it sends a SESSION REQUEST (0x81) carrying the second-level-encoded CALLED and CALLING NetBIOS names and interprets the reply. A POSITIVE SESSION RESPONSE (0x82) completes the handshake; a NEGATIVE SESSION RESPONSE (0x83) is returned as the mapped error-code error; and a RETARGET SESSION RESPONSE (0x84) re-dials the advertised IP/port and retries, up to maxRetargets times.

func (*NBTTransport) IsConnected

func (n *NBTTransport) IsConnected() bool

IsConnected returns whether the NetBIOS transport is currently connected

func (*NBTTransport) Receive

func (n *NBTTransport) Receive() ([]byte, error)

Receive reads a SESSION MESSAGE from the NetBIOS over TCP connection, handling the NetBIOS header, and rejects any other session-service message type.

func (*NBTTransport) Send

func (n *NBTTransport) Send(data []byte) (int, error)

Send transmits data over the NetBIOS over TCP connection with proper NetBIOS header

func (*NBTTransport) SetCalledName

func (n *NBTTransport) SetCalledName(name string)

SetCalledName overrides the CALLED NetBIOS name sent in the SESSION REQUEST (defaults to “*SMBSERVER”). An empty value is ignored.

func (*NBTTransport) SetCallingName

func (n *NBTTransport) SetCallingName(name string)

SetCallingName overrides the CALLING NetBIOS name sent in the SESSION REQUEST (defaults to the local hostname). An empty value is ignored.

func (*NBTTransport) SetHandshakeEnabled

func (n *NBTTransport) SetHandshakeEnabled(enabled bool)

SetHandshakeEnabled controls whether Connect performs the RFC 1002 session-establishment handshake. Disable it to talk to a modern server that accepts SESSION MESSAGEs on port 139 without a prior SESSION REQUEST.

func (*NBTTransport) SetTimeout

func (n *NBTTransport) SetTimeout(d time.Duration)

SetTimeout bounds Connect and each subsequent Receive: Connect fails if the TCP connection cannot be established within d, and Receive fails if a frame does not arrive within d. A non-positive d removes the bound (blocking I/O).