# 票据传递 Pass The Ticket

票据传递技术类似于密钥传递技术，只不过相比使用密钥，用的是票据。在讲解 PTT 之前，我们先来了解一下在 Windows 与 Linux 平台上有关域凭证的文件，它们可以通过工具实现互相转换。

##### **kirbi**

我们通过 Mimikatz 或者 rubeus 请求与导出的 TGT 或者 TGS票据格式为 kirbi。对于 Mimikatz，我们可以使用命令 **sekurlsa::ticket /export** 导出所有票据，格式为 kirbi。

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

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

 如果使用 Rubeus，可以使用 **rubeus.exe dump** 命令导出目前所有票据。

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

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

当然，我们可以指定导出哪些票据。先通过 r**ubeus.exe triage** 命令查看当前所有的登陆会话以及对应的票据，再通过 **/luid** 参数指定要导出票据的登陆会话。

```powershell
rubeus.exe triage
rubeus.exe dump /luid:<登陆会话 ID> /nowrap
```

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

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

至于将文本保存为 kirbi 文件，在Windows端，我们可以通过如下的 Powershell 命令保存 kirbi 文件。在 Linux 端，我们可以通过命令 **echo '&lt;ticket&gt;' | base64 -d &gt; example.kirbi** 实现。

```powershell
[System.IO.File]::WriteAllBytes("<目标地址>", [System.Convert]::FromBase64String("<票据>"))
```

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

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

##### **ccache**

在 Linux端，如果 Linux 主机上有活跃的会话，那么在 **/tmp** 目录下会产生该用户的凭证缓存文件，Credential Cache，即 ccache 文件，格式为 krb5cc\_xxx，例如krb5cc\_1394201122\_MerMmG。ccache 文件中保存了该用户的**票据信息**，例如 TGT，TGS 等。在 Linux 域主机上，环境变量 **KRB5CCNAME** 指向了票据的地址，以获得域用户的上下文。我们也可以通过命令 **export KRB5CCNAME=&lt;ccache 文件地址&gt;** 来手动更改环境变量。

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

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

我们可以通过 Impacket 的 **ticketConverter** 脚本将票据在 **ccache** 与 **kirbi** 形式中互相转换。

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

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

ccache 文件仅对应域用户以及 **root** 用户可读。如果作为活跃用户，我们可以通过 **kinit** 申请新的 TGT，以及通过 **kvno \[SPN\]** 申请新的 TGS。

##### **keytab**

keytab 文件包含 **Kerberos 主体名称**和**凭证**，例如NTLM哈希。我们在之前提到过可以使用脚本 ([https://github.com/sosdave/KeyTabExtract](https://github.com/sosdave/KeyTabExtract)) 从中提取 **NTLM** 或者 **AES256** 凭证，那么在此基础上我们想要获得其他格式的票据自然不是难事。每台 Linux 域计算机的 **/etc/krb5.keytab** 文件是其 keytab 文件，默认情况下可由 root 访问。

类似于 PTH，一些工具例如 Impacket 支持直接使用 keytab 进行认证。

[![image.png](http://raven-medicine.com/uploads/images/gallery/2022-10/scaled-1680-/VPxW683nY4KjT1YL-image.png)](http://raven-medicine.com/uploads/images/gallery/2022-10/VPxW683nY4KjT1YL-image.png)

好了，在了解了以上几种凭证文件类型后，我们来讨论如何利用及导入票据。

##### **Windows 端票据传递**

在 Windows 端，我们主要可以使用 Mimikatz 以及 Rubeus 等工具来导入票据。Cobalt Strike 则支持 **kerberos\_ticket\_use** 或 **kerberos\_ccache\_use** 命令来实现。

在 CobaltStrike 中通过 **make\_token** 命令生成一个**牺牲会话**，然后导入要传递的票据。至于创建一个牺牲会话后再导入凭证，原因在 Windows 认证原理小节中有提过，新导入的 TGT 会**替换原有的**，可能导致**认证紊乱**，而新创建的牺牲会话中尚无 TGT。

然后，我们能在其他主机上以 **white-bird\\serveradm** 身份顺利访问 Web02 的 **C$**。

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

##### **Linux 端票据传递**

而在 Linux 端传递票据的话，我们先需要将 kirbi 文件转换为 ccache 格式，然后设置 **KRB5CCNAME** 环境变量，之后就可以使用票据认证了。

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