mysql - 看这条sql有可能被注入吗
迷茫
迷茫 2017-04-17 15:04:00
0
3
629
SELECT * FROM table1 where condition1=1 ORDER BY $sortField$ $sortOrder$ limit 0,20

$sortField$$sortOrder$可以写任意sql

这条sql有被注入的风险吗

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(3)
左手右手慢动作

As long as you directly use variables to generate sql statements, there is a risk of being injected

SELECT * FROM table1 where condition1=1 ORDER BY $sortField$ $sortOrder$ limit 0,20

sortField="id"
sortOrder="; drop table users; --"

Your sql will become

SELECT * FROM table1 where condition1=1 ORDER BY id; drop table users; -- limit 0,20
Peter_Zhu

You are thinking about the problem in the wrong direction.

The correct way to prevent injection is to use the parameter mode of the official driver, because only the official version knows how to avoid being injected.

If you write SQL yourself, even if it is not injected now, maybe if one of the components involved in this link changes in the future, there will be a risk of being injected.

刘奇

You can directly test it with sqlmap, its engine is still very powerful

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!