目录SQL Injection (SQL 注入)Low Level源码审计攻击方法判断注入类型判断几列可控获取表中的字段名获取目标信息Medium Level源码审计攻击方式判断注入类型判断几列可控获取表中的字段名获取目标信息High Level源码审计攻击方式Impossible Level总结与防御参考资料
SQL Injection (SQL 注入)
A SQL injection attack consists of insertion or "injection" of a SQL query via the input data from the client to the application. A successful SQL injection exploit can read sensitive data from the database, modify database data (insert/update/delete), execute administration operations on the database (such as shutdown the DBMS), recover the content of a given file present on the DBMS file system (load_file) and in some cases issue commands to the operating system.
SQL 注入是从客户端向应用程序的输入数据,通过插入或“注入” SQL 查询语句来进行攻击的过程。成功的 SQL 注入攻击可以从数据库中读取敏感数据、修改数据库数据(插入/更新/删除)、对数据库执行管理操作(例如关闭 DBMS)、恢复 DBMS 文件系统上存在的给定文件的内容,并在某些情况下也能向操作系统发出命令。
SQL injection attacks are a type of injection attack, in which SQL commands are injected into data-plane input in order to effect the execution of predefined SQL commands.This attack may also be called "SQLi".
SQL 注入是一种注入攻击,在这种攻击中 SQL 命令被注入到数据平面的输入中,以此影响预定义的 SQL 命令的执行,这种攻击也可以称为 “SQLi”。
There are 5 users in the database, with id's from 1 to 5. Your mission... to steal their passwords via SQLi.
数据库中有 5 个用户,id 从 1 到 5,你的任务是通过 SQLi 窃取他们的密码。
![](https://img2020.cnblogs.com/blog/1774310/202009/1774310-20200917170645294-205326827.png)
Low Level
The SQL query uses RAW input that is directly controlled by the attacker. All they need to-do is escape the query and then they are able to execute any SQL query they wish.
SQL 查询将使用攻击者直接控制的原始输入,攻击者所需要做的就是转义查询,然后就可以执行任何他们想要的 SQL 查询。
源码审计
源码如下,PHP 的 REQUEST 变量在默认情况下包含了 GET,POST 和 COOKIE 的数组。由此可见源码对输入的 id 完全信任,没有做任何过滤。观察到接收的 id 的左右内容将会被直接放入一个 SQL 查询语句,使用 mysqli_query 函数用该语句对某个数据库进行查询。mysqli_fetch_assoc() 函数从结果集中取得一行作为关联数组,然后将查询到的数据输出。
|