Cave Expedition

Personal Rating: Medium

The challenge starts with a folder full of Event Log files as well as the seemlingly encrypted file "map.pdf.secured". The goal has to be decrypting the PDF file.

EVTX files

Hunt for Suspicious Events

The first thing that comes to my mind when presented with EVTX files after an incident is to run a chainsaw hunt on the files. And so I did:

I ran it two times, with raw output and with JSON output and I piped the output to a file as well.

Numerous detections indicated malicious actions that were logged. This is what I could see at first glance:

  • certutil was used to infiltrate the script avAFGrw41.ps1 to C:\Users\developer56546756\Desktop\avAFGrw41.ps1 2025-01-28 10:31:19

  • wevutil was used to evade ETW 2025-01-28 10:31:22

  • We have a user developer56546756

  • avAFGrw41.ps1 was executed with powershell1.0 2025-01-28 10:31:19

  • LaZagne was executed 2025-01-28 10:31:24

  • Victim: "WORKSTATION5678\developer56546756"

I filtered the logged commandlines from the chainsaw output to get a better overview and potentially extract some of the Powershell scripts that were likely executed:

Suspicious Commandlines

Deobfuscation

There were multiple similar commands that all seemed to concatenate a base64 string in the variable "b". I decoded "b", by piping it to base64 -d. The result was this script:

This indicates that we found the encryption program that encrypted the "map.pdf.secured":

Encrypted File Extension

I started deobfuscating the script. These hashtables and For-loops had actually no purpose and could be removed entirely. It appeared that the hashtable1 is created, altered in three for-loops and then inverted into hashtable2. However, none of these hashtables are ever used.

Obfuscated Features with no Function

A friend of mine explained that the $p34Vr switch is set as a flag when executed in line 73 of the screenshot below. This just sets the switch/bool $p34Vr, which is a function parameter, to true if it is given when executing the function. Since it is given in this case and the function only does anything if it is given, we can remove the flag, the parameter and the if statement.

Deobfuscating Further

This appears to be the encryption function, at least the main part of it:

Encryption Function

The main function, if the path "dca01aq2/" exists, for txt, doc, docx and pdf files and, if they exist, encrypts them, stores that in .secured and removes the old one. This is typical ransomware behavior.

Main Function of the Ransomware

After renaming variables and simplifying the script, this is the final deobfuscated result:

Creating a Decryptor

We have to understand the encryption program to create a decryptor. This part indicates, that we have a stream cipher here. $streambyte1 will be the byte of the first key (input2) at the next index, if the message is longer than the key. If the message is 61 Bytes and the key is 60 Bytes, then the key[0] will be used to encrypt the last Byte.

Encryption Process

Since I did this CTF together with a friend, he wrote the decryption program. This is what it looks like:

This could be used to decrypt the PDF file, which indeed contained the flag.

Last updated