Private Keys
Adversaries may search for private key and certificate files on compromised systems. Private keys (.key, .pem, .pfx, .p12, .ppk, .pgp, .gpg, .asc) are used for authentication, encryption, and digital signatures. SSH private keys enable key-based lateral movement. TLS/SSL private keys enable HTTPS interception. Code signing certificates enable payload signing for defense evasion. PGP keys decrypt archived data. Adversaries including Machete, Kinsing, Hildegard, Mafalda, and various APT groups actively harvest private keys. Mimikatz's CRYPTO::Extract module extracts keys via Windows CNG API. On network devices, 'crypto pki export' extracts PKI credentials.
// Detect private key file access and search
let KeyExtensions = dynamic([".pem", ".pfx", ".p12", ".key", ".ppk", ".pgp", ".gpg", ".asc", ".crt", ".cer", ".p7b"]);
let KeyDirectories = dynamic([".ssh", "ssl", "certs", "certificates", "keys", "private"]);
DeviceFileEvents
| where Timestamp > ago(24h)
| where ActionType in ("FileRead", "FileAccessed", "FileCopied")
| where (
(FileName endswith ".pem" or FileName endswith ".pfx" or FileName endswith ".p12"
or FileName endswith ".key" or FileName endswith ".ppk" or FileName endswith ".pgp"
or FileName endswith ".gpg" or FileName endswith ".asc")
or FileName in~ ("id_rsa", "id_ecdsa", "id_ed25519", "id_dsa")
)
// Exclude legitimate apps (ssh, scp, openssl) reading their own keys
| where InitiatingProcessFileName !in~ ("ssh", "scp", "sftp", "openssl", "gpg", "putty", "backup.exe")
| project Timestamp, DeviceName, InitiatingProcessAccountName, FolderPath, FileName,
InitiatingProcessFileName, InitiatingProcessCommandLine
| union (
// Detect search commands targeting private key file extensions
DeviceProcessEvents
| where Timestamp > ago(24h)
| where ProcessCommandLine has_any (KeyExtensions)
| where ProcessCommandLine has_any ("find ", "dir /s", "Get-ChildItem", "ls -la",
"findstr", "locate", "mimikatz")
| project Timestamp, DeviceName, AccountName, FileName, ProcessCommandLine, InitiatingProcessFileName
)
| sort by Timestamp desc Data Sources
Required Tables
False Positives
- SSH and SCP clients legitimately reading their own private key files for authentication (ssh -i, scp -i)
- Web servers and applications reading their own TLS certificate private keys on startup (Apache, Nginx, IIS)
- Certificate management tools (certbot, Let's Encrypt clients) managing certificate lifecycle
- Backup agents reading certificate directories as part of full system backup
- Key management systems and HSM integration software reading and rotating keys
References (6)
- https://attack.mitre.org/techniques/T1552/004/
- https://github.com/redcanaryco/atomic-red-team/blob/master/atomics/T1552.004/T1552.004.md
- https://adsecurity.org/?p=2870
- https://www.unit42.paloaltonetworks.com/hildegard-malware-teamtnt/
- https://www.aquasec.com/blog/kinsing-malware-operations/
- https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/certutil
Unlock Pro Content
Get the full detection package for T1552.004 including response playbook, investigation guide, and atomic red team tests.