text stringlengths 0 1.99k |
|---|
(Hello, Rust!) |
At the outset in the abstract, we have two pieces: the *infector* and |
the *infection*. The *infector* is obviously responsible for infecting |
executables it finds. The *infection* is simply whatever payload we want |
to inject into various executables. Already, we have a dependency to work |
with: naturally, the *infector* relies on the *infection* in the build |
system, somehow. We want the infection to be flexible and portable so |
it's as easy as possible to inject into executables. Shellcoding fits |
this purpose perfectly. |
For writing quality shellcode, we stick with the C-then-ASM philosophy |
of writing our payload. In Broodsac, we have opted to let the compiler's |
optimizer optimize our C code and hand-translated that into an assembly |
file. |
While this can be tedious the larger the shellcode gets, we luckily don't |
have to worry about traditional requirements of shellcode as it comes to |
exploitation, since we're targeting an executable, not an exploitable |
buffer. Therefore, we have relatively fewer limits. Additionally, because |
Windows has support for both 32-bit and 64-bit binaries, and being the |
dinosaur it is, 32-bit architecture is still relevant. So payloads for |
both architectures will be necessary. |
At the outset of our plan, our virus hierarchy looks like this: |
+ broodsac |
+ infection |
+ ASM |
+ 32 |
+ 64 |
+ C |
The infection is purely a necessity of the infector, and as such, should |
be contained within its directory as a dependency. We should provide |
ourselves some external ability to compile the assembly payloads into |
their own binary for testing purposes. This means, in the abstract, we |
have roughly four binaries to work with-- the infector, the 32-bit ASM, |
the 64-bit ASM, and the C payload. Our infector should merely only rely |
on the assembly payloads, so we know we should somehow connect these |
pieces at the outset to our infector build. |
Having the projects individually separated this way makes the moving |
pieces easier to manage. Disaster, so to speak, is relatively contained |
to the individual units, organized and in their place. From the outside-- |
especially when accustomed to a hack-fast lifestyle-- you would not be |
blamed for seeing this organization as mere masturbation. Again, why |
bother when I can just stick everything in the same folder and issue |
compilation commands where I deem fit? |
Demons lurk in your code. That's why. They will snap out and pull you |
under when you least expect it, splashing red on your screen, spewing |
Stoustrup's nightmare inheritance, demanding refactoring for your sinful |
C. Being organized and compartmentalized in your endeavors gives you the |
territorial high ground in the battle of bugs. Being prepared for |
something to go wrong turns these demons into mere irritants. |
Constructing a build system around your virus exposes the pain-points |
when and where things go wrong, allowing you to quickly and elegantly |
attend to the problem. It also acts as a functional, engineerable glue |
to wrap around your build. The more complex your virus gets, the more a |
solid build system becomes essential, freeing us from the chains of |
uncreative compiler corporations. |
--[ 3. Designing the Virus |
We now have the abstract design of all the pieces of our virus. Next we |
need to fill in the blanks! We have two questions we need to answer: |
+ How should our virus infect the executable? |
+ What should our viral payload do? |
The first question was answered initially-- naively-- with code caves and |
PE file entrypoint redirection. Entrypoint redirection is a technique as |
old as EXE infections[1]. Unfortunately, code caves in executables aren't |
frequently in a size capable of handling the beast that is Windows |
shellcode. On average, you get around 200 bytes. Suitable for a Linux |
shellcode, not very good for a Windows shellcode. |
After some thinking, TLS directory injection[2] was settled upon. The TLS |
directory-- or Thread Local Storage-- is one of many directories within a |
PE file. It is responsible for ultimately managing thread memory storage |
tactics within the given executable. A notable trait of the TLS directory |
is initialization callbacks. There can be many, and they're iteratively |
called on process startup. In other words, the TLS directory takes |
precedence over the main routine, as the TLS directory initialization is |
part of the PE loading process. Remember this last part-- it will bite us |
in the ass later. |
There is a matter of how our TLS section gets inserted into the binary. |
We have simply opted to insert a new section, as we can provide a |
guarantee that the section will be executable and writable, as opposed |
to containing other metadata such as program resources. If we wanted to |
be stealthier about the infection, we could control for executable |
sections and apply the 29A technique[3] of expanding the last section |
in the executable. Naturally, the trade-off for stealth here will be to |
reduce potential attack surface and-- perhaps intentionally-- increasing |
complexity of detecting the infection. The power is yours. |
We want executable targets. Where do we find them? Surprisingly, in the |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.