telnetmini

package
v3.7.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package telnetmini is a library for interacting with Telnet servers. it supports

Index

Constants

View Source
const (
	// SMB Commands
	SMB_COM_NEGOTIATE_PROTOCOL = 0x72
	SMB_COM_SESSION_SETUP_ANDX = 0x73
	SMB_COM_TREE_CONNECT_ANDX  = 0x75
	SMB_COM_NT_CREATE_ANDX     = 0xA2
	SMB_COM_READ_ANDX          = 0x2E
	SMB_COM_WRITE_ANDX         = 0x2F
	SMB_COM_CLOSE              = 0x04
	SMB_COM_TREE_DISCONNECT    = 0x71
	SMB_COM_LOGOFF_ANDX        = 0x74

	// SMB Flags
	SMB_FLAGS_CANONICAL_PATHNAMES              = 0x10
	SMB_FLAGS_CASELESS_PATHNAMES               = 0x08
	SMB_FLAGS2_UNICODE_STRINGS                 = 0x8000
	SMB_FLAGS2_ERRSTATUS                       = 0x4000
	SMB_FLAGS2_READ_IF_EXECUTE                 = 0x2000
	SMB_FLAGS2_32_BIT_ERRORS                   = 0x1000
	SMB_FLAGS2_DFS                             = 0x0800
	SMB_FLAGS2_EXTENDED_SECURITY               = 0x0400
	SMB_FLAGS2_REPARSE_PATH                    = 0x0200
	SMB_FLAGS2_SMB_SECURITY_SIGNATURE          = 0x0100
	SMB_FLAGS2_SMB_SECURITY_SIGNATURE_REQUIRED = 0x0080

	// SMB Security modes
	SMB_SECURITY_SHARE  = 0x00
	SMB_SECURITY_USER   = 0x01
	SMB_SECURITY_DOMAIN = 0x02

	// SMB Capabilities
	SMB_CAP_EXTENDED_SECURITY  = 0x80000000
	SMB_CAP_COMPRESSED_DATA    = 0x40000000
	SMB_CAP_BULK_TRANSFER      = 0x20000000
	SMB_CAP_UNIX               = 0x00800000
	SMB_CAP_LARGE_READX        = 0x00400000
	SMB_CAP_LARGE_WRITEX       = 0x00200000
	SMB_CAP_INFOLEVEL_PASSTHRU = 0x00100000
	SMB_CAP_DFS                = 0x00080000
	SMB_CAP_NT_FIND            = 0x00040000
	SMB_CAP_LOCK_AND_READ      = 0x00020000
	SMB_CAP_LEVEL_II_OPLOCKS   = 0x00010000
	SMB_CAP_STATUS32           = 0x00008000
	SMB_CAP_RPC_REMOTE_APIS    = 0x00004000
	SMB_CAP_NT_SMBS            = 0x00002000

	// NTLM constants
	NTLMSSP_NEGOTIATE_56                        = 0x80000000
	NTLMSSP_NEGOTIATE_KEY_EXCH                  = 0x40000000
	NTLMSSP_NEGOTIATE_128                       = 0x20000000
	NTLMSSP_NEGOTIATE_VERSION                   = 0x02000000
	NTLMSSP_NEGOTIATE_TARGET_INFO               = 0x00800000
	NTLMSSP_REQUEST_NON_NT_SESSION_KEY          = 0x00400000
	NTLMSSP_NEGOTIATE_IDENTIFY                  = 0x00100000
	NTLMSSP_NEGOTIATE_EXTENDED_SESSION_SECURITY = 0x00080000
	NTLMSSP_TARGET_TYPE_SERVER                  = 0x00020000
	NTLMSSP_NEGOTIATE_ALWAYS_SIGN               = 0x00008000
	NTLMSSP_NEGOTIATE_NTLM                      = 0x00000200
	NTLMSSP_NEGOTIATE_LM_KEY                    = 0x00000080
	NTLMSSP_NEGOTIATE_DATAGRAM                  = 0x00000040
	NTLMSSP_NEGOTIATE_SEAL                      = 0x00000020
	NTLMSSP_NEGOTIATE_SIGN                      = 0x00000010
	NTLMSSP_REQUEST_TARGET                      = 0x00000004
	NTLMSSP_NEGOTIATE_UNICODE                   = 0x00000001
)

SMB constants for packet crafting

View Source
const (
	IAC     = 255 // Interpret As Command
	WILL    = 251 // Will
	WONT    = 252 // Won't
	DO      = 253 // Do
	DONT    = 254 // Don't
	SB      = 250 // Subnegotiation Begin
	SE      = 240 // Subnegotiation End
	ENCRYPT = 38  // Encryption option (0x26)
)

Telnet protocol constants

Variables

This section is empty.

Functions

func CalculateTimestampSkew

func CalculateTimestampSkew(ntlmTimestamp uint64) int64

CalculateTimestampSkew calculates the time skew from NTLM timestamp This implements the timestamp calculation from the Nmap script: local unixstamp = ntlm_decoded.timestamp // 10000000 - 11644473600

func CreateLMResponse

func CreateLMResponse(challenge []byte, password string) []byte

Helper function to create LM hash response

func CreateNTCreatePacket

func CreateNTCreatePacket(fileName string) []byte

CreateNTCreatePacket creates an SMB NT create packet

func CreateNTLMAuthPacket

func CreateNTLMAuthPacket(username, password, domain, workstation string, challenge []byte, lmResponse, ntResponse []byte) []byte

CreateNTLMAuthPacket creates an NTLM authenticate packet

func CreateNTLMChallengePacket

func CreateNTLMChallengePacket(challenge []byte, targetInfo []byte) []byte

CreateNTLMChallengePacket creates an NTLM challenge packet (for testing)

func CreateNTLMNegotiateBlob

func CreateNTLMNegotiateBlob() []byte

CreateNTLMNegotiateBlob creates the NTLM negotiate blob with specific flags This matches the flags used in the Nmap script

func CreateNTLMNegotiatePacket

func CreateNTLMNegotiatePacket() []byte

CreateNTLMNegotiatePacket creates an NTLM negotiate packet for SMB authentication

func CreateNTResponse

func CreateNTResponse(challenge []byte, password string) []byte

Helper function to create NT hash response

func CreateNegotiateProtocolPacket

func CreateNegotiateProtocolPacket() []byte

CreateNegotiateProtocolPacket creates an SMB negotiate protocol packet

func CreateSMBv2NegotiatePacket

func CreateSMBv2NegotiatePacket() []byte

CreateSMBv2NegotiatePacket creates an SMBv2 negotiate protocol packet

func CreateSessionSetupPacket

func CreateSessionSetupPacket(username, password, domain string, sessionKey uint64) []byte

CreateSessionSetupPacket creates an SMB session setup packet

func CreateTNAPLoginPacket

func CreateTNAPLoginPacket() []byte

CreateTNAPLoginPacket creates the MS-TNAP Login Packet (Option Command IS) This implements the exact packet structure from the Nmap script

func CreateTreeConnectPacket

func CreateTreeConnectPacket(shareName string, password string) []byte

CreateTreeConnectPacket creates an SMB tree connect packet

Types

type Client

type Client struct {
	Conn net.Conn

	LoginPrompts    []string // matched case-insensitively
	UserPrompts     []string // alternative to LoginPrompts; if empty, LoginPrompts used for username step
	PasswordPrompts []string
	FailBanners     []string // e.g., "login incorrect", "authentication failed"
	ShellPrompts    []string // e.g., "$ ", "# ", "> "
	ReadCapBytes    int      // safety cap while scanning (default 64 KiB)
	// contains filtered or unexported fields
}

Client wraps a Telnet connection with tiny helpers.

func New

func New(conn net.Conn) *Client

New wraps an existing net.Conn.

func (*Client) Auth

func (c *Client) Auth(ctx context.Context, username, password string) error

Auth performs a minimal Telnet username/password interaction. It waits for a username/login prompt, sends username, waits for a password prompt, sends password, and then looks for fail banners or shell prompts. A timeout should be enforced via ctx.

func (*Client) Close

func (c *Client) Close() error

Close closes the underlying connection.

func (*Client) Defaults

func (c *Client) Defaults()

Defaults sets reasonable prompt patterns if none provided.

func (*Client) Exec

func (c *Client) Exec(ctx context.Context, command string, until ...string) (string, error)

Exec sends a command followed by CRLF and returns text captured until one of the provided prompts appears (typically your shell prompt). Provide a deadline via ctx.

type EncryptionInfo

type EncryptionInfo struct {
	SupportsEncryption bool
	Banner             string
	Options            map[int][]int
}

EncryptionInfo contains information about telnet encryption support

func DetectEncryption

func DetectEncryption(conn net.Conn, timeout time.Duration) (*EncryptionInfo, error)

DetectEncryption detects if a telnet server supports encryption. Based on Nmap's telnet-encryption.nse script functionality. WARNING: The connection becomes unusable after calling this function due to the encryption negotiation packets sent.

type NTLMInfoResponse

type NTLMInfoResponse struct {
	TargetName          string // Target_Name from script
	NetBIOSDomainName   string // NetBIOS_Domain_Name from script
	NetBIOSComputerName string // NetBIOS_Computer_Name from script
	DNSDomainName       string // DNS_Domain_Name from script
	DNSComputerName     string // DNS_Computer_Name from script
	DNSTreeName         string // DNS_Tree_Name from script
	ProductVersion      string // Product_Version from script
	Timestamp           uint64 // Raw timestamp for skew calculation
}

NTLMInfoResponse represents the response from NTLM information gathering This matches exactly the output structure from the Nmap telnet-ntlm-info.nse script

func ParseNTLMResponse

func ParseNTLMResponse(data []byte) (*NTLMInfoResponse, error)

ParseNTLMResponse parses the NTLM response to extract system information This implements the exact parsing logic from the Nmap telnet-ntlm-info.nse script

type SMBHeader

type SMBHeader struct {
	ProtocolID  [4]byte // 0xFF, 'S', 'M', 'B'
	Command     byte
	Status      uint32
	Flags       byte
	Flags2      uint16
	PIDHigh     uint16
	Signature   [8]byte
	Reserved    uint16
	TreeID      uint16
	ProcessID   uint16
	UserID      uint16
	MultiplexID uint16
}

SMBHeader represents the SMB header structure

func ParseSMBResponse

func ParseSMBResponse(data []byte) (*SMBHeader, error)

ParseSMBResponse parses an SMB response packet

type SMBPacket

type SMBPacket struct {
	NetBIOSHeader []byte
	SMBHeader     []byte
	SMBData       []byte
}

SMBPacket represents a complete SMB packet

func CreateSMBPacket

func CreateSMBPacket(smbData []byte) *SMBPacket

CreateSMBPacket creates a complete SMB packet with NetBIOS header

func (*SMBPacket) Bytes

func (p *SMBPacket) Bytes() []byte

Bytes returns the complete SMB packet as bytes

Jump to

Keyboard shortcuts

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