Simple ASP anti-injection code

Source: Internet
Author: User
Tags servervariables

<%

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 % 20 table"

Xh_inf = Split (xh_in, "| ")

'-------- Post part ------------------
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> operation IP Address:" & request. servervariables ("remote_addr") & "<br> operation time:" & now & "<br> operation page:" & request. servervariables ("url") & "<br> submit method: Post <br> submit parameter:" & xh_post & "<br> submit data:" & request. form (xh_post ))
Response. Write "invalid operation"
Response. End
End if
Next
Next
End if
'----------------------------------

'-------- Get part -------------------
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> operation IP Address:" & request. servervariables ("remote_addr") & "<br> operation time:" & now & "<br> operation page:" & request. servervariables ("url") & "<br> submit method: Get <br> submit parameter:" & xh_get & "<br> submit data:" & request. querystring (xh_get ))
Response. Write "invalid operation"
Response. End
End if
Next
Next
End if
'----------------------------------

'-------- Cookie section -------------------
If request. Cookies <> "" then
For each xh_cookie in request. Cookies

For xh_xh = 0 to ubound (xh_inf)
If instr (lcase (request. Cookie (xh_cookie), xh_inf (xh_xh) <> 0 then

Slog ("<br> operation IP Address:" & request. servervariables ("remote_addr") & "<br> operation time:" & now & "<br> operation page:" & request. servervariables ("url") & "<br> submit method: Cookie <br> submit parameter:" & xh_cookie & "<br> submit data:" & request. cookies (xh_cookie ))
Response. Write "invalid operation"
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

%>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.