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

How to build lnmp environment in docker

Create a project directory mkdir php Create the f...

Sample code for cool breathing effect using CSS3+JavaScript

A simple cool effect achieved with CSS3 animation...

Example code for implementing the wavy water ball effect using CSS

Today I learned a new CSS special effect, the wav...

How to change the MySQL database file directory in Ubuntu

Preface The company's Ubuntu server places th...

Detailed explanation of the abbreviation of state in react

Preface What is state We all say that React is a ...

Detailed tutorial on installing Docker and nvidia-docker on Ubuntu 16.04

Table of contents Docker Installation Nvidia-dock...

MySQL 5.7.23 decompression version installation tutorial with pictures and text

Download the MySQL installer Official download ad...

Vue implements the right slide-out layer animation

This article example shares the specific code of ...

Vue application example code based on axios request encapsulation

Table of contents What is axios? Axios request ty...

React implements the sample code of Radio component

This article aims to use the clearest structure t...