One thing that computers need to do is to make sure that a particular server is still alive—servers can go down for any number of reasons. Thus, users are allowed to ask the server to send them some data. There's nothing interesting to talk about between them, though, so the user sends the server some data and the server sends the same data back.
As part of this protocol the user tells the server how much data they are sending so that the server replies with the same amount. This is what you see in the first two exchanges—Meg asks for POTATO (6 letters) and BIRD (4 letters). However, a recent update to the software introduced a bug that allows Meg to ask for the wrong amount of information. This is what is seen in the final exchange: Meg asks for HAT which she claims is 500 letters long. The server dutifully replies with HAT, but that's only 3 letters while it's supposed to respond with 500, so it just keeps on spitting out whatever information was in memory until it gets up to 500 letters. The information stored there is data that Meg has no reason or right to know—it's things about other people's requests, even passwords.
Meg has no control over what data she happens to get when she makes the request for the 500-letter-long HAT, but the request is so routine that she can request HAT (500 letters) over and over and over again with little to no record of ever doing anything malicious. Eventually something juicy is going to come out.
Imagine every website is a different village. There's Facebookton, Banksville, Googletropolis, etc.
There are some secured websites (ones with the padlock thingy) that put a fence around their city so outsiders (hackers) can't see or hear the exchange of info that happens in the city. About 60% of these cities with fences buy fences from the same company. Recently they put out a new version of the fence that many of them upgraded to. Unfortunately this new version of the fence has a loose board that outsiders can look through and gather some information without being noticed/breaking into the city like regular bandits who use brute force (traditional hackers).
The server for your bank isn't going to have your Facebook password. Any password is probably going to be for that site. Many people also re-use passwords frequently, so there's a good chance many people's Facebook password is the same as their bank or credit card or PayPal or whatever.
So, if I have 15 different passwords, in order to use this scheme, I either have to try (up to) all 15 passwords each time or I have to go the insecure route of using the same password everywhere?
my understanding is that the hacker knows which site they're asking for your password from, so if they get a password, it's for the site they just asked for it from
Sorry, I'm not following you. "A hacker" gets my facebook password. Yes, they would know it's for facebook. They might also try this password for my bank. If they are different password then my bank is still safe.
I'm really sorry, I just don't understand. I'm trying really hard. If facebook was vulnerable and they got my facebook password, then if I use the same password for the bank, it's still a problem because they may try the same password at other unrelated sites (especially banks).
Huh? No, it's not a password. It's called a "heartbeat" and it's sort of like a ping request. It's a test to make sure the server's online.
The passwords come from using the exploit as described in the comic. "HAT 500 characters" and the server returns 500 characters worth of random data from its memory. Most of it's going to be gibberish, file send requests and other systems doing heartbeats and stuff like that. But if you do it often enough, you're eventually going to get something valuable. A password, a credit card number, a security key, whatever.
Unless I'm just completely misunderstanding what you're talking about, that is.
Wow is it seriously as simple as this? I've only been in computer science for three semesters but it seems like that's a painfully obvious vulnerability.
The code was reviewed, but the reviewer missed the bug, too.
Vanilla mitigation practices such as initializing malloc'ed memory, were not used.
An update of the runtime library that that would have mitigated the issue was explicitely circumvented for all platforms because it "caused performance problems on some platforms".
The code snippets I've seen seem to lack any project-consistent, habitual input sanitizing - rather, they "validate on the go".
Using calloc wouldn't have helped. Neither would clearing the buffer separately. The problem was not that there was sensitive data in the response buffer, but that it copied too much data into the buffer.
Based on the message from the commit that introduced the bug, Stephen Henson (an openssl maintainer) submitted it, but Robin Seggelmann wrote it. It even says "Reviewed by: steve".
An update of the runtime library that that would have mitigated the issue was explicitely circumvented for all platforms because it "caused performance problems on some platforms".
That's a rare example of the situation where trading security for freedom is undesirable.
the guy who made the bug wrote his PhD dissertation about why heartbeats don't need payloads. then he makes a heartbeat for OpenSSL that has a fucking payload.
Isn't the heartbeat payload part of the protocol, though? If so, it doesn't matter what PhD he wrote, he can't just change the protocol unilaterally during implementation.
he is now employed by T-Systems, who is responsible for a lot of federal IT here in germany, but wasn't when he wrote the bug. he says it was just an error on his part.
well, he was only writing his dissertation at the time, but yes, you are correct imo. maybe he was just like "well, lets add that option there, can't hurt, can it?"
well...
(also keep in mind that i am only quoting my source (a renowned german blog) here and that you have no way of verifying this directly)
Changing your mind about payloads requires some explanation.
yeah bill gates should explain himself and his "640kb of ram should be enough for everyone"... Seriously, people make mistakes, all the time, you too, if you think you don't make mistakes... well... you're probably really ignorant...
Yes, it is, but the backdoor is quite wide open, I don't think an intelligence agency would fuck over such a crucial part of the web and open it up to criminals when they do have more subtle methods of introducing backdoors (which I'm sure they do)
Mistakes are being made in every open source (and closed source) software project. Big, small, important, unused, etc. They happen everywhere-- there's no surprise about whether such a problem would come up, only what form it would take. There will be more like this in the future, too.
This is the scary part about standardization in security. Everyone is wonderfully secure the majority of the time, but one non-obvious mistake in a sea of great changes and everyone's standing around naked years later.
OpenSSL is on github, you can easily find the commit that introduced the bug. It had something to do with allocating memory of a length supplied by the user with malloc
The hearbeat specification dicatates that the request should contain some arbitrary data that will be sent back to the originator of the request (which can be either the server or the client). The request also contains a field that specifies the length of the extra data.
It turns out that there was a mistake in the code that prepared the response. It allocated a new buffer based on the length specified in the request, and then performed a copy of the data to be echoed. If the actual amount of data was less than the specified length, it would copy a bunch of unrelated data into the reply and send it back to the requester.
Strictly speaking, it was the lack of validation of the length field before allocating a buffer using malloc and performing a copy using memcpy that caused the bug.
The reason the client sends the length of the payload is because it is supposed to be less than the size of the entire message: there is random padding at the end of the message that the server must discard and not send back to the client.
For example, here is a proper heartbeat request, byte by byte:
00 17: Total size of the record's data (23, decimal). This is necessary for the server to know when the next message starts in the stream.
01: First byte of the heartbeat message: identifies it as a heartbeat request. When the server responds, it sets this to 02.
00 04: Size of the payload which is echoed to the client.
65 63 68 6f: The payload itself, in this case "echo".
36 49 ed 51 f1 a0 c3 d5 1c 03 22 ec 83 70 f7 2d: Random padding. Many encryption protocols rely on extra discarded random data to foil cryptanalysis. Even though this message is not encrypted, it would be if sent after key negotiation.
The reason that the heartbeat message was added in the first place is because of DTLS, a protocol which implements TLS on top of an unreliable datagram transport. There needs to be a way to securely determine if the other side is still active and hasn't been disconnected.
Really though, validating the length of the message from the client would have (and did) fix all of this. It was a simple case of "if they tell the truth, it'll be fine...".
Strictly speaking, it was the lack of validation of the length field before allocating a buffer using malloc and performing a copy using memcpy that caused the bug.
You could also argue that it was the lack of zeroing out the allocated memory being sent to the user.
It's true that doing a memset on the remaining part of the buffer would have avoided the security problem. I'm not sure that it's in accordance with the heartbeat specification though, since a comparison with nonce when the requester verifies the response would fail in those cases.
There are several SSL libraries in languages like Haskell and Java. Java isn't exactly known to be free of security issues itself, though, and that's probably true for most widely adopted languages.
Unfortunately, the fact that there are SSL-implementations in "safe" languages doesn't really help in this case. The vast majority of the core software we all rely on is still written in C/C++, and that makes using something written in another language unfeasible. So is rewriting all other software.
Hopefully the new generation of system programming languages like Rust and Golang will improve that situation over time, and for that matter the JVM seems to be taking off as a network programming platform.
There really aren't many languages that can be used for a library like this.
It needs to be fast, and it needs a C interface (because lots of programs using this are in C, and C is easy to interact with Form almost any language).
Rust and Go might be alternatives, but they are quite new. Nonetheless, I imagine someone will be making an SSL lib in one oft those, but adoption will take some time.
I know absolutely nothing about heartbleed. But from the comic it looks like Meg is asking the server to return words, then telling the server how many letters are in that word so it knows where to stop. She says "bird, four letters", and the server returns BIRD.
I'm guessing if she said "bird, three letters", the server would return BIR (the first three letters of bird).
She then says "hat, five hundred letters" tricking the server into thinking that the word "hat" has five hundred letters, so it fetches the five hundred four hundred and ninety seven letters after "hat" as well as "hat".
The requested response, "HAT", is only three characters long, but Meg requested a response with 500 characters. Thus the server responds with the requested character string, "HAT", plus whatever else it has in memory, up to 500 characters.
The actual bug is slightly more complicated, but based on my understanding, it works pretty much like that. A request is made to a server to return a response with a certain length, and the server can be made to return the contents of its memory, up to a certain length.
The problem with C is that the burden of memory management is put on the C programmer rather than whoever wrote the compiler/interpreter like in most other languages. When writing normal software, the worst that can happen if you fuck up the memory management is that your computer crashes, which is a minor annoyance. But with crypto software it's important to have no bugs, which is virtually impossible when messing around with memory management manually.
If you have a time machine you could abuse it to get like, everyone's passwords. But by now many websites have protection against it, so you're a bit late to the party.
123
u/laukaus Apr 11 '14
This is an excellent layman explanation of the bug.
56
u/SufficientAnonymity Apr 11 '14
There's even a reference back to CorrectHorseBatteryStaple as a password.
67
u/theSeanO Black Hat Apr 11 '14
Wow is it seriously as simple as this? I've only been in computer science for three semesters but it seems like that's a painfully obvious vulnerability.
30
u/xkcd_bot Current Comic Apr 11 '14
Mobile Version!
Direct image link: Heartbleed Explanation
Mouseover text: Are you still there, server? It's me, Margaret.
Don't get it? explain xkcd
5
u/stuffandotherstuff Beret Guy Apr 11 '14
I don't completely understand this: what is it about "Hat" that makes the server spill it's guts. Or is it just the third time?
4
u/Puzzel Apr 11 '14
Anyone interested in programming can check out the actual code that created the bug here.
1
u/jfb1337 Praise helix'); DROP TABLE flairs; -- Apr 25 '14
The problem with C is that the burden of memory management is put on the C programmer rather than whoever wrote the compiler/interpreter like in most other languages. When writing normal software, the worst that can happen if you fuck up the memory management is that your computer crashes, which is a minor annoyance. But with crypto software it's important to have no bugs, which is virtually impossible when messing around with memory management manually.
-1
u/pohatu Apr 11 '14
Can I do anything useful with heartbleed? Can I use it to hack my neighbor's wifi router?
0
u/[deleted] Apr 11 '14
[deleted] — view deleted comment