Add SQL injection attacks to programs

Source: Internet
Author: User

SQL injection attacks are generally used by hackers to attack other users' websites or programs. But now we can switch our minds and use SQL injection to serve us.

For example, there is an old program that uses simple Layer 3. The table name operated by this program is Table1, And the Table1 fields include:
Id (int), column1 (nvarchar (50), column2 (nvarchar (50), adddate (smalldatetime ).

Here, the adddate field is appended, that is, some data elements have values for the adddate field, some are null, and the value of the adddate field is not used in the original program, adddate is required to determine different years, and empty values are divided into old data (for example, null and 2013 both belong to data of, and data of belongs to data ), you cannot change the data in the database.

Suppose we can write a method in the DAL and BLL layers to pass in only the year (for example, pass in 2013, and the parameter is named year) and call it in the Web layer. To write programs using the SQL injection method, we do not make too many logical judgments on the passed year, just put year into a pre-written SQL statement for execution (assuming that our SQL query statement is very simple, for example: string SQL = "select * from Table1 where adddate> = '" + year + "/1/1' and adddate <= '" + year + "/12/31 '";),

In this case, the data obtained in January 2013 does not contain data elements whose time is null. In this case, we can use SQL injection to set the year value to "'or adddate is null and 1 = '1 ';--", the data found after execution is the sum of 2013 and null.

The above is just a simple reverse idea I want: Put the things originally used for hacking into a program for the correct purpose. To put it deeper, it means that the originally harmful things are not necessarily completely harmful (that is, just put the wrong place). Using them in the right place will achieve good results.

I am a newbie. Do not spray.

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.