# 用户会话与令牌

当我们在一台 Windows 域主机上获得了 **SYSTEM** 权限，我们可以模仿任何在本机登陆的域用户。如果模仿的对象在域内具有其他特权，我们可以利用此来移动到其他主机甚至域。

在 Windows 本机，我们可以有这些方式来查询

#### **进程的拥有者**

我们可以使用程序 **tasklist.exe** 来查询进程的拥有者：

```powershell
tasklist.exe /v
```

[![image.png](https://raven-medicine.com/uploads/images/gallery/2023-03/scaled-1680-/ZKN3JbpCHJQJm7cr-image.png)](https://raven-medicine.com/uploads/images/gallery/2023-03/ZKN3JbpCHJQJm7cr-image.png)

或者 PowerShell 命令 **Get-Process -IncludeUserName**

```powershell
Get-Process -IncludeUserName
```

[![image.png](https://raven-medicine.com/uploads/images/gallery/2023-03/scaled-1680-/wd03LpDK5BlwUnBU-image.png)](https://raven-medicine.com/uploads/images/gallery/2023-03/wd03LpDK5BlwUnBU-image.png)

可惜的是，就 **Web02** 上，并没有发现其他用户的进程，但在别的主机上，也许我们会有意外收获。我们不妨以 sql\_service 用户运行 cmd 程序，然后我们发现了其会话。

[![image.png](https://raven-medicine.com/uploads/images/gallery/2023-03/scaled-1680-/u1Lx9p2mJTsyncqk-image.png)](https://raven-medicine.com/uploads/images/gallery/2023-03/u1Lx9p2mJTsyncqk-image.png)

#### **会话查询**

我们可以通过命令 **query session** 来查询当前主机的会话，会话来源有交互式登陆、RDP登陆、服务执行。

```
query session
```

[![image.png](https://raven-medicine.com/uploads/images/gallery/2023-03/scaled-1680-/Q5gjMEX3MqUNFoYz-image.png)](https://raven-medicine.com/uploads/images/gallery/2023-03/Q5gjMEX3MqUNFoYz-image.png)

我们依旧没有看到其他用户的会话。虽然我们以 sql\_service 身份运行了 cmd 程序，但并不属于三种来源之一。

#### **SharpToken**

我们可以使用工具 SharpToken ([https://github.com/BeichenDream/SharpToken](https://github.com/BeichenDream/SharpToken)) 来枚举当前主机所有可用的令牌，需要在 SYSTEM 权限下使用。

[![image.png](https://raven-medicine.com/uploads/images/gallery/2023-03/scaled-1680-/B9BvNYnFQQQj8On3-image.png)](https://raven-medicine.com/uploads/images/gallery/2023-03/B9BvNYnFQQQj8On3-image.png)

我们之前 runas 的 sql\_service 用户的令牌也能有显示

[![image.png](https://raven-medicine.com/uploads/images/gallery/2023-03/scaled-1680-/KouAxOBUYJQTdIuC-image.png)](https://raven-medicine.com/uploads/images/gallery/2023-03/KouAxOBUYJQTdIuC-image.png)

### **BloodHound**

在 BloodHound 中，我们可以查看部分远程主机的 Sessions 信息，例如，我们从图中得知 file01 上有 John 的会话。

[![image.png](https://raven-medicine.com/uploads/images/gallery/2023-03/scaled-1680-/opeiSU5maccbw42l-image.png)](https://raven-medicine.com/uploads/images/gallery/2023-03/opeiSU5maccbw42l-image.png)

file01 确实当前是 john 登陆。

[![image.png](https://raven-medicine.com/uploads/images/gallery/2023-03/scaled-1680-/CVnn6qEZrE4fLUFJ-image.png)](https://raven-medicine.com/uploads/images/gallery/2023-03/CVnn6qEZrE4fLUFJ-image.png)