Skip to main content

Overview

The ntlm module provides a complete implementation of the NT LAN Manager (NTLM) authentication protocol, including NTLMv1, NTLMv2, and NTLM2 Session Security. It handles challenge-response authentication, hash generation, and session key derivation.

Key Functions

getNTLMSSPType1()

Create an NTLM Type 1 (Negotiate) message.
str
default:"''"
Workstation name to send in negotiate message
str
default:"''"
Domain name to send
bool
default:"False"
Whether message signing is required
bool
default:"True"
Use NTLMv2 protocol (recommended)
VERSION
OS version structure to include
NTLMAuthNegotiate
Type 1 message object

getNTLMSSPType3()

Create an NTLM Type 3 (Authenticate) message.
NTLMAuthNegotiate
required
Type 1 message from getNTLMSSPType1()
bytes
required
Type 2 (Challenge) message from server
str
required
Username for authentication
str
required
Password (not used if hashes provided)
str
required
Domain name
str
default:"''"
LM hash (hex string)
str
default:"''"
NT hash (hex string)
bool
default:"True"
Use NTLMv2 (recommended)
bytes
default:"b''"
Channel binding data for EPA (Extended Protection for Authentication)
str
default:"'cifs'"
Service principal name (e.g., ‘cifs’, ‘http’, ‘ldap’)
NTLMAuthChallengeResponse
Type 3 authenticate message
bytes
Session key for signing/encryption

Hash Computation

compute_lmhash()

Compute LM hash from password.
str
required
Password to hash (only Latin-1 characters supported)
bytes
16-byte LM hash
If password contains non-Latin-1 characters, returns the default empty LM hash.

compute_nthash()

Compute NT hash from password.
str
required
Password to hash (Unicode supported)
bytes
16-byte NT hash (MD4 of Unicode password)

Response Computation

computeResponse()

Compute NTLM challenge response.
int
required
NTLM negotiation flags
bytes
required
8-byte challenge from server
bytes
required
8-byte client challenge
bytes
required
Target information from Type 2 message
str
required
Domain name
str
required
Username
str
required
Password
str
default:"''"
Pre-computed LM hash
str
default:"''"
Pre-computed NT hash
bool
default:"True"
Use NTLMv2 protocol
bytes
NT response
bytes
LM response
bytes
Base session key

Signing and Sealing

SIGN()

Sign a message.
int
required
NTLM flags
bytes
required
Signing key from SIGNKEY()
bytes
required
Message to sign
int
required
Sequence number
callable
required
RC4 cipher function
NTLMMessageSignature
Message signature

SEAL()

Encrypt and sign a message.
int
required
NTLM flags
bytes
required
Signing key
bytes
required
Sealing (encryption) key
bytes
required
Message data for signature
bytes
required
Message data to encrypt
int
required
Sequence number
callable
required
RC4 cipher function
bytes
Encrypted message
NTLMMessageSignature
Message signature

SIGNKEY()

Derive signing key from session key.
int
required
NTLM flags
bytes
required
Random session key
str
default:"'Client'"
Direction: 'Client' or 'Server'
bytes
Signing key

SEALKEY()

Derive sealing (encryption) key from session key.
int
required
NTLM flags
bytes
required
Random session key
str
default:"'Client'"
Direction: 'Client' or 'Server'
bytes
Sealing key (encryption key)

Classes

NTLMAuthNegotiate

NTLM Type 1 (Negotiate) message.
int
Negotiation flags
bytes
Domain name
bytes
Workstation name
VERSION
OS version structure

NTLMAuthChallenge

NTLM Type 2 (Challenge) message.
bytes
8-byte server challenge
bytes
AV_PAIRS structure with server information
int
Server’s negotiation flags
bytes
Target domain

NTLMAuthChallengeResponse

NTLM Type 3 (Authenticate) message.
bytes
NT response
bytes
LM response
bytes
Username (UTF-16LE)
bytes
Domain name (UTF-16LE)
bytes
Workstation name (UTF-16LE)
bytes
Encrypted random session key
int
Negotiation flags

AV_PAIRS

Attribute-Value pairs for target information.
bytes
Server hostname
bytes
Domain name
bytes
DNS hostname
bytes
DNS domain name
bytes
Timestamp
bytes
Target SPN
bytes
Channel binding data

Constants

NTLM Flags

AV Pair Types

Global Settings

Usage Examples

Basic NTLM Authentication Flow

Pass-the-Hash Authentication

Computing Password Hashes

Message Signing

Message Encryption (Sealing)

Working with AV_PAIRS

HTTP NTLM Authentication

Extracting User Information

Security Considerations

NTLMv1 is deprecated and insecure. Always use NTLMv2 when possible by setting use_ntlmv2=True.
LM hashes are weak and should not be used for authentication. They are computed only from the first 14 characters of passwords converted to uppercase.

Best Practices

  1. Use NTLMv2 - Set ntlm.USE_NTLMv2 = True globally
  2. Enable signing - Use NTLMSSP_NEGOTIATE_SIGN flag
  3. Enable sealing - Use NTLMSSP_NEGOTIATE_SEAL for encryption
  4. Strong passwords - Use complex passwords to prevent hash cracking
  5. Extended session security - Enable NTLMSSP_NEGOTIATE_EXTENDED_SESSIONSECURITY

Helper Functions

NTOWFv2()

Compute NTLMv2 hash.

LMOWFv2()

Compute LMv2 hash.

hmac_md5()

Compute HMAC-MD5.

See Also

  • SMBConnection - Uses NTLM for authentication
  • SMB - SMB protocol with NTLM support