Anomali Detect

September 20 - 22, 2017

How Threat Hunting Can Help Defend Against Malware Attacks

July 19, 2017 | Justin Swisher

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.

Sysmon analysis
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.

  1. 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:\Windows\SysWoW64\rundll32.exe
      
      TargetFilename: C:\Windows\027cc450ef5f8c5f653329641ec1fed91f694e0d229928963b30f6b0d7d3a745
  2. 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:\Windows\SysWOW64\rundll32.exe
      
      Device: \Device\Harddisk0\DR0
    • 1 access to the current working volume (\Device\HarddiskVolume2) and 24 accesses to \Device\Harddisk0\DR0
  3. 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:\Windows\system32\shutdown.exe /r /f" /ST 16:06
      
      ParentCommandLine: rundll32.exe 027cc450ef5f8c5f653329641ec1fed91f694e0d229928963b30f6b0d7d3a745.dll,#1
  4. Rundll32.exe writes a .tmp file in the user’s Local\Temp 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:\Windows\SysWoW64\rundll32.exe
      
      TargetFilename: C:\Users\tanoo\AppData\Local\Temp\5695.tmp
  5. 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\tanoo\AppData\Local\Temp\5695.tmp
      
      CommandLine: "C:\Users\tanoo\AppData\Local\Temp\5695.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:\Windows\SysWoW64\rundll32.exe
        
        PipeName: \{77A05906-5A7D-4442-8140-0899A3C4423C}
      • Sysmon event ID 18 (Pipe Connected)
        Image: C:\Users\tanoo\AppData\Local\Temp\5695.tmp
        
        PipeName: \{77A05906-5A7D-4442-8140-0899A3C4423C}
  6. 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:\Windows\SysWoW64\rundll32.exe
      
      TargetFilename: C:\Windows\dllhost.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
  7. 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\tanoo\AppData\Local\Temp\5695.tmp
      
      TargetImage: C:\Windows\system32\lsass.exe
      
      CallTrace: C:\Windows\SYSTEM32\ntdll.dll+a5314|C:\Windows\System32\KERNELBASE.dll+290ad|C:\Users\tanoo\AppData\Local\Temp\5695.tmp+3390|C:\Users\tanoo\AppData\Local\Temp\5695.tmp+369a|C:\Users\tanoo\AppData\Local\Temp\5695.tmp+25e9|C:\Users\tanoo\AppData\Local\Temp\5695.tmp+4577|C:\Windows\System32\KERNEL32.DLL+8364|C:\Windows\SYSTEM32\ntdll.dll+65e91
    • Lsass.exe then accesses the malicious rundll32.exe
      • Sysmon event ID 10 (Process Accessed)
        SourceImage: C:\Windows\system32\lsass.exe
        
        TargetImage: C:\Windows\SysWoW64\rundll32.exe
        
        CallTrace: C:\Windows\SYSTEM32\ntdll.dll+a5ea4|C:\Windows\System32\RPCRT4.dll+6576f|C:\Windows\system32\lsasrv.dll+ceed|C:\Windows\SYSTEM32\SspiSrv.dll+11a2|C:\Windows\System32\RPCRT4.dll+77d63|C:\Windows\System32\RPCRT4.dll+3450f|C:\Windows\System32\RPCRT4.dll+3739a|C:\Windows\System32\RPCRT4.dll+4a2b4|C:\Windows\System32\RPCRT4.dll+491cd|C:\Windows\System32\RPCRT4.dll+49a7b|C:\Windows\System32\RPCRT4.dll+29c1c|C:\Windows\System32\RPCRT4.dll+2a09c|C:\Windows\System32\RPCRT4.dll+4438c|C:\Windows\System32\RPCRT4.dll+45beb|C:\Windows\System32\RPCRT4.dll+386ea|C:\Windows\SYSTEM32\ntdll.dll+325fe|C:\Windows\SYSTEM32\ntdll.dll+330d9|C:\Windows\System32\KERNEL32.DLL+8364|C:\Windows\SYSTEM32\ntdll.dll+65e91

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

Petya Execution Infographic

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
  • A .tmp file accesses lsass.exe
  • A schtasks.exe process command line includes the “shutdown” switch
  • Rundll32.exe writes files
  • The string "pipe" is found in a process’ command line
  • 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/

Justin Swisher
About the Author

Justin Swisher

Get the latest threat intelligence news in your email.