改進的SQL防注入

來源:互聯網
上載者:User
防注入 <%
'ASP防注入之解決方案'特殊頁面處理'因為有些頁通過流式傳遞(比如含有檔案上傳的表單)'如果單一使用窮舉Form對象的操作就會出錯'所以要把這些頁面過濾出來,同時在頁面中使用sql("檢測的字串")才行'垃圾豬zero@new57.com'http://blog.csdn.net/cfaq
'源碼下載http://www.new57.com/softback/sql.rar


'將本頁用include方法放在頭部以讓所有頁都可以調用,比如include在conn.asp裡'如果有流式上傳的頁面請把該頁加到表page中,以防form衝突

Dim N_no,N_noarray,req_Qs,req_F,N_i,N_dbstr,Conn,N_rs,N_userIP,N_thispageN_userip = Request.ServerVariables("REMOTE_ADDR")N_thispage = LCase(Request.ServerVariables("URL"))
N_no = "'|;|and|exec|insert|select|delete|update|count|*|%|chr|mid|master|truncate|char|declare" '可以自己修改懷疑是注入操作的字串N_noarray = split(LCase(N_no),"|")
Call DBopen()Call N_check_Qs()Call N_checkPage()Call DBCLose()
'檢測當前頁是否是特殊頁是就調用 N_check_form()sub N_checkPage()
set N_rs = server.CreateObject("ADODB.RecordSet") N_rs.open "select * from page where spcpage like '%"&N_thispage&"%'",conn,1,1 if (N_rs.eof AND N_rs.Bof) then Call N_check_form() end if N_rs.Close() set N_rs = nothing
end sub


'檢測給定字串sub N_sql(agsql) '這裡是不記錄資料庫,如果要改請自己修改 N_check "CUS",req_Qs,"OTHER"end sub
'檢測Request.Formsub N_check_form() If Request.Form<>"" Then For Each req_F In Request.Form N_check req_F,Request.Form(req_F),"POST" Next end ifend sub
'檢測Request.QueryStringsub N_check_Qs() If Request.QueryString<>"" Then For Each req_Qs In Request.QueryString N_check req_Qs,Request.QueryString(req_Qs),"GET" Next end ifend sub
'檢測sub N_check(ag,agsql,sqltype) For N_i=0 To Ubound(N_noarray) If Instr(LCase(agsql),N_noarray(N_i))<>0 Then call N_regsql(ag,agsql,sqltype) Response.Write "MO" end if Nextend sub
'記錄並停止輸出'ag 名稱'agsql 內容'sqltype 類型sub N_regsql(ag,agsql,sqltype) if(sqltype<>"OTHER") then Conn.Execute("insert into SqlIn(Sqlin_IP,SqlIn_Web,SqlIn_FS,SqlIn_CS,SqlIn_SJ) values('"&N_userip&"','"&N_thispage&"','"&sqltype&"','"&ag&"','"&agsql&"')") end if Response.Write "<Script Language=JavaScript>alert('請不要在參數中包含非法字元嘗試注入!');</Script>" Response.Write "<span style='font-size:12px'>非法操作!系統做了如下記錄↓<br>" Response.Write "操作IP:"&N_userip&"<br>" Response.Write "操作時間:"&Now&"<br>" Response.Write "操作頁面:"&N_thispage&"<br>" Response.Write "提交方式:"&sqltype&"<br>" Response.Write "提交參數:"&ag&"<br>" Response.Write "提交資料:"&agsql&"</span>" Response.endend sub
Sub DBopen() N_dbstr="DBQ="+server.mappath("Sql.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};" Set Conn=Server.CreateObject("ADODB.CONNECTION") Conn.open N_dbstrend SUB
Sub DBCLose() Conn.close Set Conn = NothingEnd sub%>



相關文章

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。