# 用户与组

用户与组是域的重要组成部分，并且组是用户的容器，在同一个组里的用户具有特定的相同属性。对于用户和组的枚举，自然是我们首先要做的，因为很多漏洞和不当配置的利用都是围绕着用户与组、主机、服务等展开的。

### **准备工作**

我们可以使用多种工具对域内的用于和组进行枚举，这里，我们使用 **PowerView** 脚本。我们可以通过 **powershell-import** 导入脚本，然后使用 **powershell** 或者 **powerpick** 命令进行脚本命令执行。

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

**Web02** 在 **white-bird.local** 域中，我们可以进而对该域进行枚举。虽然我们还没有正式学到域信任的概念，在课程介绍阶段，大家了解到 **white-bird.local** 与 **raven-med.local** 域互相信任，当然也包括了 Web01 主机所在的 **prod** 子域。简单来说，可以互相访问对方域的资源，至少可以枚举对方域的域信息。例如，我们在 Web02 主机上以 **white-bird\\serveradm** 的身份枚举到了 PROD 域中的所有域用户的账户名称，通过 **-domain** 指定要枚举的域。Web01 是一台 Linux 的域主机，如果一些学员对在 Linux 域主机的枚举还不熟悉的话，我们可以以这样的方式跨域枚举。

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

好了，补充了工具用法与简单的理论知识，我们来枚举域的用户与群组信息。

### **用户的枚举**

在枚举域用户的时候，我们需要关注以下这些属性：

##### **用户描述**

虽然很多时候用户描述可能是空白的，但如果不是空白的话，用户描述可能会揭露域用户的角色。 如服务器管理员、开发人员等。

```powershell
Get-NetUser | select description
```

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

我们没有发现什么特别的，然后看看 **raven-med.local** 域的：

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

我们发现 **simon** 的描述是 **CA Manager**，这也许意味着 **simon** 具有 **CA** 相关的权限，我们发现 **simon** 是分组 **CertManager** 的成员。

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

##### **预认证**

如果某些域用户禁用了预认证 ，我们可以使用 **ASREPRoasting** 攻击他们并获取 **krb5asrep** 哈希。 如果幸运的话，我们有可能离线破解这些哈希并获得明文凭证。在现代化的 **AD** 环境中，已经没有必要禁用预认证了，从安全与防御的角度出发，系统管理员应当给所有账户开启域认证。

```powershell
Get-NetUser -PreAuthNotRequired
```

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

在当前域，是没有符合条件的用户存在的，看看其他的域，发现了用户 jason 不需要预认证。

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

##### **SPN**

如果一个域用户被设置了SPN，那么它是一个**服务帐号**。我们可以对它们进行 **Kerberoasting** 攻击并获取 **krb5tgs** 哈希。 如果幸运的话，我们可能离线破解这些哈希并获得用户的明文凭证。

```powershell
Get-NetUser -SPN
```

我们发现，账户 **sql\_service** 与 **krbtgt** 被设置了 **SPN**。**sql\_service** 看起来就是一个 SQL 的服务账户，而 krbtgt 总是会被设置 SPN，但实际并不可利用。

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

##### **组归属**

每个域用户至少属于“**域用户**”组，但如果有任何域用户属于多个组，那么他们往往可能具有特别的权限，例如可以访问某台主机上的共享目录。

```powershell
Get-NetUser | select samaccountname,memberof
```

更适合通过 **BloodHound** (后续内容介绍) 查看成员与组的关系。

我们以当前用户 **serveradm** 为例，发现其来自群组 **Server Admin**。

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

查看 **Server Admin** 群组信息，根据描述得知，该组成员可以管理 **Web02** 与 **Dev01** 主机，因此 **serveradm** 可能对这 **2** 个主机具有远程访问权限，甚至最高权限 (root 和 Administrator)

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

##### **外部成员**

如果一个外部成员被拿下了，我们可借此移动到该外部成员原来所在的域。

```powershell
Get-DomainForeignUser
```

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

在我们可访问的域里，并没有发现外部成员。但是，我们发现，**raven-med.local** 中的用户 **michael**，在名为 **ExtAdmin** 的分组中。**ExtAdmin** 让人联想到 **External Administrator**，那么会不会代表 **michael** 在其他一个我们目前无法访问的域里充当着外部成员呢？这个只能在我们获得了更多的系统和域后验证了。

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

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

### **组的枚举**

而在枚举组的时候，我们需要关注一下这些

##### **组描述**

类似于用户描述。不过有很多组是内置的，因此描述也是统一的。

```powershell
Get-NetGroup | select samaccountname,description
```

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

我们查看 **raven-medicine.local** 域中的 **Cert Manager** 组的描述：

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

##### **组类型**

如果一个组并非是内置的，而是自定义的，例如**Server Admins**，那么我们需要多关注一下，因为这个组可能具有特定的权限，例如对 SQL 服务器具备本地管理员权限。

在当前域中，我们已经查看过了自定义分组 **Server Admin** 了

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

在 PROD 域中，有 1 个自定义分组，**Security Team**

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

例如在 raven-medicine.local 域中，有 2 个自定义的分组，**CertManager** 和 **ExtAdm**

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

##### **外部组**

意义同外部成员。

```powershell
Get-DomainForeignGroupMember
```

我们没有在当前域中找到相关记录

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

但是在 PROD 域中，我们找到了一些外部组，这是合理的，因为 PROD 和 RAVEN-MED 域是父子域。

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