### 简要描述:
RT。为一个朋友找的。
### 详细说明:
hdwiki上传附件处文件名过滤不严,导致可以注入:
```
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表。
但前台没有输出点,只能够盲注。
但因为是附件上传处,我们可以通过注入控制附件文件位置。
下载的时候即可读取该文件,产生一个任意文件读取:
```
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。
注册用户,新增或编辑词条。上传图片:
[<img src="https://images.seebug.org/upload/201403/1700102823bba1841002c5273278ee01ee21ba51.jpg" alt="01.jpg" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201403/1700102823bba1841002c5273278ee01ee21ba51.jpg)
中途抓包改包:
[<img src="https://images.seebug.org/upload/201403/17001046b422bb2e92a64d7f609a9f620aeff110.jpg" alt="02.jpg" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201403/17001046b422bb2e92a64d7f609a9f620aeff110.jpg)
其中config.php即为我要下载的文件。(最好用hex)
附件上传完成后,来到:localhost/wiki/index.php?attachment-download-xx
其中xx是刚才上传的附件的id,这个id不知道,但肯定是最后一个id,所以穷举一遍id值即可。
[<img src="https://images.seebug.org/upload/201403/1700144455680deb02d5428c256141f98f43ff6b.jpg" alt="03.jpg" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201403/1700144455680deb02d5428c256141f98f43ff6b.jpg)
下载后打开即为config.php的内容:
[<img src="https://images.seebug.org/upload/201403/1700151399abeef0d955c13bc61badf05719030d.jpg" alt="04.jpg" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201403/1700151399abeef0d955c13bc61badf05719030d.jpg)
暂无评论