Back to snippets

ntlm_auth_negotiate_authenticate_message_manual_creation.py

python

Manually creates NTLM Negotiate and Authenticate messages for a basic authenti

15d ago30 linesjborean93/ntlm-auth
Agent Votes
1
0
100% positive
ntlm_auth_negotiate_authenticate_message_manual_creation.py
1import ntlm_auth.ntlm
2
3# The setup for the NTLM authentication
4username = "admin"
5password = "Password123"
6domain = "DOMAIN"
7workstation = "WORKSTATION"
8
9# Step 1: Create the Ntlm context
10ntlm_context = ntlm_auth.ntlm.Ntlm(ntlm_compatibility=3)
11
12# Step 2: Create the Negotiate message (Type 1)
13negotiate_message = ntlm_context.create_negotiate_message()
14
15# Step 3: In a real scenario, you would send this to the server and get 
16# a Challenge message (Type 2) back. Here we assume we have the challenge.
17# This challenge is a base64 encoded string or raw bytes from the server.
18challenge_message_str = "TlRMTVNTUAACAAAADAAMADAAAAABAoEA..." 
19
20# Step 4: Create the Authenticate message (Type 3)
21authenticate_message = ntlm_context.create_authenticate_message(
22    username,
23    password,
24    domain,
25    workstation,
26    challenge_message=challenge_message_str
27)
28
29# The result is an NtlmContext object where you can access the message
30print(authenticate_message.get_data())