Home > PHP Framework > Laravel > A brief analysis of the latest SQL injection vulnerability in PHP framework Laravel

A brief analysis of the latest SQL injection vulnerability in PHP framework Laravel

藏色散人
Release: 2019-10-02 17:51:44
forward
3970 people have browsed it

Laravel, the well-known PHP development framework, previously reported a high-risk SQL injection vulnerability on the official blog. Here is a brief analysis.

A brief analysis of the latest SQL injection vulnerability in PHP framework Laravel

First of all, this vulnerability belongs to the irregular coding of the website. The official gave a hint:

A brief analysis of the latest SQL injection vulnerability in PHP framework Laravel

But the official still did it It has been patched and can be fixed by upgrading to the latest version V5.8.7.

Let’s first locate here:

Illuminate\Validation\Rule
Copy after login

The officially recommended writing method is:

Rule::unique('users')->ignore($id),
Copy after login

If the website coding does not process the value of $id in advance, the user can pass it directly Giving malicious data to the ignore function will cause SQL injection.

Let’s follow the function:

\Illuminate\Validation\Rules\Unique.php class Unique {
... public function ignore($id, $idColumn = null) { if ($id instanceof Model) { return $this->ignoreModel($id, $idColumn);
        } $this->ignore = $id; $this->idColumn = $idColumn ?? 'id'; return $this;
    }
Copy after login

Here we do not consider writing $id as an instance. If $id is user-controllable, $idColumn can be written directly as empty, and finally assigned The situation is as follows:

$this->ignore = $id; $this->idColumn = 'id';
Copy after login

If the website code is structured like this, the value entered by the hacker is controllable:

$id = $request->input('id');
Copy after login

Finally we will get here:

Illuminate\Validation\Rules\Unique.php public function __toString() {
        ...
        ...
    }
Copy after login

We Take a look at the key code changes:

Illuminate\Validation\Rules\Unique.php
V5.8.7【最新版】 public function __toString() { $this->ignore ? '"'.addslashes($this->ignore).'"' : 'NULL',
    } 
Illuminate\Validation\Rules\Unique.php
V5.8.4 public function __toString() { $this->ignore ? '"'.$this->ignore.'"' : 'NULL',
    }
Copy after login

The latest code here is v5.8.7, which directly gives $this->ignore to addslashes. There was no protection here before.

What’s interesting is that the author compared the diffs, during which the official also tried to filter other quoted places. Finally, unified filtering was performed at __toString.

Finally, the following code will enter DatabaseRule for subsequent SQL rule matching.

Illuminate\Validation\Rules\DatabaseRule.php
Copy after login

There was no further processing after this, and then SQL injection was formed.

For more Laravel related technical articles, please visit the Laravel Framework Getting Started Tutorial column to learn!

The above is the detailed content of A brief analysis of the latest SQL injection vulnerability in PHP framework Laravel. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
Latest Issues
Composer cannot install laravel
From 1970-01-01 08:00:00
0
0
0
Laravel Space/laravel-backup cannot be installed
From 1970-01-01 08:00:00
0
0
0
Laravel 5.1 Login laravel comes with it No more
From 1970-01-01 08:00:00
0
0
0
Why thinkphp has better performance than laravel?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template