In-depth understanding of SQL injection and SQL

Source: Internet
Author: User
Tags how to prevent sql injection

In-depth understanding of SQL injection and SQL

1. What is SQL injection )?

SQL injection is an attack method that adds SQL code to input parameters and passes it to the SQL Server for parsing and execution.

2. How to generate it?

Web developers cannot ensure that all input is filtered

Attackers use the input data sent to the SQL Server to construct executable SQL code.

The database does not have the corresponding Security Configuration

3. How to Find SQL vulnerabilities?

Recognize all input points in a web application

What types of requests will trigger exceptions? (Special Character "or ')

Detect exceptions in Server Response

4. How to launch SQL injection attacks?

Digital Injection:

Select * from tablename where id = 1 or 1 = 1;

String injection:

Note feature of Mysql:

# And -- are commented out, regardless of what password is entered, can be correctly queried. Click here to enter the image description

5. How to Prevent SQL injection?

Strictly check the input format: is_numeric (var), tp5 validate verification, and string injection using regular expressions to check whether the value is between [A-Za-z ].

Escape: addslashes (str ),

Escape the mysqli_escape_string () function

6. MySQLi pre-compilation Mechanism

Parameterized binding

Parameterized binding prevents another barrier of SQL injection. Php MySQLi and PDO provide such functions. For example, you can query MySQLi as follows:

PDO is more convenient, such:

Related Article

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.