A newly exposed vulnerability in Ruby on Rails applications allows attackers to achieve Remote Code Execution (RCE) through a flaw that permits arbitrary file writing.
This vulnerability, which leverages the Rails library Bootsnap, underscores the critical importance of secure file handling in web applications.
A case study, shared by security researchers, demonstrated how an arbitrary file write vulnerability in a Rails app could be exploited to execute malicious code remotely.
The vulnerability arises from improper handling of uploaded files in a sample Rails endpoint, combined with the exploitation of Bootsnap, a library designed to speed up application boot times by caching expensive file operations.
Investigate Real-World Malicious Links & Phishing Attacks With Threat Intelligence Lookup - Try for Free
The demonstration rested on a vulnerable section of code where uploaded files could be saved to unrestricted paths using user-provided inputs:
def save_uploaded_file(uploaded_file, filename)
upload_path = Rails.root.join("tmp", "uploads")
FileUtils.mkdir_p(upload_path)
File.open(File.join(upload_path, filename), 'wb') do |file|
file.write(uploaded_file.read)
end
end
Attackers exploited this by writing files to any writable directory, bypassing restrictions using path traversal techniques.
Bootsnap, introduced to Rails in version 5.2, caches Ruby files, YAML, and JSON resources for faster load times.
By manipulating the cache files located in tmp/cache/bootsnap, attackers can inject malicious code to execute during application startup.
The exploit requires precise knowledge of the Bootsnap cache structure and the ability to restart the Rails application. Here’s how the attack works:
`id > >&2` # Command injection to print the current user
load("/path/to/original/file") # Load the intended file to avoid crashing the app
While the vulnerability requires specific conditions—like controllable file uploads and the use of Bootsnap in the Rails app—it poses a significant risk in production environments where these conditions are met.
According to researchers, default Rails Docker configurations after version 7.1 exacerbate the issue by limiting writable paths to a few key directories such as tmp and log.
As per a report by Conviso report, the “Rails Apps Arbitrary File Write Vulnerability Let Attackers Execute Code Remotely” highlights the dangers of combining insecure coding practices with existing libraries.
Developers and system administrators must work together to audit application code and configurations regularly, ensuring vulnerabilities like these are identified and mitigated before being exploited in the wild.
Integrating Application Security into Your CI/CD Workflows Using Jenkins & Jira -> Free Webinar
A security researcher has uncovered critical vulnerabilities in Eight Sleep’s internet-connected smart beds, revealing exposed…
Apple has discontinued its Advanced Data Protection (ADP) feature for UK users following a legal…
The Wireshark Foundation has announced the release of Wireshark 4.4.4, the latest iteration of the…
The cryptocurrency sector faced one of its most significant security breaches this year as stablecoin…
GhostSocks, a Golang-based SOCKS5 backconnect proxy malware, has emerged as a significant threat within the…
In a swift and highly coordinated attack, LockBit ransomware operators exploited a critical remote code…