🐝

CVE-2024-2047

Description

The ElementsKit Elementor addons plugin for WordPress is vulnerable to Local File Inclusion in all versions up to, and including, 3.0.6 via the render_raw function. This makes it possible for authenticated attackers, with contributor-level access and above, to include and execute arbitrary files on the server, allowing the execution of any PHP code in those files. This can be used to bypass access controls, obtain sensitive data, or achieve code execution in cases where images and other “safe” file types can be uploaded and included.

Code

Analysis

Right at the bottom on line 2458, we see $style being concatenated to a file path directly. We can add ../ to $style to obtain path traversal
2455 $style = isset($ekit_testimonial_style) ? sanitize_text_field($ekit_testimonial_style) : 'default'; 2456 2457 if (is_array($testimonials) && !empty($testimonials)) { 2458 require Handler::get_dir() . 'style/' . $style . '.php'; 2459 } 2460 }

The Fix

$style is now checked to see if it’s one of the existing styles before appending to the file path
2456 $styles = [ 2457 'style1', 2458 'style2', 2459 'style3', 2460 'style4', 2461 'style5', 2462 'style6', 2463 ]; 2464 2465 if (in_array($style, $styles) && is_array($testimonials) && !empty($testimonials)) { 2466 require Handler::get_dir() . 'style/' . $style . '.php'; 2467 }

Recreation

  1. Install WordPress locally
  1. Download the vulnerable plugin and install it
  1. Add the testimonial widget to the page
notion image
  1. Edit the style by toggling Use Fixed Height
notion image
  1. Intercept the request in BurpSuite and we see the data for ekit_testimonial_style is being sent over with a value style1
notion image
  1. We create a dummy file in the root folder called a.php with the following contents
<?php echo system('whoami') ?>
  1. Now we modify the value of ekit_testimonial_style to ../../../a.php and see the PHP file being executed, and returns the host name of our machine
notion image

Fixed Version

  1. After we update the plugin to it’s latest version and send the traffic again, there is no more directory traversal because ../../../a.php is not in the array
notion image
Also, they kinda fixed type juggling in PHP 8, so in_array is pretty safe now!