Operation Aurora
The news was alive in January 2010 with talk of how Google was thinking of a new approach to China, possibly including to withdraw its business, after what was said to be a “highly sophisticated and targeted attack on our corporate infrastructure originating from China” in December 2009. Early technical analysis, including to publish that the attack exploits a vulnerability in Internet Explorer that had been unknown to the security industry, seems to have been in the hands of MacAfee, whose page Operation Aurora Hit Google, Others christens the attack and has George Kurtz effusing that “the world has changed” and that “everyone’s threat model now needs to be adapted to the new reality of these advanced persistent threats”.
Statements like that easily get my attention since I have been saying for years that reverse engineering of malware as practised by the computer security industry is primitive and seems likely to stay that way since the industry has little or no incentive to invest in improvement. The industry must eventually face malware whose complexity, if not sophistication, exceeds the industry’s capacity for analysis. Though I certainly don’t want malware to get better at what it does, that it will get better is just inevitable, and I can’t help but await the industry’s game-changing moment when it realises that reverse engineering is not a hobby, or even an occasional tool, but is more like a performance art that requires years of dedicated practice (which few would ever think to commit to without support).
For a reverse engineer from outside the industry, the first difficulty in studying an attack is with getting the code that was used for the attack. This was made public, sort of, a few days after the initial reports. Although several pages on the Internet talked of relevant code having “been published on the Internet”, Attack Code Used to Hack Google Now Public is the first I know that said where. It provided a URL at the Wepawet malware analysis website. The code given there is not syntactically valid and has a space that’s in the wrong place. Though these minor errors were presumably introduced while formatting the code for presentation, there is the additional problem that no provenance is given: it could be any code from anywhere for any purpose.
Still, the working assumption must be that people at the targeted companies were invited to visit a web page whose HTML is very similar to what’s posted at the Wepawet site. The script in this HTML triggers a bug in Internet Explorer after arranging an increased probability that Internet Explorer does not crash in response to the bug but is instead induced to execute the attacker’s bootstrap code (which is also in the script). This in turn downloads an executable file from a preset website and then runs that executable.
Mitigations
Some few practical points ought be noted at the outset. First, although the bug is present in very nearly a decade’s worth of Internet Explorer versions, and can crash all these versions, the reported attack hardly ever gets as far as trying to execute the attacker’s code if the Internet Explorer version is 7.0 or higher. Variations of the attack might, of course.
Since the bootstrap code is provided as script, it is handled by Internet Explorer only as data. If Data Execution Prevention (DEP) is enabled, then if the attack does succeed at subverting the bug so that Internet Explorer does not crash, DEP will crash Internet Explorer for you rather than let it unwittingly execute data. DEP requires at least Windows XP SP2 or Windows Server 2003 SP1 (if we don’t count undocumented AMD-specific support in the original Windows Server 2003). Really, you should have DEP enabled, always. Any software that is incompatible with DEP is better replaced or discarded.
Sadly, such software does exist, even from Microsoft. One example is the Document Explorer program that accompanies the Microsoft Developer Network (MSDN) Library on disc. Version 7, as supplied with editions from 2003 and 2004, fails to start if DEP is enabled. Fortunately for those who are curious to know what Microsoft wrote about DEP ahead of releasing Windows XP SP2, this old documentation is readable using version 8.
If you disable Active Scripting, then Internet Explorer will never interpret any script. As used in the attack, the bug cannot then cause Internet Explorer to crash, let alone to be exploited. You are entirely safe from the attack. Against that, your experience of browsing the web will be very much poorer. Although disabling scripts protects you from this and other security problems, it cannot sensibly be recommended as standard practice for everyday web browsing by everyday users. Many websites will present you with an error message directing you to enable scripting. Some will just present you with a blank page. Many more will misbehave in various ways because they don’t so much require scripting for additional functionality as assume it for basic functionality. An example is Microsoft’s MSDN site, which presents its programming documentation without a scrollbar so that you can’t read the whole text unless you enable scripting. Indeed, the widespread practice of writing web pages that take scripting for granted is largely Microsoft’s responsibility: Microsoft evidently writes its websites without much thought for the security-conscious, and it’s no surprise that numerous other websites follow Microsoft’s lead.
Anything that can be done in script can be done by executable code delivered to Internet Explorer as an ActiveX control. Although this attack uses script, other attacks that exploit the same bug may use ActiveX controls. Of course, if you’re security conscious, you will have disabled ActiveX controls long before wondering whether Active Scripting is something to disable too. You will also have noticed that many websites expect you to run ActiveX controls, if not actually to download them, and that most of these websites degrade significantly if you decline to let them execute their choice of code on your computer.
Finally, Internet Explorer the web browser is not just an application program. The essential DLLs of Internet Explorer act as operating-system components that provide HTML functionality to a wide variety of other applications. Since the bug is in one of those DLLs, it can also crash these other programs or induce them to run an attacker’s code on your computer. Unfortunately, the list of such programs is open-ended since the hosting and reuse of Internet Explorer components has long been documented by Microsoft as a significant programming feature. The good news is that most such programs don’t take as input an arbitrary HTML page received over the Internet. The ones that do typically don’t run scripts or ActiveX controls, but you may do well to check.
One such program hides in plain sight on every Windows machine. It is Microsoft’s HTML Help tool, HH.EXE, which displays CHM files. Though HH is not a web browser, it will open an arbitrary HTML or CHM file, using MSHTML for rendering, and will run JavaScript from that file. An HTML file with script could be compiled into a CHM file and sent in email as an attachment. Opening the attachment will run Internet Explorer by proxy. A special danger with this line of attack is that the users who are most exposed are those who prefer other browsers, e.g., because they think Internet Explorer is insufficiently secure. With no direct reason to update the Internet Explorer that they don’t want (and whose presence they may even resent), they are the most likely to have an old version whose known security vulnerabilities have not been fixed. Fortunately, CHM files are regarded as unsafe attachments and are blocked by most email readers.
Investigation
Some forensic points may better be noted, too. This article is concerned only with what can be known about the bug and its exploitation from the publicly disclosed script and from inspection of Internet Explorer. Where reports describe this attack as a sophisticated operation, they must be talking about things that happen before or after the attack. By before, I mean the planning of who to target and how to entice them to a web page that would run the script that launches the attack. No amount of inspecting code can help with that, and it is conspicuous that very little information of any sort is in the public domain to support any talk of how the attack was targeted. By after, I mean whatever is done by the downloaded executable, which could be any Trojan and can have been developed independently of the attack. I have no copy of the Trojan for inspection. By the time I looked at the preset URL to get the Trojan, there was no file there to download and the root of the website was just the default page of a newly installed IIS7 website.
I could, of course, get whatever Trojan has been seen in the attacks. Copies are surely in circulation. What puzzles me, though, and what I want to concentrate on, is how the attacks ever got as far as downloading a Trojan. How was the attack delivered to its victims, what is the Internet Explorer bug that allowed the attack to work, and how did this bug get exploited? On these questions, curiously little detail has been made public.
The Internet Explorer Bug
Even finding out which bug allows the attack is difficult enough. Nobody would be able to locate the bug just from what Microsoft writes about it. The Microsoft Security Advisory (979352): Vulnerability in Internet Explorer Could Allow Remote Code Execution seems to be a natural starting point for what Microsoft wants to say. Amidst large tracts of boilerplate text that apply generally to defending against an attack through this sort of bug, the page has only one sentence that describes this bug specifically:
The vulnerability exists as an invalid pointer reference within Internet Explorer.
Of course, the page is up-front about presenting only General Information, and indeed only an Executive Summary, but it’s not as if there’s any mention of another page where Microsoft gives detailed information. A little more is offered in a Microsoft blog Security Research & Defense: Assessing risk of IE 0day vulnerability:
The vulnerability is an Internet Explorer memory corruption issue triggered by an attacker using JavaScript to copy, release, and then later reference a specific Document Object Model (DOM) element.
Fortunately for any notion of independent evaluation, someone has published HTML code that was supposedly seen in real-world exploitation of this same vulnerability. The code can be read by anyone who’s interested and most who do read it will surely get at least an inkling of what’s going on, particularly that the “specific DOM element” must be the event object.
Strictly speaking, the event object is an IHTMLEventObj4 interface implemented by MSHTML.DLL in a tear-off thunk for an instantiation of the CEventObj class. Though the CEventObj in effect is the event object, it does not hold the event properties directly. These are in an EVENTPARAM structure. Most events have a source element, accessible as the srcElement property. However the srcElement is not stored directly in the EVENTPARAM as a pointer to the element’s representation as a CElement class. Instead, the EVENTPARAM has a pointer to the element’s node in the DOM tree. This is also true, incidentally, for the fromElement and toElement properties, though these are meaningful only for a couple of event types. Each tree node has a pointer to its element and vice versa. The tree nodes themselves seem intended as internal to MSHTML. The CTreeNode class is not a COM class. Indeed, it has no virtual member functions of any sort. It does have ordinary member functions that give it the appearance of its element and which perform reference counting even though the class does not hold its own reference count. It is this last point that gives us the present bug.
There can be no doubt that if CTreeNode were a COM class, then any programmer given charge of MSHTML would always be on the lookout for the possibility that a tree node’s AddRef method needs to be called before a pointer to that tree node can safely be set into any structure whose lifetime is not certainly contained in the lifetime of the node. Instead, although the CTreeNode class does have a NodeAddRef member function, and does get it used, pointers to tree nodes are often passed around without adding a reference. It may be that this was once-upon-a-time well supported by some close understanding of the relevant objects’ lifetimes, but it nowadays looks in need of a rethink.
Certainly, there is a problem when an EVENTPARAM is copied, as can be done in either of this structure’s constructors. The input EVENTPARAM may already have non-NULL pointers to nodes for the srcElement, fromElement and toElement. The new EVENTPARAM receives copies of these pointers to the nodes but without any adding of references. The nodes and their elements then know nothing of these copies. This is a problem if the new EVENTPARAM outlives the original. When the original EVENTPARAM is no longer needed once the event it was created for has been handled, if the node is no longer wanted in the tree, then the node will be freed even though the second EVENTPARAM still has a pointer to it.
That is the essence of the reported bug. It dates from MSHTML version 5.50. This is the first version to have EVENTPARAM constructors that can copy another EVENTPARAM. It is also the first to provide, via the document object’s createEventObject method, a means of getting an EVENTPARAM copied just by using script in a way that the copy can be made to outlive the original.
Demonstration
If we aim to trigger the bug entirely in script, then the following must be near to minimal. (It can be made a little smaller. Instead of creating a child element on which to fire an event, just fire the event on the body. However, removing the body from the DOM tree is artificial to the point that it might confuse about what exactly is necessary for the bug.) Just insert this script as the whole of a