Mysql database uses the concat function to execute SQL injection query _ MySQL

Source: Internet
Author: User
Tags sql injection query
This article mainly introduces how to use the concat function in Mysql to execute SQL injection queries. the concat function has an unexpected effect in SQL injection queries. This article will explain how to use it, you can refer to the SQL injection statements that sometimes use the replacement query technology to make the original query statement fail to find the result and make the self-constructed query statement run, the execution result is displayed instead of the query result of the original query statement.

For example, the original query statement is

The code is as follows:


Select username, email, content from test_table where user_id = uid;


Uid is entered by the user. The user name, user email address, and user message content are displayed normally. However, if the uid filtering is lax, we can construct the following SQL statement to obtain information about any data table.

The code is as follows:


Uid =-1 union select username, password, content from test_talbe where user_id = administrator id;


The actual execution is

The code is as follows:


Select username, email, content from test_table where user_id =-1 union select username, password, content from test_talbe where user_id = administrator id;


Where the emai of a normal user is displayed, the administrator password is displayed.

However, it is often not that simple. First, you need to find the vulnerability. second, when constructing such statements, you need to consider the types of each field. it is obviously inappropriate to display fields of the int or samllint type in varchar. Finally, I will talk about it in this article.

If the SQL statement has only one or two fields, we want to know a lot. one or two fields are too few to meet our needs. Then we can use the concat function.

The concat function uses select concat ('My, s', 'ql ') in this way. The execution result is 'mysql '. That is, the connection function. We use it to serve us,

The code is as follows:


Uid =-1 union select username, concat (password, sex, address, telephone), content from test_talbe where user_id = administrator id;


This statement actually queries six fields, but when it is displayed, the password, sex, address, telephone and other fields are combined and displayed in the original place where the email should be displayed.

Better method: separate them with separators:

The code is as follows:


Uid =-1 union select username, concat (password, 0 × 3a, sex, 0 × 3a, address, 0 × 3a, telephone), content from test_talbe where user_id = administrator id;


0 × 3a indicates the hexadecimal format.

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.