# FreeIPA Pentesting

<details>

<summary><strong>从零开始学习 AWS 黑客技术，成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE（HackTricks AWS 红队专家）</strong></a><strong>！</strong></summary>

支持 HackTricks 的其他方式：

* 如果您想看到您的**公司在 HackTricks 中做广告**或**下载 PDF 版的 HackTricks**，请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
* 获取[**官方 PEASS & HackTricks 商品**](https://peass.creator-spring.com)
* 探索[**PEASS 家族**](https://opensea.io/collection/the-peass-family)，我们的独家[**NFTs**](https://opensea.io/collection/the-peass-family)
* **加入** 💬 [**Discord 群组**](https://discord.gg/hRep4RUj7f) 或 [**电报群组**](https://t.me/peass) 或在 **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks_live)\*\* 上关注\*\*我们。
* 通过向 [**HackTricks**](https://github.com/carlospolop/hacktricks) 和 [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github 仓库提交 PR 来分享您的黑客技巧。

</details>

## 基本信息

FreeIPA 是 Microsoft Windows Active Directory 的开源**替代品**，主要用于**Unix**环境。它将完整的**LDAP 目录**与类似 Active Directory 的 MIT **Kerberos**密钥分发中心相结合。使用 Dogtag **证书系统**进行 CA 和 RA 证书管理，支持包括智能卡在内的**多因素**身份验证。SSSD 用于 Unix 认证流程的集成。

## 指纹

### 文件和环境变量

* 位于 `/etc/krb5.conf` 的文件存储着 Kerberos 客户端信息，这对于加入域是必要的，其中包括 KDC 和管理员服务器的位置、默认设置和映射。
* 位于 `/etc/ipa/default.conf` 的文件设置了 IPA 客户端和服务器的系统范围默认值。
* 域内的主机必须在 `/etc/krb5.keytab` 处拥有一个 `krb5.keytab` 文件，用于认证流程。
* 各种环境变量（`KRB5CCNAME`、`KRB5_KTNAME`、`KRB5_CONFIG`、`KRB5_KDC_PROFILE`、`KRB5RCACHETYPE`、`KRB5RCACHEDIR`、`KRB5_TRACE`、`KRB5_CLIENT_KTNAME`、`KPROP_PORT`）用于指向与 Kerberos 认证相关的特定文件和设置。

### 二进制文件

诸如 `ipa`、`kdestroy`、`kinit`、`klist`、`kpasswd`、`ksu`、`kswitch` 和 `kvno` 等工具是管理 FreeIPA 域、处理 Kerberos 票证、更改密码以及获取服务票证等功能的核心。

### 网络

提供了一个示意图，描述了典型的 FreeIPA 服务器设置。

## 认证

FreeIPA 中的认证利用**Kerberos**，与**Active Directory**中的认证类似。访问域资源需要有效的 Kerberos 票证，这些票证可以根据 FreeIPA 域配置的不同存储在不同位置。

### **CCACHE 票证文件**

CCACHE 文件通常存储在 **`/tmp`** 中，权限为 **600**，是用于存储 Kerberos 凭据的二进制格式，由于其可移植性，对于无需用户明文密码进行认证很重要。使用 `klist` 命令可以解析 CCACHE 票证，重用有效的 CCACHE 票证涉及将 `KRB5CCNAME` 导出到票证文件的路径。

### **Unix 密钥环**

另外，CCACHE 票证可以存储在 Linux 密钥环中，提供对票证管理的更多控制。票证存储的范围不同（`KEYRING:name`、`KEYRING:process:name`、`KEYRING:thread:name`、`KEYRING:session:name`、`KEYRING:persistent:uidnumber`），`klist` 能够解析用户的此信息。然而，从 Unix 密钥环中重用 CCACHE 票证可能会带来挑战，可使用类似 **Tickey** 的工具来提取 Kerberos 票证。

### Keytab

包含 Kerberos 主体和加密密钥的 Keytab 文件对于获取有效的票证授予票证（TGT）而无需主体密码至关重要。使用像 `klist` 这样的实用程序和类似 **KeytabParser** 的脚本可以轻松地解析和重用来自 Keytab 文件的凭据。

### 备忘单

您可以在以下链接中找到有关如何在 Linux 中使用票证的更多信息：

{% content-ref url="/pages/vwkbw9fjwklhIqjHRNV4" %}
[Linux Active Directory](/linux-hardening/privilege-escalation/linux-active-directory.md)
{% endcontent-ref %}

## 枚举

{% hint style="warning" %}
您可以通过 **ldap** 和其他 **二进制**工具执行**枚举**，或**连接到 FreeIPA 服务器的端口 443 上的网页**进行枚举。
{% endhint %}

### 主机、用户和组 <a href="#id-4b3b" id="id-4b3b"></a>

可以创建**主机**、**用户**和**组**。主机和用户被分类到分别称为“**主机组**”和“**用户组**”的容器中。这类似于**组织单位**（OU）。

在 FreeIPA 中，默认情况下，LDAP 服务器允许**匿名绑定**，并且大量数据可以在**未经身份验证**的情况下枚举。这可以枚举所有可用的未经身份验证的数据：

```
ldapsearch -x
```

要获取更多信息，您需要使用一个经过身份验证的会话（请查看身份验证部分以了解如何准备经过身份验证的会话）。

```bash
# Get all users of domain
ldapsearch -Y gssapi -b "cn=users,cn=compat,dc=domain_name,dc=local"

# Get users groups
ldapsearch -Y gssapi -b "cn=groups,cn=accounts,dc=domain_name,dc=local"

# Get all the hosts
ldapsearch -Y gssapi -b "cn=computers,cn=accounts,dc=domain_name,dc=local"

# Get hosts groups
ldapsearch -Y gssapi -b "cn=hostgroups,cn=accounts,dc=domain_name,dc=local"
```

从加入域的计算机，您可以使用**已安装的二进制文件**来枚举域：

```bash
ipa user-find
ipa usergroup-find
ipa host-find
ipa host-group-find

-------------------

ipa user-show <username> --all
ipa usergroup-show <user group> --all
ipa host-find <host> --all
ipa hostgroup-show <host group> --all
```

{% hint style="info" %}
**FreeIPA**的**管理员**用户相当于**AD**中的**域管理员**。
{% endhint %}

### Hashes <a href="#id-482b" id="id-482b"></a>

**IPA服务器**的**root**用户可以访问密码**哈希**。

* 用户的密码哈希以**base64**形式存储在“**userPassword**”**属性**中。该哈希可能是**SSHA512**（旧版本的FreeIPA）或**PBKDF2\_SHA256**。
* 如果系统与**AD**集成，密码的**Nthash**以**base64**形式存储在“**ipaNTHash**”中。

要破解这些哈希：

• 如果FreeIPA与AD集成，**ipaNTHash**容易破解：您应该**解码** **base64** -> 重新编码为**ASCII**十六进制 -> John The Ripper或**hashcat**可以帮助您快速破解

• 如果使用旧版本的FreeIPA，那么使用**SSHA512**：您应该解码**base64** -> 找到SSHA512 **哈希** -> John The Ripper或**hashcat**可以帮助您破解

• 如果使用新版本的FreeIPA，那么使用**PBKDF2\_SHA256**：您应该解码**base64** -> 找到PBKDF2\_SHA256 -> 其**长度**为256字节。John可以处理256位（32字节）-> SHA-265用作伪随机函数，块大小为32字节 -> 您只能使用PBKDF2\_SHA256哈希的前256位 -> John The Ripper或hashcat可以帮助您破解

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

要提取哈希，您需要成为**FreeIPA服务器**中的**root**用户，然后可以使用工具\*\*`dbscan`\*\*来提取它们：

<figure><img src="/files/2eZBPpBwJriw96YAfpsI" alt=""><figcaption></figcaption></figure>

### HBAC-Rules <a href="#id-482b" id="id-482b"></a>

这些规则授予用户或主机对资源（主机、服务、服务组等）的特定权限。

```bash
# Enumerate using ldap
ldapsearch -Y gssapi -b "cn=hbac,dc=domain_name,dc=local"
# Using ipa
ipa hbacrule-find
# Show info of rule
ipa hbacrule-show <hbacrule> --all
```

#### Sudo规则

FreeIPA通过sudo规则实现对**sudo权限**的集中控制。这些规则允许或限制在域内的主机上使用sudo执行命令。攻击者可能通过检查这些规则集来识别适用的主机、用户和允许的命令。

```bash
# Enumerate using ldap
ldapsearch -Y gssapi -b "cn=sudorules,cn=sudo,dc=domain_name,dc=local"
# Using ipa
ipa sudorule-find
# Show info of rule
ipa sudorule-show <sudorule> --all
```

### 基于角色的访问控制

一个**角色**由各种**特权**组成，每个特权包含一组**权限**。这些角色可以分配给用户、用户**组**、**主机**、主机组和服务。例如，考虑默认的FreeIPA中的“用户管理员”角色来说明这种结构。

`用户管理员`角色具有以下特权：

* **用户管理员**
* **组管理员**
* **阶段用户管理员**

通过以下命令可以枚举角色、特权和权限：

```bash
# Using ldap
ldapsearch -Y gssapi -b "cn=roles,cn=accounts,dc=westeros,dc=local"
# Using ipa binary
ipa role-find
ipa role-show <role> --all
ipa privilege-find
ipa privilege-show <privilege> --all
ipa permission-find
ipa permission-show <permission> --all
```

### 攻击场景示例

在<https://posts.specterops.io/attacking-freeipa-part-iii-finding-a-path-677405b5b95e>中，您可以找到一个简单的示例，说明如何滥用某些权限来 compromise 该域。

### Linikatz/LinikatzV2

* <https://github.com/Orange-Cyberdefense/LinikatzV2>
* <https://github.com/CiscoCXSecurity/linikatz>

## 提权

### ~~root 用户创建~~

{% hint style="warning" %}
如果您可以**创建一个名为 `root` 的新用户**，您可以冒充他，从而能够**以 root 身份 SSH 进入任何机器**。

**此问题已修复。**
{% endhint %}

您可以在<https://posts.specterops.io/attacking-freeipa-part-iv-cve-2020-10747-7c373a1bf66b>中查看详细说明。

## 参考资料

* <https://posts.specterops.io/attacking-freeipa-part-iv-cve-2020-10747-7c373a1bf66b>
* <https://posts.specterops.io/attacking-freeipa-part-i-authentication-77e73d837d6a>
* <https://posts.specterops.io/attacking-freeipa-part-ii-enumeration-ad27224371e1>
* <https://www.youtube.com/watch?v=9dOu-7BTwPQ>

<details>

<summary><strong>从零开始学习 AWS 黑客技术，成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE（HackTricks AWS 红队专家）</strong></a><strong>！</strong></summary>

支持 HackTricks 的其他方式：

* 如果您想在 HackTricks 中看到您的**公司广告**或**下载 PDF 版本的 HackTricks**，请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
* 获取[**官方 PEASS & HackTricks 商品**](https://peass.creator-spring.com)
* 探索[**PEASS 家族**](https://opensea.io/collection/the-peass-family)，我们的独家[**NFT**](https://opensea.io/collection/the-peass-family)收藏品
* **加入** 💬 [**Discord 群组**](https://discord.gg/hRep4RUj7f) 或 [**电报群组**](https://t.me/peass) 或在 **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks_live)\*\* 上关注我们\*\*。
* 通过向 [**HackTricks**](https://github.com/carlospolop/hacktricks) 和 [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github 仓库提交 PR 来分享您的黑客技巧。

</details>


---

# Agent Instructions: 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:

```
GET https://hacktricks.xsx.tw/linux-hardening/freeipa-pentesting.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
