[春秋云镜] CVE-2023-38836
1、进来后看到个admin界面,进去后尝试弱口令adminpassword,成功进入
2、点Media上传文件,传一个phpinfo提示不允许
3、我们将phpinfo.php文件头加上一个GIF文件头,发现上传成功,点击view即可访问,那我们传一个一句话拿到 flag{0523724d-616d-4c25-bd30-044ed92b39b1}
4、我们用传个马,用蚁剑连一下看看后端文件,找到文件上传的函数
/**
* Upload media file
* @param ?string $msg
* @param ?string $basename
* @return bool
*/
public function upload_media( ?string &$msg = null, ?string &$basename = null ): bool {
if ( ! isset( $_FILES[ 'file' ][ 'error' ] ) || is_array( $_FILES[ 'file' ][ 'error' ] ) ) {
$msg = 'Invalid parameters';
return false;
}
switch ( $_FILES[ 'file' ][ 'error' ] ) {
case UPLOAD_ERR_OK:
break;
case UPLOAD_ERR_NO_FILE:
$msg = 'No file has been sent';
return false;
break;
case UPLOAD_ERR_INI_SIZE:
case UPLOAD_ERR_FORM_SIZE:
$msg = 'File too large';
return false;
break;
default:
$msg = 'An unexpected error occurred';
return false;
break;
}
$tmp_name = $_FILES[ 'file' ][ 'tmp_name' ];
$finfo = new finfo( FILEINFO_MIME_TYPE );
$type = $finfo->file( $tmp_name );
$types = $this->_l( 'media_mime',
array(
'application/json',
'application/octet-stream',
'application/ogg',
'application/pdf',
'application/photoshop',
'application/rar',
'application/svg+xml',
'application/vnd.ms-excel',
'application/vnd.ms-powerpoint',
'application/vnd.ms-word',
'application/vnd.oasis.opendocument.spreadsheet',
'application/vnd.oasis.opendocument.text',
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/zip',
'audio/mp4',
'audio/mpeg',
'image/gif',
'image/jpeg',
'image/png',
'image/svg+xml',
'image/vnd.microsoft.icon',
'image/webp',
'image/x-icon',
'text/css',
'text/html',
'text/plain',
'text/x-asm',
'video/avi',
'video/mp4',
'video/mpeg',
'video/ogg',
'video/quicktime',
'video/webm',
'video/x-flv',
'video/x-matroska',
'video/x-ms-wmv'
)
);
if ( ! in_array( $type, $types ) ) {
$msg = 'File format not allowed';
return false;
}
$name = $this->esc_slug( $_FILES[ 'file' ][ 'name' ] );
$basename = basename( empty( $basename ) ? strip_tags( $name ) : $basename );
if ( move_uploaded_file( $tmp_name, $this->root( 'media/' . $basename ) ) ) {
$msg = sprintf( 'File <b>%s</b> has been uploaded successfully', $basename );
$this->get_action( 'upload_media', $basename );
return true;
}
$msg = 'Failed to move uploaded file';
return false;
}
f i n f o − > f i l e ( finfo->file( finfo−>file(tmp_name) 这行代码使用了 PHP 中的 FileInfo 扩展(File Information),它提供了一种获取文件信息的方式,特别是文件的 MIME 类型。
具体来说, f i n f o − > f i l e ( finfo->file( finfo−>file(tmp_name) 这行代码的作用是读取临时文件的内容并返回其 MIME 类型。
然而这存在漏洞,它是对比文件的前几个字节来确定文件的 MIME 类型。
若我们在shell.php文件里前几个字节加上GIF89a 则这个文件的 MIME 类型 将会是image/gif。由此便可绕过上传限制,实现木马上传。