Skip to content

feat(ntlmv2+winrm): fix NTLMv2 crypto primitives, add targetinfo helpers, refactor WinRM auth#77

Open
0xbbuddha wants to merge 4 commits intoTheManticoreProject:mainfrom
0xbbuddha:main
Open

feat(ntlmv2+winrm): fix NTLMv2 crypto primitives, add targetinfo helpers, refactor WinRM auth#77
0xbbuddha wants to merge 4 commits intoTheManticoreProject:mainfrom
0xbbuddha:main

Conversation

@0xbbuddha
Copy link
Copy Markdown

@0xbbuddha 0xbbuddha commented Mar 28, 2026

Description

Summary

  • crypto/ntlmv2: removal of broken NTResponse / LMResponse methods (they used the NTHash directly, without a blob); addition of ComputeNTChallengeResponse, ComputeLMChallengeResponse, ComputeSessionBaseKey in accordance with the MS-NLMP 3.3.2 specification; fix to ComputeResponse (the timestamp had been commented out); cleanup of NTOWFv2; addition of a complete test suite (6 tests with RFC vectors).
  • crypto/spnego/ntlm/targetinfo: addition of helpers HasTimestamp, GetTimestamp, BuildBlobTargetInfo to handle TargetInfo (MsvAvTimestamp, MsvAvFlags / MIC bit).
  • crypto/spnego/ntlm/message/authenticate: fix to CreateAuthenticateMessage in the EXTENDED_SESSIONSECURITY path to use the corrected ntlmv2 primitives.
  • network/winrm/client/session.go: refactoring of buildNTLMv2AuthBytes to use crypto/ntlmv2 and targetinfo; removal of 3 inline private helpers: ntlmTargetInfoGetAvValue, ntlmBuildBlobTargetInfo, ntlmTargetInfoHasAvId.

PS: Sorry, winrm and ntlmv2 ended up in the same PR. I simply hadn’t paid attention to the roadmap, so I decided to adapt it to take ntlmv2 into account.

  Implements a WinRM client library (MS-WSMV over HTTP, port 5985/5986)
  with full NTLMv2 message-level sealing (SIGN + SEAL + KEY_EXCH) as
  required by the Windows WinRM service.

  Public API:
    c := client.NewClient(host, port)
    c.Connect()
    err := c.SessionSetup(creds)

  Structure:
    network/winrm/types/       — protocol constants
    network/winrm/transport/   — raw TCP transport (NTLM connection-binding)
    network/winrm/client/      — Client, SessionSetup, NTLM sealing pipeline
…pers

  - Remove broken NTResponse/LMResponse (used NTHash instead of
    ResponseKeyNT, no blob — incorrect per MS-NLMP 3.3.2)
  - Add ComputeNTChallengeResponse: builds proper blob with timestamp,
    client challenge and TargetInfo; returns (NTChallengeResponse, NTProofStr)
  - Add ComputeLMChallengeResponse: returns Z(24) when MsvAvTimestamp
    present, otherwise HMAC+ClientChallenge (24 bytes)
  - Add ComputeSessionBaseKey: HMAC-MD5(ResponseKeyNT, NTProofStr)
  - Fix ComputeResponse: timestamp was commented out, sig changed to []byte
  - Add BuildBlobTargetInfo/HasTimestamp/GetTimestamp to targetinfo package
  - Fix CreateAuthenticateMessage to use the above instead of broken methods
  - Add tests for NTOWFv2, response structure and Z(24) rule
…ytes

  Replace ~80 lines of inline NTLMv2 crypto in session.go with calls to
  the cleaned-up crypto/ntlmv2 and targetinfo packages. Remove the three
  private helpers ntlmTargetInfoGetAvValue, ntlmBuildBlobTargetInfo, and
  ntlmTargetInfoHasAvId — their logic now lives in the shared packages.
@0xbbuddha 0xbbuddha changed the title feat(winrm): add WinRM client with NTLM authentication feat(ntlmv2+winrm): fix NTLMv2 crypto primitives, add targetinfo helpers, refactor WinRM auth Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant