Skip to content
Path traversal Write-up Intermediate

On insecure zip handling, Rubyzip and Metasploit RCE (CVE-2019-5624)

The Rubyzip library's extract method does not validate the destination path when one is supplied, allowing a malicious zip entry to write files outside the intended directory. In Metasploit, an authenticated user could import a crafted zip workspace to write a cron job as root and achieve remote code execution.

blog.doyensec.com

Published on blog.doyensec.com

During one of our projects we had the opportunity to audit a Ruby-on-Rails (RoR) web application handling zip files using the Rubyzip gem. Zip files have always been an interesting entry-point to triggering multiple vulnerability types, including path traversals and symlink file overwrite attacks.

Luca Carettoni, on blog.doyensec.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the library's extract method skips its name-safety check whenever a destination path is passed by the caller, leaving path validation entirely to the application.

Impact

An authenticated Metasploit user could write arbitrary files as root and achieve remote command execution; in the audited Rails application, exploitation required a reboot to load injected code, which the researchers chained with a denial-of-service and path disclosure.

What the attacker needed

Authenticated Metasploit user; ability to import a zip workspace; crafted zip with traversal entry

The fix

The library should validate the destination path against traversal before extracting, and callers should perform additional validation on entry names and destination paths.

How it was found

  1. Create a file containing a cron job that opens a reverse shell.
  2. Generate a zip archive with a path traversal payload targeting the cron directory.
  3. Add a valid Metasploit workspace to the zip so the import accepts it.
  4. Set up listeners for the reverse shell.
  5. Log in to the Metasploit web interface, create a project, and import the malicious zip.
  6. Wait for the import to finish and receive the reverse shell.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

A zip file can contain file names with '../' sequences that, when extracted, place files outside the intended folder. Rubyzip only checked for this when no destination path was given, so a crafted zip could overwrite files anywhere the application could write. In Metasploit, this let a logged-in user plant a scheduled task that ran as root and opened a remote shell.

What is Path traversal?

Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.

Similar reports

View all

Same bug class and techniques, clearest first.

Path traversal and file inclusion

The lesson behind this report.

Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.