【文件下载】Earmusic cms
下载点/template/default/source/audio.php?id=1
源码段
$id = intval(SafeRequest("id","get"));
if($row = $db->getrow("select * from ".tname('music')." where in_id=".$id)){
$file = geturl($row['in_audio']);
$headers = get_headers($file, 1);
if(array_key_exists('Content-Length', $headers)){
$filesize = $headers['Content-Length'];
}else{
$filesize = strlen(@file_get_contents($file));
}
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=".basename($file));
header("Content-Length: ".$filesize);
readfile($file);
public function getrow($sql){ $res = $this->query($sql); if($res !== false){ return $this->fetch_array($res); }else{ return false; } }
id参数传入getrow(),返回id=1的music表全部字段,由geturl()函数根据in_audio字段下载文件,即下载文件通过in_audio控制。
通过搜索in_audio,查到in_audio通过/source/user/music/add.php上传功能传入music表
<tr><th style="width:10em;">音频地址:</th><td> <input type="text" id="in_audio" class="t_input" size="45" /> <input type="button" class="button" value="上传音频" onclick="pop.up('no', '上传音频', in_path+'source/pack/upload/open.php?mode=1&type=music_audio&form=form.in_audio', '406px', '180px', '225px');" /> <input type="button" style="padding:0 5px;margin:0 0 0 3px;height:24px;border:none;background:#DDD;color:#F60;line-height:20px;letter-spacing:1px;cursor:pointer" value="录制音频" onclick="pop.record();" />
测试上传

下载后文件为safety filter,查看数据库插入in_audio为该字段。


通过Safety filter找到过滤方法,明显过滤../
$audio = checkrename(unescape(SafeRequest("audio","get")), 'attachment/music/audio'); function checkrename($file, $dir, $old='', $mode='add', $table='', $field='', $id=0){ $file = preg_match('/(\.\/|\?iframe=|.php\?)/i', $file) ? 'Safety filter' : $file; if($mode == 'add'){ if(preg_match("/^data\/tmp\/\d/", $file)){ $var = str_replace('tmp', $dir, $file); @rename(IN_ROOT.$file, IN_ROOT.$var); return $var; }else{ return $file; }
unescape 方法返回一个包含charstring 内容的字符串值。所有以%xx 十六进制形式编码的字符都用ASCII 字符集中等价的字符代替
所以添加时使用绝对路径绕过
/EarMusic/source/system/db.class.php

苟利国家生死以,岂因福祸避趋之

浙公网安备 33010602011771号