SSH Lateral Movement with Harvested Keys
Private keys found during post-exploitation are one of the most reliable lateral movement paths on Linux environments. A single key harvested from one host frequently authenticates to several others — especially in environments where the same key pair is deployed to multiple servers by a sysadmin or automation.
This page covers using those keys to move. Finding and harvesting the keys themselves is covered in SSH Keys and Agent Harvesting.
Locating Keys to Use
Private keys collected during post-exploitation are typically found at:
Check permissions before using — SSH refuses to use a key with overly permissive permissions:
Identifying Target Hosts from Known_Hosts
The known_hosts file records every host the key owner has connected to. This is a direct list of lateral movement targets.
Modern systems hash the hostnames by default. Unhash them with:
For a more complete parse including hashed entries:
Compare the scanned fingerprint against entries in known_hosts to confirm a match without connecting.
Identifying Targets from SSH Config
The per-user SSH config often hardcodes hosts, users, and key paths for specific connections:
Host jumpbox
HostName 10.10.20.5
User deploy
IdentityFile ~/.ssh/deploy_key
Host prod-*
User ubuntu
IdentityFile ~/.ssh/id_rsa
Every Host block is a lateral movement lead. The IdentityFile tells you exactly which key to use for that host.
Checking Authorized Keys on the Current Host
authorized_keys lists every public key permitted to authenticate. Cross-reference this against any private keys you have — if a public key in authorized_keys on another host matches a private key you hold, you can authenticate.
Connecting with a Harvested Key
If the key requires a passphrase and you have it:
-o StrictHostKeyChecking=no skips the host fingerprint prompt, useful for scripted access to multiple hosts. Suppress the known_hosts write as well if you want to avoid leaving traces:
Testing a Key Against Multiple Hosts
When you have a subnet of potential targets from ARP or routing enumeration, test a key across all of them:
Replace /tmp/targets.txt with a list of IPs identified during network awareness.
Host Key Files
SSH host keys at /etc/ssh/ssh_host_*_key are private keys used by the SSH daemon itself. They are normally root-readable only, but if accessible — for example after a privilege escalation — they can be used to impersonate the host in man-in-the-middle scenarios or to authenticate where the host key has been added to authorized_keys on another system.
References
-
ssh_config(5)man.openbsd.org/ssh_config.5 (opens in new tab)
OpenBSD manual page Full reference for SSH client config file options including Host, IdentityFile, and StrictHostKeyChecking.
-
ssh-keygen(1)man.openbsd.org/ssh-keygen.1 (opens in new tab)
OpenBSD manual page Reference for key generation, fingerprinting, and known_hosts operations including unhashing entries.
Was this helpful?
Your feedback helps improve this page.