A Deeper Look at SQL Injection

A Deeper Look at SQL Injection

1. What is SQL injection?

Sql injection is an attack method that adds sql code to the input parameter and passes it to the Sql server for parsing and execution.

2. How did it come about?

Web developers cannot guarantee that all input is sanitized

The attacker constructs executable SQL code using the input data sent to the SQL server

The database is not configured for security

3. How to find SQL vulnerabilities?

Identify all input points in a web application

Understand what types of requests trigger exceptions? (special characters " or ')

Detect anomalies in server responses

4. How to perform SQL injection attack?

Digital Injection:

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

String injection:

MySQL's comment feature:

The characters after # and -- are commented out, so no matter what password is entered, it can be queried correctly. Please click here to enter image description

5. How to prevent SQL injection?

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

Escape: addslashes(str),

mysqli_escape_string() function to escape

6.MySQLi's precompilation mechanism

Parameterized Binding

Parameterized binding is another barrier to prevent SQL injection. PHP MySQLi and PDO both provide such functionality. For example, MySQLi can query like this:

PDO is even more convenient, for example:

You may also be interested in:
  • Java interview question analysis: judgment and prevention of SQL injection
  • SQL injection principles and solution code examples
  • Solve SQL injection problems through ibatis
  • Win2003 server anti-SQL injection artifact--D shield_IIS firewall
  • Sql injection tool_PowerNode Java Academy
  • Introduction to the Principle of Sql Injection_PowerNode Java Academy
  • How to find websites with SQL injection (must read)
  • Share a simple sql injection
  • Mybatis prevent sql injection example
  • Several solutions to prevent SQL injection when using Hibernate
  • Summary of 5 effective ways to prevent SQL injection
  • Summary of file reading and writing methods in SQL injection

<<:  How to generate a free certificate using openssl

>>:  How to write memory-efficient applications with Node.js

Recommend

About scroll bar in HTML/removing scroll bar

1. The color of the scroll bar under xhtml In the ...

Detailed tutorial on installing CUDA9.0 on Ubuntu16.04

Preface: This article is based on the experience ...

MySQL 4 common master-slave replication architectures

Table of contents One master and multiple slaves ...

MySQL Database Basics: A Summary of Basic Commands

Table of contents 1. Use help information 2. Crea...

CSS to achieve Skeleton Screen effect

When loading network data, in order to improve th...

Summary of MySQL composite indexes

Table of contents 1. Background 2. Understanding ...

MySQL query statement grouped by time

MySQL query by year, month, week, day group 1. Qu...

Nginx reverse proxy configuration removes prefix

When using nginx as a reverse proxy, you can simp...

Summary of knowledge points about covering index in MySQL

If an index contains (or covers) the values ​​of ...

Analysis of 2 Token Reasons and Sample Code in Web Project Development

Table of contents question: There are 2 tokens in...

Usage and difference of Js module packaging exports require import

Table of contents 1. Commonjs exports and require...

How to mount the CD to find the rpm package under Linux

Written in front Sometimes you need to install so...

HTML adaptive table method

<body style="scroll:no"> <tabl...