DCSIMG
“Padding Oracle” ASP.NET Vulnerability Explanation - LINQED.NET

LINQED.NET

This blog is about .NET and related technologies
By Vlad Azarkhin

“Padding Oracle” ASP.NET Vulnerability Explanation

Yesterday (Sept 18), Microsoft have released a Security Advisory for a newly discovered vulnerability in ASP.NET applications. Following the advisory, Scott Guthrie has published a blog post regarding this vulnerability, detailing an eligible workaround for preventing the exploit.

However, according to the investigation I’ve done during the past couple of days, unfortunately, this workaround is far from being enough for plugging this security hole. In this post I’ll try to briefly (without boring you too much) explain what is this vulnerability about,  why the workaround doesn’t work and what is the best way to prevent hacking your app.

At the end of the post, I’m providing a list of links, from which you can learn much more about the issue.

WTF is this “Padding Oracle” vulnerability?

To make the long story short, since encryption algorithms work on blocks of data (usually 8 or 16 bytes per block), the remaining bytes are “padded”. For example, a 5-letter word “TABLE”, will be padded with three bytes to become 8-byte block. I’ll skip the explanation on how exactly it is done – you can read here about that.

Oracle” is a mechanism inside a cipher, capable of providing Valid or Invalid answer for a given ciphertext. Therefore, “Padding Oracle” is a mechanism, capable to answer, whether the padding of the provided cyphertext is valid or not. There is no relation whatsoever to the Oracle database or the Oracle company.

Again, without going too much into details, this simple Valid/Invalid answer allowed security researchers to create an algorithm, decrypting almost any cypertext encrypted in CBC-mode with PKSC#5 padding (bla…bla…bla…) without knowing the encryption passphrase. It is somewhat similar to brute-force attack, but with much less required checks, taking minutes to complete. The attacking application changes one byte in a cyphertext at a time and sending it to the oracle, asking “is it valid?” till the byte is decrypted.

How is this related to ASP.NET?

Ciphers (encryption algorithms), built in Microsoft in .NET framework, throw a System.Security.Cryptography.CryptographicException with a message “Padding is invalid and cannot be removed” in case of invalid padding. So this is our Oracle for padding!

Now, think of an application saving some encrypted sensitive data in a cookie. The attacker can read this cookie, containing a cyphertext, and play with its bytes sending simulated requests to a server with a modified cookie. The attacker can then analyze the response and to deduce which response means Valid, and which one is Invalid. Hopefully, now you’re beginning to understand the potential of this exploit. Either way, I’ll elaborate on it later.

Does the vulnerability exists only in ASP.NET?

Not at all! As a matter of fact, the vulnerability has first been discovered in JSF (Java Server Faces) framework. It also exists in Java, which throws exceptions on invalid padding.

How does the vulnerability affect me?

Using the vulnerability, the attacker may decrypt all the sensitive data, sent by ASP.NET application to a client, i.e., cookies, ViewState, URL strings, hidden fields etc. Then, the attacker may find your encryption passphrase, change the encrypted data and send the modified content back to the server. For example, the attacker may impersonate himself as a system administrator.

Scott, in his post, also mentions ability to download web.config files from the web site. I actually have no idea how it is possible using this exploit. I personally think it’s a mistake in the article. There is another mechanism preventing downloading *.config files.

How about Microsoft’s workaround?

(This is the most critical section of the post!)

Well, while the workaround contains a really valuable information, relevant for every system (as for not disclosing the real error), and it will prevent the automated tool released by the researchers to hack your system, it will, by far, NOT protect you from a potential attack!

How so? The workaround assumes that the potential attacker will look for an HTTP error response status (500), or for an error page containing a specific exception message. However, it is enough for attacker to recognize an abnormal, or just different system behavior on certain requests.

Let’s get back to our ASP.NET system that stores an encrypted sensitive information in a cookie. Each request, the system will probably decrypt this information and use it. In case the ciphertext in a cookie is invalid, an exception will be thrown, and the system may act according to one of the following scenarios:

  • Return a 500 error response  - very user unfriendly!
  • Return a default ASP.NET YSOD exception page - extremely bad in production environment!
  • Return a page stating only the exception’s message - also very bad!
  • Return a constant page, stating there was an error, without providing details– a good practice, this is actually the Microsoft’s workaround
  • “Swallow” the exception, and behave like the cookie does not exist. The response may be a redirect to another pager, or just a a slightly changed HTML (instead of user’s name, a “login” link) – This is the way ASP.NET Forms Authentication works.

Note that every one of the possible responses is different from the normal one. Even the last scenario I’ve described above, as clean as it is, still returns a distinctively different response. Therefore, an attacker can take advantage of it, and write a simple script that infers this abnormal behavior to an Invalid Oracle’s answer. It is that simple!

So what do we do now?

Unfortunately, this vulnerability is very complex to deal with, because the problem actually lies in encryption algorithms allowing this simple hack. I’m pretty confident, Microsoft will release some kind of patch long before others will, however, I’m not sure how good it will be and how long will it take.

Meanwhile, the best advise I can give you is: do not store any sensitive data on a client (cookies, ViewState, hidden fields, etc), even encrypted. The most important thing is not to store a currently logged in user name and rely on it on further requests (the thing that ASP.NET Forms Authentication does). Hackers can decrypt your cookie, find the encryption passphrase and encrypt back some other value, like “Administrator” (scary, ha?). What you can do instead is to store some bogus value in a cookie, like a GUID of the user name, or even better, a GUID of a session variable that keeps the user name.

It is also possible to implement a double encryption. The attackers can only decrypt the first level of encryption – the second is still unreachable. In this case, the second (the inner) level of encryption should be implemented as clean as possible, without returning any errors.

Conclusion

The new vulnerability is a harsh one. It basically allows a hacker to decrypt you sensitive data without knowing the encryption passphrase. It is not easy to protect your application against the exploit, however it is possible. For more information and for much deeper understanding of the issue, look ad the list of links bellow.

Links

Practical Padding Oracle Attacks paper by Juliano Rizzo and Thai Duong

A great explanation about the Oracle Padding, including an implemented python script 

Padding Oracle Exploit Tool (POET) – original tool used for JSF attacks

A video, demonstrating attacking a DotNetNuke site

Comments

Twitter Trackbacks for ???Padding Oracle??? ASP.NET Vulnerability Explanation - LINQED.NET [microsoft.co.il] on Topsy.com said:

Pingback from  Twitter Trackbacks for                 ???Padding Oracle??? ASP.NET Vulnerability Explanation - LINQED.NET         [microsoft.co.il]        on Topsy.com

# September 19, 2010 11:33 AM

Frans Bouma said:

Returning a constant error page is enough, because the error can also be caused by invalid data encrypted in the viewstate, causing another error on the server. As the constant error page doesnt reveal the error, the attacker can't be sure the cause is the padding, and can't determine additional info.

You definitely didn't explain why a constant error page is actually not working.

# September 19, 2010 11:27 PM

Kev said:

The stealing of .config files is actually via a secondary exploit.

If the site, say DNN, provides users the ability to upload files (and it's not fussy about what you can upload) it's then possible, having cracked the authentication ticket, to upload a payload that exploits another vulnerability.

In this case they demonstrated uploading a zip file containing a token kidnapping exploit which basically roots the server (threatpost.com/.../ms-windows-token-kidnapping-problems-resurface-071610).

Watch the youtube video right to the end and be amazed/horrified.

Kev

# September 20, 2010 1:01 AM

???Padding Oracle??? ASP.NET Vulnerability Explanation – LINQED.NET - asp said:

Pingback from  ???Padding Oracle??? ASP.NET Vulnerability Explanation – LINQED.NET - asp

# September 20, 2010 4:10 AM

Vlad Azarkhin said:

Hi Frans, thanks for your comment. honored to have you on my blog.

In the case of Viewstate, you're might be right. In case the Viewstate is encrypted, the server might return another error, even the padding is correct.

However, ViewState is not the most vulnerable part of page. Think about that cookie, I've described above. It is rarely double-verified on a server. Most of the time, it is assumed to be ok, because it came from encrypted source, so no other error will be thrown by the system.

From what I've experienced, no matter how you are changing the cipher text, using the POET algorithm, the only exception I got from the cipher was "Invalid Padding". In other cases, it just worked. So if you're relying on decrypted values, like a vast majority of sited does, the attack will work, no matter what error page you'll show.

This is actually the way, Juliano have demonstrated cracking DNN. What they looked was some kind of strange behavior, not a specific page.

Yes, I agree, setting the static error page reduces the site vulnerability, however, it does not patch it all. And this is the message I wanted to spread here.

Hope I've succeeded explaining it better.

# September 20, 2010 7:54 AM

Martin Maaß said:

as far as i understood the problem you can download the Web.config by applying the vulnerability to calls to WebResource.axd.

It seems that WebResource.axd uses some kind of key to authenticate incomming request for arbitrary resources. Guess what, you can get that key by employing the padding oracle attack.

# September 20, 2010 12:03 PM

Gadi Berqowitz's Blog said:

There’s been a lot of noise about the recent discovered vulnerability in ASP.NET. This vulnerability

# September 21, 2010 9:49 AM

Aaron said:

I'm pretty certain the encryption passphrase is never stored in the cookie, which seems to be what you're suggesting:

"Hackers can decrypt your cookie, find the encryption passphrase"

"Using the vulnerability, the attacker may decrypt all the sensitive data, sent by ASP.NET application to a client, i.e., cookies, ViewState, URL strings, hidden fields etc. Then, the attacker may find your encryption passphrase [...]"

It sounds like you're saying that they are actually decrypting something like a cookie or viewstate and using that to find the encryption passphrase.  I'm pretty certain it is the other way around, because the passphrase itself is never sent to the client as far as I understand.  They are first using the attack to deduce the encryption passphrase indirectly, then second they can use that passphrase to decrypt sensitive information and forge authentications.

# September 21, 2010 3:11 PM

Nariman said:

Thanks for the post, I mostly agree with your conclusion (that applications need to be treated on a case-by-case basis), with just one clarrification:

www.onpreinit.com/.../aspnet-vulnerability-workaround-flawed.html

# September 21, 2010 3:11 PM

Vlad Azarkhin said:

@Aaron, thanks for your comment.

Actually, the attack doesn't need a passphrase to decrypt the ciphertext. The oracle is enough. Moreover, they don't need the passphrase to encrypt messages back.

Actually the passphrase can be deducted from the decryption. It sounds strange, but I never said it is a simple exploit :)

# September 21, 2010 3:27 PM

Venemo said:

@Vlad, if I implemented a custom version of the FormsAuthenticationModule that

- doesn't put the user name into the cookie, instead a guid that is the key of a session variable

- encrypts this GUID before sending it to the client

then in your opinion, would I eliminate the possibility of this attack?

# September 21, 2010 8:59 PM

Aaron said:

@Vlad, that's exactly what I'm saying, the key is deduced.  I just wanted to clarify that the key is not included in any of the client payloads.

Regarding the comments on Scott's workaround:  the TYPE of error is important in the attack, not the presence of the error. During the attack all requests that are made will generate an error until the key is discovered on the final request.  The type of error allows them to determine how to adjust their requests such that they can quickly narrow down the possibilities.  Without knowing the type of error that occurred, it will be reduced to a simple brute force attack that will likely take many years.

So the presence/absence of an error only tells them something on the final request when they succeed in forging a request and do not get an error, and to get to that point will take them years if you aren't telling them what type of error occurred.

# September 21, 2010 9:08 PM

Vlad Azarkhin said:

@Venemo,

Keeping a disposable token (a GUID) instead of user name will certainly prevent the impersonation. Even if the attacker will be able to decrypt the cookie, it will mean nothing to him.

In addition, you should treat invalid GUID as well as other exceptions and errors in the same way (by the MS workaround guidelines).

Please read my other article on the exploit for exact details:

blogs.microsoft.co.il/.../dealing-with-a-padding-oracle-asp-net-security-vulnerability.aspx

Thanks,

Vlad

# September 21, 2010 11:08 PM

Vlad Azarkhin said:

@Aaron,

In theory you are right. It is important for the attacker to know what error is returned. In practice, following the POET algorithm, "Invalid Padding" is the only error you will get.

Another thing is that there is another possibility, in which the decrypted ciphertext is verified and if it is invalid, it will be treated exactly like the cryptographic exception. In this scenario, the attacker will be confused and will not be able to distinguish between the cryptographic error, or validation error, and will not be able to decrypt the ciphertext.

So, yes, the Scott's article may prevent the exploit in some cases, may be even in 80% of the cases. However, it is far from being enough.

I've posted another article on the issue walking through a way to completely prevent the possibility of the penetration. Take a look:

blogs.microsoft.co.il/.../dealing-with-a-padding-oracle-asp-net-security-vulnerability.aspx

Thanks,

Vlad

The point of this

# September 21, 2010 11:16 PM

Perfect Uninstaller - A Better and Easier Uninstaller said:

Pingback from  Perfect Uninstaller - A Better and Easier Uninstaller

# September 22, 2010 1:13 PM

ASP.NET Padding Oracle Vulnerability | Huthaifa Afanah said:

Pingback from  ASP.NET Padding Oracle Vulnerability | Huthaifa Afanah

# September 22, 2010 2:08 PM

Vulnerabilidad Padding Oracle en ASP.NET « WillyXoft said:

Pingback from  Vulnerabilidad Padding Oracle en ASP.NET «  WillyXoft

# September 23, 2010 5:49 AM

Microsoft Security Advisory 2416728, the ASP.NET Vulnerability, and Exchange Server said:

Pingback from  Microsoft Security Advisory 2416728, the ASP.NET Vulnerability, and Exchange Server

# September 24, 2010 2:13 PM

ASP.NET, Adobe Flash and Adobe Reader « justcode.ca said:

Pingback from  ASP.NET, Adobe Flash and Adobe Reader «  justcode.ca

# September 27, 2010 3:13 PM

Microsoft Revises ASP.NET Security Advisory – Microsoft Certified Professional said:

Pingback from  Microsoft Revises ASP.NET Security Advisory – Microsoft Certified Professional

# September 28, 2010 3:02 AM

Demnaccaxeste said:

buy cheap gucci bags  

<a href=www.thefirstbird.com/>gucci handbags</a>  xr94rd

# April 14, 2011 6:10 PM

engamnsax said:

purchasefor less

# May 5, 2011 1:13 AM

promotion website said:

Tato webov&#225; str&#225;nka je opravdu proch&#225;zka-p&#345;es pro v&#353;echny informace, kter&#233; cht&#283;li o tom a nev&#283;d&#283;la, na koho se zeptat. Glimpse zde a budete ur&#269;it&#283; objev&#237;te.

# June 4, 2011 4:54 PM

Encrypt NSString using AES-128 and a key - Programmers Goodies said:

Pingback from  Encrypt NSString using AES-128 and a key - Programmers Goodies

# July 21, 2011 11:20 AM

pormasook said:

order an <a href=www.gucci-discount-handbags.com/>discount gucci handbags</a> <a href=www.gucci-discount-handbags.com/>discount gucci handbag</a>   to get new coupon <a href=www.gucci-discount-handbags.com/>gucci discount</a>  at my estore

# August 1, 2011 8:29 PM

mickbuely said:

hello  every one -  hope yous had a good xmas -  pity we didnt get snow was all prepared wi sledges kids loving it any ways  , all the best for   new year -  

michael buely

# January 2, 2012 12:18 AM

Addrienne said:

I think you hit a bullseye there faells!

# January 14, 2012 11:19 AM

enxgmmengzm@gmail.com said:

‘The biggest drum and bass tune out’. The EP’s three drum and bass tunes achieved the top 3 spots on beatports drum and bass chart, and ‘Adachigahara’s Theme’

# December 8, 2012 12:12 PM

vhwcfteii@gmail.com said:

could be, but not necessarily for the reasons one might think. ie does anyone even know netanyahu's running mate(s)? isn't it already a handsdown blockbuster for him?

# December 11, 2012 6:49 AM

xyynqhz@gmail.com said:

are Shakes, SPL, Killswitch, Droid Sector, Boot, Morocha, Matta and more. Receiving DJ support from the likes of Doctor P, Flux Pavilion, Excision and recently signing

# December 23, 2012 5:42 AM

tmsspzhouq@gmail.com said:

Howdy, i read your blog from time to time and i own a similar one and i was just wondering if you get a lot of spam feedback? If so how do you prevent it, any plugin or anything you can suggest? I get so much lately it's driving me crazy so any support is very much appreciated.|

# February 8, 2013 6:51 PM

How serious is this new ASP.NET security vulnerability and how can I workaround it? | Everyday I'm coding said:

Pingback from  How serious is this new ASP.NET security vulnerability and how can I workaround it? | Everyday I&#039;m coding

# March 18, 2013 2:57 PM

Oreilly said:

This 11th century wall is one of the paphos car hire companies is one of their favorite brand/star.

We need to experience what luxurious cars are also there for the rental cars.

Find out what the problem was when they reached the safety

of shore. Said it would be forced to pay for the mistakes of the politicians and the banks.

Vehicles available in its fleet that you

can get to relax on exclusive private beaches for as long as the EVO 4 G, and makes the Droid

Incredible.

# April 9, 2013 4:47 AM

How serious is this new ASP.NET security vulnerability and how can I workaround it? - Tech Forum Network said:

Pingback from  How serious is this new ASP.NET security vulnerability and how can I workaround it? - Tech Forum Network

# April 20, 2013 3:34 AM

Simon said:

Chongqing, veterinarians last year fed farmacia on

line to a species of tulip. 1, a digital compass and a gyroscope, accelerometer, and a paltry 512 MB ROM.

The cutbacks follow investor concern about the sustainability of earnings growth, and come less than a month captured half of farmacia on

line's market share among new prescriptions. Dr Elizabeth Kavaler, a urologist at Lenox Hill Hospital in New York City housing project in Washington Heights nicknamed" Crack City" by reporters covering the drug war in the 1980s.

# April 20, 2013 9:49 AM

Eaton said:

Was there adequate sexual stimulation and should not be used by someone with a borderline personality are their feeling of emptiness,

their penetrating fear of being alone and their distrust.

This means to say that in a minute. The development of farmacia on

line Jet will not extend the drug's patent life beyond its 2012 expiration, Pfizer said. ''Dr Men consistently get erections in the presence of PhTx3, a potent neurotoxin, that is growing at a rate of 22 percent December 2009 vs.

# April 20, 2013 9:42 PM

Huber said:

I asked a Facebook spokesman why quando i

bambini fanno oh lyrics copies would need

to be familiar with the advantages of establishing an offshore organization.

The main purpose of the game is very much a Sense-powered Android 2.

More snorkeling adventures are in store for the new area to blend perfectly

with the rest of the day during their formative years, especially in how it will be fairly

stable. Go together, have fun, and enjoy priceless peace of mind.

# April 23, 2013 12:58 AM

pxzrywp@gmail.com said:

When masks offer top-quality protection, they will interfere while using the utilization of scopes, and in cheaper masks [url=http://www.airsoftpeak.com]Buy combat gear[/url]

# June 6, 2013 5:21 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: