Safe3 common ASP injection prevention code

Source: Internet
Author: User
Tags servervariables

<%

'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
Rochelle 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> operation IP:" & IP & "<br> operation time:" & now () & "<br> operation page:" & request. servervariables ("url") & "<br> submission method:" & request. servervariables ("request_method") & "<br> submit parameter:" & l_get & "<br> submit data:" & 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
%>

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.