SSH Enumeration (Port 22)
Enumerate SSH servers to identify authentication methods, supported algorithms, and potential vulnerabilities.
SSH is typically well-secured, but misconfigurations, weak keys, or credential reuse can provide initial access.
Quick Reference
# Banner grabbing |
Banner Grabbing
# Using netcat |
Authentication Methods
# List supported authentication methods |
Nmap NSE Scripts
# SSH host key |
Brute Force
# Hydra |
Credential Stuffing
# NetExec (1:1 user:pass mapping) |
SSH Key Authentication
# Connect with private key |
SSH Tunneling
# Local port forwarding |
File Transfer
# SCP - Copy file to remote |
SSH Configuration
# View SSH client configuration |
Common Workflow
# Step 1: Banner grabbing |
Notes
SSH Version Information:
Banner format: SSH-<protocol_version>-<software_version>
Example: SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.1
- Protocol: SSH-2.0 (only accept SSH-2 protocol)
- Software: OpenSSH version 8.2p1
- OS: Ubuntu
Authentication Methods:
- password: Traditional username/password
- publickey: SSH key-based authentication
- keyboard-interactive: Interactive prompts (often used for 2FA)
- gssapi-with-mic: Kerberos authentication
- hostbased: Host-based authentication
Common SSH Ports:
- Port 22: Default SSH
- Port 2222: Alternative SSH port
- Port 22000-22999: Custom SSH ports
Weak Algorithms to Look For:
Encryption:
- 3des-cbc
- aes128-cbc, aes192-cbc, aes256-cbc
- arcfour, arcfour128, arcfour256
MAC:
- hmac-md5
- hmac-sha1-96
- hmac-md5-96
Key Exchange:
- diffie-hellman-group1-sha1
- diffie-hellman-group14-sha1
SSH Misconfigurations:
| Setting | Risk | Description |
|---|---|---|
PermitRootLogin yes |
High | Allows direct root login |
PasswordAuthentication yes |
Medium | Allows password-based auth (brute force risk) |
PermitEmptyPasswords yes |
Critical | Allows accounts with no password |
PubkeyAuthentication no |
Low | Disables more secure key-based auth |
Protocol 1 |
Critical | Uses deprecated SSHv1 protocol |
X11Forwarding yes |
Medium | Can be abused for privilege escalation |
Common Vulnerabilities:
- CVE-2018-15473: Username enumeration
- CVE-2016-20012: Pre-auth double free (OpenSSH < 8.7)
- CVE-2021-41617: Privilege escalation
- Weak host keys: Predictable or shared keys
- Default credentials: Vendor default passwords
SSH Key Cracking:
# Convert SSH private key to John format |
Username Enumeration:
Some SSH versions are vulnerable to username enumeration:
# Using Metasploit |
SSH Escape Sequences:
When connected to SSH:
~.- Disconnect~^Z- Background SSH~#- List forwarded connections~?- Display help
Best Practices for Testing:
- Always check SSH version for known vulnerabilities
- Test for username enumeration
- Check for weak algorithms
- Try default credentials before brute forcing
- Look for exposed SSH keys in web directories, Git repos
- Check for SSH key reuse across multiple systems
- Monitor for account lockout policies
- Use credential stuffing before brute force (less noisy)
Defensive Recommendations:
- Disable root login
- Use key-based authentication only
- Implement fail2ban or similar
- Change default port (security through obscurity)
- Use strong ciphers and MACs
- Enable SSH protocol 2 only
- Implement 2FA/MFA
- Monitor SSH logs for brute force attempts
- Use AllowUsers/AllowGroups to restrict access