3.0.12版本 Tmymeleaf RCE的终结?(若依ruoyi最新版本后台RCE)

admin 2021年11月30日19:57:503.0.12版本 Tmymeleaf RCE的终结?(若依ruoyi最新版本后台RCE)已关闭评论1,249 views字数 2019阅读6分43秒阅读模式

前期利用

前段时间看到很多小伙伴研究若依这个系统的漏洞,让我想起若干年前在CNVD交的一个若依任意修改密码洞。

https://threedr3am.github.io/images/zsxq/cnvd-ruoyi.jpg

https://threedr3am.github.io/images/zsxq/cnvd-ruoyi.jpg

还有之前屯的若依后台Thymeleaf的RCE洞,所以把最新的若依代码拉了下来,用华佗扫了一下,发现漏洞貌似还存在。就是个简单的Thymeleaf ViewName注入RCE。

https://threedr3am.github.io/images/zsxq/thymeleaf1.jpg

https://threedr3am.github.io/images/zsxq/thymeleaf1.jpg

https://threedr3am.github.io/images/zsxq/thymeleaf2.jpg

https://threedr3am.github.io/images/zsxq/thymeleaf2.jpg

但是,当我拿出payload测试的时候,却发现,怎么也弹不出计算器了。。。

https://threedr3am.github.io/images/zsxq/thymeleaf3.jpg

https://threedr3am.github.io/images/zsxq/thymeleaf3.jpg

百思不得其解,所以决定debug一下thymeleaf源码,结果发现,好好的payload居然执行报错了。

https://threedr3am.github.io/images/zsxq/thymeleaf4.jpg

https://threedr3am.github.io/images/zsxq/thymeleaf4.jpg

然后把报错信息copy出来google了一下,发现,居然Thymeleaf 3.0.12版本,对其进行了限制,静态方法调用、new实例化都不被允许执行了。

https://github.com/thymeleaf/thymeleaf/issues/809

https://threedr3am.github.io/images/zsxq/thymeleaf5.jpg

https://threedr3am.github.io/images/zsxq/thymeleaf5.jpg

然后我看了下,若依在2021/2/20把spring-boot依赖升级到了2.2.13.RELEASE,凉凉,Thymeleaf RCE的终结?

https://threedr3am.github.io/images/zsxq/thymeleaf6.jpg

https://threedr3am.github.io/images/zsxq/thymeleaf6.jpg

https://threedr3am.github.io/images/zsxq/thymeleaf7.jpg

https://threedr3am.github.io/images/zsxq/thymeleaf7.jpg

https://threedr3am.github.io/images/zsxq/thymeleaf8.jpg

https://threedr3am.github.io/images/zsxq/thymeleaf8.jpg

Bypass

前段时间写了个EL表达式简单解析的程序,打算用来增强WAF,解决一些包含EL表达式的payload对WAF的绕过(利用字符串拼接、java语法trick等),刚看到Thymeleaf在3.0.12添加了Restricted mode用于限制一些静态方法和实例化的调用,好像跟我做的东西有一点点相似。所以,本着工匠精神,还是想研究了一下老外是怎么做的,所以打开了Thymeleaf的源码

细节

重点源码在:

thymeleaf)

org.thymeleaf.spring5.util.SpringStandardExpressionUtils#containsSpELInstantiationOrStatic
thymeleaf-spring)

org.thymeleaf.standard.util.StandardExpressionUtils#containsOGNLInstantiationOrStatic

分别在两个类里面,这里简单的说说,thymeleaf工程内自带的是OGNL解析的实现,而thymeleaf-spring的工程,引入了SPEL解析的实现。

看了下两个方法的源码,竟如此雷同

本以为3.0.12是Thymeleaf RCE的终结,然而,仔细一看代码,发现很简单就可以绕过。。。

只要在T和(之间添加若干个空格字符,就能绕过检测了

所以,RCE的payload只是简单的多加几个空格:

${T (java.lang.Runtime).getRuntime().exec("whoami")}

其它

已经给官方提交issue了:https://github.com/thymeleaf/thymeleaf/issues/828

参考:https://zhuanlan.zhihu.com/p/248416919

原文:https://threedr3am.github.io/2021/04/26/3.0.12%20Thymeleaf%20RCE%20Bypass%EF%BC%88%E8%8B%A5%E4%BE%9Druoyi%E6%9C%80%E6%96%B0%E7%89%88%E6%9C%AC%E5%90%8E%E5%8F%B0RCE%EF%BC%89/#more

相关推荐: 将JavaScript隐藏到PNG图片中来绕过CSP

译文来源:https://www.secjuice.com/hiding-javascript-in-png-csp-bypass/。受个人知识所限及偏见影响,部分内容可能存在过度曲解或误解,望师傅们包含并提出建议,感激。 序言 将一个恶意的JavaScrip…

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2021年11月30日19:57:50
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   3.0.12版本 Tmymeleaf RCE的终结?(若依ruoyi最新版本后台RCE)http://cn-sec.com/archives/654957.html