[FCSC 2019] - 3615 Incident (1/3)

Introduction 📌
Yet another victim of ransomware. Payment of the ransom is not an option, given the amount requested. We’re called in to try and restore the encrypted files. The first part of this challenge requires us to find :
- the name of the executable file of this ransomware,
 - its Process ID (PID),
 - the SHA1 of the file name 
flag.docxonce encrypted. 
The expected response format: ECSC{ransomware_name.exe:pid:sha1}.
The mem.dmp.tar.xz file is supplied. This is a memory image of the victim’s computer. In concrete terms, it corresponds to the contents of volatile memory (in other words, RAM) at the time of acquisition, and we’ll see that it proves to be an excellent source of information for digital forensics.
1. The search for ransomware 🔎
Volatility3
There are several tools available for analyzing a memory image. For the purposes of this challenge, we’ll be using Volatility3 and grep (more useful than it sounds :p).
Volatility3 is an open-source tool for extracting information from a memory dump on a Windows, MacOS or Linux system via plugins.
Installation is very quick:
 | 
 | 
Now the tool is ready to use. 😄
OS Identification
First of all, we need to know which operating system the dump comes from. To do this, we can use grep in the first instance, filtering on terms like Windows, Linux version, and so on.
 | 
 | 
From the result, it would appear that the memory image comes from a Windows system. To be sure, we can use the windows.info plugin:
(-f is the option for specifying the memory dump path.)
 | 
 | 
It would therefore appear that the operating system is :
- a Windows 10 (field 
NtMajorVersion), - 64-bit architecture** (field 
Is64Bitattrue), - build 10586 (field 
Major/Minor). 
Now that we have this information, we can use the right plugins.
Analyse des processus
To find the name of the ransomware executable file, we can start by listing the processes currently running, using the windows.pstree plugin. It can be used to draw up a tree structure, showing processes and their parent, their process identifier (PID), their creation date, and so on.
 | 
 | 
(Here, I’ve deliberately removed most of the results for the sake of readability)
After analysis, we find several processes that appear legitimate (firefox.exe, notepad.exe, OneDrive.exe, …). However, one of them looks suspicious. It is assistance.exe with PID 5208.
 | 
 | 
Indeed, this is not a process we usually observe. To get to the bottom of it, let’s take a closer look.
    Analysis of the binary assistance.exe
To learn more about assistance.exe, we first need to extract it from the memory dump. To do this, we can use various methods:
- Extract it using its 
PID. Simply use thewindows.dumpfilesplugin with the--pid <PID>option. - Find the location of the executable on the OS and extract it using the associated virtual address.
 
The first method is more common (and practical), so we’ll use the second. :)
To scan the files in the memory image, we can use the windows.filescan plugin. What’s more, since we know the name of the executable, we can filter using grep.
 | 
 | 
We can see that it has several different addresses. We can take one of these. Next, we need to dump the executable. Here, we use the windows.dumpfiles plugin. It comes with the --virtaddr <ADDR> option, which lets you specify the virtual address you’ve just found.
 | 
 | 
(the -o option is used to specify the destination directory for the executable).
Now that we have the executable, let’s quickly check that it’s actually one, using the file command.
 | 
 | 
Everything looks good! Now let’s check if it’s malware. If so, it’s probably recognized by VirusTotal. We can then download the executable.
Clearly, this is malware belonging to the ransomware family. Let’s delve a little deeper into the analysis by opening it in PEStudio. This is a tool for quickly finding artifacts (information of investigative value) within an executable.
Browsing the strings section, we notice the presence of a Github repo: https://github.com/mauri870/ransomware. It probably contains the ransomware’s source code. What a bargain!
At this stage of the challenge, we have 2/3 of the flag: ECSC{assistance.exe:5208.
- the name of this ransomware’s executable file,
 - its Process ID (PID),
 -  the SHA1 of the file name 
flag.docxonce encrypted. 
Now all we need to do is find the last item in this list. We’ll now be able to use the source code now available to us.
    2. Searching for flag.docx ðŸ§
Quick source code analysis
To understand how encryption works, we need to analyze the file ransomware.go located in /cmd/ransomware. Inside, we find the encryptFiles() function which, as its name suggests, is in charge of encrypting files.
*(As it’s quite large, I’ve shortened it to the interesting part (from line 256 to 268)).
 | 
 | 
We can see that this function renames files after encrypting them. The substitution name is the name of the original file encoded in base64, to which is added an extension defined by the attacker in the file common.go (line 99).
 | 
 | 
Locating the encrypted file in the memory dump
We now know that the hypothetical name of flag.docx after encryption is this one encoded in base64. We can obtain the string as follows:
 | 
 | 
We can now search for a file with the name ZmxhZy5kb2N4 in the memory dump. To do this, we’ll use the windows.filescan plugin and filter on the filename using grep.
 | 
 | 
Indeed, the file does exist. We also notice that the file extension is no longer .encrypted but .chiffré. All we have to do now is calculate the SHA1 of the full filename using sha1sum :
 | 
 | 
This gives us the last piece of the flag: :c9a12b109a58361ff1381fceccdcdcade3ec595a}, so we can check off the last item in our list.
-  the SHA1 of the file name 
flag.docxonce encrypted. 
3. Flag 🚩
Our analysis yields the following flag: ECSC{assistance.exe:5208:c9a12b109a58361ff1381fceccdcdcade3ec595a}.
This concludes the first part of the 3615 Incident challenge. I hope this writeup has helped you understand the ins and outs of this challenge. Good luck for the second part! :)