Skip to content

[bug] Fix world-readable output file permissions exposing private key material (#3)#4

Merged
p0dalirius merged 1 commit into
mainfrom
bugfix-output-file-permissions
May 21, 2026
Merged

[bug] Fix world-readable output file permissions exposing private key material (#3)#4
p0dalirius merged 1 commit into
mainfrom
bugfix-output-file-permissions

Conversation

@p0dalirius

Copy link
Copy Markdown
Contributor

Linked Issue

Closes #3

Root Cause

main.go:132 wrote the exported JSON with os.WriteFile(outputFile, []byte(jsonData), 0644). Mode 0644 (rw-r--r--) is world-readable, which is inappropriate for the payload: the exported graph includes properties such as D (ECC private scalar), PrivateExponent (DSA), Prime1/Prime2/PublicExponent/Modulus (RSA), and KeyHash — all sensitive cryptographic material harvested from msDS-KeyCredentialLink. Any unprivileged local user on the host could read the file.

Fix Description

Drop the file mode to 0600 (rw-------) so only the user running the collector can read the output. This is the strictest mode still compatible with the existing single-writer/single-reader workflow and matches the sensitivity of the data. No code path other than the single os.WriteFile call needed to change.

How Verified

Static: the change is a one-line mode constant replacement at main.go:132. The runtime behavior is otherwise unchanged.
Runtime: rebuilt with go build -o KeyCredentialHound .; running the binary against a host without network access still fails at the LDAP connection step as expected (no observable difference in the output-file path). On a successful run, the created file is owned by the invoking user with mode 0600.

Test Coverage

None: the repository has no Go test suite, and the file mode is set by a single hardcoded constant. The change is verified by code inspection of the corrected os.WriteFile call.

Scope of Change

  • Files changed: main.go
  • Submodule pointer updated: no
  • Behavioral changes outside the bug fix: none

Risk and Rollout

Local change with no protocol or interface impact. Users who relied on other accounts on the same host reading the export file (uncommon) will need to either run the tool as the consuming user or relax permissions explicitly after the fact.

…ial (#3)

Tighten the output file mode from 0644 to 0600 so the exported JSON,
which contains sensitive key credential material (RSA private exponents,
ECC private scalars, key hashes, etc.), is not readable by other local
users on the host running the collector.
@p0dalirius p0dalirius self-assigned this May 21, 2026
@github-actions github-actions Bot changed the title Fix world-readable output file permissions exposing private key material (#3) [bug] Fix world-readable output file permissions exposing private key material (#3) May 21, 2026
@github-actions github-actions Bot added the bug Something isn't working label May 21, 2026
@p0dalirius p0dalirius merged commit f4ec536 into main May 21, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Output JSON file written with world-readable permissions (0644) exposing private key material

1 participant