By Kris Merritt (Vector8) and Justin Swisher (Anomali)

Since the outbreak of Petya some days ago many articles have been written dissecting the malware, its purpose, and its attribution. These articles used reverse engineering and malware analysis to conduct post incident analysis. Vector8 and Anomali viewed the Petya outbreak differently, leveraging threat hunting techniques developed to identify and pattern malicious behavior evident in malware like Petya.

Specifically, our data source for analysis is a Microsoft Windows Sysinternals tool called Sysmon. In short, Sysmon provides an authoritative source of what’s happening on a computer by linking all observable activity on that system back to the responsible process(es). This is a boon for real-time threat hunting as well as forensic analysis; the conventional follow-on data collection to obtain such details is no longer required. In other words, Sysmon has high resolution and animation (see descriptions of these terms). Read this blog post for further information regarding Sysmon as a detection, hunting, and analysis tool.

By sending Sysmon events to an aggregation point for further querying and historical analysis, our analysis of Petya was limited only by speed of thought, not tooling or data gaps. In this case, the aggregation point is Elastic’s open source “Elastic Stack,” which consists of a Logstash aggregator, Elasticsearch cluster backend, and Kibana web user interface frontend.

Our test environment was a fresh Windows 10 install on a Virtual Machine, preloaded with Sysmon v6, a custom configuration, and a logger that feeds events to Vector8’s analysis platform (Sysmon + Elastic Stack). We copied over a confirmed sample of the Petya malware (027cc450ef5f8c5f653329641ec1fed91f694e0d229928963b30f6b0d7d3a745) to the machine. Next, we manually ran the malicious DLL via rundll32.exe on the command line with the flag “#1” to activate the malware.



Command line execution of the Petya malware

The following events are recorded by Sysmon and forwarded to the Vector8 cloud platform for analysis. This details how the malware behaves and provides insights into how to detect or prevent similar malware from executing in the future.

The first thing that happens is that Rundll32.exe (the parent process) writes a copy of the DLL to ‘C:Windows’. This activity is unusual, but not necessarily malicious on its own. Sysmon event ID 11 (File Created) Image: C:WindowsSysWoW64 undll32.exe TargetFilename: C:Windowscc450ef5f8c5f653329641ec1fed91f694e0d229928963b30f6b0d7d3a745 Rundll32.exe then accesses raw disk several times, presumably to modify the MBR. Accessing raw disk is abnormal, as it bypasses the filesystem structure to access the disk sectors directly. This level of disk access is not normal operations and is very suspicious, especially by Rundll32. Sysmon event ID 9 (Raw Disk Access Read) Image: C:WindowsSysWOW64 undll32.exe Device: DeviceHarddisk0DR0

1 access to the current working volume (DeviceHarddiskVolume2) and 24 accesses to DeviceHarddisk0DR0 Rundll32.exe schedules a task to force reboot of the system 60 minutes from time of execution. Rundll32 creating a scheduled task is a suspicious pattern that should trigger a hunter to investigate. Sysmon event ID 1 (Process Created) CommandLine: /c schtasks /Create /SC once /TN "" /TR "C:Windowssystem32shutdown.exe /r /f" /ST 16:06 ParentCommandLine: rundll32.exe 027cc450ef5f8c5f653329641ec1fed91f694e0d229928963b30f6b0d7d3a745.dll,#1 Rundll32.exe writes a .tmp file in the user’s LocalTemp directory. Temp files created in this directory would not normally cause alarm, unless linked to another more suspicious event. Sysmon event ID 11 (File Created) Image: C:WindowsSysWoW64 undll32.exe TargetFilename: C:Users anooAppDataLocalTemp.95.tmp Rundll32.exe kicks off the .tmp file it wrote earlier and directs it to a named pipe. As referenced above, since this .tmp file is now communicating with another process over a named pipe, a hunter would want to investigate the .tmp file as this is unusual behavior as well. Sysmon event ID 1 (Process Created) Image: C:Users anooAppDataLocalTemp.95.tmp CommandLine: "C:Users anooAppDataLocalTemp.95.tmp" \.pipe{77A05906-5A7D-4442-8140-0899A3C4423C

When 5695.tmp runs (Sysmon event ID 1), we get its hash (02EF73BD2458627ED7B397EC26EE2DE2E92C71A0E7588F78734761D8EDBDCD9F), which open source research and VirusTotal results purport to be mimikatz

Sysmon pipe events show the pipe creation by rundll32.exe and access by 5695.tmp Sysmon event ID 17 (Pipe Created) Image: C:WindowsSysWoW64 undll32.exe PipeName: {77A05906-5A7D-4442-8140-0899A3C4423C} Sysmon event ID 18 (Pipe Connected) Image: C:Users anooAppDataLocalTemp.95.tmp PipeName: {77A05906-5A7D-4442-8140-0899A3C4423C}

Rundll32.exe writes a file called dllhost.dat to C:Windows, which is a very suspicious event as dat files are not normally written to that directory. Sysmon event ID 11 (File Created) Image: C:WindowsSysWoW64 undll32.exe TargetFilename: C:Windowsdllhost.dat

Open source research corroborates this file write and has concluded it is a legitimately signed psexec

Since dllhost.dat wasn’t executed in our sampling (due to our VM not meeting malware checks), we don’t get this file’s hash The tmp file accesses another running process, lsass.exe. This event could be a solid candidate for a hunting trigger as it could be indicative of credential harvesting or some other abuse of Windows’ security authority service (lsass.exe). It is not unusual for lsass.exe to be accessed, but a .tmp file doing so is highly unusual. Sysmon event ID 10 (Process Accessed) SourceImage: C:Users anooAppDataLocalTemp.95.tmp TargetImage: C:Windowssystem32lsass.exe CallTrace: C:WindowsSYSTEM32 tdll.dll+a5314|C:WindowsSystem32KERNELBASE.dll+290ad|C:Users anooAppDataLocalTemp.95.tmp+3390|C:Users anooAppDataLocalTemp.95.tmp+369a|C:Users anooAppDataLocalTemp.95.tmp+25e9|C:Users anooAppDataLocalTemp.95.tmp+4577|C:WindowsSystem32KERNEL32.DLL+8364|C:WindowsSYSTEM32 tdll.dll+65e91

Lsass.exe then accesses the malicious rundll32.exe Sysmon event ID 10 (Process Accessed) SourceImage: C:Windowssystem32lsass.exe TargetImage: C:WindowsSysWoW64 undll32.exe CallTrace: C:WindowsSYSTEM32 tdll.dll+a5ea4|C:WindowsSystem32RPCRT4.dll+6576f|C:Windowssystem32lsasrv.dll+ceed|C:WindowsSYSTEM32SspiSrv.dll+11a2|C:WindowsSystem32RPCRT4.dll+77d63|C:WindowsSystem32RPCRT4.dll+3450f|C:WindowsSystem32RPCRT4.dll+3739a|C:WindowsSystem32RPCRT4.dll+4a2b4|C:WindowsSystem32RPCRT4.dll+491cd|C:WindowsSystem32RPCRT4.dll+49a7b|C:WindowsSystem32RPCRT4.dll+29c1c|C:WindowsSystem32RPCRT4.dll+2a09c|C:WindowsSystem32RPCRT4.dll+4438c|C:WindowsSystem32RPCRT4.dll+45beb|C:WindowsSystem32RPCRT4.dll+386ea|C:WindowsSYSTEM32 tdll.dll+325fe|C:WindowsSYSTEM32 tdll.dll+330d9|C:WindowsSystem32KERNEL32.DLL+8364|C:WindowsSYSTEM32 tdll.dll+65e91





Activity related to the execution of the Petya malware from 27 June 2017, as seen in Kibana

Petya Execution Timeline See an in depth view of Petya's execution timeline with this infographic. VIEW NOW

The result of this type of analysis provides some crucial insights into the behaviors this malware exhibits. These behaviors can be examined and turned into defensive measures such as hunting triggers or even preventative measures through endpoint tools, network tools, or system policies.

For this example, there are a number of behavior patterns we can key on:

​ Process writes a .tmp file, and that .tmp file is later run as a process

Process writes a .tmp file, and that .tmp file is later run as a process ​ A .tmp file accesses lsass.exe

A .tmp file accesses lsass.exe ​ A schtasks.exe process command line includes the “shutdown” switch

A schtasks.exe process command line includes the “shutdown” switch ​ Rundll32.exe writes files

Rundll32.exe writes files ​ The string "pipe" is found in a process’ command line

The string "pipe" is found in a process’ command line ​ A .dat file is written to c:windows

A .dat file is written to c:windows ​ Raw access reads to DR0 volume

Note that these patterns are all based on endpoint process metadata, like Sysmon output. It’s also important to point out that the fidelity of each of these patterns depends on what is normal in your environment.

Threat hunting can be used as a powerful tool not only to detect malicious behavior missed by other security measures but also drive a deeper understanding of how malicious software, actor tools, and behaviors work and how to proactively detect or prevent them.

Anomali partners with Vector8 to provide threat hunting services. To find out more about this service, see our Professional Services page.

This is a joint blog between Anomali and Vector8. Vector8 provides threat hunting services leveraging tools, techniques, and expertise introduced in this blog. For more information on Vector8, visit them at https://www.vector8.io/