CyberDefenders Phobos lab writeup

Overview#

PlatformCyberDefenders
CategoryMalware Analysis
DifficultyInsane
FocusAES config, CRC32 self-check, persistence, process killing
Lab LinkPhobos

Phobos has been around since late 2018 and gets sold to lots of affiliates, so samples show up everywhere. The interesting part of this one is the config: every string the malware cares about (version, kill list, shell commands) sits in one AES-encrypted blob and gets decrypted by index when it’s needed. Find that function, break on it, and a lot of the questions below are just reading EAX.

Tools: IDA Pro, x32dbg, DIE.

Q1: hashing algorithm#

What is the hashing algorithm used by the malware?

sub_4085D9:

int __usercall sub_4085D9@<eax>(int a1@<eax>, _BYTE *a2@<ecx>, int a3)
{
  unsigned int v3; // eax
  v3 = ~a1;
  while ( a3 )
  {
    --a3;
    v3 = lookup_table[(unsigned __int8)(v3 ^ *a2++)] ^ (v3 >> 8);
  }
  return ~v3;
}

Invert the seed, index a 256-entry table (at 0x40B000) with the low byte XOR the input, shift right by 8, invert at the end. That’s table-driven CRC32. To be sure, compare the table with the standard one for polynomial 0xEDB88320, which starts 00000000 77073096 EE0E612C.

CRC32 Hash Function
CRC32 with its lookup table

Answer: CRC32

Q2: .cdata checksum#

Could you provide the hard-coded value of the .cdata checksum?

Xrefs to the CRC function lead to this early in startup:

if ( CRC32_hash(0, v0, dword_40B40C) != dword_40B430 )
    return;

It hashes its own .cdata section, where the encrypted config lives, and quits if the result doesn’t match the stored value. Patch anything in there and it just exits.

.data:0040B430 dword_40B430    dd 0D55F8833h    ; DATA XREF: real_Start+62↑r

Answer: 0xD55F8833

Q3: version#

What is the malware’s version?

Two functions handle the config:

FunctionAddressDoes
sub_4062A60x004062A6sets up the config struct
sub_4063470x00406347decrypts one entry by index

No need to reverse the AES setup. Break on sub_406347 and read the index at [esp+4], break on its return at 0x00406431 and read EAX. Every config string goes through there.

Config Decrypt Breakpoint
Breakpoint on the config decrypt function
Stack Config Index
Index 0x33 (51) on the stack

Index 0x33 comes back as the version string:

Version String in EAX
EAX: "[<<ID>>-2822] v2.9.1"
[<<ID>>-2822] v2.9.1

<<ID>> gets replaced with the victim ID at runtime, and 2822 is most likely the affiliate/build number. The version is the last part.

Answer: v2.9.1

Q4: masqueraded DLL#

The malware masquerades as a legitimate Windows DLL. Which DLL does it impersonate?

DIE, version info resource:

Suspicious DLL Name
Version info claims ole32.dll

The version info says it’s ole32.dll. It’s a plain EXE, so the name is just there so it looks harmless to someone skimming file properties or a process list.

Answer: ole32.dll

Q5: first API call#

Could you provide the first API function that is called by the malware?

From the entry point sub_402FA7 into the main routine sub_4029F5. The first thing it does is check whether it’s running elevated. If not, it calls sub_40489E, which relaunches itself:

BOOL sub_40489E()
{
  // ...
  StartupInfo.cb = 68;
  v5 = CreateProcessW(0, v0, 0, 0, 0, 0, 0, 0, &StartupInfo, &ProcessInformation);
  // ...
}
CreateProcessW Function
CreateProcessW at 0x0040490E inside sub_40489E
Restart Caller
sub_40489E called from sub_4029F5 at 0x00402C74
sub_402FA7 (entry)
  -> sub_4029F5 (main)
     -> elevated? no
        -> sub_40489E (relaunch)
           -> CreateProcessW

Answer: CreateProcessW

Q6: process list decryption call#

Could you provide the address at which the process list decryption function is called?

Ransomware kills database, mail and Office processes first so their files aren’t locked when it encrypts. That happens in sub_4022EE, which runs as its own thread:

int __stdcall sub_4022EE(LPVOID lpThreadParameter)
{
  v5 = (__int16 *)sub_406347(10, 0);   // config index 10: kill list
  // ...
  while ( !sub_405962() )
  {
    sub_404DEE(lpMem);                  // kill whatever matches
    Sleep(0x1F4u);
  }
}

It asks the config function for index 10:

.text:004022F9  push    0Ah
.text:004022FB  call    sub_406347

The return value is the kill list:

Process List Decrypted
msftesql.exe, sqlagent.exe, sqlbrowser.exe...
GroupProcesses
SQLmsftesql, sqlagent, sqlservr, mysql
Oracleoracle, ocssd, dbsnmp
Officeexcel, outlook, powerpnt, onenote
Mailthunderbird, thebat
Backupsqbcoreservice

It re-checks every 500 ms, so restarting the database doesn’t help.

Answer: 0x004022FB

Q7: first security command#

What’s the first command the malware uses to turn off a critical security measure?

Same breakpoint on the config function, keep running and watch EAX. One entry comes back as a little batch script:

Firewall Disable Command
Firewall disable commands in EAX
netsh advfirewall set currentprofile state off
netsh firewall set opmode mode=disable
exit

The first line is the Vista+ syntax, the second is the old XP one, so it covers both.

Answer: netsh advfirewall set currentprofile state off

Q8: persistence function#

Could you provide the address of the function used by the malware for persistence?

Xrefs to RegSetValueExW:

RegSetValueExW Xref
Xrefs to RegSetValueExW

That’s sub_403A93, a registry write wrapper. Its caller is sub_401236:

WriteRegistry Xref
sub_403A93 called from sub_401236
Persistence Function
sub_401236 writing the Run keys

sub_401236 copies the binary somewhere new, marks the copy hidden (attribute 0x2), and points both Run keys at it:

KeyNeeds admin
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Runyes
HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Runno

If it isn’t elevated the HKLM write fails and HKCU still works.

Answer: 0x00401236

Q9: C2 protocol#

What protocol is used by the malware for C2 communication?

The imports answer this:

WinHTTP Imports
WinHttpOpen, WinHttpConnect, WinHttpSendRequest...

WinHttpOpen, WinHttpConnect, WinHttpOpenRequest, WinHttpSendRequest, WinHttpReceiveResponse. WinHTTP, so HTTP.

Answer: HTTP

Q10: drive watcher thread#

Could you provide the address of the thread used to check continuously for new disk connections?

Main spawns several threads:

Thread Creation
Threads spawned from main, including sub_401CC5

sub_401CC5 is the one polling drives:

Drive Monitor Thread
GetLogicalDrives loop
while ( !sub_405962() )
{
    v3 = GetLogicalDrives();
    if ( v3 != LogicalDrives )
    {
        v4 = v3 & ~LogicalDrives;     // bits that just appeared
        // ... encrypt the new drives
    }
    Sleep(0x3E8u);                    // 1000 ms
}

GetLogicalDrives returns a bitmask, bit 0 is A:, bit 2 is C:. new & ~old leaves only the drives that just showed up. Plug in a USB stick or map a share while it’s running and it gets hit within a second.

Answer: 0x00401CC5

Q11: file size threshold#

The file size is compared to a specific value. Could you provide this value?

Xrefs to GetFileSizeEx lead to sub_408EBE:

GetFileSizeEx Xref
GetFileSizeEx called from sub_408EBE
File Size Comparison
v10.QuadPart < 0x180000
v7 = (a5 & 1) != 0 || v10.QuadPart < 0x180000uLL
   ? sub_408782(...)    // whole file
   : sub_408C42(...);   // partial

0x180000 = 1572864 bytes = 1.5 MB. Smaller files get encrypted whole. Bigger ones only get parts encrypted, which is much faster, and a database with chunks of it encrypted is just as broken.

Answer: 1572864

Answers#

QAnswer
1CRC32
20xD55F8833
3v2.9.1
4ole32.dll
5CreateProcessW
60x004022FB
7netsh advfirewall set currentprofile state off
80x00401236
9HTTP
100x00401CC5
111572864