Safe3通用asp防注入代碼

來源:互聯網
上載者:User

<%

'Copy Right By Safe3 www.safe3.cn
if request.querystring<>"" then stopinjection(request.querystring)
if request.Form<>"" then stopinjection(request.Form)
if request.Cookies<>"" then stopinjection(request.Cookies) 
function stopinjection(values)
        dim l_get, l_get2,n_get,regex,IP
 for each n_get in values
  for each l_get in values
   l_get2 = values(l_get)
   set regex = new regexp
   regex.ignorecase = true
   regex.global = true
   regex.pattern = "('|;|\*|declare\s|\sand\s|\sor\s|\sunion\s|\bselect\b|\bupdate\b|\binsert\b|\.\./|\.\.\\)"
   if regex.test(l_get2) then
                                IP=Request.ServerVariables("HTTP_X_FORWARDED_FOR")
                                If IP = "" Then
                                  IP=Request.ServerVariables("REMOTE_ADDR")
                                end if
                                slog("<br><br>操作IP: "&ip&"<br>操作時間: " & now() & "<br>操作頁面:"&Request.ServerVariables("URL")&"<br>提交方式: "&Request.ServerVariables("Request_Method")&"<br>提交參數: "&l_get&"<br>提交資料: "&l_get2)
    Response.Write "Illegal operation!"
                                Response.end
   end if
   set regex = nothing
  next
 next
end function

sub slog(logs)
        dim toppath,fs,Ts,Errorlog
        toppath = Server.Mappath("/log.htm")
                                Set fs = CreateObject("scripting.filesystemobject")
                                If Not Fs.FILEEXISTS(toppath) Then
                                    Set Ts = fs.createtextfile(toppath, True)
                                    Ts.close
                                end if
                                Set Ts= Fs.OpenTextFile(toppath,1)
                                    Do While Not Ts.AtEndOfStream
                                             Errorlog = Errorlog  & Ts.ReadLine  & chr(13) & chr(10)
                                    loop
                                    Ts.close
                                    Errorlog =Errorlog & logs
                                    Set Ts= Fs.OpenTextFile(toppath,2)
                                    Ts.writeline (Errorlog)
                                    Ts.Close
end sub
%>

聯繫我們

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

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

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.