Beetl最近也没有更新,正好有时间贡献点其他方面的文章。
Struts2官方已经发布了多次漏洞补丁,但根源在于OGNL能调用静态办法,所以彻底解决漏洞的办法是底层禁止OGNL调用一些特定的java类,如System,Runtime类
我们目前推荐在原有过滤的基础上,增加一个patch包以对底层调用过滤,随后,公司内部已经布一个ongl_patch.jar,基本上引入后,在项目的servlet/struts/spring 任何一个框架的listener里调用里面的方法初始化一下,就可以了
其实质就是做如下初始化:
OgnlRuntime.setMethodAccessor(OgnlTest.class, new NoMethodAccessor());
OgnlRuntime.setMethodAccessor(Runtime.class, new NoMethodAccessor());
OgnlRuntime.setMethodAccessor(System.class, new NoMethodAccessor());
OgnlRuntime.setMethodAccessor(ProcessBuilder.class,
new NoMethodAccessor());
OgnlRuntime
.setMethodAccessor(OgnlRuntime.class, new NoMethodAccessor());
NoMethodAccessor实现了OGNL的 MethodAccessor,
如下:
public class NoMethodAccessor implements MethodAccessor {
public NoMethodAccessor() {
int i = 1;
}
@Override
public Object callStaticMethod(Map context, Class targetClass,
String methodName, Object[] args) throws MethodFailedException {
throw new MethodFailedException("do not run", "123");
}
@Override
public Object callMethod(Map context, Object target, String methodName,
Object[] args) throws MethodFailedException {
// TODO Auto-generated method stub
throw new MethodFailedException("do not run", "123");
}
}