HeroCTFv4 - Where all problems start
This challenge was including in the forensic category of the HeroCTF v4 event, divided in 4 parts. The first one was about a deleted lnk file. In the second one we looked into Windows forensic (Schedule Task, WSL, Registry). In the third part we had a memory dump to examine. For the final part we had to reverse a rust malware.er
Part 1
Description
For a change of pace, a company has been attacked again… Nevertheless, the means used here is quite original, indeed, it would be apparently a food delivery man who would be at the origin of the initial compromise… For your first analysis, you will have to found what the USB key that the delivery man put in the computer contains. Could you provide us the malicious URL used to download something ?
Challenge
Firstly, we run a file
command :
|
|
According to the output it’s a dump of a usb key in FAT format. Using fatcat
we can list the files, as well as the deleted files in the dump.
We could see two files README.txt
and Important_Document.lnk
.
Retrieving the first file isn’t useful, however the lnk
file seems to have a powershell command encoded in base64 in it.
By decoding the base64, we could see that a file img.png
is download from http server 146.59.156.82
as iexplorer64.exe
in C:\Users\Worty\AppData\Local\Temp\
. Then, it’s executed.
|
|
Flag: Hero{http://146.59.156.82/img.png}
Part 2
Description
Well, the USB key was pretty obvious! You are now provided with a dump of the file system of the infected machine. Can you identify the actions of the malware that was loaded from the usb drive?
Challenge
To start this part, I have opened the dump of the hard drive into Autopsy
By checking on Recent Documents, we could see that there is a link to the drive E:\
with an access date of 27/05/2022 15:50:37
.
Moreover, there is 3 files probably deleted since there is no trace of them on the system :
C:\Users\j.bertrand\Documents\background.bmp
C:\Users\j.bertrand\Documents\todo.txt
C:\Users\j.bertrand\Documents\Nouveau document texte.txt
Checking on USB Device Attached, we see a correspondance between the hard drive lnk
and the plug of usb device on the system at 15:50.
Now, that we have checked Autopsy, we will save all important file for an analysis. The $MFT
and $Extend\$UsnJrnl:$J
located in root of C drive ($LogFile
can be retreive as well). The Windows PowerShell
, Security
, System
and Application
journal log, located in C:\Windows\System32\winevt\Logs\
We convert them to csv using Zimmerman’s tool MFTECmd and EvtxECmd for event log. This will be usefull to analyze them into Timeline Explorer.
|
|
|
|
Opening Evtx_PowerShell.csv
, we can see that a new schedule task is added on the windows host victim :
|
|
This task will run a powershell script bc.ps1
from a wsl distribution. I struggled a lot on the base58 before trying cyberchef magic which gives _m4lw4r3_n0t_fl4g_
.
Then I tried to investigate on the powershell script, to do that, I export from Autopsy the vhdx of wsl located at C:\Users\j.bertrand\AppData\Local\Packages\Canonical...\LocalState\ext4.vhdx
.
I open the ext4 partition with FTK Imager and look at /tmp/bc.ps1
:
|
|
The comment at the start of the screen YnlfZDNmM25kM3J9
is the base64 of by_d3f3nd3r}
. We now have two parts of the flag.
By searching powershell xor 35 on your favorite search engine you will find that this script is a cobalt strike beacon which run a shellcode. To get the shellcode we decode the base64, and run it through a xor operation with 35 as our second parameter. Once it’s done, I used scdbg.exe
which will run our shellcode through a emulated environnement.
Another solution is to use the CS parser from Avast, you get even more informations.
|
|
Then I tried to get the next stage without success. By looking a bit back, I remember that the file iexplorer64.exe
was executed from C:\Users\Worty\AppData\Local\Temp\
. However, the file does not exist on the system.
After loading MFT.csv
into Timeline Explorer, I started to search for iexplorer64 and found only two files. A prefetch file and the binary at C:\Windows\System32
. From “Autopsy*, I export the file to the disk.
Opening the binary on IDA in pseudo-code view, we could see a lot of JUMPOUT
. In dissassembly view there is some opcode that is interpreted as data instead of code by IDA, so I forced it to be interpreted as code by pressing C
each time I see a part wrongly processed. Once the pseudo-code is almost fully corrected, we see that a new registry value is added to the key SOFTWARE\Microsoft\Windows\CurrentVersion\Run
named 41AMoD4RLwE7h2REtSWSGfUFu
. By decoding the base58 of the value name we get the first part of the flag, Hero{p3rs0n4l_3v1l
. In the following screen we also see the creation of the schedule tasks.
Flag: Hero{p3rs0n4l_3v1l_m4lw4r3_n0t_fl4g_by_d3f3nd3r}
Bonus
This solution above was not the first thing I tried. At first, I went in the wrong direction by attempting to link the flag with Windows Defender.
After finding the last part of the flag by_d3f3nd3r}
, I combed through Windows Defender log C:\ProgramData\Microsoft\Windows Defender\Support\
and found a file MPLog-20220527-111617.log
which contained some detection, including C:\Windows\System32\iexplorer64.exe
. The TelemetryName field of the log could even help us understand where to look for the malware execution context with ExeRunKeys
and SchtaskCreateByFriendly
.
|
|
Part 3
Description
The malware was therefore custom and specifically targeted this company, so there is no way to use known databases to identify its different keys… There is (or are) some malicious connexion(s) too… This malware seems to act like a droper for another ones, but we are not really sure.. could you find some informations to confirm that ?
Flag Format : Hero{ip:port-deleted_file_1-deleted_file_2-path_of_malware}
Challenge
Since we got all the information from the previous part, inspecting the memory dump was useless.
Flag: Hero{161.97.163.247:80-background.bmp-todo.txt-C:\Windows\System32\iexplorer64.exe}
Part 4
Description
A network administrator has woken up and tells us that he makes network dumps very frequently. Moreover, the malware seems to have exfiltrated files but we are not sure and the capture seems unreadable… it’s up to you to find the exfiltrated files!
Challenge
In the pcap capture, we filtered the malicious IP.
We found that there is a TCP connection between the victim and the attacker. By following the TCP stream, we see that the traffic is unreadable, probably encrypted.
At this point I was thinking that the traffic was some sort of cobalt strike. However, since the port was 1337
and 80
I was thinking that I missed something. I dug a lot on the cobalt strike subject following an article from Nvisio Lab as well as their 5 other blog post about it. The only thing interesting I found is the public RSA key using the script 1768.py in the memory dump. Without any other leads, the CS shellcode appeared to be a dead end.
I struggled a lot before going back to the initial malware iexplorer64.exe
. When I came back to the start, I remembered that I saw it using AES and base64 library while operating a strings command on it.
In the pseudo-code view of IDA, we navigate to the section right after the one about schedule tasks creation. Here, we can see a string copied to hObject
hello world! This is my plaintext.. This probably means this is a test string for encryption. The next instruction allocate an xmmword to v34
.
This variable is used in sub_140004FF0
, which seems to copy v34
to Src
and initialize some AES instance with the aeskeygenassist
operation.
Then Src
is copied to v30
and another xmmword is added to the v30
struct. After that v30
is copied to v31
and hObject
to lpMem
. Finally, sub_140003150
is called with our string and the two xmmword
.
By looking at xmmword, we recognize our plaintext as well with 2 hexadecimal numbers of 16 bytes. So there is a high chance that this is our key and IV for an AES 128 CBC.
We try using openssl
on the TCP packet with highest data lenght :
|
|
Extracting the archive, we use grep to get the flag which is inside content.xml
.
Flag: Hero{024bcd670b1a35fef0ec6a547a20cfbc}