SSH
CPTS Notes
- Foundations
- Enumeration with Nmap
- Passwords
- Wordlists
- Cracking
- Protected Files
- Spraying and Defaults
- Hunting (Windows)
- Hunting (Linux)
- Hunting (Shares)
- Hunting (Traffic)
- Looting (Windows)
- Looting (Linux)
- File Services
- FTP
- SMB
- NFS
- Rsync
- Network
- DNS
- SNMP
- SMTP
- Mail Retrieval
- Cloud Mail
- Databases
- MySQL
- MSSQL
- Remote Access
- SSH
- R-Services
- RDP
- WinRM
- WMI
- Linux
- Reading Files
- Editing Files
- Searching Files
- Requests and Transfer
- Local Enumeration
- Privesc Primer
- File Transfer
- Choosing a Method
- Serving Files
- Windows Transfers
- Linux Transfers
- Code One-Liners
- Session Transfers
- Protected Transfers
- Detection & Evasion
- Windows
- Reading Files
- Editing Files
- Searching Files
- Requests and Transfer
- Local Enumeration
- Privesc Primer
- Reference
- Port References
- DNS Resolution
- The Mail Pipeline
- SMB & NetBIOS
TL;DR
SSH (Secure Shell). Encrypted remote shell, file transfer, and tunneling on TCP 22. OpenSSH is the common server. It authenticates by password or by a public and private key pair. SSH-2 is current, and SSH-1 is broken.
First checks: the OpenSSH version from the banner, whether password auth is on, and any private key you have found.
Enumeration
Sweep and audit.
sudo nmap -p22 -sV -oA scans/ssh $TARGET # banner: OpenSSH version and OSssh-audit $TARGET # key-exchange, host-key, and MAC algorithms, weak ones flaggedCheck the auth methods.
ssh -v user@$TARGET # verbose login, lists the auth methodsThe verbose output lists the methods that can continue (publickey, password, keyboard-interactive).
-o PreferredAuthentications=password forces password auth for brute-forcing.
Common misconfigurations
- Password authentication enabled, so logins are brute-forceable.
PermitRootLogin yes.PermitEmptyPasswords yes.- A reused or weak private key, or a key file with loose permissions.
- SSH-1 (
Protocol 1) accepted.
Version exploits
Read the OpenSSH version from the banner first.
- regreSSHion (CVE-2024-6387): unauthenticated RCE as root in OpenSSH 8.5p1 up to 9.7 on glibc Linux. A signal-handler race, slow to win (hours) and rarely practical, but notable.
- User enumeration (CVE-2018-15473): OpenSSH before 7.7 leaks valid usernames through response timing.
Attack playbook
SSH is the login once you hold a credential or a key.
- Use a found private key. Keys turn up in shares, backups, and
.sshdirectories.chmod 600 key # owner-only permissions on the keyssh -i key user@$TARGET # log in with the key - Reuse credentials. Passwords found elsewhere often work here.
- Brute or spray. Last resort, slow, and fail2ban blocks it. Spray one password across users.
See Spraying and Defaults.
nxc ssh $TARGET -u users.txt -p passwords.txt # brute a user and password listhydra -L users.txt -P passwords.txt ssh://$TARGET # hydra does the same
- Run a command.
nxc ssh $TARGET -u <user> -p <pass> -x 'id' # run one command, no full session
Practice boxes
| Box | Difficulty | SSH’s role |
|---|---|---|
| Keeper | Easy | Credentials from a KeePass note log in over SSH for a user shell. |
SSH is rarely the vector itself. It is the shell after you find a credential or a private key.