Improved SQL Injection Prevention

Source: Internet
Author: User
<%
'Asp anti-injection solution 'special page process' because some pages are streamed (such as forms with file uploads) 'If you use a single Form object, an error will occur. 'filter out these pages and use SQL ("checked strings") on the page ") just get 'Spam pigs' http: // blog.111cn.net/cfaq
'Source Code Download http://www.new57.com/softback/ SQL .rar


'Put the include method on this page in the header so that all pages can be called, for example, include in conn. asp: 'If you have a streaming upload page, add this page to the table page to prevent form conflict.

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 "'can be modified on your own to suspect injection operations. string N_noarray = split (LCase (N_no ), "| ")
Call DBopen () Call N_check_Qs () Call N_checkPage () Call DBCLose ()
'If the current page is a special page, call 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


'Check the given string sub N_ SQL (agsql) '. The database is not recorded here. If you want to modify it, modify N_check "CUS", req_Qs, "OTHER" end sub
'Check the 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
'Check the 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
'Check 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

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.