防止利用百度编辑器上传木马图片
最近发现阿里云服务器报错有getshell文件木马,于是马上根据提示的路径查看了下文件。发现文件居然是.jpg的后缀,下载后用文本编辑器打开该图片发现里面居然是一串代码:
这个很明显就是攻击者伪装图片进行木马上传了。因为作者用的是PHP语言,发现这个文件是因为百度编辑器上传导致的漏洞,主要是因为是直接拿过来编辑器就用了,没有再改改百度编辑器里面的上传代码,所以导致了攻击者利用了这个漏洞进行攻击;
下面是修改代码的操作,找到文件 ueditor1.4.3.3\php\Uploader.class.php,
修改一下代码:
/**
* 上传文件的主处理方法
* @return mixed
*/
private function upFile()
{
$file = $this->file = $_FILES[$this->fileField];
//dcr163 修复木马文件通过修改后缀上传到服务器 s 从这里开始就是防止利用图片上传木马的操作
$type = strtolower($file['type']);
if( strpos($type,'image/') !== 'false' ) {
if( !getimagesize($file['tmp_name']) ) {
$this->stateInfo = '文件非法不允许上传';
return;
}
$imgStr = file_get_contents($file['tmp_name']);
if( strpos($imgStr,'eval') !== false ) {
$this->stateInfo = '该文件非法不允许上传';
return;
}
}
//dcr163 修复木马文件通过修改后缀上传到服务器 e
if (!$file) {
$this->stateInfo = $this->getStateInfo("ERROR_FILE_NOT_FOUND");
return;
}
if ($this->file['error']) {
$this->stateInfo = $this->getStateInfo($file['error']);
return;
} else if (!file_exists($file['tmp_name'])) {
$this->stateInfo = $this->getStateInfo("ERROR_TMP_FILE_NOT_FOUND");
return;
} else if (!is_uploaded_file($file['tmp_name'])) {
$this->stateInfo = $this->getStateInfo("ERROR_TMPFILE");
return;
}
$this->oriName = $file['name'];
$this->fileSize = $file['size'];
$this->fileType = $this->getFileExt();
$this->fullName = $this->getFullName();
$this->filePath = $this->getFilePath();
$this->fileName = $this->getFileName();
$dirname = dirname($this->filePath);
//检查文件大小是否超出限制
if (!$this->checkSize()) {
$this->stateInfo = $this->getStateInfo("ERROR_SIZE_EXCEED");
return;
}
//检查是否不允许的文件格式
if (!$this->checkType()) {
$this->stateInfo = $this->getStateInfo("ERROR_TYPE_NOT_ALLOWED");
return;
}
//创建目录失败
if (!file_exists($dirname) && !mkdir($dirname, 0777, true)) {
$this->stateInfo = $this->getStateInfo("ERROR_CREATE_DIR");
return;
} else if (!is_writeable($dirname)) {
$this->stateInfo = $this->getStateInfo("ERROR_DIR_NOT_WRITEABLE");
return;
}
//移动文件
if (!(move_uploaded_file($file["tmp_name"], $this->filePath) && file_exists($this->filePath))) { //移动失败
$this->stateInfo = $this->getStateInfo("ERROR_FILE_MOVE");
} else { //移动成功
$this->stateInfo = $this->stateMap[0];
}
}以上就是防止利用百度编辑器上传图片木马的操作了!
Dcr163的博客
http://dcr163.cn/240.html(转载时请注明本文出处及文章链接)