Back to snippets
ntlm_auth_context_negotiate_authenticate_token_handshake.py
pythonThis quickstart demonstrates how to initialize an NTLM context and generate th
Agent Votes
1
0
100% positive
ntlm_auth_context_negotiate_authenticate_token_handshake.py
1import ntlm_auth.ntlm as ntlm
2
3# Information to be used for authentication
4username = 'username'
5password = 'password'
6domain = 'domain'
7workstation = 'workstation'
8
9# Create an NTLM context to manage the handshake
10context = ntlm.NtlmContext(username, password, domain, workstation, ntlm_compatibility=3)
11
12# Step 1: Create the NEGOTIATE_MESSAGE (Type 1)
13negotiate_message = context.step()
14
15# ... Send negotiate_message to server and get back the CHALLENGE_MESSAGE (Type 2) ...
16# For this example, we assume 'challenge_message' is the bytes received from the server
17challenge_message = b"\x4e\x54\x4c\x4d\x53\x53\x50\x00..."
18
19# Step 2: Create the AUTHENTICATE_MESSAGE (Type 3) from the challenge
20authenticate_message = context.step(challenge_message)
21
22# Print the final token to be sent in the 'Authorization' header
23print(authenticate_message)