{"id":20932,"date":"2023-01-05T09:01:53","date_gmt":"2023-01-05T17:01:53","guid":{"rendered":"https:\/\/www.palada.net\/index.php\/2023\/01\/05\/news-14665\/"},"modified":"2023-01-05T09:01:53","modified_gmt":"2023-01-05T17:01:53","slug":"news-14665","status":"publish","type":"post","link":"https:\/\/www.palada.net\/index.php\/2023\/01\/05\/news-14665\/","title":{"rendered":"Unraveling the techniques of Mac ransomware"},"content":{"rendered":"<p><strong>Credit to Author: Microsoft Security Threat Intelligence &#8211; Editor| Date: Thu, 05 Jan 2023 17:00:00 +0000<\/strong><\/p>\n<p>Ransomware continues to be one of the most prevalent and impactful threats affecting organizations, with attackers constantly evolving their techniques and expanding their tradecraft to cast a wider net of potential targets. This is evident in the range of industries, systems, and platforms affected by ransomware attacks. Understanding how ransomware works across these systems and platforms is critical in protecting today\u2019s hybrid device and work environments.<\/p>\n<p>This blog provides details from our analysis of known ransomware families affecting macOS devices. As in other platforms, the initial vector of Mac ransomware typically relies on user-assisted methods like downloading and running fake or trojanized applications. It can, however, also arrive as a second-stage payload dropped or downloaded by other malware or part of a supply chain attack. Once running on a device, ransomware attacks usually comprise gaining access, execution, encrypting target users\u2019 files, and notifying the target with a ransom message.<\/p>\n<p>To perform these actions, malware creators abuse legitimate functionalities and devise various techniques to exploit vulnerabilities, evade defenses, or coerce users to infect their devices. We describe these techniques in detail below, based on our analysis of four Mac ransomware families: KeRanger, FileCoder, MacRansom, and EvilQuest. In particular, we take a deeper look at EvilQuest and one of its variants that had its ransomware component removed but was further improved with additional techniques and anti-analysis logic.<\/p>\n<p>While these malware families are old, they exemplify the range of capabilities and malicious behavior possible on the platform. Building durable detections for these techniques will help improve defenses for devices and networks against ransomware and other threats. As with any security research in Microsoft, this in-depth analysis of malware techniques informs the protection we provide through solutions like Microsoft Defender for Endpoint on Mac. We\u2019re sharing this information with the rest of the community as a technical reference that researchers can use and build upon to understand Mac threats and improve protections.<\/p>\n<h2>File enumeration&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/h2>\n<p>Targeting which files to encrypt is the most important step for any ransomware. We have seen various ways through which ransomware families have <a href=\"https:\/\/attack.mitre.org\/techniques\/T1083\/\">enumerated<\/a> files and directories on Mac:<\/p>\n<h3>Using the <em>Find<\/em> binary<\/h3>\n<p>FileCoder and MacRansom use the <em>find<\/em> utility to search for files to encrypt. <em>find<\/em> is a common utility binary that is generally found across many Unix based systems like macOS, Linux, etc. and incorporates many features that could help attackers to search for and select files. The output of the command is then passed as an argument to the function or binary that carries out the encryption of the files.<\/p>\n<p>Figure 1 shows part of the command used by FileCoder. It searches the \u201c\/Users\u201d and \u201c\/Volumes\u201d directories by invoking the said command twice, with a change on the path being enumerated and excluding its README file while searching the \u201c\/Users\u201d path.<\/p>\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"71\" src=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig1-mac_ransomware_techniques-1024x71.png\" alt=\"Screenshot of FileCoder\u2019s enumeration logic.\" class=\"wp-image-125461\" srcset=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig1-mac_ransomware_techniques-1024x71.png 1024w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig1-mac_ransomware_techniques-300x21.png 300w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig1-mac_ransomware_techniques-768x53.png 768w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig1-mac_ransomware_techniques-1536x106.png 1536w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig1-mac_ransomware_techniques.png 1659w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Figure 1. FileCoder\u2019s enumeration logic<\/figcaption><\/figure>\n<p>In the case of MacRansom, it searches for files in \u201c\/Volumes\u201d and the current user\u2019s directory. It uses <em>-type f<\/em> to include regular files, <em>-size +8c<\/em> to select files that are greater than 8 bytes, <em>-user `whoami`<\/em> to select files that belong to the current user, and <em>-perm -u=r<\/em> to get files for which the current user has readable permission. The output of the command in Figure 2 is then passed to another instance of the malware.<\/p>\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"103\" src=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig2-mac_ransomware_techniques-1024x103.png\" alt=\"Screenshot of MacRansom\u2019s enumeration logic\" class=\"wp-image-125462\" srcset=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig2-mac_ransomware_techniques-1024x103.png 1024w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig2-mac_ransomware_techniques-300x30.png 300w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig2-mac_ransomware_techniques-768x77.png 768w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig2-mac_ransomware_techniques-1536x155.png 1536w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig2-mac_ransomware_techniques.png 1659w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Figure 2. MacRansom\u2019s enumeration logic<\/figcaption><\/figure>\n<h3>Using library functions opendir, readdir, and closedir<\/h3>\n<p>KeRanger and EvilQuest use library functions to get the directory listing. It uses a sequence of <em>opendir()<\/em>, <em>readdir()<\/em>, and <em>closedir()<\/em> to get the list of files.<\/p>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"502\" height=\"258\" src=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig3-mac_ransomware_techniques.png\" alt=\"Screenshot of EvilQuest's code showing library functions used to enumerate files.\" class=\"wp-image-125465\" srcset=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig3-mac_ransomware_techniques.png 502w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig3-mac_ransomware_techniques-300x154.png 300w\" sizes=\"auto, (max-width: 502px) 100vw, 502px\" \/><figcaption class=\"wp-element-caption\">Figure 3. Library functions used in EvilQuest<\/figcaption><\/figure>\n<p>First, it uses <em>opendir()<\/em> to open a directory by specifying the <em>dirname<\/em>. The handle returned from the <em>opendir() <\/em>function is used by the <em>readdir()<\/em> function to scan files. <em>readdir()<\/em> returns NULL if it reaches the end of the directory. It uses <em>closedir() <\/em>at the end to close the handle to the directory.<\/p>\n<h3>Using the NSFileManager class through Objective-C<\/h3>\n<p>There are open-source proofs-of-concept (POCs) and scripts where Objective-C functions are used to enumerate files. For example, the <a href=\"https:\/\/github.com\/gdbinit\/gopher\">Gopher POC<\/a> uses this technique to scan for .docx files in the User\u2019s Documents directory.<\/p>\n<p>In this technique, <em>NSDirectoryEnumerator<\/em> object is used to enumerate the directory\u2019s contents, while the path is specified in the <em>enumeratorAtPath:<\/em> method. The function returns the enumerator, which is used to get all the paths of files and directories.<\/p>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"1000\" height=\"558\" src=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig4-mac_ransomware_techniques.png\" alt=\"Screenshot of Gopher POC's code using the NSFileManager to enumerate files.\" class=\"wp-image-125466\" srcset=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig4-mac_ransomware_techniques.png 1000w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig4-mac_ransomware_techniques-300x167.png 300w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig4-mac_ransomware_techniques-768x429.png 768w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><figcaption class=\"wp-element-caption\">Figure 4. Gopher\u2019s use of NSFileManager<\/figcaption><\/figure>\n<p>This method is unique to the Gopher POC and is not found in the four ransomware families we analyzed.<\/p>\n<h2>Anti-analysis techniques<\/h2>\n<p>Malware creators deploy various anti-analysis techniques to evade or prevent the analysis of files by either analysts or automated analysis systems such as sandboxes. Among the Mac ransomware we studied, KeRanger, MacRansom, and EvilQuest employ hardware-based checks or use specific code apart from the usual obfuscation of strings to avoid analysis.<\/p>\n<h3>Hardware-based checks<\/h3>\n<h4>Checking a device\u2019s hardware model<\/h4>\n<p>This technique (<a href=\"https:\/\/attack.mitre.org\/techniques\/T1497\/001\/\">T1497.001<\/a>), used by MacRansom, involves getting the hardware model of the system and checking a substring to detect if the malware is running in a virtual environment. Running inside a virtual machine (VM) often indicates that the malware is being analyzed by analysts or in a sandbox.<\/p>\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"156\" src=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig5-mac_ransomware_techniques-1024x156.png\" alt=\"Screenshots of results of checking the hardware model of a MacBook Pro and a device that is running macOS on a virtual machine.\" class=\"wp-image-125478\" srcset=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig5-mac_ransomware_techniques-1024x156.png 1024w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig5-mac_ransomware_techniques-300x46.png 300w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig5-mac_ransomware_techniques-768x117.png 768w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig5-mac_ransomware_techniques-1536x234.png 1536w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig5-mac_ransomware_techniques-1600x244.png 1600w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig5-mac_ransomware_techniques.png 1605w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Figure 5. The command used by MacRansom (above) determines the environment it is running on. Below the command is the comparison of the results between checking the hardware model of a MacBook Pro (left) and a Mac OS running on Parallels VM (right)<\/figcaption><\/figure>\n<p>The result of the command on a host device contains the substring \u201cMac\u201d, whereas the result on a Parallels VM setup doesn\u2019t. The malware stops if it detects its presence in a virtual environment.<\/p>\n<h4>Checking the logical and physical processors of a device<\/h4>\n<p>MacRansom uses this technique (T1497.001) to check the count of the logical and physical CPU of the device.<\/p>\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"166\" src=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig6-mac_ransomware_techniques-1024x166.png\" alt=\"Screenshots of results of the number of logical and physical CPUs in a MacBook Pro and in a macOS hosted on a Parallels virtual machine.\" class=\"wp-image-125479\" srcset=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig6-mac_ransomware_techniques-1024x166.png 1024w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig6-mac_ransomware_techniques-300x49.png 300w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig6-mac_ransomware_techniques-768x124.png 768w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig6-mac_ransomware_techniques-1536x249.png 1536w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig6-mac_ransomware_techniques-1600x260.png 1600w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig6-mac_ransomware_techniques.png 1605w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Figure 6. The command used by MacRansom\u2019s &nbsp;(above) counts logical and physical CPUs present in the device. Below that is the logical and physical processors check comparison between a MacBook Pro (left) and a Mac OS running on Parallels VM (right)<\/figcaption><\/figure>\n<p>In this case, a host device\u2019s logical CPU count is usually twice the physical CPU count, whereas the values are the same for a VM instance. The command above divides the values of these two counts and compares them with 2. It makes the comparison to determine if the malware is running in a virtual instance or not.<\/p>\n<h4>Checking the MAC OUI of the device<\/h4>\n<p>This technique (<a href=\"https:\/\/attack.mitre.org\/techniques\/T1497\/001\/\">T1497.001<\/a>), used by EvilQuest variants, involves checking the MAC organizational unique identifier (OUI) prefix, which comprises the first 24 bits of a MAC address, to determine the device vendor. Checking the OUI is another technique to determine if the malware is running in a virtual environment.<\/p>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"700\" height=\"293\" src=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig7-mac_ransomware_techniques.png\" alt=\"Screenshot of EvilQuest code checking the MAC OUI prefix of a device.\" class=\"wp-image-125480\" srcset=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig7-mac_ransomware_techniques.png 700w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig7-mac_ransomware_techniques-300x126.png 300w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><figcaption class=\"wp-element-caption\">Figure 7. EvilQuest code that checks the MAC OUI prefix<\/figcaption><\/figure>\n<p>Figure 7 shows the EvilQuest code that gets the MAC address of the <strong><em>en0<\/em> <\/strong>network interface, and compares the first three bytes with the OUI values hardcoded in EvilQuest. The values (v8, v7, and v6 in Figure 7) are attributed to many known virtualization platforms such as Parallels, VirtualBox, and VMware.<\/p>\n<h4>Checking the device\u2019s CPU count and memory size<\/h4>\n<p>Analysis environments, specifically automated ones, are often deployed with minimal CPU and memory. EvilQuest checks the device\u2019s CPU and memory size (T1497.001) to ensure it\u2019s not running in a virtual environment.<\/p>\n<p>The malware uses three different methods to check the number of CPUs. The first method uses the <em>sysctl<\/em> function by passing the MIB (Management Information Base) structure containing <em>CTL_HW<\/em> and <em>HW_AVAILCPU <\/em>identifiers. If this first method fails, the malware uses the second method where it replaces HW_AVAILCPU with <em>HW_NCPU. <\/em>If the second method also fails, it uses the command \u201c<em>sysctl -n hw.ncpu\u201d<\/em> as a third method to get the CPU count. EvilQuest further checks if the value of the CPU count is less than 2, which might indicate a virtual instance deployed with minimal hardware.<\/p>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"500\" height=\"271\" src=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig8-mac_ransomware_techniques.png\" alt=\"Screenshot of EvilQuest's code checking for CPU count on a device.\" class=\"wp-image-125481\" srcset=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig8-mac_ransomware_techniques.png 500w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig8-mac_ransomware_techniques-300x163.png 300w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><figcaption class=\"wp-element-caption\">Figure 8. EvilQuest code that checks for CPU count<\/figcaption><\/figure>\n<p>EvilQuest also checks the device\u2019s physical memory size to avoid analysis environments. It uses <em>sysctl function<\/em> with the MIB structure<em> CTL_HW<\/em> and <em>HW_MEMSIZE <\/em>constants to check the physical RAM size. The result is then compared further with the size of 1GB, which might indicate a virtual instance.<\/p>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"600\" height=\"311\" src=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig9-mac_ransomware_techniques.png\" alt=\"Screenshot of EvilQuest's code checking a device's physical memory size.\" class=\"wp-image-125482\" srcset=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig9-mac_ransomware_techniques.png 600w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig9-mac_ransomware_techniques-300x156.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><figcaption class=\"wp-element-caption\">Figure 9. EvilQuest code to check the device\u2019s physical memory size<\/figcaption><\/figure>\n<h3>Code-related checks<\/h3>\n<h4>Delayed execution<\/h4>\n<p>Malware creators often use the delayed execution (<a href=\"https:\/\/attack.mitre.org\/techniques\/T1497\/003\/\">T1497.003<\/a>) technique to prevent automated analysis systems from detecting the malware\u2019s actual behavior. KeRanger uses this delayed execution technique where, upon launching, it sleeps for three days before performing its malicious routines.<\/p>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"499\" height=\"200\" src=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig10-mac_ransomware_techniques.png\" alt=\"Screenshot of KeRanger's code used in delaying its execution.\" class=\"wp-image-125483\" srcset=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig10-mac_ransomware_techniques.png 499w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig10-mac_ransomware_techniques-300x120.png 300w\" sizes=\"auto, (max-width: 499px) 100vw, 499px\" \/><figcaption class=\"wp-element-caption\">Figure 10. KeRanger code used to delay its execution<\/figcaption><\/figure>\n<h4>PT_DENY_ATTACH (PTRACE)<\/h4>\n<p>This technique (<a href=\"https:\/\/attack.mitre.org\/techniques\/T1622\/\">T1622<\/a>), used by both EvilQuest and MacRansom, is a known anti-debugging trick that prevents debuggers from attaching to the current malware process. It is used to avoid the debugging of malware files.<\/p>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"696\" height=\"84\" src=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig11-mac_ransomware_techniques.png\" alt=\"Screenshot of MacRansom's code that invokes the PT_DENY_ATTACH argument.\" class=\"wp-image-125484\" srcset=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig11-mac_ransomware_techniques.png 696w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig11-mac_ransomware_techniques-300x36.png 300w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig11-mac_ransomware_techniques-687x84.png 687w\" sizes=\"auto, (max-width: 696px) 100vw, 696px\" \/><figcaption class=\"wp-element-caption\">Figure 11. &nbsp;Code in MacRansom where it invokes ptrace with PT_DENY_ATTACH argument<\/figcaption><\/figure>\n<p>As seen in MacRansom\u2019s code (Figure 11), it first opens the handle to itself, where the <em>ptrace<\/em> symbol is searched, and the address is retrieved. It is then called with the argument <em>0x1F<\/em>, a constant for <em>PT_DENY_ATTACH<\/em>.<\/p>\n<p>EvilQuest implements the same technique in two ways. One method is a simple call to the <em>ptrace<\/em> function with the argument <em>0x1F<\/em> as above. In another variant, the logic is implemented using <em>syscall<\/em>. This method invokes <em>ptrace<\/em> through <em>syscall <\/em>with the <em>PT_DENY_ATTACH<\/em> flag.<\/p>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"700\" height=\"341\" src=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig12-mac_ransomware_techniques.png\" alt=\"Screenshot of EvilQuest's code where it uses syscall.\" class=\"wp-image-125513\" srcset=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig12-mac_ransomware_techniques.png 700w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig12-mac_ransomware_techniques-300x146.png 300w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><figcaption class=\"wp-element-caption\">Figure 12. Code in an EvilQuest variant where it uses Syscall(ptrace) to avoid debuggers &nbsp;<\/figcaption><\/figure>\n<p>Additionally, the EvilQuest variant also verifies if the PT_DENY_ATTACH operation is successful. To do so, it first registers a handler for the signal <em>SIGSEGV<\/em> and calls the <em>ptrace<\/em> method again with the argument <em>PT_ATTACH<\/em><strong>. <\/strong>This <em>ptrace()<\/em> call with <em>PT_ATTACH<\/em> flag throws a<em> SIGSEGV<\/em> signal if it fails to attach to the process, which further invokes the handler. The handler sets a variable that is checked next to determine the success of <em>PT_DENY_ATTACH<\/em> operation.<\/p>\n<h4>P_TRACED flag<\/h4>\n<p>EvilQuest uses this technique (<a href=\"https:\/\/attack.mitre.org\/techniques\/T1622\/\">T1622<\/a>) to check whether it is being debugged. The technique is used to get the process structure and check for the <em>P_TRACED<\/em> flag. If the flag is found to be set, it indicates that the process is being debugged. The malware then alters its behavior to avoid analysis.<\/p>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"600\" height=\"382\" src=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig13-mac_ransomware_techniques-1.png\" alt=\"Screenshot of EvilQuest's code checking for the P_TRACED flag.\" class=\"wp-image-125514\" srcset=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig13-mac_ransomware_techniques-1.png 600w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig13-mac_ransomware_techniques-1-300x191.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><figcaption class=\"wp-element-caption\">Figure 13. Code in an EvilQuest variant where it checks for the P_TRACED flag<\/figcaption><\/figure>\n<h4>Time-based check<\/h4>\n<p>Malware using this technique (T1497.003) checks if it is running in a sandbox by checking if the device\u2019s <em>sleep<\/em> function is patched. Sandboxes attempt to patch the <em>sleep <\/em>function to avoid execution delay, which is used by some malware. Ransomware like EvilQuest sleeps for a specified time between two <em>time()<\/em> calls. Next, the difference in the timestamp is calculated and checked with the duration specified in <em>sleep()<\/em> call.<\/p>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"500\" height=\"165\" src=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig14-mac_ransomware_techniques.png\" alt=\"Screenshot of EvilQuest's code where it checks the sleep patching function.\" class=\"wp-image-125487\" srcset=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig14-mac_ransomware_techniques.png 500w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig14-mac_ransomware_techniques-300x99.png 300w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><figcaption class=\"wp-element-caption\">Figure 14. EvilQuest code that checks patching of sleep function<\/figcaption><\/figure>\n<h2>Persistence<\/h2>\n<p>Malware commonly uses persistence to ensure it runs even after a system restart. Among the Mac ransomware families analyzed, we\u2019ve seen persistence techniques in EvilQuest and MacRansom. The following are persistence techniques implemented by these malware families.<\/p>\n<h3>Creating launch agents or launch daemons<\/h3>\n<p>Creating Launch Agents (<a href=\"https:\/\/attack.mitre.org\/techniques\/T1543\/001\/\">T1543.001<\/a>) or Launch Daemons (<a href=\"https:\/\/attack.mitre.org\/techniques\/T1543\/004\/\">T1543.004<\/a>) is a persistence method that uses launch items. This technique utilizes a property list (PLIST) file, which is used in macOS to specify configurations and properties in respective directories to gain persistence. EvilQuest can create both Launch Agent and Launch Daemon files, while MacRansom typically creates a Launch Agent file.&nbsp;<\/p>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"900\" height=\"323\" src=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig15-mac_ransomware_techniques.png\" alt=\"Screenshot of EvilQuest's launch daemon PLIST file.\" class=\"wp-image-125488\" srcset=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig15-mac_ransomware_techniques.png 900w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig15-mac_ransomware_techniques-300x108.png 300w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig15-mac_ransomware_techniques-768x276.png 768w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><figcaption class=\"wp-element-caption\">Figure 15. EvilQuest\u2019s launch daemon PLIST file<\/figcaption><\/figure>\n<p>The <em>ProgramArguments<\/em> key in the PLIST file (Figure 15) specifies the process to run with arguments if any, and <em>RunAtLoad<\/em> and <em>KeepAlive<\/em> keys are used to ensure that the process is continuously running.<\/p>\n<h3>Using kernel queues<\/h3>\n<p>The kernel queue (<em>kqueue<\/em>) provides a way for an application to get notifications based on various conditions and events. In the case of EvilQuest, it uses this method to restore itself based on notification it receives in case any modifications are made to the list of files it wants to monitor. Different EvilQuest variants use different versions of this implementation.<\/p>\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig16-mac_ransomware_techniques.png\" alt=\"Screenshot of EvilQuest's file monitoring initialization and file restoring codes.\" class=\"wp-image-125491\" width=\"934\" height=\"308\" srcset=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig16-mac_ransomware_techniques.png 934w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig16-mac_ransomware_techniques-300x99.png 300w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig16-mac_ransomware_techniques-768x253.png 768w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig16-mac_ransomware_techniques-930x308.png 930w\" sizes=\"auto, (max-width: 934px) 100vw, 934px\" \/><figcaption class=\"wp-element-caption\">Figure 16. EvilQuest variant\u2019s codes used to initialize file monitoring (left) and to restore files after modification (right) &nbsp;<\/figcaption><\/figure>\n<p>It first creates the kernel event (<em>kevent<\/em>) queue using the <em>kqueue()<\/em> system call. Next, it forms a structure for each file containing its file handle and the required filters and flags to register the files to monitor. The pointer to this array of structures is passed in the <em>changelist<\/em> argument to the <em>kevent()<\/em> call. The <em>eventlist<\/em> parameter then stores any changes observed. The malware invokes the <em>kevent()<\/em> call in a loop. If any modifications are made to the files being monitored, EvilQuest tries to restore them.<\/p>\n<h2>Encryption<\/h2>\n<p>The ransomware families we analyzed often share similar anti-analysis and persistence techniques. However, these same ransomware families differ in encryption logic. Some use AES-RSA encryptions, while others use system utilities, XOR routine, or custom encryption logic to encrypt files. These encryption methods range from in-place modification to creating a new file while deleting the original one. Common among the ransomware observed is adding a new extension or simply encrypting the file without adding any new one.<\/p>\n<h3>FileCoder<\/h3>\n<p>FileCoder ransomware uses the ZIP utility to encrypt files. Files enumerated using the <em>find<\/em> utility are passed to the ZIP utility with the flag <em>-0<\/em> (no compression) and<em> -P<\/em> (password), along with a randomly generated key for encryption.<\/p>\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"99\" src=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig17-mac_ransomware_techniques-1024x99.png\" alt=\"Screenshot of FileCoder\u2019s encryption logic\" class=\"wp-image-125493\" srcset=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig17-mac_ransomware_techniques-1024x99.png 1024w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig17-mac_ransomware_techniques-300x29.png 300w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig17-mac_ransomware_techniques-768x74.png 768w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig17-mac_ransomware_techniques-1536x149.png 1536w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig17-mac_ransomware_techniques.png 1631w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Figure 17. FileCoder\u2019s encryption logic<\/figcaption><\/figure>\n<p>FileCoder appends the <em>.crypt<\/em> extension to encrypted files (Figure 17). It removes the original file and changes the timestamp of the newly created file, which also works as an evasion tactic. FileCoder only encrypts files present in the <em>\/Users<\/em> and <em>\/Volumes<\/em> directories. It invokes the command twice with the path change being enumerated. While enumerating files in the \/Users directory, it skips its dropped ransom note.<\/p>\n<h3>KeRanger<\/h3>\n<p>KeRanger, on the other hand, uses AES encryption in Cipher block chaining (CBC) mode to encrypt files. It leverages the <em>mbedtls<\/em> library for performing cryptographic functions.<\/p>\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig18-mac_ransomware_techniques.png\" alt=\"Illustration of how KeRanger generates its key.\" class=\"wp-image-125494\" width=\"500\" height=\"254\" srcset=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig18-mac_ransomware_techniques.png 1000w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig18-mac_ransomware_techniques-300x152.png 300w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig18-mac_ransomware_techniques-768x390.png 768w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><figcaption class=\"wp-element-caption\">Figure 18. KeRanger\u2019s key generation process<\/figcaption><\/figure>\n<p>The process begins by generating a key used for AES and hash-based message authentication code (HMAC). It generates a random number that is fed to the digest and an initialization vector, a value calculated by KeRanger and utilized in its key generation process. The result is then used as a key in the next iteration, along with the same random number. This process is done eight times, after which the result is used to set the key.<\/p>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"699\" height=\"319\" src=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig19-mac_ransomware_techniques.png\" alt=\"Screenshot of KeRanger's code showing its encryption logic.\" class=\"wp-image-125519\" srcset=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig19-mac_ransomware_techniques.png 699w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig19-mac_ransomware_techniques-300x137.png 300w\" sizes=\"auto, (max-width: 699px) 100vw, 699px\" \/><figcaption class=\"wp-element-caption\">Figure 19. KeRanger\u2019s encryption logic<\/figcaption><\/figure>\n<p>It then encrypts the random number generated earlier with the RSA key received from the server. To encrypt the files, it uses the generated AES key. It also calculates the HMAC of the original file content, which is written to the output file, along with keying information (data that can be used to decrypt the encrypted files such as key length, the encrypted random number, the initial vector, etc.) and encrypted content.<\/p>\n<h3>MacRansom<\/h3>\n<p>MacRansom uses a symmetric algorithm for encrypting files and decrypting its ransom note \u201c<em>._README_\u201d<\/em>. The ransom note contains encrypted data which MacRansom decrypts using a hardcoded key. It uses separate keys for encrypting the files and decrypting its ransom note.<\/p>\n<p>First, it enumerates the target files using the <em>find <\/em>utility and passes it to another instance of the malware as mentioned in Figure 2. This new malware instance calculates the encryption key first by permuting a hardcoded key with a random number.<\/p>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"901\" height=\"305\" src=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig20-mac_ransomware_techniques.png\" alt=\"Screenshot of MacRansom's code used to generate keys.\" class=\"wp-image-125496\" srcset=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig20-mac_ransomware_techniques.png 901w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig20-mac_ransomware_techniques-300x102.png 300w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig20-mac_ransomware_techniques-768x260.png 768w\" sizes=\"auto, (max-width: 901px) 100vw, 901px\" \/><figcaption class=\"wp-element-caption\">Figure 20. MacRansom\u2019s key generation logic<\/figcaption><\/figure>\n<p>MacRansom reads the file\u2019s content and encrypts it with the permuted key generated earlier. In the process of encryption, if MacRansom encounters its ransom note by checking the filename which is \u201c<em>._README_\u201d<\/em>, it uses a separate hardcoded key to decrypt its content.<\/p>\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig21-mac_ransomware_techniques.png\" alt=\"Screenshot of MacRansom's encryption logic.\" class=\"wp-image-125497\" width=\"840\" height=\"518\" srcset=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig21-mac_ransomware_techniques.png 950w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig21-mac_ransomware_techniques-300x185.png 300w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig21-mac_ransomware_techniques-768x474.png 768w\" sizes=\"auto, (max-width: 840px) 100vw, 840px\" \/><figcaption class=\"wp-element-caption\">Figure 21. MacRansom\u2019s encryption logic<\/figcaption><\/figure>\n<h3>EvilQuest<\/h3>\n<p>EvilQuest uses a custom symmetric key encryption routine to encrypt target files. For each target file, the malware creates a temporary file name using the format \u201c<em>.&lt;FILENAME&gt;.e\u201d<\/em> and then checks if the file has already been encrypted by checking the presence of the marker <em>0xDDBEBABE<\/em><strong>.<\/strong> If not, it reads the target file, encrypts the content, and writes the content to the temporary file. After encrypting the content, the malware encodes the file encryption key and appends the keying information to the file along with the marker. It then proceeds to delete the target file and rename the temporary file to the original target file\u2019s name.<\/p>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"900\" height=\"693\" src=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig22-mac_ransomware_techniques.png\" alt=\"Screenshot of EvilQuest's code showing its encryption process\" class=\"wp-image-125498\" srcset=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig22-mac_ransomware_techniques.png 900w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig22-mac_ransomware_techniques-300x231.png 300w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig22-mac_ransomware_techniques-768x591.png 768w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><figcaption class=\"wp-element-caption\">Figure 22. EvilQuest\u2019s encryption process<\/figcaption><\/figure>\n<h2>EvilQuest\u2019s other capabilities<\/h2>\n<p>Further analysis of some variants of EvilQuest shows interesting capabilities on top of encrypting files. In this section, we discuss other behavior that we have observed in the two EvilQuest variants analyzed apart from their encryption routine. We noted behaviors such as file infection, keylogging, info stealing, disabling security solutions, and in-memory execution.<\/p>\n<p>Over the past years, we have observed many variants of EvilQuest that removed its ransomware component. Tracking behavior changes in malware is important to understand how these affect devices and data and how to prevent these attacks effectively. These additions and changes in behavior might also provide clues about EvilQuest\u2019s future attacks.<\/p>\n<h3>File infection<\/h3>\n<p>EvilQuest can infect Mach-O files by inserting its code (<a href=\"https:\/\/attack.mitre.org\/techniques\/T1554\/\">T1554<\/a>). To identify files to infect, it scans through the <em>\/Users<\/em> directory. It calls a routine for each file found. This routine checks the magic bytes of the file to determine whether the file is a Mach-O binary. It also skips the file if the path contains <em>.app<\/em> or if the file size exceeds 25 MB<strong>.<\/strong><\/p>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"700\" height=\"443\" src=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig23-mac_ransomware_techniques.png\" alt=\"Screenshot of EvilQuest's code used to check for magic bytes.\" class=\"wp-image-125499\" srcset=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig23-mac_ransomware_techniques.png 700w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig23-mac_ransomware_techniques-300x190.png 300w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><figcaption class=\"wp-element-caption\">Figure 23. EvilQuest\u2019s code checking for the magic bytes<\/figcaption><\/figure>\n<p>After scanning and finding target files, EvilQuest prepends its code to the target file and appends a trailer, which contains data such as marker and offset to the original binary code. EvilQuest uses the marker <em>0xDEADFACE<\/em> in the trailer data to check whether a file is infected.<\/p>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"405\" height=\"250\" src=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig24-mac_ransomware_techniques.png\" alt=\"Illustration of a file infected by EvilQuest's code. The illustration shows the last three parts of the file as the trailer, and the code offset is written in the original binary's code.\" class=\"wp-image-125500\" srcset=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig24-mac_ransomware_techniques.png 405w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig24-mac_ransomware_techniques-300x185.png 300w\" sizes=\"auto, (max-width: 405px) 100vw, 405px\" \/><figcaption class=\"wp-element-caption\">Figure 24. Structure of a file infected by EvilQuest<\/figcaption><\/figure>\n<p>If any of the infected file is executed, EvilQuest has checks to identify, if it\u2019s running from an infected file and to execute the original binary using the following logic:<\/p>\n<ol type=\"1\">\n<li>Extract the trailer to check if the current process is infected.<\/li>\n<li>Go to the offset present in the trailer.<\/li>\n<li>Read the original binary content from the offset of the calculated size to a buffer.<\/li>\n<li>Format and form another path: <em>&lt;PATH&gt;\/.&lt;FILE_NAME&gt;1.<\/em><\/li>\n<li>The original binary content is written in the above file.<\/li>\n<li>Provide executable permissions to this newly created file and execute the file.<\/li>\n<\/ol>\n<h3>Keylogging<\/h3>\n<p>We observed two mechanisms of keylogging (<a href=\"https:\/\/attack.mitre.org\/techniques\/T1056\/001\/\">T1056.001<\/a>) in two EvilQuest variants we analyzed. The first mechanism uses the API <a href=\"https:\/\/developer.apple.com\/documentation\/coregraphics\/1454426-cgeventtapcreate\"><em>CGEventTapCreate<\/em><\/a>, while the second uses the <a href=\"https:\/\/developer.apple.com\/documentation\/iokit\/1438383-iohidmanagercreate\/\"><em>IOHIDManagerCreate<\/em><\/a> API.<\/p>\n<h4>Using the CGEventTapCreate API<\/h4>\n<p>This API creates an event tap to monitor human interface devices (HID) like keyboards. Keylogging starts upon receiving commands from a command and control (C2) server.<\/p>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"800\" height=\"477\" src=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig25-mac_ransomware_techniques.png\" alt=\"Screenshot of EvilQuest's code used for logging keystrokes.\" class=\"wp-image-125501\" srcset=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig25-mac_ransomware_techniques.png 800w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig25-mac_ransomware_techniques-300x179.png 300w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig25-mac_ransomware_techniques-768x458.png 768w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><figcaption class=\"wp-element-caption\">Figure 25. EvilQuest code for logging keystrokes using the CGEventTapCreate API<\/figcaption><\/figure>\n<p>The malware creates an event tap using <em>CGEventTapCreate<\/em> and uses <em>CGEventTapEnable<\/em> to activate it. The callback function seen in this EvilQuest variant converts the constant and prints it on the standard output.<\/p>\n<h4>Using the IOHIDManagerCreate API<\/h4>\n<p>This API is used to communicate with and monitor HID devices. To achieve this, EvilQuest uses the following functions:<\/p>\n<ul>\n<li>It uses <em>IOHIDManagerCreate<\/em> to create the HID manager handle.<\/li>\n<li><em>CreateMatchingDirectory<\/em> method is used with argument value <em>6 (kHIDUsage_GD_Keyboard)<\/em> for setting the device type filtering.<\/li>\n<li>It uses <em>IOHIDManagerRegisterInputValueCallback<\/em> to set the callback function.<\/li>\n<li><em>IOHIDManagerOpen<\/em> further opens the <em>HIDManager.<\/em><\/li>\n<li><em>IOHIDManagerScheduleWithRunLoop<\/em> for scheduling the manager with run loop.<\/li>\n<\/ul>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"899\" height=\"440\" src=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig26-mac_ransomware_techniques.png\" alt=\"Screenshot of an EvilQuest variant's code that uses the IOHIDManager API to monitor devices.\" class=\"wp-image-125502\" srcset=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig26-mac_ransomware_techniques.png 899w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig26-mac_ransomware_techniques-300x147.png 300w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig26-mac_ransomware_techniques-768x376.png 768w\" sizes=\"auto, (max-width: 899px) 100vw, 899px\" \/><figcaption class=\"wp-element-caption\">Figure 26. An EvilQuest variant using the IOHIDManager API<\/figcaption><\/figure>\n<p>Figure 27 shows the callback code that is specified in the <em>IOHIDManagerRegisterInputValueCallback<\/em> function. It uses <em>IOHIDValueGetElement<\/em> and <em>IOHIDElementGetUsage<\/em> to get the usage for the element. It then gets the ASCII mapping, which is written to the <em>.DS_State<\/em> file.<\/p>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"912\" height=\"279\" src=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig27-mac_ransomware_techniques.png\" alt=\"Screenshot of an EvilQuest variant's code using the callback function.\" class=\"wp-image-125503\" srcset=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig27-mac_ransomware_techniques.png 912w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig27-mac_ransomware_techniques-300x92.png 300w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig27-mac_ransomware_techniques-768x235.png 768w\" sizes=\"auto, (max-width: 912px) 100vw, 912px\" \/><figcaption class=\"wp-element-caption\">Figure 27. EvilQuest\u2019s callback function<\/figcaption><\/figure>\n<h2>Disabling security programs<\/h2>\n<p>EvilQuest tries to stop security processes to evade detection. Microsoft Defender for Endpoint on Mac\u2019s tamper protection feature safeguards the application from this disabling behavior.<\/p>\n<p>First, it gets the process list by forming the MIB structure, which contains <em>CTL_KERN, KERN_PROC<\/em><strong>, <\/strong><em>KERN_PROC_ALL <\/em>identifiers. The first systcl call gets the output\u2019s size, which is then passed to the second <em>sysctl<\/em> call. This returns the structure for each process.<\/p>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"901\" height=\"268\" src=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig28-mac_ransomware_techniques.png\" alt=\"Screenshot of an EvilQuest variant's code getting the structure of running processes on the device.\" class=\"wp-image-125504\" srcset=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig28-mac_ransomware_techniques.png 901w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig28-mac_ransomware_techniques-300x89.png 300w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig28-mac_ransomware_techniques-768x228.png 768w\" sizes=\"auto, (max-width: 901px) 100vw, 901px\" \/><figcaption class=\"wp-element-caption\">Figure 28. EvilQuest getting the structure of running processes on the device<\/figcaption><\/figure>\n<p>Next, it parses these structures and gets the process ID, passed along with <em>CTL_KERN<\/em>,<em>KERN_PROCARGS2 <\/em>identifiers to get the process arguments. The results are then searched against known patterns for security programs that are hardcoded in EvilQuest. Finding a matching pattern in the hardcoded list leads to EvilQuest stopping the process and removing executable permissions from the process file.<\/p>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"800\" height=\"455\" src=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig29-mac_ransomware_techniques.png\" alt=\"Screenshot of an EvilQuest variant's code where it stops security processes.\" class=\"wp-image-125505\" srcset=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig29-mac_ransomware_techniques.png 800w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig29-mac_ransomware_techniques-300x171.png 300w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig29-mac_ransomware_techniques-768x437.png 768w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><figcaption class=\"wp-element-caption\">Figure29. Code that stops the security process EvilQuest finds<\/figcaption><\/figure>\n<h2>In-memory execution<\/h2>\n<p>This technique <a href=\"https:\/\/attack.mitre.org\/techniques\/T1620\/\">(T1620)<\/a> is a way to execute any file from memory without dropping hence, leaving no trace of the malware on disk. EvilQuest uses the following APIs to implement in-memory execution:<\/p>\n<ul>\n<li><em>NSCreateObjectFileImageFromMemory<\/em> \u2013 used for creating an object file image from the data present in memory<\/li>\n<li><em>NSLinkModule \u2013 <\/em>used to link the object file image<\/li>\n<li><em>NSLookupSymbolInModule \u2013 used <\/em>for looking for a specific symbol<\/li>\n<li><em>NSAddressOfSymbol<\/em> \u2013 used to get the address of the symbol.<\/li>\n<\/ul>\n<p>The address of the function returned from the previous call is then executed.<\/p>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"900\" height=\"355\" src=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig30-mac_ransomware_techniques.png\" alt=\"Screenshot of an EvilQuest variant's API use for in-memory execution.\" class=\"wp-image-125506\" srcset=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig30-mac_ransomware_techniques.png 900w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig30-mac_ransomware_techniques-300x118.png 300w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig30-mac_ransomware_techniques-768x303.png 768w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><figcaption class=\"wp-element-caption\">Figure 30. EvilQuest\u2019s API use for its in-memory execution<\/figcaption><\/figure>\n<h2>Defending against macOS ransomware<\/h2>\n<p>Ransomware continues to be one of the most significant threats affecting any platform. Our analysis of ransomware on Mac operating systems shows how its creators use various techniques to remain hidden from automated analysis systems or make manual inspection by analysts challenging. Understanding ransomware routines and their effects on any device or platform is essential for individual users to take steps toward device and data protection. Organizations can benefit from knowing these malicious behaviors and protect their networks in the age of securing multiple systems and devices operating in their networks.<\/p>\n<p>Defenders can take the following mitigation steps to defend against these ransomware attacks:<\/p>\n<ul>\n<li>Install apps from trusted sources only, such as a software platform\u2019s official app store.<\/li>\n<li>Restrict access to privileged resources like <em>LaunchDaemons <\/em>or <em>LaunchAgents <\/em>folders and sudoers files through OSX enterprise management solutions. This helps mitigate common persistence and privilege escalation techniques.<\/li>\n<li>Use web browsers like <a href=\"https:\/\/www.microsoft.com\/edge\">Microsoft Edge<\/a>\u2014available on macOS and various platforms\u2014that support <a href=\"https:\/\/docs.microsoft.com\/deployedge\/microsoft-edge-security-smartscreen\">Microsoft Defender SmartScreen<\/a>. SmartScreen identifies and blocks malicious websites, including phishing sites, scam sites, and sites that contain exploits and host malware.<\/li>\n<li>Run the latest version of your operating systems and applications. Deploy the latest security updates as soon as they become available. These ensure your device is benefiting from the latest cloud-delivered protections.<\/li>\n<li>Use Microsoft Defender for Endpoint on Mac, which detects, stops, and quarantines the malware discussed in this blog using the following detection names:\n<ul>\n<li>Ransom:MacOS\/EvilQuest<\/li>\n<\/ul>\n<ul>\n<li>Ransom:MacOS\/Filecoder.YC!MTB<\/li>\n<\/ul>\n<ul>\n<li>Ransom:MacOS_X\/Ratatonilly.A<\/li>\n<\/ul>\n<ul>\n<li>Ransom:MacOS\/Crypat.A!MTB<\/li>\n<\/ul>\n<ul>\n<li>Ransom:MacOS_X\/KeRanger.A<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><a href=\"https:\/\/www.microsoft.com\/security\/business\/endpoint-security\/microsoft-defender-endpoint\">Microsoft Defender for Endpoint<\/a> tracks the techniques mentioned in the MITRE ATT&amp;CK\u00ae tactics and techniques table below and creates alerts where applicable. Defender for Endpoint provides cross-platform defense and a unified investigation experience that gives organizations visibility across all endpoints in the network.<\/p>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"900\" height=\"387\" src=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig31-mac_ransomware_techniques.png\" alt=\"Screenshot of Mac ransomware-related alerts on Microsoft Defender for Endpoint.\" class=\"wp-image-125507\" srcset=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig31-mac_ransomware_techniques.png 900w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig31-mac_ransomware_techniques-300x129.png 300w, https:\/\/www.microsoft.com\/en-us\/security\/blog\/wp-content\/uploads\/2023\/01\/Fig31-mac_ransomware_techniques-768x330.png 768w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><figcaption class=\"wp-element-caption\">Figure 31. Mac ransomware-related alerts on Microsoft Defender for Endpoint<\/figcaption><\/figure>\n<h2>MITRE ATT&amp;CK\u00ae tactics and techniques observed<\/h2>\n<p><strong>Execution<\/strong><\/p>\n<ul>\n<li>T1204.002 User Execution: Malicious File<\/li>\n<li>T1059.002 Command and Scripting Interpreter: AppleScript<\/li>\n<li>T1569.001 System Services: Launchctl<\/li>\n<\/ul>\n<p><strong>Persistence<\/strong><\/p>\n<ul>\n<li>T1543.001 Create or Modify System Process: Launch Agent<\/li>\n<li>T1543.004 Create or Modify System Process: Launch Daemon<\/li>\n<li>T1554 Compromise Client Software Binary<\/li>\n<\/ul>\n<p><strong>Privilege Escalation<\/strong><\/p>\n<ul>\n<li>T1548.003 Abuse Elevation Control Mechanism: Sudo and Sudo caching<\/li>\n<li>T1543.004 Create or Modify System Process: Launch Daemon<\/li>\n<\/ul>\n<p><strong>Defense Evasion<\/strong><\/p>\n<ul>\n<li>T1140 Deobfuscate\/Decode Files or Information<\/li>\n<li>T1222.002 File and Directory Permissions Modification: Linux and MAC File and Directory Permissions <\/li>\n<\/ul>\n<p><strong>Modification<\/strong><\/p>\n<ul>\n<li>T1562.001 Impair Defences: Disable or Modify tools<\/li>\n<li>T1070.004 Indicator Removal on Host: File Deletion<\/li>\n<li>T1070.006 Indicator Removal on Host: Timestomp<\/li>\n<li>T1036.005 Masquerading: Match Legitimate Name or Location<\/li>\n<\/ul>\n<p><strong>Discovery<\/strong><\/p>\n<ul>\n<li>T1083 File and Directory Discovery<\/li>\n<li>T1057 Process Discovery<\/li>\n<li>T1518.001 Software Discovery: Security Software Discovery<\/li>\n<li>T1082 System Information Discovery<\/li>\n<li>T1033 System Owner\/User Discovery<\/li>\n<\/ul>\n<p><strong>Collection<\/strong><\/p>\n<ul>\n<li>T1005 Data from Local System<\/li>\n<\/ul>\n<p><strong>Command &amp; Control<\/strong><\/p>\n<ul>\n<li>T1071.001 Application Layer Protocol: Web protocols<\/li>\n<li>T1132.002 Data Encoding: Non-Standard Encoding<\/li>\n<li>T1105 Ingress Tool Transfer<\/li>\n<\/ul>\n<p><strong>Exfiltration<\/strong><\/p>\n<ul>\n<li>T1041 Exfiltration over C2 channel<\/li>\n<\/ul>\n<p><strong>Impact<\/strong><\/p>\n<ul>\n<li>T1486 Data Encrypted for Impact<\/li>\n<\/ul>\n<h2>Indicators of compromise<\/h2>\n<ul>\n<li>b34738e181a6119f23e930476ae949fc0c7c4ded6efa003019fa946c4e5b287a (EvilQuest)<\/li>\n<li>bcdb0ca7c51e9de4cf6c5c346fd28a4ed28e692319177c8a94c86dc676ee8e48 (EvilQuest variant)<\/li>\n<li>617f7301fd67e8b5d8ad42d4e94e02cb313fe5ad51770ef93323c6115e52fe98 (MacRansom)<\/li>\n<li>d19b903adbd0f8c119d0d8f25b194bdd24b737357a517f23ca5cdc6c75b35038 (FileCoder)<\/li>\n<li>31b6adb633cff2a0f34cefd2a218097f3a9a8176c9363cc70fe41fe02af810b9 (KeRanger)<\/li>\n<\/ul>\n<p>The post <a rel=\"nofollow\" href=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/2023\/01\/05\/unraveling-the-techniques-of-mac-ransomware\/\">Unraveling the techniques of Mac ransomware<\/a> appeared first on <a rel=\"nofollow\" href=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\">Microsoft Security Blog<\/a>.<\/p>\n<p><a href=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/2023\/01\/05\/unraveling-the-techniques-of-mac-ransomware\/\" target=\"bwo\" >https:\/\/blogs.technet.microsoft.com\/mmpc\/feed\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p><strong>Credit to Author: Microsoft Security Threat Intelligence &#8211; Editor| Date: Thu, 05 Jan 2023 17:00:00 +0000<\/strong><\/p>\n<p>Understanding how Mac ransomware works is critical in protecting today\u2019s hybrid environments. We analyzed several known Mac ransomware families and highlighted these families\u2019 techniques, which defenders can study further to prevent attacks. <\/p>\n<p>The post <a rel=\"nofollow\" href=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\/2023\/01\/05\/unraveling-the-techniques-of-mac-ransomware\/\">Unraveling the techniques of Mac ransomware<\/a> appeared first on <a rel=\"nofollow\" href=\"https:\/\/www.microsoft.com\/en-us\/security\/blog\">Microsoft Security Blog<\/a>.<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout","footnotes":""},"categories":[10759,10378],"tags":[4500,10403,22453,3765],"class_list":["post-20932","post","type-post","status-publish","format-standard","hentry","category-microsoft","category-security","tag-cybersecurity","tag-macos","tag-microsoft-security-intelligence","tag-ransomware"],"_links":{"self":[{"href":"https:\/\/www.palada.net\/index.php\/wp-json\/wp\/v2\/posts\/20932","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.palada.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.palada.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.palada.net\/index.php\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.palada.net\/index.php\/wp-json\/wp\/v2\/comments?post=20932"}],"version-history":[{"count":0,"href":"https:\/\/www.palada.net\/index.php\/wp-json\/wp\/v2\/posts\/20932\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.palada.net\/index.php\/wp-json\/wp\/v2\/media?parent=20932"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.palada.net\/index.php\/wp-json\/wp\/v2\/categories?post=20932"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.palada.net\/index.php\/wp-json\/wp\/v2\/tags?post=20932"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}