LevelBlue Completes Acquisition of Cybereason. Learn more

LevelBlue Completes Acquisition of Cybereason. Learn more

Services
Cyber Advisory
Managed Cloud Security
Data Security
Manage Detection & Response
Email Security
Managed Network Infrastructure Security
Exposure Management
Security Operations Platforms
Incident Readiness & Response
SpiderLabs Threat Intelligence
Solutions
BY TOPIC
Offensive Security
Solutions to maximize your security ROI
Operational Technology
End-to-end OT security
Microsoft Security
Unlock the full power of Microsoft Security
Securing the IoT Landscape
Test, monitor and secure network objects
Why LevelBlue
About Us
Awards and Accolades
LevelBlue SpiderLabs
LevelBlue Security Operations Platforms
Security Colony
Partners
Microsoft
Unlock the full power of Microsoft Security
Technology Alliance Partners
Key alliances who align and support our ecosystem of security offerings

PHP-CGI Exploitation by Example

Late last week, a vulnerability in PHP-CGI was disclosed, which allows all sorts of bad for folks running PHP-CGI. It was met with lots of controversy and questions about how it was leaked before a patch was available. What we'll talk about today is how the bad guys (aka: "the baddies") could be exploiting your PHP-CGI implementation right now (it's worth noting the distinction here: PHP-CGI is a much less common way of running PHP web applications, so many PHP installations are not affected).

Below I have provided a set of Apache configuration directives that would put a server in a vulnerable state. If you would like to implement a server yourself to follow along, this article was a helpful resource in setting up a vulnerable PHP-CGI instance.

9815_6d87adbc-f576-438d-b399-23d13458464e

For demonstration purposes, WordPress will be used as a test site for the examples that will follow. However, it is important to note that the issue is not with WordPress or any particular PHP application, but an issue with the underlying PHP-CGI installation it stands on.

Here is what our test WordPress installation looks like before we start meddling with it…

9524_5e2d864a-00b2-4064-8174-70543eb16b87

Example #1 PHP-CGI Source Disclosure

A simple abuse case for this vulnerability is obtaining the source code for any PHP file on the site, which can be done with a simple "-s" query parameter:

12076_d809e9f8-145a-4aa8-b80e-32ab38553594
Example #2 PHP-CGI Remote Code Execution

A more complex but much more damaging abuse case is using the vulnerability to execute arbitrary code on the server. This can be done using a "-d" query parameter, and passing the code to be executed. Ouch.

11728_c74f7c3b-d769-4703-95d0-2f4b4c83dc3c

In fact, Trustwave's MSS services are seeing a rising number of exploitation attempts similar to this example since it's release last week.

Example #3 PHP-CGI PHP Reverse Shell Shoveling

Taking that idea further, we can even use remote code execution to get a fully functional reverse shell using a slightly modified version of @pentestmonkey's php-reverse-shell.

10177_7cbab723-3d11-44c4-a723-35cf418d520b

7760_07a35067-e2e2-428a-ad44-53a7ecc41191

If you'd like to see more information on the PHP-CGI vulnerability, please check out the recent blog post by Trustwave's Ryan Barnett on the active exploitation happening in the wild identified by our honey pots and additional protections to help mitigate this issue.

ABOUT LEVELBLUE

LevelBlue is a globally recognized cybersecurity leader that reduces cyber risk and fortifies organizations against disruptive and damaging cyber threats. Our comprehensive offensive and defensive cybersecurity portfolio detects what others cannot, responds with greater speed and effectiveness, optimizes client investment, and improves security resilience. Learn more about us.

Latest Intelligence

Discover how our specialists can tailor a security program to fit the needs of
your organization.

Request a Demo