Mysql DATA Truncation

Source: Internet
Author: User

LengF: I read these two points carefully in PHP advanced vulnerability review technology. I will keep a note for the time being.
For many web application files, repeated data is not allowed in many functions, such as the user registration function. The general application compares the username submitted for registration with the existing username in the database to see if there is already repeated data. However, we can repeat these judgments through "Data truncation, when the database is processing, truncation is generated, leading to the insertion of duplicate data.

1) Mysql SQL Column Truncation Vulnerabilities

This vulnerability was discovered by Stefan Esser (Stefan Esser is my idol :)), because when mysql sets SQL _mode to default, that is, when the STRICT_ALL_TABLES option is not enabled, mySQL only prompts the warning message for inserting a very long value, instead of an error (insertion fails if it is an error), which may cause some truncation problems. The test is as follows:

Mysql> insert into truncated_test ('username', 'Password') values ("admin", "pass ");

Mysql> insert into truncated_test ('username', 'Password') values ("admin x", "new_pass ");
Query OK, 1 row affected, 1 warning (0.01 sec)

Mysql> select * from truncated_test;
+ ---- + ------------ + ---------- +
| Id | username | password |
+ ---- + ------------ + ---------- +
| 1 | admin | pass |
| 2 | admin | new_pass |
+ ---- + ------------ + ---------- +
2 rows in set (0.00 sec)


2) Mysql charset Truncation vulnerability

This vulnerability was discovered by 80 sec. when mysql stores and processes utf8 and other data, data is truncated due to certain characters. The test is as follows:

Mysql> insert into truncated_test ('username', 'Password') values (concat ("admin", 0xc1), "new_pass2 ");
Query OK, 1 row affected, 1 warning (0.00 sec)

Mysql> select * from truncated_test; www.2cto.com
+ ---- + ------------ + ---------- +
| Id | username | password |
+ ---- + ------------ + ---------- +
| 1 | admin | pass |
| 2 | admin | new_pass |
| 3 | admin | new_pass2 |
+ ---- + ------------ + ---------- +
2 rows in set (0.00 sec)


Many web applications do not consider these issues, but simply query whether the data contains the same data before data storage. The following code:

$ Result = mysql_query ("SELECT * from test_user where user = '$ user '");
....
If (@ mysql_fetch_array ($ result, MYSQL_NUM )){
Die ("already exist ");
}

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.