Blog

Ducktail and Peeling the Layers of PowerShell

BY eSentire Threat Response Unit (TRU)

January 4, 2024 | 7 MINS READ

Attacks/Breaches

Threat Intelligence

Threat Response Unit

TRU Positive/Bulletin

Want to learn more on how to achieve Cyber Resilience?

TALK TO AN EXPERT

Adversaries don’t work 9-5 and neither do we. At eSentire, our 24/7 SOCs are staffed with Elite Threat Hunters and Cyber Analysts who hunt, investigate, contain and respond to threats within minutes.

We have discovered some of the most dangerous threats and nation state attacks in our space – including the Kaseya MSP breach and the more_eggs malware.

Our Security Operations Centers are supported with Threat Intelligence, Tactical Threat Response and Advanced Threat Analytics driven by our Threat Response Unit – the TRU team.

In TRU Positives, eSentire’s Threat Response Unit (TRU) provides a summary of a recent threat investigation. We outline how we responded to the confirmed threat and what recommendations we have going forward.

Here’s the latest from our TRU Team…

What did we find?

In early December 2023, the eSentire Threat Response Unit (TRU) detected an attempted, and ultimately unsuccessful, Ducktail malware infection, targeting an employee in digital marketing at a customer within the business services industry. The Ducktail distributors contacted the employee via LinkedIn with a private message containing an attachment leading to a ZIP archive.

The ZIP archive contains bloated shortcuts that are over 800MB in size. The shortcuts contain the batch scripts that execute PowerShell commands.

Figure 1: Contents of the ZIP archive

An example of one of the shortcut files is shown in Figure 2.

Figure 2: 1 _ Project information records and working contracts.lnk contents

Upon decoding the script, we get base64-encoded strings that decodes to the script shown in Figure 3.

Figure 3: Decoded PowerShell script

The script downloads the file from hxxps://gdfsgfdrgetgergdsf[.]tech/file/ps/5f8f8c05db68cca200c6379b825648b5.jpg (MD5: 5f8f8c05db68cca200c6379b825648b5).

The downloaded file is another PowerShell script (Figure 4) that downloads the decoy PDF file from hxxp://gdfsgfdrgetgergdsf[.]tech/file/docs/ (Figure 5).

Figure 4: Contents of 5f8f8c05db68cca200c6379b825648b5.jpg
Figure 5: Decoy PDF file

Next, the script (Figure 6) does the following:

Figure 6: Cleaned up script

As you can see in Figure 6, some of the commands are assigned to variables that are base64-encoded.

The payload retrieved contains another PowerShell script (Figure 7) that does the following:

Figure 7: Snippet of d4e1a9191216420ce7989cf6c3e203cd.jpg

The retrieved file 5be7408b84fbd40c8e7930f4c28a585a.jpg (MD5: 5be7408b84fbd40c8e7930f4c28a585a ) contains the obfuscated PowerShell command to retrieve the d4e1a9191216420ce7989cf6c3e203cd.jpg file as shown in Figure 8. The command is being decrypted via the hardcoded XOR key, but the threat actors made sure to make it hard to find it via numerous bitwise operations and conditional jump instructions (Figure 8).

Figure 8: Snippet of the decryption routine in 5be7408b84fbd40c8e7930f4c28a585a.jpg file

The payload mainbot.exe retrieved from C2 is responsible for establishing the connection with the C2 server and taking remote commands. Upon successful bot registration, the infected host obtains myRdpService.exe (MD5: 1ade74bbf88c1a41a352682a8f2265f9) from C2 and RDP Wrapper configuration (hxxp://138.201.8[.]186:8000/file/rdpwrap.txt).

The commands upon checking in from mainbot.exe:

begin connect
begin sending DEVICEINFO|quyet!D5A7F263FE404D449438C649AA1E54EE|79b707124b0b4a92b2949acb220b1235|Admin|1.7.2

Further commands from the bot:

STATUS|23/12/2023 10:26:56|Set permission of C:\Users\Default\AppData
STATUS|23/12/2023 10:27:12|add exclude result 
STATUS|23/12/2023 10:26:56|Success
STATUS|23/12/2023 10:26:56|Set permission of C:\Users\Default User\AppData
STATUS|23/12/2023 10:26:56|Success
STATUS|23/12/2023 10:26:56|Set permission of C:\Users\username\AppData
STATUS|23/12/2023 10:26:56|role admin name Administrators
STATUS|23/12/2023 10:26:56|Set permission of C:\Windows\Temp
STATUS|23/12/2023 10:26:56|RDP|False
STATUS|23/12/2023 10:26:56|Success
STATUS|23/12/2023 10:26:56|Set permission of C:\Users\Default\AppData
STATUS|23/12/2023 10:26:56|role admin name Administrators
STATUS|23/12/2023 10:26:56|Success
STATUS|23/12/2023 10:27:29|status term service 
STATUS|23/12/2023 10:27:05|Success
STATUS|23/12/2023 10:27:08|create user result
STATUS|23/12/2023 10:27:12|term service install state True
STATUS|23/12/2023 10:27:20|delete old rdpwrap ok
STATUS|23/12/2023 10:27:20|delete file rdpwrap.ini ok
STATUS|23/12/2023 10:27:22|try download from hxxp://138.201.8[.]186:8000/file/rdpwrap.txt OK
STATUS|23/12/2023 10:27:22|start TermService againt
STATUS|23/12/2023 10:27:20|try download from hxxp://138.201.8[.]186:8000/file/rdpwrap.txt
STATUS|23/12/2023 10:27:20|delete old rdpwrap ok
STATUS|23/12/2023 10:27:20|delete file rdpwrap.ini ok
STATUS|23/12/2023 10:27:20|try download from hxxp://138.201.8[.]186:8000/file/rdpwrap.txt
STATUS|23/12/2023 10:27:22|try download from hxxp://138.201.8[.]186:8000/file/rdpwrap.txt OK
STATUS|23/12/2023 10:27:22|start TermService againt
STATUS|23/12/2023 10:27:29|status term service
STATUS|23/12/2023 10:27:34|check file hash 1ade74bbf88c1a41a352682a8f2265f9 of file <a href="http://138.201.8">http://138.201.8</a>[.]186:8001/file/t/RdpService[.]exe
STATUS|23/12/2023 10:27:34|download my rdp service new success, setup
STATUS|23/12/2023 10:27:37|result install myRdpService 
STATUS|23/12/2023 10:27:44|hide user
STATUS|23/12/2023 10:27:44|hide user success

As you can observe from the hints above, mainbot.exe checks the hash of the retrieved RdpService[.]exe file, attempts to create the user “User1” on infected machine, performs the exclusion of “C:\Program Files” folder for Windows Defender and changes the access control list for specific folders. Periodically it also sends “TESTDATA”.

myRdpService.exe establishes the remote connection with hxxp://23.88.71[.]29:8000 sending the following command containing Device ID and the presumably threat actor’s name that is used as an argument to run mainbot.exe and myRdpService.exe payloads (DEVICEID_quyet_5C0B1DC44D4E637D1A6B43502D6F6167_1.6.5).

Two files are dropped in the working directory after successful exection of myRdpService.exe: deviceId.txt (contains device ID) and log_rdp_<ddmmyyyy_yy>.txt (contains log messages) (Figure 9).

Figure 9: Contents of log_rdp_.txt file

The service “myRdpService” is created to start myRdpService.exe with an argument “quyet” under the working directory.

Two core payloads, named 'mainbot.exe' and 'myRdpService.exe,' are .NET payloads compiled using native Ahead-Of-Time (AOT) compilation to make the analysis process more complicated.

The rest of the shortcuts perform similar actions described above but the hashes for files for some shortcuts are different.

What did we do?

Our team of 24/7 SOC Cyber Analysts isolated the affected host, contained the threat, and notified the customer of suspicious activities.

What can you learn from this TRU Positive?

Recommendations from our Threat Response Unit (TRU):

Detection Rules

Indicators Of Compromise

You can access the IOCs for Ducktail here.

References

eSentire Unit
eSentire Threat Response Unit (TRU)

The eSentire Threat Response Unit (TRU) is an industry-leading threat research team committed to helping your organization become more resilient. TRU is an elite team of threat hunters and researchers that supports our 24/7 Security Operations Centers (SOCs), builds threat detection models across the eSentire XDR Cloud Platform, and works as an extension of your security team to continuously improve our Managed Detection and Response service. By providing complete visibility across your attack surface and performing global threat sweeps and proactive hypothesis-driven threat hunts augmented by original threat research, we are laser-focused on defending your organization against known and unknown threats.

Read the Latest from eSentire