{"id":90536,"date":"2021-11-02T16:31:48","date_gmt":"2021-11-02T11:01:48","guid":{"rendered":"https:\/\/blogs.quickheal.com\/?p=90536"},"modified":"2023-02-15T17:49:58","modified_gmt":"2023-02-15T12:19:58","slug":"stay-alert-malware-authors-deploy-elf-as-windows-loaders-to-exploit-wsl-feature","status":"publish","type":"post","link":"https:\/\/www.quickheal.com\/blogs\/stay-alert-malware-authors-deploy-elf-as-windows-loaders-to-exploit-wsl-feature\/","title":{"rendered":"Stay Alert \u2013 Malware Authors Deploy ELF as Windows Loaders to Exploit WSL feature"},"content":{"rendered":"<h2 style=\"font-size: 27px;\"><strong><b>What is WSL?<\/b><\/strong><\/h2>\n<p>The Windows Subsystem for Linux (WSL) is a resource inside the Windows operating system that allows users to execute Linux command lines on a machine running Windows operating system. The Windows Subsystem for Linux uses an application known as Bash.exe, which launches a Linux dialogue box within the Windows operating system interface. This might be considered as a &#8220;shell&#8221; application that runs within Windows.<\/p>\n<p>There is a new attack chain that is going on in which attackers target the WSL environment. The files are written in Python 3 and then, with the help of PyInstaller, converted into an ELF executable for Debian Linux. These files act as loaders running a payload embedded within the sample or retrieved from a remote server and then injected into a running process. This tradecraft can enable an actor to obtain an unnoticed footing on a compromised machine. The ELF loader has two variants: the first is written entirely in Python, while the second uses Python to call several Windows APIs via ctypes and launch a <a href=\"https:\/\/blogs.quickheal.com\/powershell-an-attackers-paradise\/\">PowerShell<\/a> script to perform further operations on the host machine. Some of the samples included lightweight payloads generated by an open-source tool like Meterpreter. In other situations, the files try to download shellcode from a remote C2.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-large wp-image-90544 aligncenter\" src=\"https:\/\/blogs.quickheal.com\/wp-content\/uploads\/2021\/11\/Fig1-396x390.png\" alt=\"\" width=\"396\" height=\"390\" srcset=\"https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/Fig1-396x390.png 396w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/Fig1-300x296.png 300w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/Fig1-70x70.png 70w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/Fig1-45x45.png 45w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/Fig1.png 412w\" sizes=\"(max-width: 396px) 100vw, 396px\" \/><\/p>\n<p><em><i>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Fig1:<\/i><\/em>\u00a0Flow Diagram<\/p>\n<p>PowerShell is used to inject and execute the shellcode in some samples, while Python ctypes is used to resolve Windows APIs in others.<\/p>\n<p>In the PowerShell sample, the compiled python code calls three functions named &#8211;<\/p>\n<ul>\n<li>reverseshell()<\/li>\n<li>kill_av()<\/li>\n<li>windowspersistance()<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-large wp-image-90545 aligncenter\" src=\"https:\/\/blogs.quickheal.com\/wp-content\/uploads\/2021\/11\/Fig2-650x245.png\" alt=\"\" width=\"650\" height=\"245\" srcset=\"https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/Fig2-650x245.png 650w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/Fig2-300x113.png 300w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/Fig2-768x289.png 768w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/Fig2-789x297.png 789w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/Fig2.png 1278w\" sizes=\"(max-width: 650px) 100vw, 650px\" \/><\/p>\n<p>The <strong><b>reverseshell()<\/b><\/strong>\u00a0function contains the PowerShell payload encoded using multilevel base64 encoding. The decoded PowerShell used the MSF Venom payload.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-large wp-image-90546 aligncenter\" src=\"https:\/\/blogs.quickheal.com\/wp-content\/uploads\/2021\/11\/Fig3-650x179.png\" alt=\"\" width=\"650\" height=\"179\" srcset=\"https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/Fig3-650x179.png 650w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/Fig3-300x83.png 300w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/Fig3-768x212.png 768w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/Fig3-789x217.png 789w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/Fig3-304x84.png 304w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/Fig3.png 1172w\" sizes=\"(max-width: 650px) 100vw, 650px\" \/><\/p>\n<p>In an infinite, while true loop, the <strong><b>reverseshell() <\/b><\/strong>function uses a sub process to execute a Base64-encoded PowerShell script every 20 seconds, blocking any other process from being executed.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-large wp-image-90547 aligncenter\" src=\"https:\/\/blogs.quickheal.com\/wp-content\/uploads\/2021\/11\/Fig4-650x169.png\" alt=\"\" width=\"650\" height=\"169\" srcset=\"https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/Fig4-650x169.png 650w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/Fig4-300x78.png 300w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/Fig4-768x200.png 768w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/Fig4-789x205.png 789w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/Fig4.png 1266w\" sizes=\"(max-width: 650px) 100vw, 650px\" \/><\/p>\n<p>The <strong>kill_av() <\/strong>function does what its name implies: it uses <strong>os.popen<\/strong>\u00a0to try to kill suspected AV products and analysis tools ().<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-large wp-image-90548 aligncenter\" src=\"https:\/\/blogs.quickheal.com\/wp-content\/uploads\/2021\/11\/Fig5-650x149.png\" alt=\"\" width=\"650\" height=\"149\" srcset=\"https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/Fig5-650x149.png 650w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/Fig5-300x69.png 300w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/Fig5-768x176.png 768w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/Fig5-789x181.png 789w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/Fig5.png 1239w\" sizes=\"(max-width: 650px) 100vw, 650px\" \/><\/p>\n<p>The <strong>windowspersistence()<\/strong>\u00a0function used a subprocess to create a registry run key for persistence, copying the original ELF file to the app data subdirectory under the name payload.exe.<\/p>\n<p>Meterpreter payload provides an interactive shell from which an attacker can explore the target machine and execute code. Meterpreter is deployed using in-memory DLL injection. As a result, Meterpreter resides entirely in memory and writes nothing to disk.<\/p>\n<p>So here, in this case Meterpreter payload is injected in Apache HTTP server benchmarking tool (ab.exe) using MSF Venom.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-large wp-image-90538 aligncenter\" src=\"https:\/\/blogs.quickheal.com\/wp-content\/uploads\/2021\/11\/payload_-1-650x303.jpg\" alt=\"\" width=\"650\" height=\"303\" srcset=\"https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/payload_-1-650x303.jpg 650w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/payload_-1-300x140.jpg 300w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/payload_-1.jpg 716w\" sizes=\"(max-width: 650px) 100vw, 650px\" \/><\/p>\n<p style=\"text-align: center;\">The above figure shows the Meterpreter payload.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-large wp-image-90543 aligncenter\" src=\"https:\/\/blogs.quickheal.com\/wp-content\/uploads\/2021\/11\/socket_connect-650x294.jpg\" alt=\"\" width=\"650\" height=\"294\" srcset=\"https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/socket_connect-650x294.jpg 650w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/socket_connect-300x136.jpg 300w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/socket_connect-768x347.jpg 768w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/socket_connect.jpg 787w\" sizes=\"(max-width: 650px) 100vw, 650px\" \/>The above figure shows that it tries to connect to C2 server for further interaction, but it fails and exits.<\/p>\n<p>As IP is not active, it is unable to connect with server and therefore we were not able to trace further activity.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-large wp-image-90540 aligncenter\" src=\"https:\/\/blogs.quickheal.com\/wp-content\/uploads\/2021\/11\/receive-416x390.jpg\" alt=\"\" width=\"416\" height=\"390\" srcset=\"https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/receive-416x390.jpg 416w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/receive-300x281.jpg 300w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/receive.jpg 548w\" sizes=\"(max-width: 416px) 100vw, 416px\" \/><\/p>\n<p>As per static analysis shown in the above figure, after connecting to the server, it receives some data for which it allocates memory virtually, and then it continues to receive data in a loop until it gets zero. It frees memory which is allocated and closes the socket, and then it exits.<\/p>\n<p>Also found some other IOCs that all communicate with the same IP address. These samples are of Telegram Desktop Setup, which contains a Meterpreter payload, and the payload is obfuscated with Shikata Ga Nai (SGN) encoder.<\/p>\n<p>SGN is a polymorphic XOR additive feedback encoder. In the case of XOR additive feedback, the algorithm is XORing future instructions via a random key and then adding that instruction to the key to be used again to encode the next instruction. For decoding the shellcode, steps need to be followed in reverse.<\/p>\n<p>This encoder allows multiple iterations. Here, in this case, it has encoded payload five times<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-large wp-image-90542 aligncenter\" src=\"https:\/\/blogs.quickheal.com\/wp-content\/uploads\/2021\/11\/sGN_start-650x290.jpg\" alt=\"\" width=\"650\" height=\"290\" srcset=\"https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/sGN_start-650x290.jpg 650w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/sGN_start-300x134.jpg 300w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/sGN_start-768x343.jpg 768w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/sGN_start-789x352.jpg 789w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/sGN_start.jpg 800w\" sizes=\"(max-width: 650px) 100vw, 650px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-large wp-image-90541 aligncenter\" src=\"https:\/\/blogs.quickheal.com\/wp-content\/uploads\/2021\/11\/sgn_encoder-650x311.jpg\" alt=\"\" width=\"650\" height=\"311\" srcset=\"https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/sgn_encoder-650x311.jpg 650w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/sgn_encoder-300x144.jpg 300w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/sgn_encoder.jpg 717w\" sizes=\"(max-width: 650px) 100vw, 650px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>After decoding we get the final Meterpreter payload as below figure shows.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-large wp-image-90539 aligncenter\" src=\"https:\/\/blogs.quickheal.com\/wp-content\/uploads\/2021\/11\/payload_other-650x290.jpg\" alt=\"\" width=\"650\" height=\"290\" srcset=\"https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/payload_other-650x290.jpg 650w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/payload_other-300x134.jpg 300w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/payload_other-768x343.jpg 768w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/payload_other-789x352.jpg 789w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2021\/11\/payload_other.jpg 795w\" sizes=\"(max-width: 650px) 100vw, 650px\" \/><\/p>\n<p>The further activity of this payload is same as above.<\/p>\n<p>&nbsp;<\/p>\n<p><strong><b>Conclusion<\/b><\/strong><\/p>\n<p>We recommend that users who have enabled WSL ensure proper logging to prevent themselves from these kinds of attacks as threat actors attempt to exploit this new feature of the operating system. <a href=\"https:\/\/www.quickheal.co.in\/\">Quickheal<\/a> protects its users by detecting these with the detection names ELF.Trojan.44270.GC and Trojan.Swrort<strong><b>\u00a0<\/b><\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong><b>Indicators of Compromise (IOCs):<\/b><\/strong><\/p>\n<p><strong><b>ELF IoCs:<\/b><\/strong><\/p>\n<ul>\n<li>53854c6d163bfd0c56d8b297ac43bd25c21f696de6063031241e792ee65df441 \u00a0ELF.Trojan.44270.GC<\/li>\n<li>c297e545b8f150cc5ff56dbb68dc74fe30a421d9d40f38f4a53083192697c44c \u00a0ELF.Trojan.44270.GC<\/li>\n<li>17921368901f23e0cad0d2fe4ce5694aebaf4727699ed0358117500701914d1b \u00a0ELF.Trojan.44270.GC<\/li>\n<li>198a2d42df010d838b4207f478d885ef36e3db13b1744d673e221b828c28bf77 \u00a0ELF.Trojan.44270.GC<\/li>\n<\/ul>\n<p><strong><b>PE IoCs:<\/b><\/strong><\/p>\n<ul>\n<li>85acfee86fd742ac5b6e347cd860324b: Trojan.Swrort.S23689749<\/li>\n<li>F15ef7b1c22aa23fa5de99980501b2dc: Trojan.Swrort.S23689749<\/li>\n<li>C21e299905613e5cd5d79432934e47e3: Trojan.Swrort.S23689749<\/li>\n<li>Ae094056a41854ab04409c6f791194df: Trojan.Swrort.A<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><strong><b>Subject matter experts:<\/b><\/strong><\/p>\n<p>&nbsp;<\/p>\n<ul>\n<li>Rahul Pawar, Security Researcher I<\/li>\n<li>Rutuja Mane, Security Researcher I<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is WSL? The Windows Subsystem for Linux (WSL) is a resource inside the Windows operating system that allows users to execute Linux command lines on a machine running Windows operating system. The Windows Subsystem for Linux uses an application known as Bash.exe, which launches a Linux dialogue box within the Windows operating system interface. [&hellip;]<\/p>\n","protected":false},"author":98,"featured_media":90552,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1739,1],"tags":[1881,1880,1879,1053,49,72,1249,1809],"class_list":["post-90536","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cybersecurity","category-uncategorized","tag-elf","tag-python","tag-wsl","tag-linux","tag-malware","tag-microsoft","tag-windows","tag-windows10"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.quickheal.com\/blogs\/wp-json\/wp\/v2\/posts\/90536"}],"collection":[{"href":"https:\/\/www.quickheal.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.quickheal.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.quickheal.com\/blogs\/wp-json\/wp\/v2\/users\/98"}],"replies":[{"embeddable":true,"href":"https:\/\/www.quickheal.com\/blogs\/wp-json\/wp\/v2\/comments?post=90536"}],"version-history":[{"count":7,"href":"https:\/\/www.quickheal.com\/blogs\/wp-json\/wp\/v2\/posts\/90536\/revisions"}],"predecessor-version":[{"id":91422,"href":"https:\/\/www.quickheal.com\/blogs\/wp-json\/wp\/v2\/posts\/90536\/revisions\/91422"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.quickheal.com\/blogs\/wp-json\/wp\/v2\/media\/90552"}],"wp:attachment":[{"href":"https:\/\/www.quickheal.com\/blogs\/wp-json\/wp\/v2\/media?parent=90536"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.quickheal.com\/blogs\/wp-json\/wp\/v2\/categories?post=90536"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.quickheal.com\/blogs\/wp-json\/wp\/v2\/tags?post=90536"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}