当前位置:网站首页>[HarekazeCTF2019]encode_and_encode
[HarekazeCTF2019]encode_and_encode
2022-07-26 22:39:00 【茶经新读.】
[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');
$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]);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);审计上面代码得知,我们需要用json的方式传page,并且会用到伪协议,并且会涉及到php file_get_contents函数:
php file_get_contents()函数:
定义与用法:
file_get_contents() 函数把整个文件读入一个字符串中。
和 file() 一样,不同的是 file_get_contents() 把文件读入一个字符串。
file_get_contents() 函数是用于将文件的内容读入到一个字符串中的首选方法。如果操作系统支持,还会使用内存映射技术来增强性能。
语法:
file_get_contents(path,include_path,context,start,max_length)
参数:
path 必需。规定要读取的文件。 include_path 可选。如果您还想在 include_path(在 php.ini 中)中搜索文件的话,请设置该参数为 '1'。 context 可选。规定文件句柄的环境。context 是一套可以修改流的行为的选项。若使用 NULL,则忽略。 start 可选。规定在文件中开始读取的位置。该参数是 PHP 5.1 中新增的。 max_length 可选。规定读取的字节数。该参数是 PHP 5.1 中新增的。 提示和注释:
提示:该函数是二进制安全的。(意思是二进制数据(如图像)和字符数据都可以使用此函数写入。)
示例:
<?php
echo file_get_contents("test.txt");
?>
上面的代码将输出:
This is a test with test text.
构造payload:
{"page":"php://filter/convert.base64-encode/resource=/flag"}
但是由于关键字flag、php都被禁用了,可以利用unicode编码来代替,构造新的payload:
{"page":"\u0070\u0068\u0070://filter/convert.base64-encode/resource=/\u0066\u006c\u0061\u0067"}
利用bp传一下数据,当抓包后点击about的时候,页面出来了{"page":"pages/about.html"},所以就用这个页面进行传值,就得到了base64加密字符串:

解密即得flag:

边栏推荐
- V-viewer use
- C语言 关机小程序
- Blue Bridge Cup 1004 [recursive] cow story
- C语言 求素数、闰年以及最小公倍数最大公约数
- [PCB open source sharing] stc32g12k128/stc8h8k64u development board
- JSCORE day_05(7.6)
- [leetcode] no duplicate longest string
- 3_Jupyter Notebook, numpy和matplotlib
- 6_ Gradient descent method
- [qt] container class, iterator, foreach keyword
猜你喜欢

JSCORE day_01(6.30) RegExp 、 Function

Vector size performance problems

Ubantu installing Oracle JDK

JSCORE day_04(7.5)

Find method of web page parsing by crawler

并行MPI程序传递发送消息
![[PCB open source sharing] stc32g12k128/stc8h8k64u development board](/img/f1/48b344722820ab262e751aebf65411.png)
[PCB open source sharing] stc32g12k128/stc8h8k64u development board
![[3. Basic search and first knowledge of graph theory]](/img/a2/dced231f746cc049d310e364a81856.png)
[3. Basic search and first knowledge of graph theory]

继承,继承,继承
Alibaba internal "shutter" core advanced notes~
随机推荐
AutoCAD的卸载后重新安装,删除注册表的详细过程
公司给了IP地址如何使用(详细版)
ES6中的export和import
Comparative simulation of LEACH protocol performance, including the number of dead nodes, data transmission, network energy consumption, the number of cluster heads and load balance
Signal and system impulse response and step response
【AcWing第61场周赛】
CDs simulation of minimum dominating set based on MATLAB
js中this指向详解
Helicopter control system based on Simulink
Ubantu installing Oracle JDK
寻找真凶
Complete review of parsing web pages
6_ Gradient descent method
【4.4 快速幂详解及快速幂求逆元】
简单的素数程序 初学者 希望码龄高的大佬可以一下
Friend friend function and singleton mode
输入一串字母 将里面的元音输出希望各位大佬能给指导
MySQL associative table queries (reducing the number of queries)
Openharmony quick start
【Codeforces Round #808 (Div 2.) A·B·C】