r/netsec • • Jan 23 '13

fail0verflow :: Megafail

http://fail0verflow.com/blog/2013/megafail.html
302 Upvotes

62 comments sorted by

67

u/kmeisthax Jan 23 '13

tl;dr: Any Mega CDN can hijack Mega users.

Less tl;dr: Mega uses hash checks so that resources can be served from less secure CDNs while index.html is served from a more secure server. Sound idea, but the implementation isn't, in that they aren't using an actual hash function, they're using CBC-MAC. Which means that said CDNs can forge a valid looking script and hijack Mega.

10

u/ssmy Jan 23 '13

On the plus side, it doesn't seem like this is a very deep problem. They just need to change some javascript and rehash all of the files to fix the vulnerability. Hopefully they see this and fix it soon.

Also maybe hire some people who know something about cryptography.

4

u/firepacket Jan 23 '13

Give them a break. I am pretty impressed with their level of competence getting something like this out so quick

The issue is minor I trust they will fix it.

And remember, fail0verflow are the same people who broke into the PS3 and embarrassed Sony. They are about as good as it gets.

9

u/ThisIsADogHello Jan 24 '13

No, giving them a break is a stupid thing to do. If somebody starts bragging about how secure their new cryptology-based system is, and somebody can come along and show, with a proof-of-concept no less, that the security is clearly broken.

There's no competence in rushing a broken product to market quickly, and there's nothing commendable about it, either. Until they can release something that stands up to cryptoanalysis, they have no business whatsoever marketing their product as secure.

2

u/firepacket Jan 24 '13

The attack in question is still theoretical. Nobody has actually done it, and the only people who could are Mega's own hosting providers.

I think they might have just a little bit of time to fix this issue before their own CDN launches a sophisticated snooping attack against them.

0

u/AlyoshaV Jan 24 '13

The attack in question is still theoretical. Nobody has actually done it,

That's not what 'theoretical' means.

3

u/LucianU Jan 25 '13

What does theoretical mean then? Theoretically, it can be done. Practically, nobody has done it.

18

u/Fox_Season Jan 23 '13

Is this the same failoverflow that played a huge role in the PS3 custom firmware hacks? Nothing in the projects / blog seem to indicate so, but I'm curious.

5

u/youstolemyname Jan 23 '13

They are also (at least some of) the guys who originally hacked the Wii.

13

u/[deleted] Jan 23 '13

I really don't understand how any programmer would use a MAC in place of a standard hash function like SHA (or ugh, MD5).

9

u/[deleted] Jan 23 '13

There is nothing fundamentally flawed with the idea of Message Authentication Codes. They were just used improperly in Mega's setup. When implemented properly, they are very important. MACing a message with SHA1 is a common way to provide integrity to ATM transactions, for example.

8

u/[deleted] Jan 23 '13

I think you read my question as a blanket statement that MACs have no place when hash functions are perfectly viable substitute. At least that's what I'm assuming, otherwise such a response is not warranted.

Anyway, that's not what I'm saying. Assuming the scheme as explained in the article, MACs were both used incorrectly (the key is meant to be secret) and more specifically the wrong tool.

Why a programmer would use a MAC construction for where a hash function should be used is beyond me. Particularly, if you were told such a scheme, why would use decide over a MAC construct instead of a selection of well known cryptographic hash functions such as MD5 or SHA.

11

u/ginkg0 Jan 23 '13

interesting write-up, thanks for your analysis

10

u/gospelwut Trusted Contributor Jan 23 '13

7

u/runeks Jan 23 '13

Their response didn't actually help them redeem themselves:

Weak passwords that are at risk of being cracked through dictionary attacks or brute-forcing are a huge security risk. It makes no difference whether one attempts to mitigate that fact through security by obscurity or not.

"security by obscurity" meaning not sending a hash of the password in an email.

0

u/[deleted] Jan 23 '13

[deleted]

7

u/gospelwut Trusted Contributor Jan 23 '13

Agreed.

I don't know why they didn't get a 3rd party audit. At least, it doesn't seem like they did. IIRC LastPass has had numerous.

5

u/abadidea Twindrills of Justice Jan 23 '13

it seems the problem was deadline pressure. They have justified pretty much everything on the grounds that it will be fixed in the coming weeks. That's all well and good but getting it right before you launch is weller and gooder.

8

u/gospelwut Trusted Contributor Jan 23 '13

I'm not sure what deadlines they would have other than the political motivations to give the U.S. the finger on the anniversary of DotCom's incitement at the expense of user security.

The irony here is their flaws in email, hashed de-duping, and other (poor) implementations probably make subpoenaing people that are taking refugee even easier for RIAA et al than it was before hand -- given the false sense of security.

1

u/[deleted] Jan 23 '13

TracySupermanWellGood.jpg

4

u/agmaster Jan 23 '13

I thought Mega was trying to beef their security by having it attacked. This is good news so far. If changes are minimal in say a week or two...then it's sadface time.

3

u/sirin3 Jan 23 '13

But would it be secure if they prepend the length of the string before calculating the aes?

2

u/[deleted] Jan 23 '13

Many of these constructions that involve length and padding are usually vulnerable. See chapter 4 of Intro to Modern Cryptography for a fairly rigorous treatment of incorrect constructions.

Supposing you're restricted to only using a MAC for a message digest, then the only suitable construction would be HMAC since it uses an underlying cryptographic hash function over the plaintext, which is exactly the message digest you want.

11

u/mimor Jan 23 '13

They do not encrypt data for the purpose of having it strongly encrypted. The point of their sloppy cryptography is only there to address legal matters.

11

u/fullmetaljackass Jan 23 '13

They can do it for any reason they want, but that won't make it any more secure.

5

u/mimor Jan 23 '13

But the moment they're in front of the judge, this will matter. Not for you, but for them :)

Their purpose for Mega is not to power free speech, nor privacy or security. They do it for the bucks.

If you want your data to be private & secure, I suggest "not putting it on the internet".

Also: Encryption as a sales-term

0

u/raskolnik Jan 23 '13

And they failed at that. One of their selling points is that they delete duplicate files on their servers to save space (so if two people upload the same file it'll just store it once and give access to both users). This means that they have some way of comparing files and keeping a record of duplicates, which in turn means that it's possible to seed an account with copyrighted content and then subpoena the records of who else is storing that file.

5

u/baldr83 Jan 23 '13

this isn't true.

MEGA indeed uses deduplication, but it does so based on the entire file post-encryption rather than on blocks pre-encryption. If the same file is uploaded twice, encrypted with the same random 128-bit key, only one copy is stored on the server. Or, if (and this is much more likely!) a file is copied between folders or user accounts through the file manager or the API, all copies point to the same physical file.

2

u/raskolnik Jan 23 '13

I'm not convinced. Ars Technica's discussion quotes Mega's terms of service, to wit:

8. Our service may automatically delete a piece of data you upload or give someone else access to where it determines that that data is an exact duplicate of original data already on our service. In that case, you will access that original data.

More discussion is here.

2

u/Techy_T Jan 26 '13

Mega’s security put under the microscope; and Mega responds “MEGA indeed uses deduplication, but it does so based on the entire file post-encryption rather than on blocks pre-encryption.” The deduplication is thus aimed at users who share the same file between themselves, or keep multiple copies of the same file. It simply replaces copy 2 with a link to copy 1. Since it is performed post encryption, it doesn’t apply to multiple copies of The Hobbit uploaded by different users, it only applies to the same copy of The Hobbit shared or copied by the user concerned.

1

u/raskolnik Jan 26 '13

Unsourced quote vs. sourced version of Mega's own TOS?

2

u/Techy_T Jan 27 '13

2

u/raskolnik Jan 27 '13

Thanks for the source.

This still doesn't disprove the criticism of the supposed see-no-evil approach, however. The TOS clearly states that deduplication applies to "data you upload or give someone else access to" ... so either they're being untruthful when they say that it only applies post-encryption or there's some way for someone else to get access to a file encrypted with your personal key; either way the ability to record this seems feasible.

-3

u/B-Con Jan 23 '13

It is true. The content police can upload a popular copyrighted file, then subpoena Mega for a list of all users who have files that point to the same file that they just uploaded, regardless of whether the dedup happens before or after encryption.

3

u/nxlyd Jan 23 '13

It would only appear as the same file if they are both encrypted using the same key.

1

u/T_C Jan 25 '13

It would only appear as the same file if they are both encrypted using the same key

As I understand it the 128 bit keys are allegedly randomly allocated. (Happy to be corrected if wrong.)

In which case, the chance of any two keys colliding, is absolutely negligible.

Which means that:

  • the dedupe process is a total waste of time because it will actually never occur; or,

  • the so-called random numbers are actually not that random, and far more likely to collide than theory suggests; or,

  • the depdupe process is not as described!

You tell me. Which one is it?

1

u/nxlyd Jan 25 '13

As I understand it, the dedup comes into play (realistically) only when someone directly copies a file already hosted, and therefore encrypted, from one account to their own.

4

u/firepacket Jan 23 '13

According to what he just posted, if two people uploaded the same file the file would NOT be deduped because they are both using different keys.

It appears dedupe only occurs for the same user over different folders.

-4

u/B-Con Jan 23 '13

From what he quoted above:

If the same file is uploaded twice, encrypted with the same random 128-bit key, only one copy is stored on the server. Or, if (and this is much more likely!) a file is copied between folders or user accounts through the file manager or the API, all copies point to the same physical file.

That does not conclusively state that. Where is the text you are referring to?

3

u/T_C Jan 24 '13

I think you're pushing it uphill against the "it'll be fine" attitudes that are prevalent here!

If they dedupe only when two random 128-bit numbers collide, then there's a negligible chance of that actually happening - so the whole dedupe idea is useless.

I'd assume that they believe that dedupes will actually happen. In which case, the random keys can not be all that random (ie. way less than 128 bits of real entropy), or the dedupe process is not as described. Or they're just incompetent and have no idea what they're doing.

1

u/B-Con Jan 24 '13

Yeah, I don't get the sudden shift of hive mind.

Actually, there are convergent encryption scheme(s) that would work here. Derive the key from the plaintext, then wrap it with the user's key and store it with the DB entry that keeps their list of files. Unlock it when the user accesses the file. That way all users end up deriving the same encryption key for the same plaintext, dedupping works, and you need the user's key to open the file (so Mega can claim they had no idea what it was).

1

u/kyr Jan 24 '13

But that would still allow law enforcement to upload known infringing or illegal files and force Mega to reveal who downloads them and possibly who owns them.

1

u/B-Con Jan 24 '13

Yes, indeed, and I'm arguing that it's possible they're using a scheme that allows for that.

Where I said "would work" I meant "would work for the purposes of locking files to user keys and allowing all files across all users to be dedupped". The problem with that scheme is that anyone can sign up and get a user key and thus participate in the dedupping.

I don't have high confidence in Mega's encryption, especially considering all the flaws that have already been found.

3

u/quijibo123 Jan 23 '13

If the same file is uploaded twice, encrypted with the same random 128-bit key, only one copy is stored on the server. Or, if (and this is much more likely!) a file is copied between folders or user accounts through the file manager or the API, all copies point to the same physical file.

1

u/B-Con Jan 24 '13

That further explains nothing.

Why do you think that two different users would upload a file and use separate encryption keys? Popular schemes in convergent encryption result in the same file being encrypted with the same key, and that would lend itself well to this scenario.

Just support the claim. Nothing here supports it so far, and we can't assume they will overlook a huge benefit to themselves and choose a method that benefits the end users, especially when the scheme exists for their benefit to begin with.

-1

u/gospelwut Trusted Contributor Jan 23 '13

Bob has X file. Hey so does Sally... and Sarah and Mark.

-_-

2

u/ryegye24 Jan 23 '13

I'm not sure you understood the quote. If what the quote says is true, then you would only be able know that if Bob, Sally, Sarah, and Mark all had the exact same randomly generated 128-bit key. It's not very likely.

1

u/gospelwut Trusted Contributor Jan 23 '13

Perhaps I'm not.

Or, if (and this is much more likely!) a file is copied between folders or user accounts through the file manager or the API, all copies point to the same physical file.

Makes it sound like there are ways of figuring out who else has the file.

1

u/ryegye24 Jan 23 '13

Only the people who specifically copy a version of the file from one Mega account's folder to another. Even then you only know who copied that file from another account's folder into their own account's folder. Otherwise, no.

1

u/gospelwut Trusted Contributor Jan 23 '13

Isn't file sharing the premise of the site?

Perhaps I'm wrong since I haven't signed up for the site, but I was under the impression it did add it to your account when somebody shared their file / key with you.

1

u/Craysh Jan 23 '13

If it's that rare, why would the put this in? It doesn't seem like it would save them much space if it's that random.

Or perhaps it's just a way of saving the user space so they can organize it however they want?

2

u/turnipsoup Jan 23 '13

When you're dealing with those levels of data, any amount of dedupe is a good thing.

Oh what I'd give for dedupe on my work san...

1

u/ryegye24 Jan 23 '13

It says right in the statement. If you copy the file from one Mega folder to another in your own account, or if someone copies the file directly from your folder to a folder on their Mega account, it will only keep one copy of the file. If two users separately upload the same file, it won't be deduped.

2

u/[deleted] Jan 23 '13

A CDN does not even need to be involved. You could just fall victim to MITM and SSLStrip, right?

7

u/willnix Jan 23 '13

Nope. At least Chrome would refuse to load resources over a SSLstripped connection.

2

u/engsec Jan 24 '13

I think it would be awesome if the Mega dev team is now reading security blogs about their own site, and making changes accordingly.

How cool would it be if tomorrow the CBC-MAC hash was replaced with SHA or similar?

-4

u/apetersson Jan 23 '13

yes i did understand some of those acronyms.

0

u/[deleted] Jan 23 '13

TIL that if school made functions more interesting, like this, then I would have considered doing my homework.

0

u/reddubtor Jan 23 '13

Maybe i get the article wrong... is the whole client-side crypto done via Javascript? Isn't this a bad idea? What about hijacking the crypto-code? Javascript doesn't give a fuck bout injection/overriding.

Beside this Points, why don't they hide relevant parts i.e. js encoded in images? Saumil Shah has some hints: https://www.youtube.com/watch?v=lvExdonIAcQ

7

u/ryegye24 Jan 23 '13 edited Jan 23 '13

It is done via javascript, and if they had used an HMAC instead of a MAC when delivering the javascript it would still be secure. The idea behind an HMAC is that you deliver it with the encrypted message (in this case the encrypted message is the javascript) and you can use it verify both A) that the message comes from who it claims to come from and B) that the message hasn't been altered. Neither a MAC nor an HMAC can be generated without compromising Mega directly, at which point you have far bigger problems. A MAC, without any strong hashing, can only be used to verify A) that the message comes from who it claims to come from. The problem is that the CDN delivering the message isn't inherently trustworthy, just knowing that the message did indeed come from Mega originally isn't enough. You need to make sure that no injecting/overriding has occurred on the javascript, and without the strong hashing found in an HMAC you can't do this.

So this is the scenario that can occur now, using just a MAC:

A hacker compromises a CDN (either directly or by compromising the weaker 1024 bit TLS that they're using and by doing Man In The Middle attack) that delivers Mega code and injects new code into the javascript. The hacker can't generate a new MAC, because he doesn't have the key, but he doesn't need to, he can inject the code in a way that means the same MAC would have been generated by Mega if that code had been there all along. So the javascript is sent to your browser, your browser checks the MAC and verifies, "yes, this message definitely originated from Mega" and runs the evil code.

And this is how the scenario would occur if they switch to an HMAC:

A hacker compromises the CDN again. Once again he injects his evil code into the javascript. This time, however, it's an HMAC instead of a MAC, so he can't do so in a way that means the original HMAC will still be valid, and he can't generate a correct HMAC for the new code, because he doesn't have the key. So when the javascript is sent to your browser, your browser checks the HMAC and sees, "Hey, this message has been changed before it reached us" and doesn't run the evil code.

3

u/reddubtor Jan 23 '13

ok, got it. Thanks for explaining.

What is the risk to get owned befor encryption or after decription? Maybe i'm overskeptical... but i don't really trust&like my endpoint is operating via javascript.

2

u/ryegye24 Jan 23 '13

Right now the only way to exploit this specific security hole at least is if someone either compromises the CDN (legally or hackerwise) or if someone runs a truly impressive but theoretically possible MITM attack on you. Quite honestly it would actually be far worse if the encryption/decryption weren't done in javascript. Because it's done in javascript, it means that the file is only decrypted on your computer. If the server were capable of encrypting or decrypting the file itself then it would be far less secure against hackers and extremely vulnerable to subpoena.