Generated from Manticore v1.1.5 • 201 packages. View on pkg.go.dev

nbns

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

Index

Constants

const (
    // Challenge timeouts and retries
    ChallengeTimeout = 2 * time.Second
    ChallengeRetries = 3
)

Constants for name encoding

const (
    NetBIOSNameLength = 16 // NetBIOS names are exactly 16 bytes
    EncodedNameLength = 32 // Each half-byte becomes a byte in encoded form
    ASCII_A           = 0x41
)

Constants for packet types and flags

const (
    // Operation codes
    OpNameQuery    uint16 = 0x0000
    OpRegistration uint16 = 0x2800
    OpRelease      uint16 = 0x3000
    OpWACK         uint16 = 0x3800
    OpRefresh      uint16 = 0x4000
    OpRedirect     uint16 = 0x4800
    OpConflict     uint16 = 0x5000
    OpNodeStatus   uint16 = 0x2100

    // Response codes
    RcodeSuccess     uint16 = 0x0000
    RcodeFormatError uint16 = 0x0001
    RcodeServerError uint16 = 0x0002
    RcodeNameError   uint16 = 0x0003
    RcodeNotImpl     uint16 = 0x0004
    RcodeRefused     uint16 = 0x0005
    RcodeActive      uint16 = 0x0006
    RcodeConflict    uint16 = 0x0007

    // Flags
    FlagResponse      uint16 = 0x8000
    FlagAuthoritative uint16 = 0x0400
    FlagTruncated     uint16 = 0x0200
    FlagRecursion     uint16 = 0x0100
    FlagBroadcast     uint16 = 0x0010

    // Question Type
    QuestionTypeNB     uint16 = 0x0020
    QuestionTypeNBSTAT uint16 = 0x0021

    // Question Class
    QuestionClassIn uint16 = 0x0001 // Internet class
)
const (
    // Default ports for NetBIOS name service
    DefaultNBNSPort = 137

    // Timeouts and retry counts
    ReadTimeout  = 5 * time.Second
    WriteTimeout = 5 * time.Second
)
const (
    // Default TCP port for NetBIOS name service
    DefaultNBNSTCPPort = 137

    // TCP timeouts
    TCPReadTimeout  = 30 * time.Second
    TCPWriteTimeout = 30 * time.Second

    // Maximum message size
    MaxTCPMessageSize = 65535
)
const (
    // Default UDP port for NetBIOS name service
    DefaultNBNSUDPPort = 137

    // UDP timeouts and buffer sizes
    UDPReadTimeout  = 5 * time.Second
    UDPWriteTimeout = 5 * time.Second
    MaxUDPSize      = 576 // Minimum reassembly buffer size per RFC 1001
)
const (
    // DefaultCleanupInterval is how often expired names are cleaned up
    DefaultCleanupInterval = 5 * time.Minute
)

func ParseIPFromRData

func ParseIPFromRData(rdata []byte) (net.IP, error)

ParseIPFromRData extracts an IP address from NB resource record RData. RData is expected to be in ADDR_ENTRY format (2 bytes flags + 4 bytes address).

type ADDR\_ENTRY

POSITIVE NAME QUERY RESPONSE

type ADDR_ENTRY struct {
    Flags   uint16
    Address uint32
}

func (*ADDR_ENTRY) IP

func (n *ADDR_ENTRY) IP() net.IP

IP returns the address as a net.IP

func (*ADDR_ENTRY) Length

func (n *ADDR_ENTRY) Length() uint16

returns static 6 bytes number

func (*ADDR_ENTRY) Marshal

func (n *ADDR_ENTRY) Marshal() []byte

Marshals ADDR_ENTRY to buffer

func (*ADDR_ENTRY) Unmarshal

func (n *ADDR_ENTRY) Unmarshal(data []byte) error

Unmarshal decodes an ADDR_ENTRY from a byte slice

type NBNSHeader

NBNSHeader represents the header of a NetBIOS name service packet

type NBNSHeader struct {
    TransactionID uint16
    Flags         uint16
    Questions     uint16
    Answers       uint16
    Authority     uint16
    Additional    uint16
}

type NBNSPacket

NBNSPacket represents a complete NetBIOS name service packet

type NBNSPacket struct {
    Header     NBNSHeader
    Questions  []NBNSQuestion
    Answers    []NBNSResourceRecord
    Authority  []NBNSResourceRecord
    Additional []NBNSResourceRecord
}

func (*NBNSPacket) Marshal

func (p *NBNSPacket) Marshal() ([]byte, error)

Marshal encodes an NBNSPacket into a byte slice

func (*NBNSPacket) Unmarshal

func (p *NBNSPacket) Unmarshal(data []byte) (int, error)

Unmarshal decodes a byte slice into an NBNSPacket

type NBNSQuestion

NBNSQuestion represents a question section in a NetBIOS name service packet

type NBNSQuestion struct {
    Name  *NetBIOSName
    Type  uint16
    Class uint16
}

type NBNSResourceRecord

NBNSResourceRecord represents a resource record in a NetBIOS name service packet

type NBNSResourceRecord struct {
    Name     *NetBIOSName
    Type     uint16
    Class    uint16
    TTL      uint32
    RDLength uint16
    RData    []byte
}

type NameChallenger

NameChallenger handles name conflict detection and resolution

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

func NewNameChallenger

func NewNameChallenger(nbns *NetBIOSNameServer, handlers *PacketHandler) *NameChallenger

NewNameChallenger creates a new name challenger instance

func (*NameChallenger) ChallengeOwnership

func (c *NameChallenger) ChallengeOwnership(name string, owner net.IP) (bool, error)

ChallengeOwnership verifies if a node still owns a name

func (*NameChallenger) DefendName

func (c *NameChallenger) DefendName(packet *NBNSPacket, response *NBNSPacket)

DefendName actively defends a name against challenges

type NameRecord

NameRecord represents a registered NetBIOS name and its attributes

type NameRecord struct {
    Name            string
    Type            NameType
    Status          NameStatus
    Owners          []net.IP  // IP addresses of nodes that own this name
    TTL             time.Time // Time-to-live for name registration
    RefreshInterval time.Duration
    ScopeID         string // NetBIOS scope identifier
}

type NameStatus

NameStatus represents the current state of a name

type NameStatus uint8
const (
    Active NameStatus = iota
    Conflict
    Releasing
)

type NameType

NameType indicates whether a name is unique or group

type NameType uint8
const (
    Unique NameType = iota // Only one owner allowed
    Group                  // Multiple owners allowed
)

type NetBIOSName

NetBIOSName represents a NetBIOS name with its scope

type NetBIOSName struct {
    Name    string
    ScopeID string
}

func FirstLevelDecode

func FirstLevelDecode(encoded string) (*NetBIOSName, error)

FirstLevelDecode decodes a first level encoded NetBIOS name

func (*NetBIOSName) FirstLevelEncode

func (n *NetBIOSName) FirstLevelEncode() (string, error)

FirstLevelEncode performs the first level encoding of a NetBIOS name as specified in RFC 1001 section 14.1

func (*NetBIOSName) Validate

func (n *NetBIOSName) Validate() error

Validate checks if a NetBIOS name is valid

type NetBIOSNameServer

NetBIOSNameServer represents a NetBIOS Name Server

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

func NewNetBIOSNameServer

func NewNetBIOSNameServer(secured bool) *NetBIOSNameServer

NewNetBIOSNameServer creates a new NetBIOS Name Server instance. Call StartCleanup to begin background TTL expiration, and StopCleanup to stop it.

func (*NetBIOSNameServer) CleanExpiredNames

func (n *NetBIOSNameServer) CleanExpiredNames()

CleanExpiredNames removes names that have exceeded their TTL

func (*NetBIOSNameServer) MarkNameConflict

func (n *NetBIOSNameServer) MarkNameConflict(name string, scopeID string) error

MarkNameConflict marks a name as being in conflict

func (*NetBIOSNameServer) QueryName

func (n *NetBIOSNameServer) QueryName(name string, scopeID string) ([]net.IP, NameType, time.Duration, error)

QueryName looks up a name and returns its owners, type, and remaining TTL

func (*NetBIOSNameServer) RefreshName

func (n *NetBIOSNameServer) RefreshName(name string, scopeID string, owner net.IP) error

RefreshName updates the TTL for a name registration

func (*NetBIOSNameServer) RegisterName

func (n *NetBIOSNameServer) RegisterName(name string, scopeID string, nameType NameType, owner net.IP, ttl time.Duration) error

RegisterName attempts to register a name with the name server

func (*NetBIOSNameServer) ReleaseName

func (n *NetBIOSNameServer) ReleaseName(name string, scopeID string, owner net.IP) error

ReleaseName removes a name registration for a specific owner

func (*NetBIOSNameServer) SetCleanupInterval

func (n *NetBIOSNameServer) SetCleanupInterval(interval time.Duration)

SetCleanupInterval configures the interval between cleanup cycles. Must be called before StartCleanup.

func (*NetBIOSNameServer) StartCleanup

func (n *NetBIOSNameServer) StartCleanup()

StartCleanup begins a background goroutine that periodically removes expired name registrations.

func (*NetBIOSNameServer) StopCleanup

func (n *NetBIOSNameServer) StopCleanup()

StopCleanup stops the background cleanup goroutine and waits for it to finish.

type PacketHandler

PacketHandler provides common packet handling methods for both TCP and UDP servers

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

func NewPacketHandler

func NewPacketHandler(nbns *NetBIOSNameServer) *PacketHandler

NewPacketHandler creates a new packet handler instance

type RedirectInfo

RedirectInfo contains information about where to redirect a client

type RedirectInfo struct {
    ServerIP   net.IP
    ServerPort uint16
}

type RedirectManager

RedirectManager handles NBNS redirection

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

func NewRedirectManager

func NewRedirectManager() *RedirectManager

NewRedirectManager creates a new redirect manager

func (*RedirectManager) AddRedirect

func (r *RedirectManager) AddRedirect(scope string, serverIP net.IP, port uint16)

AddRedirect adds or updates a redirect mapping

func (*RedirectManager) GetRedirect

func (r *RedirectManager) GetRedirect(scope string) (RedirectInfo, bool)

GetRedirect returns redirect information for a scope

func (*RedirectManager) HandleRedirect

func (r *RedirectManager) HandleRedirect(request *NBNSPacket, response *NBNSPacket) bool

HandleRedirect modifies a response packet for redirection if needed

func (*RedirectManager) RemoveRedirect

func (r *RedirectManager) RemoveRedirect(scope string)

RemoveRedirect removes a redirect mapping

type Server

Server represents a NetBIOS Name Server

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

func NewServer

func NewServer(addr string, secured bool) (*Server, error)

NewServer creates a new NBNS server instance

func (*Server) Start

func (s *Server) Start() error

Start begins listening for NBNS requests

func (*Server) Stop

func (s *Server) Stop()

Stop gracefully shuts down the server

type TCPServer

TCPServer represents a NetBIOS Name Server TCP component

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

func NewTCPServer

func NewTCPServer(addr string, nbns *NetBIOSNameServer) (*TCPServer, error)

NewTCPServer creates a new NBNS TCP server instance

func (*TCPServer) Start

func (s *TCPServer) Start() error

Start begins listening for TCP connections

func (*TCPServer) Stop

func (s *TCPServer) Stop()

Stop gracefully shuts down the server

type UDPServer

UDPServer represents a NetBIOS Name Server UDP component

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

func NewUDPServer

func NewUDPServer(addr string, nbns *NetBIOSNameServer) (*UDPServer, error)

NewUDPServer creates a new NBNS UDP server instance

func (*UDPServer) Start

func (s *UDPServer) Start() error

Start begins listening for UDP packets

func (*UDPServer) Stop

func (s *UDPServer) Stop()

Stop gracefully shuts down the server