the_open_door
coffee
ESEN
← Back to index

PuTTY private key reuse (.ppk)

ATT&CKT1552.004

An SSH private key stored in a password manager, in a backup .zip or in a Windows user profile is usually not in OpenSSH format: it is in PuTTY's, which is the client it was generated with. And the header says so on the first line:

PuTTY-User-Key-File-3: ssh-rsa
Encryption: none
Comment: rsa-key-20230519
Public-Lines: 6
...
Private-Lines: 14
...
Private-MAC: b0a0fd2edf4f0e557200121aa673732c9e76750739db05adc3ab65ec34c55cb0

Recognising the header saves you fighting an ssh -i that is never going to work. PuTTY-User-Key-File-3 (or -2) is not a -----BEGIN OPENSSH PRIVATE KEY-----, and ssh rejects it with a format error that does not say the format is the problem.

There are two routes and both work:


puttygen key.ppk -O private-openssh -o id_rsa       # convert
chmod 600 id_rsa && ssh -i id_rsa root@<host>

putty                                               # or use the client that understands it

On the PuTTY route the key is loaded under Connection > SSH > Auth > Credentials and the host under Session. It authenticates just the same, and the session says so on login: Authenticating with public key "rsa-key-20230519".

The Encryption: line decides whether there is work to do. With none, the key is in the clear and is used as-is. With aes256-cbc it has a passphrase, and then this is cracking material: john has a format of its own (PuTTY) that attacks it without converting it.

Two things worth checking in the same place the key turned up:

It belongs to the family of proprietary formats that store credentials and have to be recognised before they can be used: .pfx files, SolarPuTTY sessions, KeePass dumps and PortableKanban.

Requirements#

Read access to the .ppk file (or to the entry holding it) and the matching public key still present in the target's authorized_keys. With Encryption: none nothing else is needed; with a passphrase, crack it first.

How to detect it. The detection is not in the use of the key (an SSH public-key logon is exactly what normal looks like) but in where it comes from: the same rsa-key-<date> authenticating from a new address, or a root key used from outside the administration network. On the host, /var/log/auth.log records the fingerprint of the key used to log in (Accepted publickey ... SHA256:...), so a baseline of which key comes from where turns this into an alert. And before any of that, file access: a .ppk read by an account that does not own it.

Defence. Private keys do not belong in shared password managers or in notes fields, least of all without a passphrase: an unencrypted key is a cleartext password with more bytes. If they must be stored, store them with a passphrase and restrict the public key at the destination (command=, from= in authorized_keys). And root keys should not exist: log in as a user and escalate through an audited rule.

Machines where it's used