Home Database SQL Are you sure SQL injection is dead?

Are you sure SQL injection is dead?

Mar 15, 2021 am 09:46 AM
sql injection

Are you sure SQL injection is dead?

For a long time, I thought that the most common security problem in back-end development was SQL injection. Through the magical SQL writing method where 1=1, you can easily attack a problematic system, and eventually evolve into the existence of an artifact like sqlmap.

Are you sure SQL injection is dead?

The later fastjson refreshed my understanding. This framework can also be regarded as a promotion of the concept of Internet security. Even bosses who don't understand technology know that fastjson is extremely fast, and as a programmer, the safety concept has been improved.

Recommended (free):

sql##Why do you have a soft spot for sql injection? Because there are too many places where developers deal with SQL. Some students who specialize in report development even write more lines of SQL than lines of code!

The issue is. A long time ago, as early as 10 years ago, some people were shouting that SQL injection was dead, but to this day, there are still a large number of SQL injection tutorials and SQL injection cases.

SQL injection is the king of vulnerabilities, this is not a boast.

Of course, in this regard, PHP has made the greatest contribution, and Java is at a disadvantage.

The reason why SQL injection is popular is that developers are too confident in themselves, or the tools they use are too primitive and have not been filtered by the framework layer. If you use MyBatis or JPA in the Java world, the possibility of SQL injection becomes very low. Now PHP also has a framework similar to

thinkphp

, which means that there are fewer and fewer SQL injection vulnerabilities.

But that doesn’t mean there isn’t, it just means the threshold has been raised. Let's take MyBatis as an example to see if SQL injection can still occur.

SQL injection still exists in MyBatis

Students who use Mybatis, the first concepts they come into contact with are

# and

$ difference. These two symbols are very similar to the magic symbols in Shell, but fortunately there are only two situations.

  • # represents the use of sql pre-compilation, which is safe and reliable

  • $
  • represents The splicing method is used, and there is a risk of SQL injection

    For example, the following xml configuration is an absolutely safe way of writing. Because the entire
  • #{id}
will be replaced with

?.

<select id="queryAll"  resultMap="resultMap">
  SELECT * FROM order WHERE id = #{id}
</select>
Copy after login
But unfortunately, in some scenarios, precompilation cannot be used (or you just don't know or are lazy). For example, in some code refactorings, when fields such as table name/column name/sort are dynamically passed in, SQL splicing is inevitably required, and SQL injection still occurs.

But the more likely problems are statements like

LIKE

and

IN. The following is how to write two sentences of Like fuzzy query. In actual testing, it will be found that using

# is not easy to use and an error will be reported. You need to use sql splicing

$ . This is where the problem arises.

SELECT * FROM order WHERE name like &#39;%#{name}%&#39;  //会报语法错
SELECT * FROM order WHERE name like &#39;%${name}%&#39;  //可以运行
Copy after login
The correct way to write it is to use function splicing. But the construction deadline is overwhelming, and without even realizing it, most people choose the simple way of writing. After all, function comes first, and it is also the most important way to reflect workload.
SELECT * FROM order WHERE  name like concat(‘%’,#{name}, ‘%’) //正确的写法
Copy after login

The same problem exists in the

IN

statement.

in (#{tag}) //报错
in (${tag}) //可以运行
Copy after login
Since it can be run with just a few characters, of course no one chooses the complicated writing method below.
tag in
<foreach collection="tag" item="item" open="("separatosr="," close=")">
#{tag} 
</foreach>
Copy after login

Also order by, don’t take it lightly, otherwise you will be doomed.

SELECT * FROM order order by createDate #{sortType} //报错
SELECT * FROM order order by createDate ${sortType} //正常
Copy after login

In this case, you need to whitelist sortType. It’s not just ASC and DESC. You sent me a long string. What’s going on?

Summary

SQL injection still exists in 2021 , but the threshold has been raised. The decrease in SQL injection now is all due to the framework and has nothing to do with the level of programmers. The situation of sql splicing will never go away because it is the fastest and easiest way and will make people addicted to it. There are countless outsourcing projects, and there are many systems that have been lying dormant for more than ten years. It is a dream to hope that SQL injection will be eliminated at the framework layer.

Because its opponent is human laziness. No one can defeat it.

The above is the detailed content of Are you sure SQL injection is dead?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Nginx basic security knowledge: preventing SQL injection attacks Nginx basic security knowledge: preventing SQL injection attacks Jun 10, 2023 pm 12:31 PM

Nginx is a fast, high-performance, scalable web server, and its security is an issue that cannot be ignored in web application development. Especially SQL injection attacks, which can cause huge damage to web applications. In this article, we will discuss how to use Nginx to prevent SQL injection attacks to protect the security of web applications. What is a SQL injection attack? SQL injection attack is an attack method that exploits vulnerabilities in web applications. Attackers can inject malicious code into web applications

How to use exp for SQL error injection How to use exp for SQL error injection May 12, 2023 am 10:16 AM

0x01 Preface Overview The editor discovered another Double data overflow in MySQL. When we get the functions in MySQL, the editor is more interested in the mathematical functions. They should also contain some data types to save values. So the editor ran to test to see which functions would cause overflow errors. Then the editor discovered that when a value greater than 709 is passed, the function exp() will cause an overflow error. mysql>selectexp(709);+-----------------------+|exp(709)|+---------- ------------+|8.218407461554972

Laravel Development Notes: Methods and Techniques to Prevent SQL Injection Laravel Development Notes: Methods and Techniques to Prevent SQL Injection Nov 22, 2023 pm 04:56 PM

Laravel Development Notes: Methods and Techniques to Prevent SQL Injection With the development of the Internet and the continuous advancement of computer technology, the development of web applications has become more and more common. During the development process, security has always been an important issue that developers cannot ignore. Among them, preventing SQL injection attacks is one of the security issues that requires special attention during the development process. This article will introduce several methods and techniques commonly used in Laravel development to help developers effectively prevent SQL injection. Using parameter binding Parameter binding is Lar

PHP Programming Tips: How to Prevent SQL Injection Attacks PHP Programming Tips: How to Prevent SQL Injection Attacks Aug 17, 2023 pm 01:49 PM

PHP Programming Tips: How to Prevent SQL Injection Attacks Security is crucial when performing database operations. SQL injection attacks are a common network attack that exploit an application's improper handling of user input, resulting in malicious SQL code being inserted and executed. To protect our application from SQL injection attacks, we need to take some precautions. Use parameterized queries Parameterized queries are the most basic and most effective way to prevent SQL injection attacks. It works by comparing user-entered values ​​with a SQL query

Detection and repair of PHP SQL injection vulnerabilities Detection and repair of PHP SQL injection vulnerabilities Aug 08, 2023 pm 02:04 PM

Overview of detection and repair of PHP SQL injection vulnerabilities: SQL injection refers to an attack method in which attackers use web applications to maliciously inject SQL code into the input. PHP, as a scripting language widely used in web development, is widely used to develop dynamic websites and applications. However, due to the flexibility and ease of use of PHP, developers often ignore security, resulting in the existence of SQL injection vulnerabilities. This article will introduce how to detect and fix SQL injection vulnerabilities in PHP and provide relevant code examples. check

How to prevent SQL injection attacks using PHP How to prevent SQL injection attacks using PHP Jun 24, 2023 am 10:31 AM

In the field of network security, SQL injection attacks are a common attack method. It exploits malicious code submitted by malicious users to alter the behavior of an application to perform unsafe operations. Common SQL injection attacks include query operations, insert operations, and delete operations. Among them, query operations are the most commonly attacked, and a common method to prevent SQL injection attacks is to use PHP. PHP is a commonly used server-side scripting language that is widely used in web applications. PHP can be related to MySQL etc.

PHP form filtering: SQL injection prevention and filtering PHP form filtering: SQL injection prevention and filtering Aug 07, 2023 pm 03:49 PM

PHP form filtering: SQL injection prevention and filtering Introduction: With the rapid development of the Internet, the development of Web applications has become more and more common. In web development, forms are one of the most common ways of user interaction. However, there are security risks in the processing of form submission data. Among them, one of the most common risks is SQL injection attacks. A SQL injection attack is an attack method that uses a web application to improperly process user input data, allowing the attacker to perform unauthorized database queries. The attacker passes the

Improve system security: MyBatis tips to prevent SQL injection attacks Improve system security: MyBatis tips to prevent SQL injection attacks Feb 21, 2024 pm 09:12 PM

Improving system security: MyBatis tips for preventing SQL injection attacks With the continuous development of information technology, database applications have become an indispensable part of modern software systems. However, what follows is database security issues, the most common and serious of which is probably SQL injection attacks. SQL injection attacks refer to attackers inserting malicious SQL code into input fields to illegally obtain information in the database or destroy the integrity of the database. To protect against SQL

See all articles