hdwiki注入导致任意文件下载

hdwiki上传附件处文件名过滤不严,导致可以注入:

1
2
3
4
5
6
7
8
9
10
11
12
13
function douploadimg() {
$imgname=$_FILES['photofile']['name'];
$extname=file::extname($imgname);
$destfile=$_ENV['attachment']->makepath($extname);
$arrupload=file::uploadfile($_FILES['photofile'],$destfile);

if($arrupload['result']==true){
if(isset($this->setting['watermark'])){
$_ENV['watermark']->image($destfile,$destfile);
}
$uid=intval($this->user['uid'])?$this->user['uid']:0;
$did=intval($this->get['2'])?$this->get['2']:0;
$_ENV['attachment']->add_attachment($uid ,$did,$imgname ,$destfile ,htmlspecialchars($this->post['picAlt']) ,$extname);

直接将$imgname插入attachment表,前台没有输出点,只能够盲注。

但因为是附件上传处,我们可以通过注入控制附件文件位置。下载的时候即可读取该文件,产生一个任意文件读取:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function dodownload(){
if(!isset($this->get[2]) || !is_numeric($this->get[2])){
$this->message($this->view->lang['parameterError'],'BACK');
}
$result=$_ENV['attachment']->get_attachment('id',$this->get[2],0);
if(!(bool)$attachment=$result[0]){
$this->message($this->view->lang['attachIsNotExist'],'BACK');
}
if($this->user['uid'] != $attachment['uid']) {
// 判断金币
$credit1 = $this->user['credit1']; // 拥有金币数
$coindown = $attachment['coindown']; // 下载此附件需要消耗金币数
if(0 > $credit1 - $coindown) {
// 金币不足
$this->message($this->view->lang['goldNotEnough'],"index.php?doc-view-".$attachment['did'],0);
}
// 扣除金币
$_ENV['user']->add_credit($this->user['uid'],'attachment-down',0,-$coindown);
// 增加金币
$_ENV['user']->add_credit($attachment['uid'],'attachment-down',0,$coindown);
}
$_ENV['attachment']->update_downloads($attachment['id']);
file::downloadfile($attachment['attachment'],$attachment['filename']);
}

本地搭建最新版5.1。

注册用户,新增或编辑词条。上传图片。

01.jpg

中途抓包改包:

02.jpg

其中config.php即为我要下载的文件。(最好用hex)

附件上传完成后,来到:localhost/wiki/index.php?attachment-download-xx

其中xx是刚才上传的附件的id,这个id不知道,但肯定是最后一个id,所以穷举一遍id值即可。

03.jpg

下载后打开即为config.php的内容:

04.jpg