GraphQL中api漏洞

admin 2023年8月28日01:39:49评论47 views字数 2742阅读9分8秒阅读模式

正文

通常graphql接口位于类似 www.example.com/graphql 的地方

这里的接口如下所示:(其实这种情况在国外的网站经常会看到)

GraphQL中api漏洞

首先,检查一下目标是否启用了自省模式(可以参考以前本公众号中的文章: 漏洞赏金猎人笔记-GraphQL-IV ),如果在GraphQL中启用了自省,则允许客户端查询并检索关于GraphQL API中可用类型、字段和指令的详细信息

这里发送内省查询:

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}}}}}}}}

请求如下:

POST /graphql HTTP/1.1
Accept-Encoding: gzip, deflate
Connection: close
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:55.0) Gecko/20100101 Firefox/55.0
Host: xxxxxxx.com
Content-Length: 746
Content-Type: application/json

{"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}}}}}}}}"}

响应如下:

HTTP/1.1 200 OK
Server: nginx/1.14.1
Date: Thu, 22 Jun 2023 09:37:18 GMT
Content-Type: application/json
Connection: close
Cache-Control: private, must-revalidate
pragma: no-cache
expires: -1
Vary: Origin
Content-Length: 367316

{"data":{"__schema":{"queryType":{"name":"Query"},"mutationType":{"name":"Mutation"},[REDACTED]"description":"Explains why this element was deprecated, usually also including a suggestion for how to access supported similar data. Formatted using the Markdown syntax (as specified by [CommonMark](https://commonmark.org/).","type":{"kind":"SCALAR","name":"String","ofType":null},"defaultValue":""No longer supported""}]}]}}}]

也可以使用插件InQL(bp中插件)

将GraphQL接口粘贴到这里,然后点击加载。

GraphQL中api漏洞

一会将列出模式上可用的所有突变和查询。

GraphQL中api漏洞

上面两个操作可能存在脆弱点

首先测试deleteUser突变。但需要一个用户id。这里使用user查询来查找用户的id。

GraphQL中api漏洞

这里来尝试一下删除这个admin账户

GraphQL中api漏洞

没有起到作用,尝试打开一个用户帐户,并再次尝试同样的事情。

GraphQL中api漏洞

这次没有出现任何误差。来验证一下有效载荷是否有效。

再次对id -> 2运行用户查询。

GraphQL中api漏洞

admin(管理员账户)被删除了!

更新一下操作

GraphQL中api漏洞

发现起作用了,用户密码更新了。

在GraphQL中启用内省可以提供有价值的开发和调试功能,但会在生产环境中引入安全风险和潜在的资源问题。这里建议关闭该模式。

原文始发于微信公众号(迪哥讲事):GraphQL中api漏洞

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2023年8月28日01:39:49
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   GraphQL中api漏洞http://cn-sec.com/archives/1983394.html

发表评论

匿名网友 填写信息