Skip to content

Fix false-positive successes, locale bugs, and clean-list formatting - #3

Open
TheSulak3 wants to merge 8 commits into
bradselph:masterfrom
TheSulak3:master
Open

Fix false-positive successes, locale bugs, and clean-list formatting#3
TheSulak3 wants to merge 8 commits into
bradselph:masterfrom
TheSulak3:master

Conversation

@TheSulak3

Copy link
Copy Markdown

Summary

  • Admin-privilege detection: several commands (e.g. Get-Tpm, Confirm-SecureBootUEFI) print a localized "administrator privileges required" message to stdout while still exiting 0, so they were previously logged as SUCCESS with the error text recorded as data. Added detection for these phrases (and for PowerShell's empty-table-with-no-error output pattern) so they now correctly report FAILED with a clear reason. Also added an Administrator: Yes/No line to report headers and a startup warning when not elevated.
  • Fixed a Windows command-line quoting bug: piping a command containing embedded quotes (e.g. findstr /C:"OS Serial Number") through exec.Command("cmd.exe","/C", fullCommand) got double-escaped by Go's default Windows argument handling, splitting the quoted phrase into bogus separate file-open attempts. Now uses syscall.SysProcAttr.CmdLine directly to bypass the re-escaping.
  • Removed locale-dependent findstr label parsing: the "Windows Product ID (Alternative)" and "MAC Addresses (IPConfig)" checks searched for English-only labels ("OS Serial Number", "Physical Address") in systeminfo/ipconfig output, which don't exist on non-English Windows installs. Replaced both with locale-independent CIM/PowerShell equivalents.
  • Fixed garbled "Clean HWID List" output: the clean-list extractor used one generic header-stripping heuristic for every command, which worked for single-value wmic output but glued every row of MAC adapter tables, volume tables, and TPM property lists into one unreadable line. Added dedicated extractors (regex MAC pulling with dedup, TPM property summary, volume drive/size parsing) dispatched by check description.
  • Added a TPM Endorsement Key check: Win32_Tpm has no serial number property, so added Get-TpmEndorsementKeyInfo as the closest thing to a real per-chip TPM identifier.

Test plan

  • Built and ran the full detailed scan (option 12) and clean list (option 13) both elevated and non-elevated on a real Windows machine (Spanish locale) — went from 87.5% to 100% success rate on the elevated run, with no more garbled multi-column output in the clean list.

Get-Tpm and other elevated commands print a localized "requires
administrator" message to stdout while still exiting 0, so the
tool logged them as SUCCESS with error text as data. Now detects
these privilege-denied phrases and reports FAILED correctly, and
surfaces admin status in the console and report header.
CmdLine now bypasses Go's default Windows arg re-escaping so quoted
findstr patterns (e.g. /C:"OS Serial Number") reach cmd.exe intact
instead of being split into bogus file-open attempts. The Windows
Product ID (Alternative) and MAC Addresses (IPConfig) checks also
relied on English-only systeminfo/ipconfig labels that don't exist
on non-English Windows installs; replaced both with locale-independent
CIM/PowerShell equivalents.
extractCleanValue used a generic header-stripping heuristic that
worked for single-value wmic output but glued every row of MAC
adapter tables, volume tables, and TPM property lists into one
unreadable line. Added dedicated extractors: regex-based MAC
address pulling (dedup, locale-independent), TPM property summary,
and volume drive/size parsing, dispatched by check description.
Win32_Tpm has no SerialNumber property; the EK public key hash is
the closest thing to a real per-chip identifier, retrieved via
Get-TpmEndorsementKeyInfo. That cmdlet returns an empty formatted
table (header + dashes, no data, exit 0) instead of an error when
not elevated, which slipped past the existing success checks as a
false SUCCESS with no actual data. Added isEmptyTableOutput to
catch that pattern generally. Also dropped the EK fallback command,
which used an invalid -HashAlgorithm value and always errored.
Get-TpmEndorsementKeyInfo writes its "administrator privileges
required" message through a channel that gets silently dropped
once a downstream Select-Object stage exists in the pipeline, so
the check always looked like an empty result with no explanation
regardless of the real cause. Running it unpiped lets the actual
message reach stdout/stderr, where isPrivilegeError now catches it
correctly.
Menu, examples, and output samples were still describing the old
12-option/14-check version. Documents the current 15-option menu,
17-check scan, Clean HWID List, Compare Scans, Administrator
detection, and the recent locale/false-success fixes.
Adds a native check that replicates how Samuel Tulach's tpm-info.exe
reads the EK: NCryptOpenStorageProvider + NCryptGetProperty against
the Microsoft Platform Crypto Provider directly (ncrypt.dll), rather
than going through PowerShell's Get-TpmEndorsementKeyInfo. The raw
BCRYPT_RSAPUBLIC_BLOB is DER-encoded as a PKCS#1 RSAPublicKey and
hashed with MD5/SHA1/SHA256, matching tpm-info.exe's output exactly
(verified byte-for-byte against the real tool). Notably this route
works without Administrator privileges, unlike the PowerShell cmdlet.
Adds a note (console + written into the detailed report file) right
after both EK checks run, explaining that they read the same physical
key but hash different byte encodings of it: Get-TpmEndorsementKeyInfo
hashes Microsoft's internal PublicKeyHash property, while the Tulach
Method hashes a PKCS#1 DER encoding of the raw key pulled via ncrypt.dll
directly. Otherwise the differing strings look like a bug or a sign the
two methods disagree about the actual key.
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