Compile a common asp anti-injection program

Source: Internet
Author: User

Compile a general asp anti-injection program and select the Blog from ph4studio
Write common asp injection prevention program with keywords
Source

SQL Injection has been played by so-called cainiao-level hackers. It is found that most of today's hacker intrusions are implemented based on SQL injection.
Hey, who makes it easy to get started? Well, let's not talk nonsense. Now I am going to say that if you write a general SQL anti-injection program
Generally, http requests are similar to get and post requests, so as long as we filter all the parameters in post or get requests in the file
Invalid characters, so we can filter the http request information to determine whether it is being attacked by SQL injection.
The get Request passed by iis to asp. dll is a string. After the data is passed to Request. QueryString ,,
The asp parser analyzes the information of Request. QueryString, and then splits the data in each array according "&".
So the get interception is as follows:
First, we define that the request cannot contain the following characters:
'| And | exec | insert | select | delete | update | count | * | % | chr | mid | master | truncate | char | declare
Each character is separated by "|", and then the obtained Request. QueryString is determined.
The Code is as follows:
Dim SQL _injdata
SQL _injdata = "'| and | exec | insert | select | delete | update | count | * | % | chr | mid | master | truncate | char | declare"
SQL _inj = split (SQL _Injdata, "| ")

If Request. QueryString <> "Then
For Each SQL _Get In Request. QueryString
For SQL _Data = 0 To Ubound (SQL _inj)
If instr (Request. QueryString (SQL _Get), SQL _Inj (SQL _DATA)> 0 Then
Response. Write "<Script Language = ***> alert! '); History. back (-1) </Script>"
Response. end
End if
Next
Next
End If
In this way, we implement the get request injection interception, but we also need to filter the post request, so we have to continue to consider the request. form, which also exists in the form of an array. We only need to make another round-robin judgment. The Code is as follows:
If Request. Form <> "" Then
For Each SQL _Post In Request. Form
For SQL _Data = 0 To Ubound (SQL _inj)
If instr (Request. Form (SQL _Post), SQL _Inj (SQL _DATA)> 0 Then
Response. Write "<Script Language = ***> alert! NnHTTP: // www.521movie.com '); history. back (-1) </Script>"
Response. end
End if
Next
Next
End if
Now, we have implemented information interception for get and post requests. You only need to reference this page before opening database files such as conn. asp. Rest assured that you will continue to develop your program, and you do not have to consider whether or not you will be attacked by SQL injection. Isn't it?

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.