SSH
SSH Security & Exploitation Guide
1. About SSH
Secure Shell (SSH) is a cryptographic network protocol that enables two computers to establish an encrypted and secure connection over potentially insecure networks.
Default Port:
22/TCPConfiguration File:
/etc/ssh/sshd_config
Check configuration:
cat /etc/ssh/sshd_config | grep -v "#" | sed -r '/^\s*$/d'2. Authentication Methods in OpenSSH
OpenSSH supports six different authentication mechanisms:
Password Authentication – Users log in with username + password.
Public-Key Authentication – Most secure; uses private/public key pairs.
Host-Based Authentication – Trusts authentication from specific hosts.
Keyboard-Interactive Authentication – Step-by-step challenges (MFA).
Challenge-Response Authentication – One-time tokens or OTPs.
GSSAPI Authentication – Kerberos-based authentication.
3. Public Key Authentication (Recommended)
Private Key → Stays on client machine (
id_rsa). Must be kept secret.Public Key → Stored in server’s
~/.ssh/authorized_keys.
Process:
Server sends a challenge encrypted with client’s public key.
Client decrypts with its private key.
Successful validation = secure login without typing password.
File Permissions:
4. Dangerous SSH Config Settings
Be cautious if any of these appear in sshd_config:
PermitRootLogin yes→ Allows direct root logins (should be disabled).PasswordAuthentication yes→ Weaker than key-based authentication.PermitEmptyPasswords yes→ Allows accounts with blank passwords.AllowTcpForwarding yes→ Can be abused for tunneling.X11Forwarding yes→ May allow GUI hijacking.HostbasedAuthentication yes→ Trusts clients too easily.
5. Tools & Exploitation Techniques
SSH Audit
Scan SSH server for weaknesses:
Change Authentication Method
Force SSH to use password authentication:
Use Private Key for Login
Inject Your Own Public Key
If you gain write access to:
→ Add your public key and log in without a password.
Searching for Private Keys on Compromised Systems
6. Tips2Hack
Hunt for exposed private keys in backups, config files, or misconfigured directories.
Abuse weak configs (like
PermitRootLogin yes).Pivot using SSH tunnels:
Bruteforce (last resort): Tools like
hydraormedusacan test credentials, but key-based logins often bypass rate-limiting.
Last updated