Research

A Deep Dive Into ALPHV/BlackCat Ransomware

Executive summary

ALPHV/BlackCat is the first widely known ransomware written in Rust. The malware must run with an access token consisting of a 32-byte value (–access-token parameter), and other parameters can be specified. The ransomware comes with an encrypted configuration that contains a list of services/processes to be stopped, a list of whitelisted directories/files/file extensions, and a list of stolen credentials from the victim environment. It deletes all Volume Shadow Copies, performs privilege escalation using the CMSTPLUA COM interface, and enables “remote to local” and “remote to remote” symbolic links on the victim’s
machine.

The files are encrypted using the AES algorithm, with the AES key being encrypted using the RSA public key contained in the configuration. The extension of the encrypted files is changed to uhwuvzu by the malware.

Analysis and findings

SHA256: 847fb7609f53ed334d5affbb07256c21cb5e6f68b1cc14004f5502d714d2a456

The malware can run with one of the following parameters:

blackcat-fig-1

Figure 1
Whether the ransomware is running with no parameters or with an invalid access token, an error message is displayed:

blackcat-fig-2
Figure 2
By performing the dynamic analysis, we’ve found that the access token must be a 32-byte value that is not unique.

The binary registers a new top-level exception handler via a function call to SetUnhandledExceptionFilter:

blackcat-fig-3
Figure 3
The AddVectoredExceptionHandler API is utilized to register a vectored exception handler:

blackcat-fig-4
Figure 4
The executable retrieves the command-line string for the process using the GetCommandLineW function:

blackcat-fig-5
Figure 5
BlackCat opens the “SOFTWARE\Microsoft\Cryptography” registry key by calling the RegOpenKeyExW routine (0x80000002 = HKEY_LOCAL_MACHINE, 0x20019 = KEY_READ):

blackcat-fig-6
Figure 6
The binary extracts the MachineGUID value from the registry:

blackcat-fig-7
Figure 7
The malicious process searches for cmd.exe in the current directory and then in the System32 directory via a function call to CreateFileW (0x7 = FILE_SHARE_DELETE | FILE_SHARE_WRITE | FILE_SHARE_READ, 0x3 = OPEN_EXISTING, 0x2000000 = FILE_FLAG_BACKUP_SEMANTICS):

blackcat-fig-13
Figure 8
The executable generates 16 random bytes by calling the BCryptGenRandom API (0x2 = BCRYPT_USE_SYSTEM_PREFERRED_RNG):

blackcat-fig-9
Figure 9
A named pipe whose name contains the current process ID and random bytes generated above is created using CreateNamedPipeW (0x40080001 = FILE_FLAG_OVERLAPPED | FILE_FLAG_FIRST_PIPE_INSTANCE | PIPE_ACCESS_INBOUND, 0x8 = PIPE_REJECT_REMOTE_CLIENTS):

blackcat-fig-10
Figure 10
The process opens the named pipe for writing using the CreateFileW routine (0x40000000 = GENERIC_WRITE, 0x3 = OPEN_EXISTING):

blackcat-fig-11
Figure 11
The ransomware creates a read and a write named pipe, respectively.

The wmic process is used to extract the UUID (0x08000400 = CREATE_NO_WINDOW | CREATE_UNICODE_ENVIRONMENT):

blackcat-fig-12
Figure 12
The CreateEventW API is utilized to create two unnamed event objects:

blackcat-fig-13 (1)
Figure 13
The binary waits until the event objects are in the signaled state by calling WaitForMultipleObjects:

blackcat-fig-14
Figure 14
The output of the above process is read from the named pipe using the ReadFile routine:

blackcat-fig-15
Figure 15
The malware creates multiple threads by calling the CreateThread function (0x00010000 = STACK_SIZE_PARAM_IS_A_RESERVATION):

blackcat-fig-16
Figure 16
The content of the ransom note and the text that will appear on the Desktop Wallpaper are decrypted by the ransomware:

blackcat-fig-17
Figure 17

blackcat-fig-18

Figure 18
The malicious binary obtains information about the current system via a function call to GetSystemInfo:

blackcat-fig-19
Figure 19
There is a call to SHTestTokenMembership that verifies whether the user token is a member of the Administrators group in the built-in domain (0x220 = DOMAIN_ALIAS_RID_ADMINS):

blackcat-fig-20
Figure 20
The process opens the access token associated with the current process (0x80000000 = GENERIC_READ):

blackcat-fig-21
Figure 21
BlackCat extracts a TOKEN_GROUPS structure containing the group accounts associated with the above token using the NtQueryInformationToken function (0x2 = TokenGroups):

blackcat-fig-22
Figure 22
The OpenProcess API is utilized to open a local process object (0x438 = PROCESS_QUERY_INFORMATION | PROCESS_VM_WRITE | PROCESS_VM_READ | PROCESS_VM_OPERATION):

blackcat-fig-27
Figure 23
The malicious binary retrieves a pointer to a PEB structure using the ZwQueryInformationProcess routine (0x0 = ProcessBasicInformation):

blackcat-fig-26
Figure 24
The executable retrieves a pointer to a PEB_LDR_DATA structure containing information about the loaded modules in the process and then to the head of a doubly linked list that contains the loaded modules:

blackcat-fig-25
Figure 25

blackcat-fig-24

Figure 26
The path of the image file for the current process is retrieved using ReadProcessMemory:

blackcat-fig-23
Figure 27

Privilege escalation via UAC bypass using CMSTPLUA COM interface

The ransomware initializes the COM library for use by the current thread via a call to CoInitializeEx (0x2 = COINIT_APARTMENTTHREADED):

blackcat-fig-28
Figure 28
BlackCat ransomware uses the auto-elevated CMSTPLUA interface {3E5FC7F9-9A51-4367-9063-A120244FBEC7} in order to escalate privileges:

blackcat-fig-34
Figure 29
The initial executable is spawned with administrative privileges:

blackcat-fig-30
Figure 30
The LookupPrivilegeValueW routine is utilized to retrieve the locally unique identifier that represents the following privileges:

  • SeIncreaseQuotaPrivilege SeSecurityPrivilege SeTakeOwnershipPrivilege
  • SeLoadDriverPrivilege SeSystemProfilePrivilege SeSystemtimePrivilege
  • SeProfileSingleProcessPrivilege SeIncreaseBasePriorityPrivilege
  • SeCreatePagefilePrivilege SeBackupPrivilege SeRestorePrivilege
  • SeShutdownPrivilege SeDebugPrivilege SeSystemEnvironmentPrivilege
  • SeChangeNotifyPrivilege SeRemoteShutdownPrivilege SeUndockPrivilege
  • SeManageVolumePrivilege SeImpersonatePrivilege SeCreateGlobalPrivilege
  • SeIncreaseWorkingSetPrivilege SeTimeZonePrivilege
  • SeCreateSymbolicLinkPrivilege SeDelegateSessionUserImpersonatePrivilege

blackcat-fig-31

Figure 31
All the above privileges are enabled in the access token using AdjustTokenPrivileges:

blackcat-fig-32
Figure 32
The binary creates the following processes that enable “remote to local” and “remote to remote” symbolic links on the local machine:

blackcat-fig-33
Figure 33

blackcat-fig-34 (1)

Figure 34
The malware tries to stop the Internet Information service (IIS) using IISReset.exe:

blackcat-fig-35
Figure 35
The ransomware deletes all volume shadow copies using the vssadmin.exe utility:

blackcat-fig-36
Figure 36
There is also a second process that is responsible for deleting all volume shadow copies with wmic:

blackcat-fig-37
Figure 37
Interestingly, the malware runs the following command that is incomplete and returns an error:

blackcat-fig-38
Figure 38

blackcat-fig-39

Figure 39
The binary disables Automatic Repair using the bcdedit tool:

blackcat-fig-40

Figure 40
The ransomware tries to clear all event logs, however, the command is incorrect and returns an error, as highlighted below:

blackcat-fig-41

Figure 41

blackcat-fig-42

Figure 42

Killing targeted services

The binary opens the service control manager database via a function call to OpenSCManagerW (0xF003F = SC_MANAGER_ALL_ACCESS):

blackcat-fig-43

Figure 43
The process obtains a list of active services using EnumServicesStatusExW (0x30 = SERVICE_WIN32, 0x1 = SERVICE_ACTIVE):

blackcat-fig-44

Figure 44
The malware targets the list of services from the kill_services element in the BlackCat configuration.

A targeted service is opened by calling the OpenServiceW routine (0x2c = SERVICE_STOP | SERVICE_ENUMERATE_DEPENDENTS | SERVICE_QUERY_STATUS):

blackcat-fig-45

Figure 45
EnumDependentServicesW is utilized to retrieve the active services that depend on the targeted service (0x1 = SERVICE_ACTIVE):

blackcat-fig-46

Figure 46
BlackCat stops the targeted service using the ControlService function (0x1 = SERVICE_CONTROL_STOP):

blackcat-fig-47

Figure 47

Killing targeted processes

The executable takes a snapshot of all processes and threads in the system (0xF = TH32CS_SNAPALL):

blackcat-fig-48

Figure 48
The processes are enumerated using the Process32FirstW and Process32NextW APIs:

blackcat-fig-49

Figure 49

blackcat-fig-50

Figure 50
The malware targets the list of processes from the kill_processes element in the BlackCat configuration.

It opens a targeted process using OpenProcess (0x1 = PROCESS_TERMINATE):

blackcat-fig-51

Figure 51
The ransomware terminates the targeted process by calling the TerminateProcess API:

blackcat-fig-52

Figure 52
The binary spawns multiple child processes by adding the “–child” parameter to the command line (see figure 53). The new processes run in the security context of credentials that were specified in the credentials entry from the BlackCat configuration.

blackcat-fig-53

Figure 53
The number of network requests the Server Service can make is set to the maximum by modifying “HKLM\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters\MaxMpxCt” Registry value:

blackcat-fig-54

Figure 54
The malicious process obtains the ARP table using the arp command, as shown below:

blackcat-fig-55

Figure 55
The net use command is utilized to connect to the local computer using different credentials stored in the BlackCat configuration:

blackcat-fig-56

Figure 56
The malware retrieves the currently available disk drives by calling the GetLogicalDrives routine:

blackcat-fig-57

Figure 57
The GetDriveTypeW API is utilized to obtain the drive type:

blackcat-fig-58

Figure 58
The ransomware starts scanning the volumes on the local machine using FindFirstVolumeW:

blackcat-fig-59

Figure 59
The list of drive letters and mounted folder paths for the above volume is extracted by the malware:

blackcat-fig-60

Figure 60
The volume’s enumeration continues by calling the FindNextVolumeW function:

blackcat-fig-61

Figure 61
All unmounted volumes are mounted via a function call to SetVolumeMountPointW:

blackcat-fig-62

Figure 62
BlackCat traverses the file system using the FindFirstFileW and FindNextFileW APIs:

blackcat-fig-63

Figure 63

blackcat-fig-64

Figure 64

The BlackCat configuration is stored in JSON form and is decrypted at runtime. It contains:

  • the extension appended to the encrypted files
  • RSA public key that is used to encrypt the AES encryption key
  • ransom note name and content
  • stolen credentials specific to the victim’s environment
  • encryption cipher: AES
  • list of services and processes to be killed
  • list of folders, files, and extensions to be skipped
  • boolean values that indicate network discovery, lateral movement, setting the Desktop Wallpaper, killing VMware ESXi virtual machines, removing VMware ESXi virtual machine snapshots, excluding VMware ESXi virtual machines from termination

blackcat-fig-65

Figure 65

Files encryption

The CreateFileW API is used to open a targeted file (0xC0000000 = GENERIC_READ | GENERIC_WRITE, 0x7 = FILE_SHARE_DELETE | FILE_SHARE_WRITE | FILE_SHARE_READ, 0x3 = OPEN_EXISTING):

blackcat-fig-66

Figure 66
The ransom note is created in every traversed directory (0x40000000 = GENERIC_WRITE, 0x7 = FILE_SHARE_DELETE | FILE_SHARE_WRITE | FILE_SHARE_READ, 0x2 = CREATE_ALWAYS):

blackcat-fig-67

Figure 67
The ransom note is populated using the WriteFile routine:

blackcat-fig-68

Figure 68

blackcat-fig-69

Figure 69
The file’s extension is changed using the MoveFileExW function. The renamed file is opened using CreateFileW (0x7 = FILE_SHARE_DELETE | FILE_SHARE_WRITE | FILE_SHARE_READ, 0x3 = OPEN_EXISTING, 0x02000000 = FILE_FLAG_BACKUP_SEMANTICS):

blackcat-fig-70

Figure 70
Interestingly, BlackCat creates intermediary files called “checkpoints-<encrypted file name>” during the encryption process:

blackcat-fig-71

Figure 71
The malware generates 16 random bytes that will be used to derive the AES key:

blackcat-fig-72

Figure 72
The ransomware moves the file pointer to the beginning of the file by calling the SetFilePointerEx API (0x0 = FILE_BEGIN):

blackcat-fig-73

Figure 73
The process reads 4 bytes from the beginning of the file using ReadFile:

blackcat-fig-74

Figure 74
A JSON form containing the encryption cipher (AES), the AES key used to encrypt the file, the data, and the chunk size, is constructed in the process memory:

blackcat-fig-75

Figure 75
The binary generates 0x50 (80) random bytes that are used to border the JSON form. The resulting buffer has a size of 256 bytes and is rotated using instructions such as pshuflw:

blackcat-fig-76

Figure 76

blackcat-fig-77

Figure 77
A 4-byte border “19 47 B2 CE” that separates the encrypted file content from the encrypted AES key is written to the file:

blackcat-fig-78

Figure 78
The buffer that contains the AES key presented in figure 77 is encrypted with the RSA public key from the BlackCat configuration. The result is written to the file using WriteFile:

blackcat-fig-79

Figure 79
The size of encrypted key (0x100) is written to the file:

blackcat-fig-80

Figure 80
The file content is read by using the ReadFile function:

blackcat-fig-81

Figure 81
The file content is encrypted using the AES-128 algorithm. The malware uses the aesenc and aesenclast instructions for this purpose:

blackcat-fig-82

Figure 82

blackcat-fig-83

Figure 83
The encrypted file content is written back to the file using WriteFile:

blackcat-fig-84

Figure 84
An example of an encrypted file is displayed below:

blackcat-fig-90

Figure 85
The ransomware creates a PNG image called “RECOVER-uhwuvzu-FILES.txt.png”:

blackcat-fig-89

Figure 86

blackcat-fig-88

Figure 87

The Desktop wallpaper is changed to the above image by calling the SystemParametersInfoW API (0x14 = SPI_SETDESKWALLPAPER, 0x3 = SPIF_UPDATEINIFILE | SPIF_SENDCHANGE):

blackcat-fig-88

Figure 88

Running with the –verbose parameter

The ransomware writes multiple actions to the command line output:

blackcat-fig-86

Figure 89

Running with the –extra-verbose –ui parameters

The malware presents the relevant information in the following window:

blackcat-fig-85

Figure 90

Indicators of Compromise

Pipe

\\.\pipe\__rust_anonymous_pipe1__.<Process ID>.<Random number>

BlackCat Ransom Note

RECOVER-uhwuvzu-FILES.txt

Files created

checkpoints-<Filename>.uhwuvzu

RECOVER-uhwuvzu-FILES.txt.png

Processes spawned

cmd.exe /c “wmic csproduct get UUID”

cmd.exe /c “fsutil behavior set SymlinkEvaluation R2L:1”

cmd.exe /c “fsutil behavior set SymlinkEvaluation R2R:1”

cmd.exe /c “iisreset.exe /stop”

cmd.exe /c “vssadmin.exe Delete Shadows /all /quiet”

cmd.exe /c “wmic.exe Shadowcopy Delete”

cmd.exe /c “bcdedit /set {default}”

cmd.exe /c “bcdedit /set {default} recoveryenabled No”

cmd.exe /c for /F “tokens=*” %1 in (‘wevtutil.exe el’) DO wevtutil.exe cl %1

cmd.exe
/c “reg add
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters
/v MaxMpxCt /d 65535 /t REG_DWORD /f”

cmd.exe /c “arp -a”