Tuesday, 3 April 2012

The Emerging WebSocket Protocol

Simply put, WebSocket (RFC6455) is Raw Socket over HTTP (Web). It allows real-time (e.g. push) and bidirectional communication between the web client and the web application. Consider if you want to write a stock ticker application, instead of periodically polls the server for updates, you can use WebSocket to create an (almost) raw socket to the server and do whatever you want. WebSocket runs over HTTP, therefore, access control rules on existing firewalls will simply work without any modifications. And as of this writing, 3 out of 4 browsers installed on my laptop support WebSocket already (the only exception is IE).

WebSocket doesn't prescribe any particular way to handle authentication, you can authenticate using Session cookie when your first initiate your WebSocket over HTTP, or you can authenticate right after the WebSocket is established (similar to how you handle authentication in FTP). WebSocket supports cross domain communications by mandating the ORIGIN header (but is only available if the client is a browser). Web applications should check the ORIGIN header and refuse the connection if it is originated from an untrusted 3rd party website.

In 2010, Huang et al. reported a vulnerability that can trick a vulnerable proxy server to incorrectly redirect WebSocket connections from a Java Applet or a Flash to arbitrary host (IP hijacking) and hence allowing unauthorized cross domain connections, or can poison the proxy server cache (Cache Poisoning). After that, WebSocket adopted Huang's recommendation and requires XOR on packet payloads with a random key to avoid proxy servers that don't understand WebSocket to incorrectly pick up counterfeit HTTP requests embedded in the raw socket.

The current WebSocket protocol represents a low-level communication channel only, the protocol merely defines how to switch an existing HTTP connection into a low level socket connection without much other add-on features. Furthermore, the protocol itself is not stable and server side API is not standardized yet (Java will support WebSocket in Servlet 3.1). However, with the growing demand on real-time and bidirectional communications in Web 2.0 era, I can foresee many frameworks will build around it and make it a more secure and useable protocol in the future.

Reference:
WebSocket Echo Demo http://websocket.org/echo.html (requires a WebSocket compliant browser)

Posted by sam at 4:51 AM in Research

Wednesday, 2 November 2011

Misunderstandings on HttpOnly Cookie

HttpOnly Cookie is nothing new, it was first introduced by Microsoft back in 2002 when it released IE 6 SP1. Of course I don't think HttpOnly alone can solve all XSS problems but I believe it is a useful feature if used correctly. And while I don't think we can set every cookie with HttpOnly flag, at least we should set it on all session cookies whenever possible. However, statistics [1] show that only about 9% of websites use HttpOnly cookies. I don't know exactly why the usage rate is so low, but I think it may be related to the following misunderstandings:

1) HttpOnly is only for IE

No.

According to Google's Browser Security Handbook [2] and OWASP [3], almost 99% of all browsers (the only exception is Android) support HttpOnly cookies.

Test description MSIE6 MSIE7 MSIE8 FF2 FF3 Safari Opera Chrome Android
Is httponly flag supported? YES YES YES YES YES YES YES YES NO

 

2) On .NET platform, it's disabled by default

Yes and No.

For custom application cookies, you have to manually enable it, but for session cookies, it is enabled by default.

Starting from .NET 2.0 (which was released in 2005, three years after HttpOnly was introduced), all session cookies come with the HttpOnly flag, and you can't even disable it. When decompiling that part of .NET program code, you will see:

System.Web.SessionState.SessionIDManager
private static HttpCookie CreateSessionCookie(string id)
{
    HttpCookie cookie = new HttpCookie(Config.CookieName, id);
    cookie.Path = "/";
    cookie.HttpOnly = true; // <-- burned in, not configurable
    return cookie;
}

The <httpCookies httpOnlyCookies="true" …> in web.config is only for custom application cookies, not for session cookies.

3) Most Java Application Servers don't support HttpOnly cookies

No.

But it is true that Java's support for the HttpOnly flag is very slow. There was no setHttpOnly() method in javax.servlet.http.Cookie until Java EE 6 (Servlet API 3.0) which was just released in December 2009. However, this doesn't mean application servers can't support HttpOnly without Java EE 6.

Type Support HttpOnly Since Comment
Tomcat 5.5.28[4] or 6.0.20 Default "false" for 5.5.28 to 6.0. Default "true" for 7.0+
JBoss# 6.0 Servlet 3.0, default "false", config via web.xml <cookie-config>
WebLogic 9.2 MP4[5] Servlet 2.4, default "true"
WebSphere## 8.0[6] Servlet 3.0, default "true", can config via console as well
#: According to OWASP [3], JBoss 5.1 supports HttpOnly by using Context.xml (similar to Tomcat 5.5), but I can't make this work.
##: According to IBM [7], the custom property addHttpOnlyAttributeToCookies on WAS 6.1 and 7.0 does not affect every cookie that passes through the application server. The list of non-HTTPOnly cookies includes JSESSIONID cookies.

 

Summary

As you can see, many application servers already support HttpOnly cookies, some even set the HttpOnly flag on session cookies by default. The risk of setting HttpOnly flag on session cookies should be pretty low, and the steps for enabling it are not difficult. Therefore, if your web application is running on a “supported but default false” application server, such as Tomcat 6.0, you should enable it.

References:
[1] http://w3techs.com/technologies/details/ce-httponlycookies/all/all
[2] http://code.google.com/p/browsersec/wiki/Part2
[3] https://www.owasp.org/index.php/HTTPOnly
[4] http://tomcat.apache.org/tomcat-5.5-doc/config/context.html
[5] http://download.oracle.com/docs/cd/E13222_01/wls/docs92/webapp/weblogic_xml.html#wp1071982
[6] http://publib.boulder.ibm.com/infocenter/ieduasst/v1r1m0/index.jsp?topic=/com.ibm.iea.was_v8/was/8.0/Security/WASv8_SecurityEnhancements/player.html
[7] http://www-1.ibm.com/support/docview.wss?rs=180&uid=swg27004980

Posted by sam at 7:47 AM in Research

Tuesday, 7 December 2010

Securing Python From Path Manipulation

Path manipulation is where a hacker injects a fake path into an application to trick it into reading something different than it would normally. Take for example this simple application:

import csv
import sys

filename = sys.argv[1]
user = sys.argv[2]
password = sys.argv[3]

csvfile = '%(file)s.csv' % { 'file': filename }
print 'Checking %(file)s' % { 'file': csvfile }

userReader = csv.reader( open(csvfile, 'rb'), delimiter=',' )
found = 0
for row in userReader:
	if user == row[0] and password == row[1]:
		found = 1
		print 'Logged in'
if found == 0:
		print 'Not logged in'

This is a simple application that reads user accounts and does a login check. The first parameter is supposed to be 'users' or 'administrators'. The second and third parameters are the user name and password. Because the coder (me) is lazy I'm just going to use that first parameter to point to a particular password file. And because I believe that the file system permissions for the directory prevent tampering all is well.

Not so fast. Sure the happy path works just fine:

$ python bad.py users user1 password
Checking users.csv
Logged in

But so does the hacker path:

$ python bad.py ../mydata/users hacker password
Checking ../mydata/users.csv
Logged in

Because of the way I construct the path a hack can easily point the application at a completely different users file in another directory which they control and, viola, they have access. Whoops.

There are some simple fixes for this. One would be to selectively sanitize the input.

password = sys.argv[3]

filename = filename.replace( '.', '' )
filename = filename.replace( '/', '' )

csvfile = '%(file)s.csv' % { 'file': filename }
print 'Checking %(file)s' % { 'file': csvfile }

In this case I'm using a string replace to remove any dots or slashes. That will kill any directory referencing on most operating systems.

The problem with this approach is that there is still too much to check to be guaranteed that there will never be an issue. So another, better, option is to just check the value against known goods:

password = sys.argv[3]

if filename != 'users' and filename != 'administrators':
	print 'Bad user type'
	exit( 0 )

csvfile = '%(file)s.csv' % { 'file': filename }
print 'Checking %(file)s' % { 'file': csvfile }

This way we can give the user some informative response if their input is invalid, and we can check all of the possible input variations without worrying about patterns we hadn't yet come up with.

Posted by jherrington at 7:59 AM in Research

Friday, 8 October 2010

Malware, You're the Disease

Scott Charney of Microsoft advocates a public health model for malware and botnets. I found Charney's paper worth the time to read. He offers some fine definitions of individual defence, collective defense, active defense, and offense as means to combat cyber crime, and compares these to their physical conuterparts.

That said, I'm not getting in line for a laptop health certificate. I do not find the public health model valid. It's an old saw in cyber threat modeling. I object to it as a false analogy. Measures like vaccination and quarantine are weighed carefully against civil liberties because in public health concerns, we deal with people and populations. Computers, ISPs, and the like do not have such advocates. My ISP can choke off my traffic, and no one would blink.

Furthermore Charney acknowledges that his proposal sacrifices privacy at the intent of security. Using his health model, he further blunders in his discussion on anti-smoking regulations as a comparative privacy loss for the public good. We must acknowledge that smoking in public is a willful act, unlike my computer's infection. Downloading software doesn't compare to lighting up.

It's time that security researchers shelve our copies of Outbreak and The Hot Zone. We need a model for the spread of software threats that applies to software threats.

Posted by ssundar at 11:19 AM in Research

Tuesday, 28 September 2010

SRG Goes Mobile, Part Three -- iOS Security and Old Attacks Getting A Makeover

As an intern at Fortify this past summer, I researched analysis techniques for Objective-C and potential security vulnerabilities in iOS (iPhone, iPod Touch, iPad) applications. In this blog post I discuss recent attacks against the iOS platform and note some parallels to older attacks. In my next post, I'll discuss what a attack at the application layer of iOS might look like.

First, I'd like to discuss some articles I've been seeing in the news recently regarding mobile security. There have been a number of articles about "new mobile threats" and "mobile malware," but the attacks described are simply applications that have additional malicious functionality beyond the purpose they claim to the user. This is the exact same type of attack as 10 years ago when downloading a dancing smiley cursor would also give you pop-up ads. When you download a program, whether it be to your desktop or to your phone, there's a possibility that it may have malicious functionality. This type of problem is as old as computers.

Most public attacks aimed at iOS focus on attacking the platform itself or on stealing private data, with the former representing a vast majority. For a glimpse into attacks on the iOS platform, you can get an idea by reviewing the bugs fixed in iOS 4.0. Many of the bugs are from libraries used by iOS, with a large number being in Safari and Webkit. As for privacy, the main public attacks have been from malicious apps that actively steal personal data or legitimate apps that accidentally leave sensitive information in places where unintended agents may access it.

What interests me about these attack trends on iOS so far is that almost no (public) attack has been at the application layer - they've all been attacking the underlying OS or attacking the storage of sensitive data. It's like everyone has been attacking Apache or other programs running on a web server, but no one's been trying to hack the website itself. I think we can expect to see more attacks aimed at iOS applications themselves.

Written by Clint Gibler
Posted by ssundar at 8:18 AM in Research

Friday, 24 September 2010

SRG Goes Mobile, Part One -- An Unsolvable Problem

For the first time, Fortify's Security Research Group investigated platforms and applications in the mobile space. In an upcoming post, SRG summer intern turned Ph.D. candidate Clint Gibler will detail his foray into iOS. Here we consider general security issues with mobile. We will go on to discuss how these vulnerabilities manifest in Google's Android operating system and applications.

The foremost security flaw with mobile is that you will lose your hardware. You may lose it to theft, you may hand your phone to a nefarious airport personnel for a few minutes as you walk through the metal detector. Moving away from the sinister side of the spectrum, you may inadvertently leave your phone in a bar. You may innocently recycle your phone when you upgrade to the newer model. Regardless of scenario, losing control of your multi-hundred dollar hardware hands over access to gigabytes of your valuable data: your contacts, your stored passwords, sensitive documents riding along as e-mail attachments.

We acknowledge this problem is endemic to mobile. Any data storage platform is a target for theft: a desktop machine, a laptop, thumb drive, or smartphone; even a manila folder. The risk of loss grows as the device size shrinks. Also, the target's value increases in proportion to its capacity. Thirdly, as a device performs more functions, there exist more types of information on it. A mobile phone contains a list of phone numbers, but a web-enabled mobile computing platform can contain this and bank account information and sensitive documents. Hence we believe that a mobile device like an Android-enabled phone lives in an attacker's sweet spot.

No software solution will prevent losing your phone. Fortify's Security Research Group addressed the resultant data loss by ensuring that sensitive data is not written to an unprotected location in Android. As your phone gains more of the functionality of you computer, you must protect it as such. For example, Android provides full support for SQLite databases that an application may use for structured storage. Mostly full, that is; SQLite mostly mitigates your fears of SQL injection, mostly. Analogous to your desktop, your mobile platform opens itself to attack through its software. These security issues - data loss and malware - exist for the Android platform.

In the next post, we will describe SRG's third quarter efforts to save Android from itself.
Posted by ssundar at 10:59 AM in Research

Thursday, 23 September 2010

Str0ng P@22w!rd?

On Sunday September 5, the New York Times printed an article about password strength. I have mixed feelings about this article. On the one hand, publication in a widely-circulated periodical brings application security issues to general audience. However the analysis in the NYT piece lacks the depth of a security publication. Security professionals are obliged to provide that depth. Consider the theses of the Times' piece, their destructive implications, and how we can guide the conversation to the benefit of users.

1. Complicated password policies are counter-productive. No one likes to create a new password of length eight to twelve characters, using a a combination of uppercase and lowercase letters, numbers and non-alphanumerics. Furthermore it is difficult to create a new one every ninety days, and to remember it. Multiply this onerous task by three or five or ten such accounts and one sways toward Donald Norman and Microsoft's security researchers quoted in the article.

By referring to Amazon, PayPal, and Fidelity's websites, the Times insinuates that since a simple password policy is good enough for these guys, it ought to be for everyone. But this obscures the fact that these corporations' simple password policies are just one element of multi-faceted information security infrastructure. If your information security policy is no more than your password policy, your system is in danger. Effective security policy is multi-layered; no single factor will adequately harden the target.

A strong password policy contributes hardness. A non-dictionary password, eight or more characters long defends against an off-line password guessing attack. Bruce Schneier wrote on this in 2007; his technical analysis remains sound.

Most of us do not set security policy in the organization; we merely abide. In 2009, Slate Magazine offered salient password creation guidance. Create your password out of a memorable pass-phrase. You might know that I'm a rabid Abba fan, but that won't help you or your password-cracking software deduce Dqy&so17
Dancing queen, young and sweet only seventeen...

2. Complicated password policies do not provide security. A second thesis of the NYT piece avers that password policies provide a false sense of security. False because a password will not protect against some more onerous threats. To evaluate this claim, one must consider the threat highlighted by the Times: a key-logger. Key-logging software on your machine will take your password, your bank account number, your mother's maiden name, and your best friend's e-mail address. Perhaps anti-virus software can detect this malicious program, though I've not found a security expert willing to risk her social security number on an anti-virus suite.

I acknowledge that this is a damning, damaging attack; as such it makes for good copy. A strong password would not stop a key-logger, nor would a dictionary password. Then again, multi-factor authentication, identity-based cryptography, and military-grade command and control would be ineffective. A key-logger is an infallible scribe recording each tap and click. Mentioning this omniscient, omnipresent demon obscures the discussion of passwords entirely. Security policy should prevent a key-logger from landing. A most conservative approach would restrict software downloads. But this circles back to Don Norman's criticism that security policy hampers usability to the point that users ignore the policy.

The NYT makes a valid statement in the title "A Strong Password Isn't the Strongest Security". A strong password is a necessary element of strong security. What are some additional elements?
Posted by ssundar at 2:42 PM in Research

Friday, 10 September 2010

Q3 Rulepack Update

The Security Research Group released its Q3 update to the Fortify Secure Coding Rulepacks and the Fortify RTA Rulepack Kits last week and I wanted to take a chance to update you on the latest and greatest from SRG.

As of this release, the Fortify Secure Coding Rulepacks detect 459 unique categories of vulnerabilities across 18 programming languages and over 680,000 individual APIs. Please see the attached PDF document for the full release details, but in summary, our latest updates include the following exciting features:

Fortify Secure Coding Rulepacks
Google Android – Rules support for programs that run on the Google Android platform, which identify insecure data storage and categorize applications by their security permissions.
HTML 5 – Support for this revision of the HTML specification targets features aimed at rich web applications, including vulnerabilities related to offline applications, inter- and intra-session data storage, and client-side SQL statements.
Microsoft .NET 4.0 – Expanded coverage for the latest version of the .NET framework includes data visualization tools, updated encoding methods, and routing mechanisms as well as strengthened core support for tuples, memory mapped files, file system enumeration, and string manipulation methods.
Amazon Cloud – Targeted support for the Amazon Web Services (AWS) Java API, including: S3, SimpleDB, and EC2.
Facelets – Coverage of common vulnerabilities exposed in Facelets, which is an open source XHTML template framework designed as an alternative to JSP in applications that use Java Server Faces (JSF).
JAX-WS 2.0 – Support for web applications that leverage annotations from the Java API for XML Web Services.
DISA STIG Version 3 – Vulnerabilities generated by the Fortify Secure Coding Rulepacks now include references to like issues found in the latest version of the DISA STIG (Version 3 Release 1).

Fortify RTA Rulepack Kits for Java and .NET
Tuning Capabilities – This update includes enhanced rules for SQL Injection and Cross-Site Scripting that allow users to easily and accurately tune the rules to produce the highest fidelity results.

Premium Content
Cloud Security Process Template – As a complement to the project template released last quarter, this update includes a process template that highlights ways to reduce risk during the SDLC when migrating a program from an internal data center to a cloud provider. Compliance and Standards Report – Expanding on the reporting capabilities of Fortify 360 Server, this release includes an updated compliance report for DISA STIG Version 3 Release 1.

Posted by jwest at 2:02 PM in Research

Tuesday, 31 August 2010

Richard Clarke on Cyberwar

ITWorld has just published a short Q&A with Richard Clarke focusing on Cyberwarfare and how companies can prepare.

Posted by jherrington at 2:09 PM in Research

Tuesday, 24 August 2010

Python Security Site

The guys at Python Security are doing an awesome job not only categorizing types of security attacks, but also specific vulnerabilities in Python packages. If you are involved in security and work in Python I hope you will help out their site and contribute your expertise on the Wiki.

Posted by jherrington at 9:35 AM in Research