{"id":21268,"date":"2020-08-27T18:03:09","date_gmt":"2020-08-27T17:03:09","guid":{"rendered":"https:\/\/www.kaspersky.co.uk\/blog\/black-hat-macos-macros-attack\/21268\/"},"modified":"2020-09-03T15:52:40","modified_gmt":"2020-09-03T14:52:40","slug":"black-hat-macos-macros-attack","status":"publish","type":"post","link":"https:\/\/www.kaspersky.co.uk\/blog\/black-hat-macos-macros-attack\/21268\/","title":{"rendered":"How to launch malicious macros unnoticed on macOS"},"content":{"rendered":"<p>Many macOS computer users are still confident that their machines do not need protection. Worse, system administrators at companies where employees work on Apple hardware often hold the same opinion.<\/p>\n<p>At the <a href=\"https:\/\/www.kaspersky.com\/blog\/tag\/black-hat\/\" target=\"_blank\" rel=\"noopener noreferrer nofollow\">Black Hat USA 2020<\/a> conference, researcher Patrick Wardle tried to disabuse the audience of this misconception by presenting his analysis of malware for macOS and building an exploit chain to take control of an Apple computer.<\/p>\n<h2>Microsoft, macros, and Macs<\/h2>\n<p>One of the most common ways of attacking computers running macOS is through documents with malicious macros \u2014 that is, through Microsoft Office applications. Indeed, despite the availability of Apple\u2019s own productivity apps, many users prefer to use Microsoft Office. Some do so out of habit; others for the sake of compatibility with the documents their colleagues create.<\/p>\n<p>Of course, everyone has long known about the potential threat posed by documents containing macros. Therefore, both Microsoft and Apple have mechanisms to protect the user.<\/p>\n<p>Microsoft alerts users when they open a document that contains a macro. In addition, if the user decides to launch the macro anyway, then the code is executed in a sandbox, which, according to Microsoft\u2019s developers, prevents the code from accessing the user\u2019s files or causing other damage to the system.<\/p>\n<p>For Apple\u2019s part, the company introduced several new security features in the latest version of its operating system, macOS Catalina. In particular, these include file quarantine and \u201cnotarization,\u201d which is a technology that prevents the launch of executables from external sources.<\/p>\n<p>Basically, these technologies, combined, should be sufficient to prevent any harm from malicious macros. In theory, everything seems quite secure. <\/p>\n<input type=\"hidden\" class=\"category_for_banner\" value=\"ksc-trial-generic\">\n<h2>An exploit chain gets the macro out of the sandbox<\/h2>\n<p>In practice, however, many security mechanisms are implemented rather problematically. Therefore, researchers (or attackers) can potentially find methods to bypass them. Wardle illustrated his presentation by demonstrating a chain of exploits.<\/p>\n<h3>1. Bypassing the mechanism that disables macros<\/h3>\n<p>Take, for example, the system that warns the user when it detects a macro in a document. In most cases, it works as the developers intended. But at the same time, it is possible to create a document in which the macro launches automatically and without any user notification, even if macros have been disabled in the settings.<\/p>\n<p>This can be done using the <a href=\"https:\/\/en.wikipedia.org\/wiki\/SYmbolic_LinK_(SYLK)\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Sylk <\/a>(SLK) file format. The format, which uses the XLM macro language, was developed in the 1980s and was last updated in 1986. However, Microsoft applications (e.g., Excel) still support Sylk for reasons of backward compatibility. This vulnerability is not new, and it was <a href=\"https:\/\/outflank.nl\/blog\/2019\/10\/30\/abusing-the-sylk-file-format\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">described in detail in 2019<\/a>.<\/p>\n<h3>2. Escaping from the sandbox<\/h3>\n<p>As we have now established, an attacker can run a macro invisibly. But the code is still executed within MS Office\u2019s isolated sandbox. How can a hacker attack the computer anyway? Well, it turns out it\u2019s not very hard to escape Microsoft\u2019s sandbox on a Mac.<\/p>\n<p>It\u2019s true you cannot modify files already stored on your computer from within the sandbox. You can, however, <em>create<\/em> them. This exploit has already been used to escape the sandbox before, and it seems Microsoft released an update to close the vulnerability. However, the problem was not really solved, as a more detailed examination of the patch has shown: The fix addressed the symptoms, blocking file creation from within places that some of the developers considered insecure, such as in the LaunchAgents folder, which is the storage location for scripts that are automatically launched after a reboot.<\/p>\n<p>But who decided that Microsoft accounted for every \u201cdangerous location\u201d when creating the patch? As it happened, a script written in Python and launched from an Office document \u2014 and therefore executed inside a sandbox \u2014 could be used to create an object called \u201cLogin Item.\u201d An object with that name launches automatically when the user logs in to the system. The system launches the object, so it will be executed <em>outside<\/em> the Office sandbox and thus bypass Microsoft\u2019s security restrictions.<\/p>\n<h3>3. Bypassing Apple\u2019s security mechanisms<\/h3>\n<p>So, now we know how to secretly run a macro and create a Login Item object. Of course, the security mechanisms in macOS still prevent the backdoor, which having been created by a suspicious process from inside the sandbox is untrusted, from being launched \u2014 right?<\/p>\n<p>On the one hand, yes: Apple\u2019s security mechanisms indeed block the execution of code obtained in such a way. On the other hand, there is a workaround: If you slip in a ZIP archive as a Login Item, then at the next login the system will automatically unzip the file.<\/p>\n<p>All that remains for the attacker to do is choose the right location to unzip the file. For example, the archive can be placed in the same directory as user libraries, one step above the one where Launch Agent\u2013type objects are supposed to be stored (the ones Microsoft correctly considers dangerous). The archive itself can include a directory called LaunchAgents, containing the Launch Agent script.<\/p>\n<p>Once unzipped, the script is placed in the LaunchAgents folder to execute on reboot. Having been created by a trusted program (the Archiver) and not having quarantine attributes, it can be used to launch something more dangerous. Security mechanisms will not even prevent this file from launching.<\/p>\n<p>As a result, an attacker can launch a mechanism through the Bash command shell to obtain remote access (thereby obtaining a so-called reverse shell). This Bash process can be used to download files, which will also lack the quarantine attribute, letting the attacker download truly malicious code and execute it without any restrictions.<\/p>\n<h2>In summary:<\/h2>\n<ul>\n<li>An attacker can secretly launch a malicious macro without displaying any warnings or asking the user any questions, even if macro execution is disabled in the settings. All the attacker needs is for a user to download an Office document and open it.<\/li>\n<li>Next, the attacker can escape the Microsoft Office sandbox and create a Login Item object and an archive with the Launch Agent inside that executes automatically outside the sandbox at the next login.<\/li>\n<li>With just a few steps, the attacker can easily bypass Apple\u2019s security mechanisms by extracting a Launch Agent\u2013type object from a ZIP archive. Having thus evaded the system\u2019s security mechanisms, the program can then download and run the \u201ccombat\u201d part of the malicious code.<\/li>\n<\/ul>\n<h2>How you can protect yourself against malicious macros on macOS<\/h2>\n<p>Of course, the researcher reported his findings to both Apple and Microsoft, and both companies quietly made corrections without advertising them or even assigning official CVE identifiers to the vulnerabilities. But the situation suggests that with careful study of security mechanisms, it is quite possible to find methods to bypass them.<\/p>\n<p>In the past, macOS was more rightly considered secure, but that was less about having particularly advanced security mechanisms than a result of attackers by and large ignoring it. However, Apple computers have become much more popular, including in the corporate environment, and therefore attacks that target macOS are becoming much more interesting to cybercriminals.<\/p>\n<p>So, to stay secure, you need not only to keep your system and all of the software on it up to date, but also to use security solutions that can detect and counteract suspicious activity. For example, our line of security products, both for <a href=\"https:\/\/www.kaspersky.co.uk\/premium?icid=gb_bb2022-kdplacehd_acq_ona_smm__onl_b2c_kdaily_lnk_sm-team___kprem___\" target=\"_blank\" rel=\"noopener\">home users<\/a> and for <a href=\"https:\/\/www.kaspersky.co.uk\/small-to-medium-business-security?icid=gb_kdailyplacehold_acq_ona_smm__onl_b2b_kasperskydaily_wpplaceholder_______\" target=\"_blank\" rel=\"noopener\">corporate clients<\/a>, includes versions for macOS.<\/p>\n<input type=\"hidden\" class=\"category_for_banner\" value=\"kesb-top3\">\n","protected":false},"excerpt":{"rendered":"<p>Researcher Patrick Wardle has demonstrated how a chain of exploits can be successfully used to attack macOS Catalina.<\/p>\n","protected":false},"author":700,"featured_media":21269,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1836,2360,2361,2026],"tags":[111,746,3009,527,2204,529],"class_list":{"0":"post-21268","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-business","8":"category-enterprise","9":"category-smb","10":"category-threats","11":"tag-attacks","12":"tag-black-hat","13":"tag-black-hat-2020","14":"tag-macos","15":"tag-sandbox","16":"tag-threats"},"hreflang":[{"hreflang":"en-gb","url":"https:\/\/www.kaspersky.co.uk\/blog\/black-hat-macos-macros-attack\/21268\/"},{"hreflang":"en-in","url":"https:\/\/www.kaspersky.co.in\/blog\/black-hat-macos-macros-attack\/21731\/"},{"hreflang":"en-ae","url":"https:\/\/me-en.kaspersky.com\/blog\/black-hat-macos-macros-attack\/17195\/"},{"hreflang":"ar","url":"https:\/\/me.kaspersky.com\/blog\/black-hat-macos-macros-attack\/8539\/"},{"hreflang":"en-us","url":"https:\/\/usa.kaspersky.com\/blog\/black-hat-macos-macros-attack\/23076\/"},{"hreflang":"es-mx","url":"https:\/\/latam.kaspersky.com\/blog\/black-hat-macos-macros-attack\/19996\/"},{"hreflang":"es","url":"https:\/\/www.kaspersky.es\/blog\/black-hat-macos-macros-attack\/23733\/"},{"hreflang":"it","url":"https:\/\/www.kaspersky.it\/blog\/black-hat-macos-macros-attack\/22675\/"},{"hreflang":"ru","url":"https:\/\/www.kaspersky.ru\/blog\/black-hat-macos-macros-attack\/28979\/"},{"hreflang":"tr","url":"https:\/\/www.kaspersky.com.tr\/blog\/black-hat-macos-macros-attack\/8738\/"},{"hreflang":"x-default","url":"https:\/\/www.kaspersky.com\/blog\/black-hat-macos-macros-attack\/36855\/"},{"hreflang":"fr","url":"https:\/\/www.kaspersky.fr\/blog\/black-hat-macos-macros-attack\/15556\/"},{"hreflang":"pt-br","url":"https:\/\/www.kaspersky.com.br\/blog\/black-hat-macos-macros-attack\/15976\/"},{"hreflang":"pl","url":"https:\/\/plblog.kaspersky.com\/black-hat-macos-macros-attack\/13915\/"},{"hreflang":"de","url":"https:\/\/www.kaspersky.de\/blog\/black-hat-macos-macros-attack\/25054\/"},{"hreflang":"zh","url":"https:\/\/www.kaspersky.com.cn\/blog\/black-hat-macos-macros-attack\/11929\/"},{"hreflang":"ja","url":"https:\/\/blog.kaspersky.co.jp\/black-hat-macos-macros-attack\/29103\/"},{"hreflang":"nl","url":"https:\/\/www.kaspersky.nl\/blog\/black-hat-macos-macros-attack\/26003\/"},{"hreflang":"ru-kz","url":"https:\/\/blog.kaspersky.kz\/black-hat-macos-macros-attack\/22785\/"},{"hreflang":"en-au","url":"https:\/\/www.kaspersky.com.au\/blog\/black-hat-macos-macros-attack\/28022\/"},{"hreflang":"en-za","url":"https:\/\/www.kaspersky.co.za\/blog\/black-hat-macos-macros-attack\/27852\/"}],"acf":[],"banners":"","maintag":{"url":"https:\/\/www.kaspersky.co.uk\/blog\/tag\/black-hat\/","name":"black hat"},"_links":{"self":[{"href":"https:\/\/www.kaspersky.co.uk\/blog\/wp-json\/wp\/v2\/posts\/21268","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kaspersky.co.uk\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kaspersky.co.uk\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kaspersky.co.uk\/blog\/wp-json\/wp\/v2\/users\/700"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kaspersky.co.uk\/blog\/wp-json\/wp\/v2\/comments?post=21268"}],"version-history":[{"count":1,"href":"https:\/\/www.kaspersky.co.uk\/blog\/wp-json\/wp\/v2\/posts\/21268\/revisions"}],"predecessor-version":[{"id":21420,"href":"https:\/\/www.kaspersky.co.uk\/blog\/wp-json\/wp\/v2\/posts\/21268\/revisions\/21420"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.kaspersky.co.uk\/blog\/wp-json\/wp\/v2\/media\/21269"}],"wp:attachment":[{"href":"https:\/\/www.kaspersky.co.uk\/blog\/wp-json\/wp\/v2\/media?parent=21268"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kaspersky.co.uk\/blog\/wp-json\/wp\/v2\/categories?post=21268"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kaspersky.co.uk\/blog\/wp-json\/wp\/v2\/tags?post=21268"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}