Blogs & Stories

SpiderLabs Blog

Attracting more than a half-million annual readers, this is the security community's go-to destination for technical breakdowns of the latest threats, critical vulnerability disclosures and cutting-edge research.

Petya Ransomware: A glimpse of the past, the present, and the future

Contributed by: Gerald Carsula, Rodel Mendez, and Nicholas Ramos

Ransomware seem to be the trend now and this type of malware will no doubt continue to grow. But do you still remember in the 90's when boot viruses were the norm? These malwares typically infect the boot sector of floppy and bootable drives just to display annoying things. How about 10-15 years ago when most worm malware used exploits to spread either thru SMB or DCERPC? What if you mix everything, the past and the present? You'll end up with Petya and the future.

In the last few days a destructive new Petya ransomware strain arose after earlier variants became notable last year which infected the MBR to display a ransom note. One noticeable behavior of previous Petya variants is that they only encrypted the MFT (Master File Table) to make the file system unreadable. In contrast, the new variant now also uses the typical ransomware file encryption. And in comparison to WannaCry, this new Petya does not just use the EternalBlue exploit for propagation, but also uses shared folders to spread through the network. It also uses legitimate tools like PSExec and WMI to execute Petya malware remotely. It is these features which allowed the malware to spread quickly in an internal network, regardless of whether systems were patched with the MS17-010 patch.

To further appreciate this new exciting malware, we took a deep dive into it to map out exactly what it is doing. Here is the overview of infection process.


Infection Vector

There were initial reports suggesting emails and documents related to the new Petya but based on data from our Spam Research Database there is no evidence of such. Others have suggested that the DLL (perfc.dat) was executed thru an exploited Ukrainian taxation software called MeDoc.

Technical Walkthrough

Even without the main loader from the MeDoc Software, one can execute the DLL by calling the lone exported function using the rundll32.exe with the equivalent ordinal number #1. (These ordinal numbers are a chronological representation of each exported API functions within each DLL).

C:\Windows\system32\rundll32.exe perfc.dat #1

Setting up Privileges

To make sure the malware can perform most of its malicious behaviors, it needs to check and adjust the required privileges of SeShutdownPrivilege, SeDebugPrivilege, and SeTcbPrivilege.


Note that the extent of the privilege that malware can attain will affect how it will perform other malicious behavior and how it can perform a system shutdown.

Detecting AV Process

Petya next performs a process enumeration, and, by using its own propriety algorithm, it computes the hash of each process name that is currently running. It compares each hash with the following hardcoded hash related to AV processes.

0x2E214B44 – AVP.exe

0x6403527E – ccSvcHst.exe

0x651B3005 – NS.exe

AV products

Infecting the MBR

If the malware has achieved a "SeDebugPrivilege" it will perform the following:

  1. It checks if the machines have already been infected. If the file path "C:\WINDOWS\perfc" already exists it will terminate the process. This could be a possible "kill-switch" to avoid further infection.Check_perc_file
  2. It infects the MBR thru \\.\PhsysicalDrive0 and writes the malicious code by chunk.Infected MBR2

Infected MBR2
Creates Scheduled Task

It creates a scheduled task to perform a System Shutdown an hour later. Just enough time to finish the propagation routine so as to infect other machines on the network.


Scans the Local Address

It scans the local network for possible targets.


Loads files from the Resource

From the resource section of the DLL, it will load RT_RCDATA #1 and drop it in the user's temp folder as {random}.tmp. At the same time, a thread will be triggered to create a new pipe which will allow for the *.tmp file to connect and send out information.

Currently, we are still investigating this *.tmp file as it behaves like a trimmed down Mimikatz by opening and reading the LSASS memory space.


Another file will be loaded from the resource (RT_RCDATA #3) and will be dropped as dllhost.dat in the windows directory. This file is a legitimate PSEXEC tool from Sysinternals.



There are multiples ways the malware tries to spread itself and one of them is through network shares by performing the following:

  1. Enumerate all available network shares using WNet* APIs.Enum_network
  2. It gathers credentials either a hostname or IP address from the Credential Store used by Remote Desktop. CredEnum
  3. Locate ADMIN$ shares in the local network and attempt copying of itself to those shared folder: Admin_shares
  4. Attempt to run a copy of itself in the remote host using PSEXEC (dropped as dllhost.dat in %windows%)
  5. Also, it attempts to execute a copy of itself in the remote host using WMIC.exeWMIC

Another way to spread is to perform an SMB attack using the EternalBlue exploit.


File Encryption

Petya ransomware performs the following to encrypt the files:

  1. It retrieves all fixed logical drives
  2. A new thread will be created for each drive that will do the following:
    1. Gets a CSP – Microsoft Enhanced RSA and AES Cryptographic Provider
    2. Generates a customized key
    3. Traverse all directories and encrypt files which meets the following criteria:
      • If it is not a Directory or a Symbolic Link
      • If the files are not within the C:\WINDOWS directory
      • If has the following file extensions:





    4. Creates a ransom note file.


Covering the tracks

To cover its tracks and make it hard for forensics, Petya will execute the following:

  1. WEVTUTIL to delete the following event logs:
    1. Setup
    2. System
    3. Security
    4. Application
  2. FSUTIL to delete USN journal which keeps track of the changes within the disk volume.



Whether this is Petya or NotPetya, here in Trustwave SpiderLabs we believe that this malware is tailor-made to avoid a bunch of current security protections. It has used a DLL where the codes are within the export function which helps avoid it being executed in a sandbox. It infects the ever vulnerable MBR. It has several methods to spread without user-triggered events, and even tries to execute itself remotely using non-malicious software. It even covers it tracks to avoid forensics experts digging deep into how the system is being infected. We must admit that this malware has done a pretty good job knitting things together from the past to perhaps create an insight of what's ahead.

Recent SpiderLabs Blog Posts