NTLM Authentication Library

1.5.0 · active · verified Sat Apr 11

ntlm-auth is a Python library designed to create NTLM authentication structures, supporting NTLMv1 and NTLMv2, MIC for message integrity, channel binding tokens, and message signing/sealing. The current version is 1.5.0, with releases occurring periodically to add features and improve compatibility, though not on a strict schedule.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the three-step NTLM authentication handshake using the `NtlmContext` class: creating a Type 1 Negotiate message, processing a (simulated) Type 2 Challenge message from the server, and generating a Type 3 Authenticate message. In a real application, the Type 2 message bytes would be received from the server.

from ntlm_auth.ntlm import NtlmContext
import base64

# Replace with your actual username and password
username = "DOMAIN\\username" # or just "username" for local accounts
password = "your_password"

# 1. Client creates a Type 1 Negotiate message
context = NtlmContext(username=username, password=password)
type1_message = context.create_negotiate_message()
print(f"Type 1 (Negotiate) message: {base64.b64encode(type1_message).decode()}")

# 2. Server (simulated) responds with a Type 2 Challenge message
# In a real scenario, this would come from the server
# Example Type 2 challenge bytes (replace with actual server response)
# This is a dummy example, actual challenge bytes would be different.
# You can often capture this from network traffic or server logs.
dummy_type2_challenge_bytes = (
    b'\x4e\x54\x4c\x4d\x53\x53\x50\x00\x02\x00\x00\x00\x08\x00\x08\x00\x38\x00\x00\x00\x01\x82\x88\xe2\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x06\x01\x0c\x00\x00\x00\x00\x0f')

# Client processes the Type 2 message
# The context state is updated with server details.
type2_processed = context.create_challenge_message(dummy_type2_challenge_bytes)
print(f"Type 2 (Challenge) processed, context updated.")

# 3. Client creates a Type 3 Authenticate message
type3_message = context.create_authenticate_message()
print(f"Type 3 (Authenticate) message: {base64.b64encode(type3_message).decode()}")

# This Type 3 message would then be sent to the server for authentication.

view raw JSON →