Hacker from cainiao (1) php

Source: Internet
Author: User
Our question: why do I need to add an and11 post at the end of the vulnerability to test the php website and then input an and12 post for submission? Next let's take a look at the most typical injection vulnerability code in PHP programs, as shown below: $. $ id.; very classic

Our question: why do I need to add an and 1 = 1 at the end of the php website to submit the php website? Let's take a look at the most typical injection vulnerability code in PHP programs, as shown below: $ id = $ _ GET [id]; $ query = SELECT * FROM my_table where id = '. $ id. '; // very classic

Our question: why do I need to add an and 1 = 1 at the end of the php website to submit the php website?

Let's take a look at the most typical injection vulnerability code in PHP programs, as shown below:

$ Id = $ _ GET ["id"];

$ Query = "SELECT * FROM my_table where id = '". $ id. "'"; // classic SQL Injection Vulnerability

$ Result = mysql_query ($ query );

The $ id parameter uses the $ _ GET method to access the content in the form field id and use it to obtain the value of the input id parameter. Without any filtering, $ id connects to the database query code with a string connector (.), and then executes the database query. Therefore, we can construct any data for the parameter id, resulting in a classic injection vulnerability.

We already know that in PHP, only $ _ GET is used to obtain the input data from the client. You can also use the $ _ POST and $ _ REQUEST methods to obtain data, so for the above $ id = $ _ GET ["id"]; you can also change it to $ id = $ _ POST ["id"]; or $ id = $ _ REQUEST ["id"];, but they still have the injection vulnerability, the method for obtaining client data is different.

Here, we assume that the correct value of the parameter id is 10. When we only submit id = 10, the query statement $ query is equivalent to SELECT * FROM my_table where id = 10, and the execution result is the information contained in id = 10. Of course, we will not be so obedient, just Enter id = 10. For example, if we enter id = 10', $ query is equivalent to SELECT * FROM my_table where id = 10 '. Because we know that the parameter id in the database cannot have a 10' value, the execution result must be incorrect, this is also the reason why an error is returned when we enter a single quotation mark page when the injection vulnerability exists. At this time, we can preliminarily determine that the injection vulnerability exists. If we enter id = 10 and 1 = 1, $ query is equal to SELECT * FROM my_table where id = 10 and 1 = 1, we already know the and operation rules. Because the result of the SELECT * FROM my_table where id = 10 operation is true and 1 = 1 is true, the true and operation is still true, therefore, the result returned by adding and 1 = 1 is still true. But what if we enter id = 10 and 1 = 2? $ Query is equivalent to SELECT * FROM my_table where id = 10 and 1 = 2, because SELECT * FROM my_table where id = 10 is true, 1 = 2 is false, that is, true and false, therefore, the execution result is false. This is why the result returned by adding input and 1 = 2 is incorrect. Therefore, by using single quotes, and 1 = 1, and 1 = 2, we can determine whether a website has an injection vulnerability.

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.