簡單的asp防注入代碼

來源:互聯網
上載者:User

<%

Dim XH_Post,XH_Get,XH_Cookie,XH_In,XH_Inf,XH_Xh

XH_In = "'|;|*|and|union|declare|exec|insert|select|update|delete%20from|drop%20table|create%20table"

XH_Inf = split(XH_In,"|")

'--------POST部份------------------
If Request.Form<>"" Then
For Each XH_Post In Request.Form

For XH_Xh=0 To Ubound(XH_Inf)
If Instr(LCase(Request.Form(XH_Post)),XH_Inf(XH_Xh))<>0 Then

slog("<br><br>操作ip:"&Request.ServerVariables("REMOTE_ADDR")&"<br>操作時間:"&Now&"<br>操作頁面:"&Request.ServerVariables("URL")&"<br>提交方式:POST<br>提交參數:"&XH_Post&"<br>提交資料:"&Request.Form(XH_Post))
Response.Write "非法操作"
Response.End
End If
Next
Next
End If
'----------------------------------

'--------GET部份-------------------
If Request.QueryString<>"" Then
For Each XH_Get In Request.QueryString

For XH_Xh=0 To Ubound(XH_Inf)
If Instr(LCase(Request.QueryString(XH_Get)),XH_Inf(XH_Xh))<>0 Then

slog("<br><br>操作ip:"&Request.ServerVariables("REMOTE_ADDR")&"<br>操作時間:"&Now&"<br>操作頁面:"&Request.ServerVariables("URL")&"<br>提交方式:GET<br>提交參數:"&XH_Get&"<br>提交資料:"&Request.QueryString(XH_Get))
Response.Write "非法操作"
Response.End
End If
Next
Next
End If
'----------------------------------

'--------COOKIE部份-------------------
If Request.Cookies<>"" Then
For Each XH_Cookie In Request.Cookies

For XH_Xh=0 To Ubound(XH_Inf)
If Instr(LCase(Request.Cookies(XH_Cookie)),XH_Inf(XH_Xh))<>0 Then

slog("<br><br>操作ip:"&Request.ServerVariables("REMOTE_ADDR")&"<br>操作時間:"&Now&"<br>操作頁面:"&Request.ServerVariables("URL")&"<br>提交方式:Cookie<br>提交參數:"&XH_Cookie&"<br>提交資料:"&Request.Cookies(XH_Cookie))
Response.Write "非法操作"
Response.End
End If
Next
Next
End If

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.