text
stringlengths
0
1.99k
4. compile the assembly (2x)
5. test the assembly (2x)
6. incorporate the shellcode into our infector
7. compile the infector
8. test the infector
9. verify the infections succeed
When we fully enumerate the steps needed to build a sound virus, we can
appreciate the simplification a build system provides a complex ecosystem.
Because at any given step in this process, something can fail. At any
given point in the process, if there *is* failure, we will have to restart
at a certain point. The more time it takes to resume where we failed, the
more time that is wasted. And not being clear from an organizational
standpoint where you need to go to restart is a time waster. A good build
system saves you time, a very precious resource.
In this case, it was discovered that ShellExecuteA and URLDownloadToFileA
were failing all the way at step 9. Ass status: bitten. And look at when
it chose to bite us-- testing, rather than deployment. Why was it bitten?
Our infection technique of TLS injection.
Due to choosing to perform TLS injection on the binary, we were tempted by
the fact that we got precedence over the entrypoint of the infected
executable. But this means we're currently executing in the context of the
executable loader. This means our infected executable is not yet fully
loaded. In particular to our conundrum, *threads* are not yet fully
initialized. It was observed when ShellExecuteA and URLDownloadToFileA
were executed within the context of a TLS directory callback, they would
hang. It was noted, too, that the process attempted to create a thread
before it hung. This likely meant we could not use any functions which
wound up spawning threads.
The payload was changed to something slightly less conventional:
CreateProcessA. While not unconventional for our payload program, the way
we eventually went about downloading the payload certainly was.
CreateProcessA eventually calls NtCreateProcess, a function of ntdll.dll
which ultimately culminates in a kernel syscall. This would undoubtedly
be thread-safe in our TLS directory. So how did we eventually download
our payload? A call to Powershell.
Certainly goofy for a shellcode payload to make an external call to
Powershell when the API is at your fingertips, isn't it? So is the nature
of hacking-- when faced with a challenge, we heed the call with non-
standard solutions, in spite of our opinions, when it simply works.
Nonetheless, this solution required a significant rewrite of the code.
The C payload would need to be rewritten, recompiled, translated into
assembly, those assembly files compiled, and stuck back into our infector.
Essentially, we are forced to go back to the beginning of our steps
enumerated and work our way back to our infector. That's a lot of time, and
even more steps to take without the simplification provided by a build
system!
But with everything glued together, the only time we are wasting is simply
the equivalent of raking the sand in our zen garden: coding and analyzing.
All because our build system makes our complicated abstract verification
steps relatively mindless:
$ cd infection/c/build
$ cmake --build ./
$ ./Debug/infection_c.exe # any sheep? try again
$ cmake --build ./ --config Release # for translating to asm
$ cd ../../asm/32/build
$ cmake --build ./
$ ./Debug/infection_asm_32.exe # any sheep? try again
$ cd ../../64/build
$ cmake --build ./
$ ./Debug/infection_asm_64.exe # any sheep? try again
$ cd ../../../../build # footgun: are you debug configured?
$ cmake --build ./
$ ./Debug/broodsac.exe # at least you just get sheep if you footgun
Every step where something could functionally go wrong is isolated into
its own place, manageable in their own regards. Each action we need to
create our virus, from payload to delivery, is instrumented and flows
smoothly between one another. When something goes wrong at any point in
this chain, we know exactly where to restart, and can quickly act and
tackle the issue.
It's one thing to be agile when it comes to mitigating the demons of bugs,
though, but what of the demons of emergency feature requests? It is not
merely a push of management that inspires such spikes in development, but
of surprise necessity.
--[ 5.2 Antivirus Catches It
It was incredibly amusing to me when I noticed the sheep being detected as
malware. Curious, because the sheep itself was technically benign-- the
infector and the infection were actually the malware. Initially, I
whitelisted it in Windows Defender while I was working and didn't really
think anything of it, I'll fix it later. Eventually, I had to face the
music and figure out why my virus was being detected, even if the sheep
was curiously benign.
The hints we were receiving from Windows Defender was that it was some
kind of script that triggered it, and that the signature it was hitting
on was called "Trojan-Script/Wacatac.B!ml." Some research on the signature
told us absolutely nothing, as procedurally generated signatures are wont
to do. It did manage to tell us that everyone is pissed that all sorts of
random benign executables were being flagged as Wacatac. We're being taken