# Web API Pentesting

<details>

<summary><strong>从零开始学习 AWS 黑客技术，成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE（HackTricks AWS 红队专家）</strong></a><strong>！</strong></summary>

支持 HackTricks 的其他方式：

* 如果您想看到您的**公司在 HackTricks 中做广告**或**下载 PDF 版本的 HackTricks**，请查看[**订阅计划**](https://github.com/sponsors/carlospolop)！
* 获取[**官方 PEASS & HackTricks 商品**](https://peass.creator-spring.com)
* 探索[**PEASS 家族**](https://opensea.io/collection/the-peass-family)，我们的独家[**NFT**](https://opensea.io/collection/the-peass-family)收藏品
* **加入** 💬 [**Discord 群组**](https://discord.gg/hRep4RUj7f) 或 [**电报群组**](https://t.me/peass) 或在 **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live) 上**关注**我们。
* 通过向 [**HackTricks**](https://github.com/carlospolop/hacktricks) 和 [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github 仓库提交 PR 来分享您的黑客技巧。

</details>

<figure><img src="https://615200056-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1DLBZdNLkY4FUHtMnjPr%2Fuploads%2Fgit-blob-78abb7891633b1e8147b4e743e4f00af375d3cd6%2Fimage%20(45).png?alt=media" alt=""><figcaption></figcaption></figure>

使用 [**Trickest**](https://trickest.com/?utm_campaign=hacktrics\&utm_medium=banner\&utm_source=hacktricks) 可以轻松构建和**自动化工作流程**，使用世界上**最先进**的社区工具。\
立即获取访问权限：

{% embed url="<https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks>" %}

## API 渗透测试方法论总结

渗透测试 API 包括一个结构化方法来发现漏洞。本指南概括了一套全面的方法论，强调实用技术和工具。

### **理解 API 类型**

* **SOAP/XML Web 服务**：使用 WSDL 格式的文档，通常在 `?wsdl` 路径下找到。像 **SOAPUI** 和 **WSDLer**（Burp Suite 扩展）这样的工具对解析和生成请求非常有用。示例文档可在 [DNE Online](http://www.dneonline.com/calculator.asmx) 上访问。
* **REST API（JSON）**：文档通常以 WADL 文件形式提供，但像 [Swagger UI](https://swagger.io/tools/swagger-ui/) 这样的工具提供了一个更用户友好的界面进行交互。**Postman** 是一个用于创建和管理示例请求的有价值的工具。
* **GraphQL**：一种用于 API 的查询语言，提供了对 API 中数据的完整和可理解的描述。

### **实践实验室**

* [**VAmPI**](https://github.com/erev0s/VAmPI)：一个故意设计成易受攻击的 API，用于实践，涵盖 OWASP 十大 API 漏洞。

### **API 渗透测试的有效技巧**

* **SOAP/XML 漏洞**：探索 XXE 漏洞，尽管 DTD 声明通常受限。如果 XML 保持有效，CDATA 标记可能允许插入有效载荷。
* **权限提升**：测试具有不同权限级别的端点，以识别未经授权访问的可能性。
* **CORS 配置错误**：调查 CORS 设置，以便从经过身份验证的会话中进行 CSRF 攻击的潜在利用。
* **端点发现**：利用 API 模式发现隐藏的端点。工具如模糊器可以自动化此过程。
* **参数篡改**：尝试在请求中添加或替换参数，以访问未经授权的数据或功能。
* **HTTP 方法测试**：变化请求方法（GET、POST、PUT、DELETE、PATCH），以发现意外行为或信息泄露。
* **内容类型操纵**：在不同的内容类型之间切换（x-www-form-urlencoded、application/xml、application/json），以测试解析问题或漏洞。
* **高级参数技术**：在 JSON 负载中测试意外数据类型，或者尝试使用 XML 数据进行 XXE 注入。还可以尝试参数污染和通配符字符进行更广泛的测试。
* **版本测试**：旧的 API 版本可能更容易受到攻击。始终检查并针对多个 API 版本进行测试。

### **API 渗透测试的工具和资源**

* [**kiterunner**](https://github.com/assetnote/kiterunner)：用于发现 API 端点的优秀工具。使用它来扫描和暴力破解目标 API 的路径和参数。

```bash
kr scan https://domain.com/api/ -w routes-large.kite -x 20
kr scan https://domain.com/api/ -A=apiroutes-220828 -x 20
kr brute https://domain.com/api/ -A=raft-large-words -x 20 -d=0
kr brute https://domain.com/api/ -w /tmp/lang-english.txt -x 20 -d=0
```

* 类似 **automatic-api-attack-tool**、**Astra** 和 **restler-fuzzer** 这样的附加工具提供了针对 API 安全测试的定制功能，从攻击模拟到模糊测试和漏洞扫描不等。
* [**Cherrybomb**](https://github.com/blst-security/cherrybomb)：这是一个基于 OAS 文件对 API 进行审计的 API 安全工具（该工具用 Rust 编写）。

### **学习和实践资源**

* **OWASP API 安全前 10 名**：了解常见 API 漏洞的必读内容（[OWASP Top 10](https://github.com/OWASP/API-Security/blob/master/2019/en/dist/owasp-api-security-top-10.pdf)）。
* **API 安全检查清单**：用于保护 API 的全面检查清单（[GitHub 链接](https://github.com/shieldfy/API-Security-Checklist)）。
* **Logger++ 过滤器**：对于查找 API 漏洞，Logger++ 提供了有用的过滤器（[GitHub 链接](https://github.com/bnematzadeh/LoggerPlusPlus-API-Filters)）。
* **API 端点列表**：用于测试目的的潜在 API 端点的策划列表（[GitHub gist](https://gist.github.com/yassineaboukir/8e12adefbd505ef704674ad6ad48743d)）。

## 参考资料

* <https://github.com/Cyber-Guy1/API-SecurityEmpire>

<figure><img src="https://615200056-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1DLBZdNLkY4FUHtMnjPr%2Fuploads%2Fgit-blob-78abb7891633b1e8147b4e743e4f00af375d3cd6%2Fimage%20(45).png?alt=media" alt=""><figcaption></figcaption></figure>

使用 [**Trickest**](https://trickest.com/?utm_campaign=hacktrics\&utm_medium=banner\&utm_source=hacktricks) 可以轻松构建和 **自动化工作流**，使用全球 **最先进** 的社区工具。\
立即获取访问权限：

{% embed url="<https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks>" %}

<details>

<summary><strong>从零开始学习 AWS 黑客技术，成为专家，使用</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE（HackTricks AWS 红队专家）</strong></a><strong>！</strong></summary>

支持 HackTricks 的其他方式：

* 如果您想在 HackTricks 中看到您的 **公司广告** 或 **下载 PDF 版本的 HackTricks**，请查看 [**订阅计划**](https://github.com/sponsors/carlospolop)！
* 获取 [**官方 PEASS & HackTricks 商品**](https://peass.creator-spring.com)
* 探索 [**PEASS 家族**](https://opensea.io/collection/the-peass-family)，我们的独家 [**NFT**](https://opensea.io/collection/the-peass-family) 收藏品
* **加入** 💬 [**Discord 群组**](https://discord.gg/hRep4RUj7f) 或 [**电报群组**](https://t.me/peass) 或 **关注** 我们的 **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**。**
* 通过向 [**HackTricks**](https://github.com/carlospolop/hacktricks) 和 [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github 仓库提交 PR 来分享您的黑客技巧。

</details>
