BACK TO BLOGS Back to Press Releases

ThreatLocker Threat Intelligence discovers unknown malware "CookieMorpher"

Written by:

Jacob Meyer, Threat Intelligence Team Lead, William Pires, Threat Analyst, Pandeli Zi, Threat Analyst

Written by:

ThreatLocker Threat Intelligence observed an active C2 campaign using infrastructure masquerading as StaticVPN that has been dubbed CookieMorpher.  

Victims directed toward the malicious website download a multistage payload, leading to the delivery of an inconspicuous memory-based RAT. The initial payload is polymorphic and falsely presented as a Netscape cookie file which takes several measures to evade detection and tamper with Windows Defender features.  

The resulting final stage and post exploitation behavior is consistent across all instances of delivery. The ever-changing signatures and hashes allow the stages to evade public databases and detection frameworks such as Virus Total and Windows Defender, giving curious victims a false sense of security.

Cookies.txt delivery

Figure 1: Attack Chain

‍

The malicious StaticVPN domain employs a polymorphic payload delivery system: The victim’s automatic download of cookies.txt contains a multistage loader that exhibits minor differences on each download. ThreatLocker Threat Intelligence downloaded 10 different samples to evaluate their behavior accordingly.

‍

Figure 2: Unique Cookies.txt SHA values per download

Each generated payload contains the exact same functionality with minor changes in how strings are built, varying between two methods: concatenation of split strings and character arrays. Additionally, each downloaded file contains fake Netscape cookies that show unique combinations of private IPs and “localhost” to appear as a fake HTTP Cookie File.  

Considering how a string can be split several different ways, this method of signature evasion allows for numerous permutations of slightly different payloads. Several of the payloads were proven to bypass Windows Defender’s real-time protection scanning on download.

Figure 3: Cookies.txt download
Figure 4: Defender scan deems Cookies files clean

Attacker commands utilize the delimiters lsSZA4B6 and WG#0 to continue downloading additional payloads and execute the remainder of the attack chain. The first action parses a value within cookies.txt named PSAGCMD which, after the lsSZA4B6 delimiter, uses a custom alphabet with a set of obfuscated cmd instructions to execute an encoded PowerShell command. This encoded command is where the two primary loader actions are taken through ScriptBlock objects.

Figure 5: Cookies.txt lsSZA4B6 delimiter

Attempted AMSI bypass

The first ScriptBlock parses the remainder of cookies.txt with the regex pattern WG#(\d{2})#(.+), combining the three different sections of base64 in numerical order and executing them as an encoded PowerShell command.  

The resulting code uses a variable weighted distribution of string concatenation and character arrays, along with four additional levels of base64 encoding to conceal an AMSI patch bypass performed on the parent PowerShell process.

Figure 6: Differences in string concatenation and character array per file

‍

After using LoadLibrary and OpenProcess to find the loaded amsi.dll module, VirtualProtectEx and WriteProcessMemory overwrite the address of the AmsiScanBuffer function. On testing this bypass, Threat Intelligence was able to locate the written bytes but did not observe any change in AMSI behavior on PowerShell versions 5.1 and 7.7.

Figure 7: Stage 4 AMSI bypass

Final stage loader

The second ScriptBlock object performs a second connection to staticVPN[.]us and executes the response. The full URL shows several unique identifiers such as wire, iid, and t that appear to specify which version of the final stage to deploy as well as the agent’s own identifier.  

This response uses another four layers of embedded base64 to reach the third and final download link from staticvpn[.]us, which contains the same query values as the previous call in addition to “inject=classic” being added to the end of the URL.  

This final download link provides the last block of base64 which, when parsed, decodes into the C2 client, psag-agent.exe. This binary is injected as shellcode into a new thread under the calling PowerShell process (the same process that received the AMSI patch) and executed.

Figure 8: Next stage payload

‍

Figure 9: PSAG-Agent final download differences

PSAG-Agent

PSAG is an unknown agent with no current attribution to any known family or threat actor(s). Following the apparent theme of heavy encoding and obfuscation, the client does very little without receiving specifically crafted, encrypted commands to avoid detection. Command options for several features include running arbitrary commands, local tools and scripts, file upload and download, migration through shellcode injection, and pivoting through netsh firewall rules.

The unique implementation of these different options is what characterizes this framework as unknown. Most notably, specific features are available to deploy a cryptominer and brute force and run commands on available MSSQL databases.  

A full table of available commands, their options, and descriptions are shown beneath the IOCs listed below.

Beacon and response

The process taken to decrypt communication began by comparing several encrypted strings. Each connection request and response began with the characters 11w.  

Considering the C2 endpoint is an API, a detail about the encryption method became clear before obtaining the key: The first characters of an API response ‘{“’ are consistently and directly translated instead of a nonce-based method such as ChaCha or AES-GCM.  

Common methods that use this direct translation are fixed substitutions using lookup tables and byte addition or subtraction. The most common method is XOR, which is what the key was determined to be. The key itself was found as a base64 value labeled “wire_key_b64” in the embedded config section of the binary, .psagcfg.

Figure 10: Hex dump of .psagcfg section

Another method is available to deduce the key. Extensive logging is written to a temp file %TEMP%\psag-native-<instance id>.log which includes log entries named sync: payload and http: req. These two log entries contain the same data before and after encryption by the unknown XOR key. Due to the nature of XOR, if the same data before and after XOR encryption are XORed together, the full XOR key can be revealed. The encrypted data in http: req contains a field before lining up with the plaintext sync: payload message that populates the beginning of the encrypted string with 70 base64 characters.  

To derive the XOR key from only the log file, the first 70 offsets in the encrypted message would need to be attempted before finding the correct offset that “hostname” starts to produce the XOR key. The rolling aspect of this encryption also becomes clear when the derived 33rd byte of the key is the same as the first, the 34th byte is also the second, etc.

‍

ac7e6ff9d4f6f8a2419a5e82bcd5c6435060a24f4180cbfd223353b20e0c2275

‍XOR encryption key

‍

Figure 11: psag-native-<unique ID>.log
Figure 12: XOR key derivation

Command emulation

Once the XOR key was discovered, Threat Intelligence was able to emulate the available commands to the client.  

Burp suite’s invisible proxying feature was used to intercept outbound connections and their responses, allowing for communication to be edited both ways. Once the initial beacon was sent from the client, the server response to that beacon was edited to contain the emulated commands. The client then sent the output of those commands as a new request to the server, which was intercepted for analysis. Commands from the server used the following format when decrypted:

Figure 13: Command format
Figure 14: Burp suite interception
Figure 15: get_system_info command
Figure 16: Ping pong functionality

The inject_shell feature was validated and confirmed with a custom Windows message box injected into explorer.exe. Injected shellcode is encrypted with its own XOR key, which is provided in the injection command as a separate JSON value.

Figure 17: Shellcode injection
Figure 18: Shellcode injection continued

Other command options such as cryptominer deployment and MSSQL brute forcing were mentioned but did not include embedded brute forcing algorithms or instructions. Instead, they simply allowed the attacker to supply relevant options such as database, login credentials, port, and mssql_task (which included checks, batches, and actions), or a host process to start suspended and use for cryptomining via process hollowing.

Analysis shows primary objective is staged payload execution and evading detection

The analyzed samples demonstrate a multistage, polymorphic malware delivery chain designed to conceal its activity and load additional code. A file presented as a Netscape cookie file contains obfuscated commands and Base64 fragments that reconstruct multiple PowerShell scripts to attempt modification the AmsiScanBuffer function in memory before retrieving and executing additional content.  

The samples also use hidden PowerShell processes, string reconstruction, and nested encoding to obscure their functionality. Each of the cookies.txt files differ in their hashes, variable names, string-building methods, sleep intervals, and request parameters. The core loader and AMSI patching logic are substantially the same, with each variation altering just enough to avoid detection based on a single file hash or exact string.  

The scripts and binaries analyzed support that the primary objective intended is staged payload execution while evading detection with C2 capabilities and additional functionality as secondary post-exploitation objectives. The extensive effort into evading detection and tampering with Defender functionality will be monitored along with the final stage RAT for potential future builds and implementations.  

IOCs

File(s)

  • psag-agent.exe
    b9b717ee96019dc1614621852a01db1f4d6c12c754fab0ca20e86921f593d12f
  • Cookies.txt
    588aa7c40c2d6c51e684182cfc1a4027be56d73ce3a3821d669893dcbd32b602
  • Psag-native-<instance id>.log
    12ded0267696642eea8ef240b56d260def223a4485ea996c4e5ff718773d399f

Domains

  • hxxps://test[.]staticvpn[.]us/api/v1/deploy/REDACTED/qehF_3c_0Pdp?wire=agent&iid=/<instance id>&t<instance id>
  • https://test.staticvpn.us/api/v1/deploy/REDACTED?iid=<instance id>&t=<instance id>&inject=classic
  • https://test.staticvpn.us/api/v2/sync/
  • https://test.staticvpn.us/api/v2/sync/<instance id>
  • https://ntp.nexusvpn.cloud/api/v2/sync
  • https://ntp.nexusvpn.cloud/api/vs/sync/<instance id>

Commands

  • /c for /f "tokens=2* delims=|" %a in ('f^i^n^d^s^t^r /i /c:"|lssza4b6|" "c:\users\<USER>\downloads\cookies.txt"') do @cmd /c "%b"
  • "schtasks.exe" /Create /TN "PSAG<8 hex digits>" /TR "cmd /c exit 0" /SC ONLOGON /RU "admin" /IT /F
  • Powershell -nop -w hidden -c iex([system.text.encoding]::UTF8.GetString([system.Convert]::frombase64string(<next stage base64>)
  • $PsagRestartFlag = ‘C:\Windows\Temp\<unique .flg file>’
  • netsh.exe advfirewall firewall add rule name="PSAG-P-<port>" dir=in action=allow protocol=TCP localport=<port>
  • powershell.exe -NoProfile -ExecutionPolicy Bypass -File “$env:TEMP\psag-script-<agent-PID>.ps1"
  • sqlcmd.exe -S "<server>,<port>" -d "<database>" -U "<username>" -P "<password>" -C -b -V 1 -i "<temp>\psag-exec-<agent-PID>-<tick>.sql"

PSAG commands

Start your path to stronger defenses

Start your trial

Try ThreatLocker free for 30 days and experience full Zero Trust protection in your own environment.

Book a demo

Schedule a customized demo and explore how ThreatLocker aligns with your security goals.

Ask an expert

Just starting to explore our platform? Find out what ThreatLocker is, how it works, and how it’s different.