Skip to content

fix: SSH key regex false positive with ImageMagick mime.xml#546

Merged
carlospolop merged 1 commit intopeass-ng:masterfrom
JohannesLks:fix/ssh-key-regex-false-positive
Jan 16, 2026
Merged

fix: SSH key regex false positive with ImageMagick mime.xml#546
carlospolop merged 1 commit intopeass-ng:masterfrom
JohannesLks:fix/ssh-key-regex-false-positive

Conversation

@JohannesLks
Copy link
Copy Markdown
Contributor

Fixes #526
The regex -----BEGIN .* PRIVATE KEY.*----- was matching -----BEGIN PGP PRIVATE KEY BLOCK----- in /etc/ImageMagick-6/mime.xml, causing a false positive for SSH keys.

Fixed by removing the trailing .* before ----- so the regex now requires the key header to end directly with -----, which excludes PGP key definitions that have BLOCK-----` at the end.

Tested key types still detected:

  • RSA PRIVATE KEY
  • EC PRIVATE KEY
  • OPENSSH PRIVATE KEY
  • DSA PRIVATE KEY

The regex '-----BEGIN .* PRIVATE KEY.*-----' was matching
'-----BEGIN PGP PRIVATE KEY BLOCK-----' in /etc/ImageMagick-6/mime.xml,
causing a false positive for SSH keys.

Fixed by removing the trailing .* before ----- so the regex now requires
the key header to end directly with -----, which excludes PGP key
definitions that have 'BLOCK-----' at the end.

Tested key types still detected:
- RSA PRIVATE KEY
- EC PRIVATE KEY
- OPENSSH PRIVATE KEY
- DSA PRIVATE KEY
@carlospolop
Copy link
Copy Markdown
Collaborator

Might this exclude other real private keys?

@JohannesLks
Copy link
Copy Markdown
Contributor Author

@carlospolop No, the fix should be safe.
But you are indeed correct that any private key with text after KEY would not be detected. But I am not aware of any.
According to ssh-keygen manual, all supported key types (rsa, ecdsa, ecdsa-sk, ed25519, ed25519-sk) generate one of these headers:

  • OpenSSH format : -----BEGIN OPENSSH PRIVATE KEY-----
  • Legacy PEM: -----BEGIN RSA/EC/DSA PRIVATE KEY-----
  • Encrypted: -----BEGIN ENCRYPTED PRIVATE KEY-----

RFC 7468 defines all standard PEM labels for private keys, and none of them have text after PRIVATE KEY.

The generic PKCS#8 header -----BEGIN PRIVATE KEY----- is not matched by the regex, but this was already the case before this fix and ssh-keygen never generates this format anyway.

@carlospolop carlospolop merged commit bf9d474 into peass-ng:master Jan 16, 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.

ImageMagick "SSH key" false positive

2 participants