時(shí)間:2015-06-28 00:00:00 來(lái)源:IT貓撲網(wǎng) 作者:網(wǎng)管聯(lián)盟 我要評(píng)論(0)
Ewebeditor及fckeditork,90%的網(wǎng)站都是采用這兩種編輯器作為產(chǎn)品或者內(nèi)容的說(shuō)明部分的編輯窗口,近日,一客戶(hù)的外貿(mào)站點(diǎn)基本上快完工了,因客戶(hù)產(chǎn)品分類(lèi)多,故而讓客戶(hù)自己在后臺(tái)添加產(chǎn)品,但是客戶(hù)反映,在后臺(tái)添加產(chǎn)品時(shí),如果產(chǎn)品說(shuō)明內(nèi)容太過(guò)復(fù)雜的話(huà),產(chǎn)品怎么也添加不入數(shù)據(jù)庫(kù)中。
當(dāng)時(shí),我們也好生郁悶,這到底怎么回事,我們親自測(cè)試后臺(tái)添加任意的產(chǎn)品或者文字都能成功,偏偏他就不行,在網(wǎng)站搜索了相關(guān)的如"Ewebeditor 不能添加到數(shù)據(jù)庫(kù)",似乎找到了一點(diǎn)答案,因Ewebeditor自身沒(méi)對(duì)單引號(hào)過(guò)濾,導(dǎo)致了添加不到數(shù)據(jù)庫(kù)的問(wèn)題。于是乎,我們把編輯器換成了fckeditork,可是還是不行,那是Ewebeditor及fckeditork自帶的不完善導(dǎo)致的嗎?為什么一個(gè)簡(jiǎn)單的單引號(hào)會(huì)引發(fā)不能添加到數(shù)據(jù)庫(kù)呢,想到這里,我們想到了分析下入庫(kù)代碼,我們采用的是SQL=insert into product(title,content) values(' " &request("title")& "' ,' "&request("content")& " ' )的寫(xiě)法,于是我們找到客戶(hù)當(dāng)時(shí)COPY進(jìn)編輯器里的內(nèi)容,發(fā)現(xiàn),果然這內(nèi)容中包括有單引號(hào),原來(lái),正是由于客戶(hù)提交到編輯器里的內(nèi)容中含有單引號(hào),導(dǎo)致我們的SQL語(yǔ)句變化了,相當(dāng)于原來(lái)是SQL=insert into product(title,content) values('內(nèi)容' ,'內(nèi)容' )變成了SQL=insert into product(title,content) values(' 內(nèi)容' ,' 內(nèi)容'' ),我們細(xì)看就知道,就因?yàn)檫@content里多了個(gè)單引號(hào),SQL語(yǔ)句發(fā)生的嚴(yán)重的寫(xiě)法錯(cuò)誤,但是,我們也奇怪,既然他寫(xiě)法錯(cuò)誤,為什么SQL語(yǔ)句不給出錯(cuò)誤提示呢,竟然也會(huì)提示操作成功,想到這里,我們想到了2003年那幾年,普遍的小黑客喜歡用的' or' =' or' 的后臺(tái)入侵法,是乎正是利用了SQL執(zhí)行時(shí),沒(méi)過(guò)濾單引號(hào)的BUG,導(dǎo)致SQL怎么執(zhí)行,結(jié)果都返回真,呵呵,沒(méi)想到,原以為寫(xiě)程序盡量圖個(gè)簡(jiǎn)單明了,也是個(gè)錯(cuò)啊。好了,問(wèn)題找到了,以后,凡是SQL入庫(kù)前,我們都把字段過(guò)濾后再傳值,就不會(huì)再出這樣的問(wèn)題了,下面是一個(gè)非常完善的SQL安全過(guò)濾函數(shù),大家直接拿去就可以調(diào)用了。
Function HTMLEncode(Str) ?If Isnull(Str) Then ???? HTMLEncode = "" ???? Exit Function ?End If ?Str = Replace(Str,Chr(0),"", 1, -1, 1) ?Str = Replace(Str, """", """, 1, -1, 1) ?Str = Replace(Str,"<","<", 1, -1, 1) ?Str = Replace(Str,">",">", 1, -1, 1) ?Str = Replace(Str, "script", "script", 1, -1, 0) ?Str = Replace(Str, "SCRIPT", "SCRIPT", 1, -1, 0) ?Str = Replace(Str, "Script", "Script", 1, -1, 0) ?Str = Replace(Str, "script", "Script", 1, -1, 1) ?Str = Replace(Str, "object", "object", 1, -1, 0) ?Str = Replace(Str, "OBJECT", "OBJECT", 1, -1, 0) ?Str = Replace(Str, "Object", "Object", 1, -1, 0) ?Str = Replace(Str, "object", "Object", 1, -1, 1) ?Str = Replace(Str, "applet", "applet", 1, -1, 0) ?Str = Replace(Str, "APPLET", "APPLET", 1, -1, 0) ?Str = Replace(Str, "Applet", "Applet", 1, -1, 0) ?Str = Replace(Str, "applet", "Applet", 1, -1, 1) ?Str = Replace(Str, "[", "[") ?Str = Replace(Str, "]", "]") ?Str = Replace(Str, """", "", 1, -1, 1) ?Str = Replace(Str, "=", "=", 1, -1, 1) ?Str = Replace(Str, "'", "''", 1, -1, 1) ?Str = Replace(Str, "select", "select", 1, -1, 1) ?Str = Replace(Str, "execute", "execute", 1, -1, 1) ?Str = Replace(Str, "exec", "exec", 1, -1, 1) ?Str = Replace(Str, "join", "join", 1, -1, 1) ?Str = Replace(Str, "union", "union", 1, -1, 1) ?Str = Replace(Str, "where", "where", 1, -1, 1) ?Str = Replace(Str, "insert", "insert", 1, -1, 1) ?Str = Replace(Str, "delete", "delete", 1, -1, 1) ?Str = Replace(Str, "update", "update", 1, -1, 1) ?Str = Replace(Str, "like", "like", 1, -1, 1) ?Str = Replace(Str, "drop", "drop", 1, -1, 1) ?Str = Replace(Str, "create", "create", 1, -1, 1) ?Str = Replace(Str, "rename", "rename", 1, -1, 1) ?Str = Replace(Str, "count", "count", 1, -1, 1) ?Str = Replace(Str, "chr", "chr", 1, -1, 1) ?Str = Replace(Str, "mid", "mid", 1, -1, 1) ?Str = Replace(Str, "truncate", "truncate", 1, -1, 1) ?Str = Replace(Str, "nchar", "nchar", 1, -1, 1) ?Str = Replace(Str, "char", "char", 1, -1, 1) ?Str = Replace(Str, "alter", "alter", 1, -1, 1) ?Str = Replace(Str, "cast", "cast", 1, -1, 1) ?Str = Replace(Str, "exists", "exists", 1, -1, 1) ?Str = Replace(Str,Chr(13)," ", 1, -1, 1) ?HTMLEncode = Replace(Str,"'","''", 1, -1, 1) End Function |
文章首發(fā):http://www.seohf.com/seonews/view654.html 如需轉(zhuǎn)載,請(qǐng)注明出處。
關(guān)鍵詞標(biāo)簽:Ewebeditor,fckeditor
相關(guān)閱讀
熱門(mén)文章 ASP編程代碼:隱藏圖片的真實(shí)地址 ASP教程:0177:800401f3錯(cuò)誤解決 ASP代碼中如何屏蔽ip地址 禁止某IP段訪(fǎng)問(wèn)網(wǎng)站 錯(cuò)誤80004005信息處理方法
人氣排行 ASP下標(biāo)越界的解決方法 ASP代碼中如何屏蔽ip地址 禁止某IP段訪(fǎng)問(wèn)網(wǎng)站 “文件共享鎖定數(shù)溢出” 原因及解決方法 無(wú)法寫(xiě)入數(shù)據(jù)庫(kù)的解決方法 ASP教程:0177:800401f3錯(cuò)誤解決 ASP常用函數(shù)列表 如何用ASP來(lái)獲取客戶(hù)端真實(shí)IP的地址 ASP用FSO生成HTML簡(jiǎn)單實(shí)例+詳解[原創(chuàng)]