CVE-2018-1270, CVE-2018-1273: Spring Expression Language Vulnerability Analysis

0x00 background

 

 

Recently, the Spring framework is not very peaceful, and there have been multiple CVE vulnerabilities of RCE remote code execution, including CVE-2018-1270 and CVE-2018-1273. Through the analysis of the code that caused the vulnerability, it was found that they were all caused by the abuse of SpEL. StandardEvaluationContext.

 

0x01 Vulnerability Impact

An attacker could launch a remote code execution attack by injecting crafted request parameters into the vulnerable server without authorization.

Affected Scope

· Spring Data Commons 1.13 - 1.13.10 (Ingalls SR10)

Spring Data REST 2.6 - 2.6.10 (Ingalls SR10)
Spring Data Commons 2.0 to 2.0.5 (Kay SR5)
Spring Data REST 3.0 - 3.0.5 (Kay SR5)
Earlier versions are also affected

 

0x02 GAMES

 

 

SpEL is a very simple expression language, but it is too large in terms of functions or permissions, so if the expression can be polluted by the outside, it can basically cause RCE.

The specific syntax of SpEL, I will not introduce them one by one here, please refer to the official documentation for details. I only mention two points here that can be effectively used.

 

class type expression

Using class type expressions can also access class static methods and class static fields. Use T() to represent, where the class name must be the full name, except for the java.lang package. So here comes the first type of payload

1.PNG

 

class instantiation

Create a Java class instance, as above, the class name is required to be the full name. Therefore, the second type of payload can be generated here

2.PNG

 

Use of variables and functions

在表达式里面要是用变量或者函数,需要提前在context使用setVariable和registerFunction才能使用,因此初步看没有太大利用价值。其中有两个内置变量#root根对象,#this代表Context对象。而在CVE-2018-1273的Spring Data Commons中

3.PNG

context在初始化的时候,没有传入根对象,但是后面显式调用了setRootObject,因此#root为Map对象,利用价值不大,#this为StandardEvaluationContext对象,方法比较多,还在研究中,感觉这里也能提取出一类payload,未完待续。

 

0x03 SpEL调试

 

 

我们在写出来payload后,需要校验一下payload是否有效,可以使用如下的代码快速进行校验。

4.PNG

 

0x04 实战分析

 

 

CVE-2018-1273

上面也贴出来部分造成漏洞的代码,现在把完整的代码贴出来,代码位于org,springframework.data.web.MapDataBinder类中

code1.PNG

propertyName是攻击者可以控制的变量,但是代码中将它直接用来生成Expression。但是在使用之前我们发现有一段代码进行propertyName的有效性校验,它用来判断实体类的propertyName属性是否可写。

6.PNG

但是经过我们对这个isWritableProperty函数的分析,我们发现这里存在一个逻辑问题。

code2.PNG

这个函数会造成propertyName如果是name和name[huangjacky]返回一个东西。

 

攻击Exploit的诞生

我们的演示程序中,实体类是这样定义的

8.PNG

因此我们对应的Exploit就应该为:

9.PNG

不出意外的话,这个时候可爱的计算器就出来了。

10.PNG

 

CVE-2018-1270

 

这个漏洞已经有网友分析得很透彻了,我就不说了,直接上链接。

spring-messaging Remote Code Execution 分析-【CVE-2018-1270】

 

0x05 修复建议

 

 

使用华为云WAF立即防护

华为云安全团队第一时间对漏洞进行分析,云端下发内置规则进行防护,用户只需要接入华为云

WAF即可。点击开通WAF

 

使用华为云漏洞扫描服务进行安全检测

华为云漏洞扫描服务根据华为云安全团队漏洞分析后提取出对用户网站无害的安全检测规则,有效

帮助用户发现该漏洞。点击体验

 

升级代码框架

Spring Data Commons

2.0.x的用户升级到2.0.6

1.13.x的用户升级到1.13.11

 

Spring Data REST

2.x用户升级到2.6.11

3.x用户升级到3.0.6

 

Spring Boot

1.5.x用户升级到1.5.11

2.x用户升级到2.0.1

 

0x06 参考资料

 

[1] Spring Expressions Language 官方文档

[2] 漏洞公告

[3] Spring官方公告

[4] 漏洞修复代码Commit

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326186226&siteId=291194637