Skip to content

GetLAPSPassword: fix LAPS v2 password JSON parse#41

Merged
psycep merged 1 commit into
mainfrom
fix-lapsv2-json-parse
Jul 17, 2026
Merged

GetLAPSPassword: fix LAPS v2 password JSON parse#41
psycep merged 1 commit into
mainfrom
fix-lapsv2-json-parse

Conversation

@psycep

@psycep psycep commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

Follow-up from testing #37. Once LAPS v2 decryption worked end-to-end, the tool still failed to parse the recovered password with failed to parse decrypted JSON, leaving the password unusable in the output.

Root cause. The decrypted LAPS v2 blob is UTF-16LE JSON. The parse path scanned the raw UTF-16LE bytes backwards for } (0x7D) and truncated there — but } encodes as the two bytes 7D 00, so it kept the low byte and dropped the high 00. utf16ToString then couldn't pair the orphaned byte and discarded it, silently deleting the closing brace and breaking every parse.

Fix. Decode the full UTF-16LE plaintext (utf16ToString already stops at the first NUL, so NUL-terminated trailing metadata is dropped) and parse with a streaming json.Decoder, which reads exactly one object and ignores any trailing metadata that isn't NUL-delimited. Removes the byte-level brace scan entirely.

Test. Adds a regression test covering the brace-splitting case plus NUL-terminated, trailing-metadata, and password-containing-} variants.

Validation. Verified end-to-end against a live Windows LAPS v2 (encrypted / MS-GKDI) host — the tool now prints the LAPS username and password cleanly where it previously errored.

@google-cla

google-cla Bot commented Jul 17, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

The decrypted LAPS v2 blob is UTF-16LE JSON. The parse path scanned the raw
UTF-16LE bytes backwards for '}' (0x7D) and truncated there, but '}' encodes as
7D 00 - so it kept the low byte and dropped the high 00. utf16ToString then
discarded the orphaned byte, deleting the closing brace and failing every parse.

Decode the full UTF-16LE plaintext (utf16ToString already stops at the first
NUL) and parse with a streaming json.Decoder so trailing metadata after the
object is ignored. Add a regression test for the brace-splitting and
trailing-metadata cases.

Verified end-to-end against a live Windows LAPS v2 (encrypted) host.
@psycep
psycep force-pushed the fix-lapsv2-json-parse branch from 35cf4d3 to e93d2a4 Compare July 17, 2026 03:29
@psycep
psycep merged commit 664122e into main Jul 17, 2026
7 checks passed
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