Querying private posts and changing post meta
An unauthenticated PHP file in a WordPress theme accepted request parameters and passed them straight into a WP_Query call and into add_post_meta(), so anyone could run arbitrary post queries and write numeric post meta. An attacker could read unpublished scheduled posts and alter plugin or theme behaviour, such as hiding a background image or faking a share count.
Originally disclosed on HackerOne
- Triaged in 32 hours
- Fixed in 33 hours
- Paid in 33 hours
- Disclosed after 42 hours
Summary by the program
Unauthenticated user can run arbitrary post queries and insert arbitrary numeric post meta via vulnerable /wp-content/themes/SecNews-NewCustom/functions/ajax.php file. The researcher have done a great job. We appreciate security researching work that are according to our bug bounty program.
The report
Summary
Unauthenticated user can run arbitrary post queries and insert arbitrary numeric post meta via vulnerable /wp-content/themes/SecNews-NewCustom/functions/ajax.php file.
I'm including two exploits in one report because the fix for both is the same, i.e. delete ajax.php.
Run arbitrary post queries
Consider this request:
curl https://www.secnews.gr/wp-content/themes/SecNews-NewCustom/functions/ajax.php \
--data 'action=sort&loop=main loop¤tquery[key1]=value1¤tquery[key2]=value2'
It executes a WP_Query against the database with array('key1' => 'value1', 'key2' => 'value2') as the argument.
Attacker can exploit this, for example, to see posts that are scheduled to be published in the future, i.e. posts that are not public yet:
curl https://www.secnews.gr/wp-content/themes/SecNews-NewCustom/functions/ajax.php \
--data 'action=sort&loop=main loop¤tquery[post_status]=future'
For example "Δείτε τα πιο Geeky Raspberry Pi Smartwatches!" by Bl4ckPr0xyon will be published on 15.08.2016 at 13:21, i.e. in 8 days from today.
Insert arbitrary numeric post meta
Consider this request:
curl https://www.secnews.gr/wp-content/themes/SecNews-NewCustom/functions/ajax.php \
--data 'id=100000&action=rate&meta=test&rating=42'
The request parameters get passed to add_post_meta() function, which inserts a row to the post's meta with an arbitrary key and arbitrary value. The value can only be a number though.
mysql> select * from wp_postmeta where meta_key = "test";
+---------+----------+------------+
| post_id | meta_key | meta_value |
+---------+----------+------------+
| 100000 | test | 42 |
+---------+----------+------------+
This can be used by attacker to alter behavior of plugins and themes. For example:
- I removed background image from https://www.secnews.gr/100000 by setting
_bg_color_overrideto1in the post meta. - I set shares count to
-56994at https://www.secnews.gr/100000 by changingmashsb_sharesandmashsb_timestampmeta of the post.
Potentially this can be used to:
- Change booleans, counters and timestamps in other plugins leading to information disclosure or website defacement.
- Unnoticeably fill the database with garbage data until the disk space is full.
Affected posts
While looking for vulnerabilities I changed some meta for posts 95513, 100000 and 104030. You can clean it up with something like this:
DELETE * FROM wp_postmeta WHERE post_id IN (95513, 100000, 104030) AND meta_key IN ('_bg_color_override', 'mashsb_shares', 'mashsb_timestamp');
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
Impact
An unauthenticated attacker could read scheduled, not-yet-public posts and could change numeric post meta to alter plugin and theme behaviour, potentially causing information disclosure, defacement or database bloat; the text notes the injected value can only be a number.
What the attacker needed
No account needed; network access to the theme file
The fix
The vulnerable ajax.php file should be deleted, which the researcher says fixes both issues.
How it was found
- Send a POST request to the theme's ajax.php with an action parameter and a currentquery array of query arguments.
- Observe that the site runs a WP_Query with those arguments against the database.
- Set the post status argument to future to list posts scheduled for later publication.
- Send a second request with an id, an action of rate, a meta key and a numeric rating value.
- Observe that a new row with that key and value appears in the post meta table.
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.
A WordPress theme shipped a small helper script that anyone on the internet could call without logging in. That script took values from the request and used them directly to ask the database for posts and to save extra data on a post. Because nothing checked who was calling or what values were allowed, a stranger could read posts that were not published yet and change small settings that other parts of the site rely on.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.