Flag:
<?php
// code by SEC@USTC
echo \'<html><head>< http-equiv=\"charset\" content=\"gbk\"></head><body>\';
$URL = $_SERVER[\'REQUEST_URI\'];
//echo \'URL: \'.$URL.\'<br/>\';
$flag = \"CTF{???}\";
$code = str_replace($flag, \'CTF{???}\', file_get_contents(\'./index.php\')); //将./index.php中内容的$flag替换为CTF{???}
$stop = 0;
//这道题目本身也有教学的目的
//第一,我们可以构造 /indirection/a/../ /indirection/./ 等等这一类的
//所以,第一个要求就是不得出现 ./
if($flag && strpos($URL, \'./\') !== FALSE){ // strpos()返回 ./ 在$url第一次出现的位置
$flag = \"\";
$stop = 1; //Pass
}
//第二,我们可以构造 \\ 来代替被过滤的 /
//所以,第二个要求就是不得出现 ../
if($flag && strpos($URL, \'\\\\\') !== FALSE){
$flag = \"\";
$stop = 2; //Pass
}
//第三,有的系统大小写通用,例如 indirectioN/
//你也可以用?和#等等的字符绕过,这需要统一解决
//所以,第三个要求对可以用的字符做了限制,a-z / 和 .
$matches = array();
preg_match(\'/^([0-9a-z\\/.]+)$/\', $URL, $matches); // 将url中的0-9,a-z,/.匹配出来放到$matches数组中
if($flag && empty($matches) || $matches[1] != $URL){
$flag = \"\";
$stop = 3; //Pass
}
//第四,多个 / 也是可以的
//所以,第四个要求是不得出现 //
if($flag && strpos($URL, \'//\') !== FALSE){
$flag = \"\";
$stop = 4; //Pass
}
//第五,显然加上index.php或者减去index.php都是可以的
//所以我们下一个要求就是必须包含/index.php,并且以此结尾
if($flag && substr($URL, -10) !== \'/index.php\'){
$flag = \"\";
$stop = 5; //Pass
}
//第六,我们知道在index.php后面加.也是可以的
//所以我们禁止p后面出现.这个符号
if($flag && strpos($URL, \'p.\') !== FALSE){
$flag = \"\";
$stop = 6; //Pass
}
//第七,现在是最关键的时刻
//你的$URL必须与/indirection/index.php有所不同
if($flag && $URL == \'/indirection/index.php\'){
$flag = \"\";
$stop = 7; //Not Pass
}
if(!$stop) $stop = 8;
echo \'Flag: \'.$f】lag;
echo \'<hr />\';
for($i = 1; $i < $stop; $i++)
$code = str_replace(\'//Pass \'.$i, \'//Pass\', $code);
for(; $i < 8; $i++)
$code = str_replace(\'//Pass \'.$i, \'//Not Pass\', $code);
echo highlight_string($code, TRUE);
echo \'</body></html>\';
进行了七次条件限制
url伪静态
简单来说,比如http://ctf5.shiyanbar.com/indirection/index.php/user/index.php,虽然在index.php后面还加上了一些东西,但是这个user会被解析成参数名,而index.php则会被解析成user的值
题目的意思就是通过改变URL地址栏访问index.php,但是限制了条件不能使用 ./ ../ \\\\ 而且只能使用小写字母,不可以在php后加点,
关键是不能直接是http://ctf5.shiyanbar.com/indirection/index.php
这里我们可以利用伪静态技术,使用http://ctf5.shiyanbar.com/indirection/index.php/index.php,index.php后的index.php会被当做参数处理,所以服务器只会解析第一个index.php,满足条件成功绕过。
继续阅读与本文标签相同的文章
上一篇 :
十个实用MySQL命令
下一篇 :
【设计模式】桥接模式
-
史上最详细Java内存区域讲解
2026-05-19栏目: 教程
-
Hystrix Dashboard:断路器执行监控
2026-05-19栏目: 教程
-
AGV为什么要选择视觉导航
2026-05-19栏目: 教程
-
《Absolute Java 中文版》| 每日读本书
2026-05-19栏目: 教程
-
汽车圈微信聊天记录大曝光
2026-05-19栏目: 教程
