# Leakage

## nmap

```
mdkir nmap
sudo rustscan -a 172.31.1.6 --ulimit 5000 -- -T4 -A -oA nmap/all-ports-service-scan
```

A web server on port 80 is open

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-MjLFE8kI5GosblizckN%2F-MjLF_X0tv5cwp4r9yOO%2Fimage.png?alt=media&#x26;token=d00c319d-859d-462a-b099-deef59b36752" alt=""></div>

Upon checking, looks like it has GitLab installed

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-MjLFE8kI5GosblizckN%2F-MjLG06GwTQO_yklE6um%2Fimage.png?alt=media&#x26;token=f6e7449c-9f37-4e2d-8d76-6a9f6107c4bd" alt=""></div>

## Web enumeration

First, create a GitLab account, and log in. Once logged in, check the projects section. You will notice there's a public repository of Jonathan.

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-MjLFE8kI5GosblizckN%2F-MjLGRhFL2kQby779ORl%2Fimage.png?alt=media&#x26;token=8d2fe341-9ba8-48c8-9e2c-dae85b2bd984" alt=""></div>

The CMS repository sounds interesting, let's take a look and check the commit logs.

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-MjLFE8kI5GosblizckN%2F-MjLH2AKbWF-Mgro5229%2Fimage.png?alt=media&#x26;token=07e18f4d-ec3a-4e17-a1ed-8203c2708547" alt=""></div>

Click at the third commit, you will see credentials that have been removed.

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-MjLFE8kI5GosblizckN%2F-MjLHF7GOjPi1V6dl9Nu%2Fimage.png?alt=media&#x26;token=8620019e-e2cc-4df7-9c11-4050451bbe86" alt=""></div>

Take note the `SQL_LOGIN` and `SQL_PWD` of user `jonathan` then use this credential to log in on GitLab.

![](https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-MjLFE8kI5GosblizckN%2F-MjLHc0KQlpBxiNBByDi%2Fimage.png?alt=media\&token=2e50d58c-47de-4138-a8f4-0838e5028abe)

Upon logging in, there's an interesting repository called `security`.&#x20;

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-MjLFE8kI5GosblizckN%2F-MjLHn9ccvQOsxv9Nq6n%2Fimage.png?alt=media&#x26;token=b179f6c4-d413-4e50-9db7-e6b0721642dd" alt=""></div>

Right out of the bat, you will see the shiny gold called `id_rsa`. Let's copy it to our local machine.

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-MjLFE8kI5GosblizckN%2F-MjLI9hHHnNF2vfuko_6%2Fimage.png?alt=media&#x26;token=33bd29e6-49dc-4a78-9163-eb0606b6ad5f" alt=""></div>

## Exploitation

Looks like the private SSH key has a password.

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-MjLFE8kI5GosblizckN%2F-MjLILFp2DMcbTDiNqNt%2Fimage.png?alt=media&#x26;token=fd4d7794-3fda-4df6-9746-09fc3fdede1c" alt=""></div>

Let's perform a dictionary attack using `john`

```
ssh2john jonathan_id_rsa > jonathan_id_rsa.ssh2john 
john jonathan_id_rsa.ssh2john -w=/opt/wordlist/rockyou.txt  
```

After a few seconds, we got the password. Sweet :D

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-MjLFE8kI5GosblizckN%2F-MjLIzwsvFBsiGP0vQPz%2Fimage.png?alt=media&#x26;token=6cc958cf-53d6-4a79-8477-909d24c8b471" alt=""></div>

Now we can log in using the private SSH key, the password, and the username we have found.

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-MjLFE8kI5GosblizckN%2F-MjLJDv1IVTxBmZUga-3%2Fimage.png?alt=media&#x26;token=c5ff59d7-dfae-4c65-b328-36b6c1189eae" alt=""></div>

## Post Exploitation

First, let's transfer `linpeas.sh` from our machine to the target machine

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-MjLFE8kI5GosblizckN%2F-MjLJvqVRB3yHkU8wvIB%2Fimage.png?alt=media&#x26;token=a4be8869-c76e-4f58-9d4e-478719412a39" alt=""></div>

You can find the machine IP address by executing the following.

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-MjLFE8kI5GosblizckN%2F-MjLJlQmKAy8Lv1YB3j4%2Fimage.png?alt=media&#x26;token=30e4ef44-beab-481e-b607-305299e81824" alt=""></div>

Then transfer the script using `wget`

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-MjLFE8kI5GosblizckN%2F-MjLK42p8npxCVf4ALhf%2Fimage.png?alt=media&#x26;token=8634e687-6c6d-4aef-8bf8-b2f581846eb0" alt=""></div>

And run `linpeas.sh`

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-MjLFE8kI5GosblizckN%2F-MjLKDLu04cey2sEAB7q%2Fimage.png?alt=media&#x26;token=8c57b43b-3fef-4f69-9290-19bf3a7a6675" alt=""></div>

After quite some time, looks like the SUID of `/bin/nano` is set. We can use this to gain root by writing a new user on /etc/passwd.

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-MjLFE8kI5GosblizckN%2F-MjLLp1XiDZLgDKMIWuT%2Fimage.png?alt=media&#x26;token=d7281590-2f55-433d-b84e-e037ba3eda03" alt=""></div>

First, execute `nano /etc/passwd` to get to editing mode. And at the very bottom, paste the following and hit save.

```
root2:WVLY0mgH0RtUI:0:0:root:/root:/bin/bash
```

Now we can log in, as root with password `mrcake`

```
jonathan@leakage:~$ su root2                                                                                                                                                                                       
Password: mrcake                                                                                                                                                                                                          
root@leakage:/home/jonathan#  
```

Thanks, and enjoy!
