Chinese Edition: Ruby on Rails 路径穿越与任意文件读取漏洞分析 - 【CVE-2019-5418】
Security Advisory
https://groups.google.com/forum/#!topic/rubyonrails-security/pFRKI96Sm8Q
Analysis
The render method can use a view that’s entirely outside of your application. So in actionview-5.2.1/lib/action_view/renderer/template_renderer.rb:22
, it will call find_file
to determine which template to be rendered。
In the find_file
method:
step into args_for_lookup
method which to generate the options. When it returns, our payload will be saved in details[formats]
:
then it will execute @view_paths.find_file
which located in actionview-5.2.1/lib/action_view/path_set.rb
:
Because the view is outside of your application,so outside_app
equalsTrue
and then will call find_all_anywhere
Skip cached
part, the find_templates
will according the options to find the template to render:
|
|
After build_query
, the variables :
SO here we use ../
to make directory traversal,and use double {
to make sure syntax right. After File.expand_path
, the result is:
|
|
so the /etc/passwd
will be treated the template to be rended ,which lead to a arbitrary file read attack.
Reproduce
install vulnerable Rails (e.g 5.2.1)
Generate controller:
Inapp/controllers/chybeta_controller.rb
:
add resources in config/routes.rb
:
Patch
https://github.com/rails/rails/commit/f4c70c2222180b8d9d924f00af0c7fd632e26715