m4lwhere/profilehound

GitHub: m4lwhere/profilehound

ProfileHound 是一款通过枚举域内计算机用户配置文件并生成 BloodHound 自定义图边来辅助红队定向窃取凭据的后渗透工具。

Stars: 162 | Forks: 9

``` ____ _____ __ __ __ __ / __ \_________ / __(_) /__ / / / /___ __ ______ ____/ / / /_/ / ___/ __ \/ /_/ / / _ \/ /_/ / __ \/ / / / __ \/ __ / / ____/ / / /_/ / __/ / / __/ __ / /_/ / /_/ / / / / /_/ / /_/ /_/ \____/_/ /_/_/\___/_/ /_/\____/\__,_/_/ /_/\__,_/ ``` # ProfileHound ProfileHound 是一款提权后工具,旨在通过定位域用户在计算机上的配置文件,帮助红队发现并达成目标。它使用 BloodHound 的 OpenGraph 格式构建了一条名为 `HasUserProfile` 的新边,用于确定计算机上是否存在某个用户配置文件。这条边使得操作人员能够做出明智的决策,确定应该以哪些计算机为目标来窃取机密。 此工具需要对目标计算机上的 `C$` 共享拥有管理员访问权限,才能枚举用户配置文件。 特别感谢 Remi Gascou ([@podalirius](https://github.com/p0dalirius)) 提供的 [ShareHound](https://github.com/p0dalirius/ShareHound) 和 [bhopengraph](https://github.com/p0dalirius/bhopengraph) 工具。我一直想构建一个工具来收集这些数据,而使用这些库让我能够将精力集中在核心功能上,而不是基础代码的编写。 ## 为什么需要它? 在 Active Directory 中,后渗透目标已经从本地存储的数据转向了 SaaS 应用程序和云端。为了在攻防演练中证明攻击价值,我们需要展示如何攻陷这些服务的访问权限。在许多情况下,这些服务仅由特定的组或用户(如 HR、财务等)使用。在某些场景下,特定的 SaaS 应用程序只能从特定的计算机上访问。 BloodHound 的 `HasSession` 边非常实用,但它仅在用户登录到计算机时才有用。如果在收集数据时用户没有登录计算机,就很难找到哪台计算机可能包含有助于进一步渗透的机密。用户配置文件可能在 DPAPI、缓存的凭据、SSH 密钥、云密钥等方面包含大量有价值的情报——这些都不需要活动用户会话即可访问。 ![HasUserProfile Edge 示例](/images/1.png) ProfileHound 使用 BloodHound 的 [OpenGraph 格式](https://bloodhound.specterops.io/opengraph/overview) 来构建一条名为 `HasUserProfile` 的新图边,用于确定域计算机上是否存在某个用户配置文件。这有助于操作人员将注意力集中在高价值用户或组拥有配置文件的计算机上。 `HasUserProfile` 边包含了配置文件的创建日期和最后修改日期属性。该信息有助于判断: - 配置文件是否正在被积极使用(在过去几天内登录过) - 配置文件是否已使用了数年(很可能包含大量机密!) ![HasUserProfile Edge 属性示例](/images/2.png) 此边还包含配置文件创建和修改时间戳的属性,允许通过特定的 Cypher 查询在特定计算机上查找活动的或长期存在的用户配置文件。 ## 安装 使用 `pipx` 安装 ProfileHound(除非你喜欢深陷依赖地狱): ``` pipx install profilehound ``` 要使用最新的前沿版本,可以从源码安装: ``` pipx install git+https://github.com/m4lwhere/profilehound.git ``` ### Docker 要使用容器化的方式,请使用以下命令构建镜像并运行该工具: ``` docker build -t profilehound . docker run --rm profilehound --help docker run --rm -v ${PWD}:/profilehound profilehound --auth-user alice --auth-password whiteRabbit --auth-domain sccm.lab --dns 192.168.57.10 --auth-dc-ip 192.168.57.10 ``` ## 使用方法 例如,要使用密码为 `whiteRabbit` 的域管理员账户 `sccm.lab\alice` 运行: ``` $ profilehound --auth-user alice --auth-password whiteRabbit --auth-domain sccm.lab --target 192.168.57.0/27 ____ _____ __ __ __ __ / __ \_________ / __(_) /__ / / / /___ __ ______ ____/ / / /_/ / ___/ __ \/ /_/ / / _ \/ /_/ / __ \/ / / / __ \/ __ / / ____/ / / /_/ / __/ / / __/ __ / /_/ / /_/ / / / / /_/ / /_/ /_/ \____/_/ /_/_/\___/_/ /_/\____/\__,_/_/ /_/\__,_/ v0.1.1 @m4lwhere BloodHound CE OpenGraph collector for user profiles stored on domain machines. [12/30/25 11:58:05] INFO Loaded 32 targets [12/30/25 11:58:08] INFO Successful authentication on 192.168.57.10 (192.168.57.10) as sccm.lab\alice INFO Successfully connected to share \\192.168.57.10\C$ as sccm.lab\alice INFO Enumerating profiles in \\192.168.57.10\C$\Users\... INFO vagrant: S-1-5-21-3016982856-3796307652-1246469985-1000 created:2025-11-07 modified:2025-11-07 INFO Found 1 domain profile(s) for 192.168.57.10 INFO Successful authentication on 192.168.57.11 (192.168.57.11) as sccm.lab\alice [12/30/25 11:58:09] INFO Successfully connected to share \\192.168.57.11\C$ as sccm.lab\alice INFO Enumerating profiles in \\192.168.57.11\C$\Users\... INFO administrator: S-1-5-21-3016982856-3796307652-1246469985-500 created:2025-11-07 modified:2025-11-07 INFO alice: S-1-5-21-3016982856-3796307652-1246469985-1112 created:2025-12-28 modified:2025-11-07 INFO eve: S-1-5-21-3016982856-3796307652-1246469985-1116 created:2025-12-27 modified:2025-11-07 INFO Found 3 domain profile(s) for 192.168.57.11 INFO Successful authentication on 192.168.57.12 (192.168.57.12) as sccm.lab\alice INFO Successfully connected to share \\192.168.57.12\C$ as sccm.lab\alice INFO Enumerating profiles in \\192.168.57.12\C$\Users\... INFO alice: S-1-5-21-3016982856-3796307652-1246469985-1112 created:2025-12-28 modified:2025-12-28 INFO franck: S-1-5-21-3016982856-3796307652-1246469985-1117 created:2025-12-27 modified:2025-11-07 INFO sccm-sql: S-1-5-21-3016982856-3796307652-1246469985-1121 created:2025-11-07 modified:2025-11-07 INFO Found 3 domain profile(s) for 192.168.57.12 INFO Successful authentication on 192.168.57.13 (192.168.57.13) as sccm.lab\alice INFO Successfully connected to share \\192.168.57.13\C$ as sccm.lab\alice INFO Enumerating profiles in \\192.168.57.13\C$\Users\... INFO alice: S-1-5-21-3016982856-3796307652-1246469985-1112 created:2025-12-26 modified:2025-12-28 INFO sccm-account-da: S-1-5-21-3016982856-3796307652-1246469985-1119 created:2025-12-26 modified:2025-11-07 INFO Found 2 domain profile(s) for 192.168.57.13 [12/30/25 11:59:27] INFO Found 4 machines with profiles INFO Exported OpenGraph intel to profilehound_20251230-115805.json ``` 这将在当前目录下创建一个名为 `profilehound_20251230-115805.json` 的文件。可以通过将该文件直接拖放到 BloodHound UI 中来将其导入到 BHCE。它将被自动解析并通过 SID 关联节点。名为 `HasUserProfile` 的新边将被创建,以显示用户与配置文件之间的关系。 完成后,ProfileHound 还会在控制台打印一份简短的统计摘要: ``` ╭───────────────────────── General Summary ──────────────────────────────╮ │ ProfileHound Statistics │ │ Total Targets with Profiles 4 │ │ Total Unique Profiles (Users) 7 │ │ Average Profiles per Target 2.25 │ ╰────────────────────────────────────────────────────────────────────────╯ Top Connected Users ┏━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓ ┃ User ┃ Machine Count ┃ ┡━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩ │ alice │ 3 │ │ vagrant │ 1 │ │ administrator │ 1 │ │ eve │ 1 │ │ franck │ 1 │ └───────────────┴───────────────┘ Top Populated Machines ┏━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓ ┃ Machine ┃ Profile Count ┃ ┡━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩ │ 192.168.57.11 │ 3 │ │ 192.168.57.12 │ 3 │ │ 192.168.57.13 │ 2 │ │ 192.168.57.10 │ 1 │ └───────────────┴───────────────┘ Oldest User Profiles ┏━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓ ┃ User ┃ Machine ┃ Created ┃ Last Modified ┃ ┡━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩ │ vagrant │ DC.sccm.lab │ 2025-11-07 │ 2025-11-07 │ │ sccm-sql │ MSSQL.sccm.lab │ 2025-11-07 │ 2025-11-07 │ │ administrator │ MECM.sccm.lab │ 2025-11-07 │ 2025-11-07 │ │ sccm-account-da │ CLIENT.sccm.lab │ 2025-12-26 │ 2025-11-07 │ │ alice │ CLIENT.sccm.lab │ 2025-12-26 │ 2025-12-28 │ └─────────────────┴─────────────────┴────────────┴───────────────┘ Longest Lived Profiles (Created -> Modified) ┏━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓ ┃ User ┃ Machine ┃ Age (Days) ┃ Created ┃ Last Modified ┃ ┡━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩ │ alice │ CLIENT.sccm.lab │ 1.8 │ 2025-12-26 │ 2025-12-28 │ │ alice │ MSSQL.sccm.lab │ 0.0 │ 2025-12-28 │ 2025-12-28 │ │ sccm-sql │ MSSQL.sccm.lab │ 0.0 │ 2025-11-07 │ 2025-11-07 │ │ administrator │ MECM.sccm.lab │ 0.0 │ 2025-11-07 │ 2025-11-07 │ │ vagrant │ DC.sccm.lab │ 0.0 │ 2025-11-07 │ 2025-11-07 │ └───────────────┴─────────────────┴────────────┴────────────┴───────────────┘ Top 5 Machines to Focus On (Hubs) ┏━━━━━━━━━━━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Machine ┃ Score ┃ Reason ┃ ┡━━━━━━━━━━━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ MECM.sccm.lab │ 4.5 │ Has 3 profiles, potential lateral movement hub │ │ MSSQL.sccm.lab │ 4.5 │ Has 3 profiles, potential lateral movement hub │ │ CLIENT.sccm.lab │ 3.5 │ Has 2 profiles, potential lateral movement hub │ │ DC.sccm.lab │ 1.0 │ Has 1 profiles, potential lateral movement hub │ └─────────────────┴───────┴────────────────────────────────────────────────┘ ``` # 工作原理 ProfileHound 使用 `C$` 共享来枚举域计算机上位于 `\\\C$\Users\` 的用户配置文件。它将读取用户的 `NTUSER.DAT` 文件,通过从文件元数据中检索 SID 来确定该用户是域帐户还是本地帐户。例如,它将收集 `\\\C$\Users\` 下的所有用户目录,然后遍历每个目录以查找位于 `\\\C$\Users\\NTUSER.DAT` 的 `NTUSER.DAT` 文件。如果 `NTUSER.DAT` 文件属于一个众所周知的 SID,它将尝试通过读取该用户的 DPAPI 目录(例如 `\\\C$\Users\\AppData\Roaming\Microsoft\Protect\`)来找到用户的 SID。 因为我们正在访问 `C$` 共享,所以我们需要一个管理员帐户来向目标计算机进行身份验证。ProfileHound 将使用提供的凭据向目标计算机进行身份验证。如果您使用的是域帐户,可以使用 `--auth-domain` 选项指定域。如果您使用的是本地帐户,可以使用 `--smb-local-auth` 选项。 默认情况下,ProfileHound 在遇到 SMB 域身份验证失败后会停止运行,以降低帐户被锁定的风险。如果预期某些端点会拒绝域身份验证并且您希望继续扫描剩余目标,请使用 `--smb-ignore-failed-domain-auth`。 如果在找到配置文件后,ProfileHound 在 SMB 数据收集期间停止运行,它将在退出前尝试导出部分的 OpenGraph 结果。 `NTUSER.DAT` 文件的创建时间和最后修改时间会被收集,并可用于确定配置文件是否处于活跃状态。这种关联是通过边属性中的 cypher 查询处理的,示例如下。 值得注意的是,如果 `NTUSER.DAT` 文件的最后修改日期早于创建日期,则该配置文件很可能只是被创建但并未被实际使用。出现这种情况是因为在创建新用户配置文件时,`NTUSER.DAT` 文件是从 `C:\Users\Default` 配置文件复制过来的,尽管创建日期较晚,但仍保留了相同的修改日期。因此,我们可以确信该特定配置文件不会包含任何机密。 ## 选择目标 ProfileHound 使用 @podalirius_ 的 [ShareHound](https://github.com/p0dalirius/ShareHound) 作为库来枚举目标。如果未提供 `--target` 或 `--target-file` 选项,ProfileHound 将通过连接到 LDAP 自动收集域中所有计算机的 FQDN 来枚举目标。 # 有趣的查询 我们可以从这些数据中得出许多强有力的结论,从而告诉我们应该将注意力集中在哪里。所有这些查询都可以通过在 BloodHound UI 的 **Saved Queries** 页面上使用 **Import** 按钮拖放 [ProfileHound_Cypher_Queries.zip 文件](/BloodHound_Queries/ProfileHound_Cypher_Queries.zip) 导入到 BloodHound 中。 以下是几个示例: ### 查找所有用户配置文件边 这是一个简单的查询,将查找图中的所有用户配置文件。 ``` MATCH p=(u:User)-[:HasUserProfile]->(c:Computer) RETURN p ``` ### 根据组名查找用户配置文件 这将查找属于域“Administrators”组成员的所有用户配置文件。 ``` MATCH p=(g:Group)<-[:MemberOf*1..]-(u:User)-[:HasUserProfile]->(c:Computer) WHERE toLower(g.samaccountname) = "administrators" RETURN p ``` ### 查找最近 3 天内活跃的用户配置文件 这将查找在过去 3 天内修改过的所有用户配置文件。这有助于确定哪个用户配置文件可能是用户的主要机器,并包含有价值的战利品。 ``` WITH 3 as active_days MATCH p = (u:User)-[e:HasUserProfile]-(c:Computer) WHERE e.profileModified > (datetime().epochseconds - (active_days * 86400)) RETURN p ``` ### 特定组内的活跃用户配置文件(功能强大) 这是一个极其强大的查询,可以定位特定组成员在过去 3 天内使用的特定用户配置文件。 ``` WITH 3 as active_days, "administrators" as group_name MATCH p = (g:Group)<-[:MemberOf*1..]-(u:User)-[e:HasUserProfile]-(c:Computer) WHERE e.profileModified > (datetime().epochseconds - (active_days * 86400)) AND toLower(g.samaccountname) = group_name RETURN p ``` ### 移除未使用的用户配置文件 这将移除任何 `NTUSER.DAT` 文件修改日期早于创建日期的用户配置文件。这表明该配置文件虽已创建但并未被实际使用。出现这种情况是因为在创建新用户配置文件时,`NTUSER.DAT` 文件是从 `C:\Users\Default` 配置文件中复制的,尽管创建日期较晚,但仍保留了相同的修改日期。 ``` match p = (u:User)-[e:HasUserProfile]-(c:Computer) where e.profileCreated < e.profileModified return p ``` # 致谢 如果没有 Remi Gascou ([@podalirius](https://github.com/p0dalirius)) 的 [ShareHound](https://github.com/p0dalirius/ShareHound) 和 [bhopengraph](https://github.com/p0dalirius/bhopengraph) 库,这一切都是不可能实现的。 # 未来改进 此工具的重点是确定哪些计算机最有可能包含特定用户的机密。未来的改进将包括: - [ ] 将 @garrettfoster13 的 [SCCMHunter](https://github.com/garrettfoster13/sccmhunter) 作为库集成以改进数据收集。 - [ ] 使用 `get_lastlogon` 函数在计算机上创建 `HasUserProfile` 边。 - [ ] 使用 `get_puser` 函数将域用户关联为特定计算机的主要设备所有者。 - [ ] 实现来自 AzureHound 的 Azure AD 设备所有权关联。 - [ ] 这似乎已经作为一个 `AZDeviceOwner` 对象在 `.data.owners[owner.DeviceOwner.onPremisesSecurityIdentifier]` 处被收集。 - [ ] 使用 [ShareHound](https://github.com/p0dalirius/ShareHound) 抓取匹配配置文件中的敏感文件并将其提取到图中。 - [ ] 从 `NTUSER.DAT` 文件中挖掘最近的程序、文档和浏览器活动记录。
标签:Active Directory, AD域, BloodHound, C$共享, Checkov, Conpot, DPAPI解密, HTTP工具, OpenGraph, Plaso, Red Teaming, StruQ, TTPs, Windows安全, 内网横向移动, 凭据获取, 协议分析, 哈希提取, 图数据库分析, 安全助手, 恶意样本开发, 数据窃取, 权限提升, 检测规则, 活动目录, 用户枚举, 网络资产发现, 请求拦截, 逆向工具