CVE-2016-6802
影响版本:shiro < 1.3.2
shiro < 1.3.2
Shiro使用非根servlet上下文路径中存在安全漏洞。远程攻击者通过构造的请求,利用此漏洞可绕过目标servlet过滤器并获取访问权限。
Shiro
servlet
上一个请求路径未标准化类似
getPathWithinApplication先后获取到上下文路径和请求路径,若请求路径以上下文路径开头,截断后并返回;否则返回整个请求路径
getPathWithinApplication
跟进getContextPath
getContextPath
request.getContextPath()实际上是tomcat内部去解析的,逻辑在org.apache.catalina.connector#getContextPath
request.getContextPath()
org.apache.catalina.connector#getContextPath
获取Application Context和请求的URL,对URL进行如下操作
Application Context
去除开头的斜杠,只保留一个
获取第二个斜杠前面的内容作为candidate
candidate
去除请求参数、URL解码、标准化(处理/./、/../、//等),判断candidate和Application Context是否相等,若不等则继续获取下一个斜杠之前的内容
/./、/../、//等
假设Application Context为/taco,若我们请求的路径为////hello/try/../../taco/admin/put
/taco
////hello/try/../../taco/admin/put
保留首个斜杠 => /hello/try/../../taco/admin/put
/hello/try/../../taco/admin/put
/hello不匹配/taco,获取下一个斜杠前面的内容
/hello
/hello/try不匹配/taco
/hello/try
/hello/try/..标准化后/hello不匹配/taco
/hello/try/..
/hello/try/../..标准化后/不匹配/taco
/hello/try/../..
/
/hello/try/../../taco标准化后/taco,成功匹配,返回/hello/try/../../taco
/hello/try/../../taco
Shiro 1.0.0之后的版本对Request uri进行了标准化,而getContextPath()返回的是没有标准化的,可以利用此绕过
Shiro 1.0.0
Request uri
getContextPath()
显然后面版本的修复就是对getContextPath()进行normalize标准化。
normalize
Shiro这波感觉有点自己造轮子了。
getContextPath()可以直接调用request.getServletContext().getContextPath()
request.getServletContext().getContextPath()
Last updated 2 years ago