Skip to main content

Content Injection Vulnerability in WordPress

Content Injection Vulnerability in WordPress

As part of a vulnerability research project for our Sucuri Firewall (WAF), we have been auditing multiple open source projects looking for security issues. While working on WordPress, we discovered was a severe content injection (privilege escalation) vulnerability affecting the REST API. This vulnerability allows an unauthenticated user to modify the content of any post or page within a WordPress site.
We disclosed the vulnerability to the WordPress Security Team who handled it extremely well. They worked closely with us to coordinate the disclosure timeline and get as many hosts and security providers aware and patched before this became public.
A fix for this was silently included on version 4.7.2 along with other less severe issues. This was done intentionally to give everyone time to patch. We are now disclosing the details because we feel there has been enough time for most WordPress users to update their sites.

Are You At Risk?

This privilege escalation vulnerability affects the WordPress REST API that was recently added and enabled by default on WordPress 4.7.0.
One of these REST endpoints allows access (via the API) to view, edit, delete and create posts. Within this particular endpoint, a subtle bug allows visitors to edit any post on the site.
The REST API is enabled by default on all sites using WordPress 4.7.0 or 4.7.1. If your website is on these versions of WordPress then it is currently vulnerable to this bug.

Technical Details

Our journey begins in ./wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

There are a couple of things to notice here. The registered route is designed to populate the ID request parameter with digits. For example, if you are sending a request to /wp-json/wp/v2/posts/1234 – the ID parameter would be set to 1234.
This behavior alone could be a good way to prevent attackers from crafting malicious ID values, but when looking at how the REST API manages access, we quickly discover that it prioritizes $_GET and $_POST values over the ones generated by the route’s regular expression. This makes it possible for an attacker to send a request like: /wp-json/wp/v2/posts/1234?id=12345helloworld  – which would assign 12345helloworld to the ID parameter – which now contains more than just digits.
Investigating further, we had a look at the various callbacks (in the screenshot above) and one of them kept our attention: the update_item and its permission check method update_item_permissions_check.

In short, it passes our alphanumeric ID value directly to the get_post() function. This function validates the request by checking if the post actually exists and whether our user has permission to edit this post. We found this to be a curious way of sanitizing the request. If we send an ID that doesn’t have a corresponding post, we can just pass through the permission check and be allowed to continue executing requests to the update_item method!
Curious about what could cause get_post() to fail at finding a post (other than a non-existent ID), we realized it used the get_instance() static method in wp_posts to grab posts.

As you can see from the code, it would basically fail on any input that isn’t all made of numeric characters – so 123ABC would fail.
For an attacker, this means that WordPress (thinking it’s a user with enough privilege to edit this post) would run the update_item method.
We thought it would make sense to check what this method does.

There is a very subtle, yet important detail in that last screenshot – WordPress casts the ID parameter to an integer before passing it to get_post!
This is an issue because of the way PHP does type comparisons and conversions. For example, one can see that the following snippet would return 123:

This leads to a very dangerous situation where an attacker could submit a request like /wp-json/wp/v2/posts/123?id=456ABC to change the post whose ID is 456!
Due to this type-juggling issue, it is then possible for an attacker to change the content of any post or page on a victim’s site. From there, they can add plugin-specific shortcodes to exploit vulnerabilities (that would otherwise be restricted to contributor roles), infect the site content with an SEO spam campaign, or inject ads, etc.
Depending on the plugins enabled on the site, even PHP code could be executed very easily.

In Conclusion

If you have not enabled automatic updates on your website, update as soon as possible!
This is a serious vulnerability that can be misused in different ways to compromise a vulnerable site. Update now!

https://blog.sucuri.net/2017/02/content-injection-vulnerability-wordpress-rest-api.html

Comments

Post a Comment

Popular posts from this blog

Hướng dẫn cài LibreOffice trên Kali Linux

Xin chào mọi người ! Một số bạn không biết cài bộ công cụ văn phòng nào cho máy tính cài HĐH Kali Linux. Hôm nay mình sẽ hướng dẫn cho các bạn cài  LibreOffice trên Kali Linux. Nó giống như bộ Office của Microsoft và trên thực tế thì không bằng Microsoft được đâu. Việc cài đặt bộ Office này khá là đơn giản. Đầu tiên để cài thì bạn hãy tải LibreOffice phù hợp với phiên bản của máy tính đang sử dụng. Như của mình hiện tại là phiên bản LibreOffice_5.2.4 + Link Download (Download) Hãy tải phiên bản mới nhất có đuôi *.deb cho dễ cài đặt. Sau khi tải xong có 2 cách để các bạn cài đặt nó: + Cách 1: Sử dụng phần mềm Gdebi để cài đặt các file *.deb một cách dễ dàng. Tuy nhiên rất hay bị lỗi và không cài đặt được. + Cách 2: (Nên theo cách này) 1- Giải nén file LibreOffice ra. 2- Mở Terminal ra gõ:   ~# cd Downloads Các bạn có thể dùng lệnh ls để biết chính xác tên thư mục của mình và copy paste cho chuẩn. Tiếp sau đó thì gõ:   ~# cd LibreOffice_5....

Cách mã hóa mật khẩu trong Kali Linux 2016.2 | Encrypt Passwords

Xin chào tất cả mọi người ! Như tất cả mọi người cũng đã biết việc mã hóa mật khẩu là vô cùng quan trọng trong thời buổi công nghệ thông tin phát triển như vũ bão hiện nay. Việc để mật khẩu một cách bình thường là vô cùng nguy hiểm. Hôm nay tôi xin giới thiệu cho tất cả mọi người một công cụ chuyên mã hóa mật khẩu trên Kali Linux đó chính là HashCode Tool. Việc cài đặt và sử dụng HashCode rất đơn giản, chúng ta sẽ bắt đầu luôn nào ! Bước 1:Download  Để Download HashCode các bạn có thể tải bằng cách: ~# cd Desktop ~# git clone https://github.com/Sup3r-Us3r/HashCode.git Sau đó chờ tải file HashCode về. File sẽ được lưu ở ngoài màn hình Desktop. Bước 2: Cài đặt (Install) Sau khi file đã tải xong các bạn trỏ tới file: ~# cd HashCode Chạy 3 lệnh tiếp theo: ~# sudo chmod +x hashcode-en.py ~# sudo chmod +x hashcode-pt.py ~# sudo chmod +x hashcodegui.py Sau khi chạy xong 3 lệnh trên vậy là việc cài đặt của chúng ta đã hoàn tất và bây giờ chúng ta hãy c...

Google Hacking - Kiến thức cơ bản mà Pentester thường bỏ qua!

Mình để ý thấy có nhiều bạn đang bị lu mờ giữa 2 khái niệm Pentest và Hacking. Thực sự thì cũng sẽ khó có thể phân biệt rõ ràng nhưng "Hacking" là cụ từ bạn sẽ sử dụng khi bạn tìm thấy lổ hổng ( cả về lổ hổng logic và lổ hổng đến từ tech ) và khai thác được lổ hổng đó. Còn Pentest theo mình thì chỉ là kiểm tra đánh giá tính bảo mật của một hệ thống hoặc một server nào đó thôi. OK! Bắt đầu với chủ đề mà mình đề cập tới sau đây. Có nhiều bạn trẻ hỏi mình: "Làm sao để có thể nhanh chóng tìm được lỗi từ ứng dụng web?". Câu trả lời của mình là:"Hãy bắt đầu với Google Hacking." Google Hacking là một thuật ngữ mà gói gọn một loạt các kĩ thuật cho phép truy vấn trên công cụ tìm kiếm Google.com, đôi khi được dùng để xác định các lổ hổng trong các ứng dụng web cụ thể.(Cụ thể như thế nào thì mình sẽ cố gắng giải thích tiếp trong giới hạn kiến thức mà mình biết). Bên cạnh việc truy vấn từ google có thể tiết lộ các lỗ hổng trong các ứng dụng web, Go...