취약점 테스트를 위해 구버전 워드프레스 환경을 도커로 구축했다.


CVE-2024-7627이 발생한 `Bit File Manager` 플러그인의 6.5.5 version을 설치했다.

취약점이 발생한 코드는 `\plugins\file-manager\backend\app\Providers\\FileEditValidator.php` 경로에서 찾을 수 있다.
<?php
namespace BitApps\FM\Providers;
use BitApps\WPKit\Utils\Capabilities;
use BitApps\FM\Exception\PreCommandException;
use BitApps\FM\Plugin;
\defined('ABSPATH') or exit();
class FileEditValidator
{
public function validate($cmd, &$args, $elfinder, $volume)
{
try {
$this->checkPermission();
} catch (PreCommandException $th) {
return $th->getError();
}
$args['content'] = stripcslashes($args['content']); // Default wordpress slashing removed.
// Checking syntax for PHP file.
if (strpos($args['content'], '<?php') !== false) {
try {
$this->checkSyntax($args['content']);
} catch (PreCommandException $th) {
return $th->getError();
}
}
}
public function checkSyntax($content)
{
$error = '';
if (!\function_exists('exec')) {
$error = __('exec() is required for php syntax check');
} else {
$tempFilePath = FM_UPLOAD_BASE_DIR . 'temp.php';
$fp = fopen($tempFilePath, 'w+');
fwrite($fp, $content);
fclose($fp);
exec('php -l ' . escapeshellarg($tempFilePath), $output, $return);
$errorMessages = [];
foreach ($output as $result) {
if (
strpos($result, 'No syntax errors detected') !== false
|| $result == ''
) {
continue;
}
if (strpos($result, 'Errors parsing') !== false) {
$error = wp_sprintf(
// translators: 1: Temporary file path
__('Errors parsing the file [ %s ] as php script', 'file-manager'),
str_replace('temp', '', $tempFilePath)
);
} else {
$errorMessages[] = $result;
}
}
unlink($tempFilePath);
if ($return !== 0 && !empty($errorMessages)) {
$error = !\is_string($errorMessages[0]) ? json_encode($errorMessages[0]) : $errorMessages[0];
}
}
if (\defined('BFM_DISABLE_SYNTAX_CHECK') && BFM_DISABLE_SYNTAX_CHECK) {
return;
}
if (!empty($error) && !Capabilities::check('install_plugins')) {
throw new PreCommandException(esc_html($error));
}
}
private function checkPermission()
{
$error = '';
if (\defined('DISALLOW_FILE_EDIT') && DISALLOW_FILE_EDIT) {
$error = __('File edit is disabled. To allow edit, please set DISALLOW_FILE_EDIT to false in wp-config file', 'file-manager');
}
if (\is_null($error) && !Plugin::instance()->permissions()->currentUserCanRun('edit')) {
$error = __('Not Authorized to edit file', 'file-manager');
}
if (!empty($error)) {
throw new PreCommandException(esc_html($error));
}
}
}
중간고사 기간 이후에 해당 취약점뿐만 아니라 같은 php 라이브러리 `elFinder`를 사용한 다른 플러그인들에서 비슷한 취약점이 발생하는지 코드 정적 분석과 동적 분석을 통해 연구할 계획이다.
'𝐄𝐰𝐡𝐚 > 𝐄-𝐂𝐎𝐏𝐒' 카테고리의 다른 글
| 🍀5월 2주차 TWIL (0) | 2025.05.20 |
|---|---|
| 🍀 5월 1주차 TWIL (0) | 2025.05.12 |
| 시스템해킹 스터디 - (5) 입출력장치 (0) | 2025.04.09 |
| 시스템해킹 스터디 - (4) 보조기억장치 (0) | 2025.04.09 |
| 시스템해킹 스터디 - (3) 메모리와 캐시 메모리 (0) | 2025.04.09 |