在本博客中,我将解释如何在 Active Directory 环境中快速清点、利用和修复配置有过多权限的网络共享。过多的共享权限代表了一种风险,可能导致企业环境中的数据泄露、权限升级和勒索软件攻击。因此,我还将探讨为什么在经过 20 年的主流漏洞管理和渗透测试之后,配置了过多权限的网络共享仍然困扰着大多数环境。
最后,我将分享一个名为 PowerHuntShares 的新开源工具,它可以帮助简化 Active Directory 环境中过多的 SMB 共享权限的共享搜索和修复。此内容也可在此处以演示格式提供。或者,如果您想听我谈论这个话题,请查看我们的网络研讨会,*如何大规模评估 Active Directory SMB 共享*。
这对于负责在 Active Directory 环境中管理网络共享访问的人员(身份和访问管理/IAM 团队)以及负责利用该访问的红队/渗透测试人员来说应该很有趣。
TLDR;我们可以利用 Active Directory 来帮助创建系统和共享清单。配置有过多权限的共享可能会以多种方式导致远程代码执行 (RCE),可以通过简单的数据分组技术加快修复工作,并且可以使用一些常见的事件 ID 和一点相关性来检测恶意共享扫描(总是说起来容易做起来难)。
问题
如果只是一个问题就好了。我不认识没有涉及未经授权的网络共享访问的战争故事的渗透测试人员。在现实世界中,这个故事通常以勒索软件的部署和双重勒索而告终。这就是为什么我们尝试了解这个问题背后的一些根本原因很重要。下面总结了在大多数 Active Directory 环境中经常导致大量网络共享暴露的根本原因。
但是,根据我的观察,业界只是在过去五年中才对 Active Directory 生态系统产生了浓厚的兴趣。这似乎主要是由于 Active Directory (AD) 攻击的曝光率和意识增加,这些攻击严重依赖于配置并且不会丢失补丁。
我也不是说 IAM 团队没有努力完成他们的工作,但在许多情况下,他们陷入了相当于团队管理的困境,而忘记(或没有时间)查看实际全局/通用组可以访问的资产。那是一口深井,不过今天的重点是网络股。
渗透测试人员一直都知道共享是一种风险,但在 Active Directory 环境中实施、管理和评估最小权限是一项不小的挑战。即使对安全社区越来越感兴趣,也很少有解决方案可以有效地清点和评估整个 Active Directory 域(或多个域)的共享访问权限。
根据我的经验,很少有组织从一开始就执行经过身份验证的漏洞扫描,但即使是那些似乎确实缺乏关于常见过度特权、继承权限和提炼摘要数据的环境的发现,这些数据提供了大多数 IAM 团队需要的洞察力做出正确的决定。长期以来,人们一直过度依赖这些类型的工具,因为许多公司的印象是,它们提供的覆盖范围比网络共享权限方面的覆盖范围更大。
简而言之,良好的资产库存和攻击面管理为更好的漏洞管理覆盖率铺平了道路——许多公司还没有做到这一点。
不考虑分割边界
大多数大型环境都有主机、网络和 Active Directory 域边界,在执行任何类型的身份验证扫描或代理部署时都需要考虑这些边界。试图准确盘点和评估网络份额的公司经常错过一些事情,因为他们没有考虑隔离其资产的边界。在评估资产时,请确保在这些范围内工作。
多年来,有很多与共享权限管理相关的不良做法已经被 IT 文化所吸收,仅仅是因为人们不了解他们的工作方式。过度共享权限的最大贡献者之一是通过本机嵌套组成员身份进行的特权继承。此问题也不限于网络共享。十多年来,我们一直在滥用相同的特权继承问题来访问 SQL Server 实例。在接下来的部分中,我将概述该问题以及如何在网络共享的上下文中利用它。
网络共享权限继承盲点
网络共享只是使网络上的远程用户可以使用本地文件的一种媒介,但两组权限控制远程用户对共享文件的访问。要了解权限继承问题,快速回顾一下 NTFS 和共享权限如何在 Windows 系统上协同工作会有所帮助。让我们探索基础知识。
NTFS 权限
用于控制对本地 NTFS 文件系统的访问
会影响本地和远程用户
共享权限
用于控制对共享文件和文件夹的访问
只影响远程用户
简而言之,从远程用户的角度来看,首先审查网络共享权限(远程),然后审查 NTFS 权限(本地),但无论如何,最严格的权限总是胜出。下面是一个简单示例,显示 John 对共享具有完全控制权限,但对关联的本地文件夹只有读取权限。大多数限制性获胜,因此 John 仅被提供对通过共享文件夹远程提供的文件的读取访问权限。
将 DLL 写入应用程序文件夹以执行 DLL 劫持。您可以使用由NetSPI自己的研究主管 Nick Landers 编写的 Koppeling。
将 DLL 和配置文件写入应用程序文件夹,以对 .net 应用程序执行 appdomain 劫持。
将可执行文件或脚本写入“所有用户”启动文件夹,以便在下次登录时启动它们。
修改计划任务执行的文件。
修改 PowerShell 启动配置文件以包含后门。
修改 Microsoft Office 模板以包含后门。
编写恶意 LNK 文件以捕获或中继 NetNTLM 哈希。
您可能已经注意到,我列出的许多技术也常用于持久性和横向移动,这很好地提醒了旧技术可以有多个用例。
下面是一个简单的图表,试图说明基本的 web shell 示例。
攻击者危害域用户。
攻击者扫描共享,找到一个 wwwroot 目录,然后上传一个 web shell。wwwroot 目录存储目标 IIS 服务器上托管的 Web 应用程序使用的所有文件。因此,您可以将 Web shell 视为扩展已发布 Web 应用程序功能的东西。
使用标准 Web 浏览器,攻击者现在可以访问目标 IIS Web 服务器托管的上传的 Web Shell 文件。
攻击者使用 web shell 访问作为 web 服务器服务帐户在操作系统上执行命令。
Web 服务器服务帐户可能具有访问网络上其他资源的额外权限。
显示使用 Web shell 的 RCE 的 5 步图。
下面是另一个简化图,显示了可用于执行我的前 10 个列表中的攻击的通用步骤。让我们关注被滥用的 C 共享是 Windows 中的默认隐藏共享,标准域用户不应访问。它映射到 C 驱动器,该驱动器通常包括系统上的所有文件。不幸的是,devOops、应用程序部署和单用户错误配置意外(或故意)使 C 共享的写入访问权限超过一半的时间。
基于 10 个常见远程代码执行 (RCE) 选项列表的简化图。
网络共享修复
在过度的共享修复工作中追踪系统所有者、应用程序和有效的业务案例对于 IAM 团队来说可能是一个巨大的痛苦。对于大型企业而言,这可能意味着对数十万个共享 ACL 进行分类。因此,在该工作期间有办法对共享进行分组和优先级排序可以节省大量时间。
runas /netonly /user:domainuser PowerShell.exe Invoke-HuntSMBShares -Threads 100 -RunSpaceTimeOut 10` -OutputDirectory c:folder` -DomainController 10.1.1.1` -Credential domainuser =============================================================== PowerHuntShares =============================================================== This function automates the following tasks: o Determine current computer's domain o Enumerate domain computers o Filter for computers that respond to ping requests o Filter for computers that have TCP 445 open and accessible o Enumerate SMB shares o Enumerate SMB share permissions o Identify shares with potentially excessive privileges o Identify shares that provide reads & write access o Identify shares that are high risk o Identify common share owners, names, & directory listings o Generate creation, last written, & last accessed timelines o Generate html summary report and detailed csv files Note: This can take hours to run in large environments. --------------------------------------------------------------- ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| --------------------------------------------------------------- SHARE DISCOVERY --------------------------------------------------------------- [*][03/01/202109:35] Scan Start [*][03/01/202109:35] Output Directory: c:tempsmbsharesSmbShareHunt-03012021093504 [*][03/01/202109:35] Successful connection to domain controller: dc1.demo.local [*][03/01/202109:35] Performing LDAP query for computers associated with the demo.local domain [*][03/01/202109:35] - 245 computers found [*][03/01/202109:35] Pinging 245 computers [*][03/01/202109:35] - 55 computers responded to ping requests. [*][03/01/202109:35] Checking if TCP Port 445 is open on 55 computers [*][03/01/202109:36] - 49 computers have TCP port 445 open. [*][03/01/202109:36] Getting a list of SMB shares from 49 computers [*][03/01/202109:36] - 217 SMB shares were found. [*][03/01/202109:36] Getting share permissions from 217 SMB shares [*][03/01/202109:37] - 374 share permissions were enumerated. [*][03/01/202109:37] Getting directory listings from 33 SMB shares [*][03/01/202109:37] - Targeting up to 3 nested directory levels [*][03/01/202109:37] - 563 files and folders were enumerated. [*][03/01/202109:37] Identifying potentially excessive share permissions [*][03/01/202109:37] - 33 potentially excessive privileges were found across 12 systems. [*][03/01/202109:37] Scan Complete --------------------------------------------------------------- SHARE ANALYSIS --------------------------------------------------------------- [*][03/01/202109:37] Analysis Start [*][03/01/202109:37] - 14 shares can be read across 12 systems. [*][03/01/202109:37] - 1 shares can be written to across 1 systems. [*][03/01/202109:37] - 46 shares are considered non-default across 32 systems. [*][03/01/202109:37] - 0 shares are considered high risk across 0 systems [*][03/01/202109:37] - Identified top 5 owners of excessive shares. [*][03/01/202109:37] - Identified top 5 share groups. [*][03/01/202109:37] - Identified top 5 share names. [*][03/01/202109:37] - Identified shares created in last 90 days. [*][03/01/202109:37] - Identified shares accessed in last 90 days. [*][03/01/202109:37] - Identified shares modified in last 90 days. [*][03/01/202109:37] Analysis Complete --------------------------------------------------------------- SHARE REPORT SUMMARY --------------------------------------------------------------- [*][03/01/202109:37] Domain: demo.local [*][03/01/202109:37] Start time: 03/01/202109:35:04 [*][03/01/202109:37] End time: 03/01/202109:37:27 [*][03/01/202109:37] Run time: 00:02:23.2759086 [*][03/01/202109:37] [*][03/01/202109:37] COMPUTER SUMMARY [*][03/01/202109:37] - 245 domain computers found. [*][03/01/202109:37] - 55 (22.45%) domain computers responded to ping. [*][03/01/202109:37] - 49 (20.00%) domain computers had TCP port 445 accessible. [*][03/01/202109:37] - 32 (13.06%) domain computers had shares that were non-default. [*][03/01/202109:37] - 12 (4.90%) domain computers had shares with potentially excessive privileges. [*][03/01/202109:37] - 12 (4.90%) domain computers had shares that allowed READ access. [*][03/01/202109:37] - 1 (0.41%) domain computers had shares that allowed WRITE access. [*][03/01/202109:37] - 0 (0.00%) domain computers had shares that are HIGH RISK. [*][03/01/202109:37] [*][03/01/202109:37] SHARE SUMMARY [*][03/01/202109:37] - 217 shares were found. We expect a minimum of 98 shares [*][03/01/202109:37] because 49 systems had open ports and there are typically two default shares. [*][03/01/202109:37] - 46 (21.20%) shares across 32 systems were non-default. [*][03/01/202109:37] - 14 (6.45%) shares across 12 systems are configured with 33 potentially excessive ACLs. [*][03/01/202109:37] - 14 (6.45%) shares across 12 systems allowed READ access. [*][03/01/202109:37] - 1 (0.46%) shares across 1 systems allowed WRITE access. [*][03/01/202109:37] - 0 (0.00%) shares across 0 systems are considered HIGH RISK. [*][03/01/202109:37] [*][03/01/202109:37] SHARE ACL SUMMARY [*][03/01/202109:37] - 374 ACLs were found. [*][03/01/202109:37] - 374 (100.00%) ACLs were associated with non-default shares. [*][03/01/202109:37] - 33 (8.82%) ACLs were found to be potentially excessive. [*][03/01/202109:37] - 32 (8.56%) ACLs were found that allowed READ access. [*][03/01/202109:37] - 1 (0.27%) ACLs were found that allowed WRITE access. [*][03/01/202109:37] - 0 (0.00%) ACLs were found that are associated with HIGH RISK share names. [*][03/01/202109:37] [*][03/01/202109:37] - The 5 most common share names are: [*][03/01/202109:37] - 9 of 14 (64.29%) discovered shares are associated with the top 5 share names. [*][03/01/202109:37] - 4 backup [*][03/01/202109:37] - 2 ssms [*][03/01/202109:37] - 1 test2 [*][03/01/202109:37] - 1 test1 [*][03/01/202109:37] - 1 users [*] -----------------------------------------------
评论