writeup-vault by Yuriibe

A collection of technical writeups on CTFs, malware analysis, exploitation, and infosec research.

View on GitHub

🛠️ Part 2 – DLL Search Order Hijacking via explorer.exe

After messing around with in-memory payloads hidden in images (LSB), I wanted to try something more native like getting code to run just by dropping a DLL. So I started looking into DLL search order hijacking, and explorer.exe turned out to be a solid target.

🎯 Goal

Inject a custom DLL that gets loaded by explorer.exe at startup, without any UAC prompt, and without using any EXE dropper or direct process injection.


🔍 Step 1: Find a Missing DLL

Using Procmon, I filtered for:

Process Name is explorer.exe Result is NAME NOT FOUND

I was looking for DLLs that Windows tries (and fails) to load, especially from:

This revealed several missing DLLs,

procmon

But I couldn’t find a consistently missing DLL that actually worked when hijacked most of them either existed or didn’t get loaded even if I dropped a fake one.

So I took a step back and did some research. That’s when I came across cscapi.dll a DLL that’s often referenced in hijacking examples. It turns out:

So it’s a perfect candidate. I didn’t need to overwrite an active system file, and I knew explorer.exe would try to load it automatically — which makes it great for a DLL hijack.


⚙️ 2. Create the Hijack DLL

A basic C-style DLL with DllMain was enough to verify execution:

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
    if (fdwReason == DLL_PROCESS_ATTACH) {
        MessageBoxA(NULL, "DLL Loaded!", "Hijack", MB_OK);
    }
    return TRUE;
}

Compiled as a 64-bit DLL (since explorer.exe is x64), named it cscapi.dll.


🚨 3. Replace or Drop into System32

Because explorer.exe only looks in System32, I needed to place my DLL directly into:

C:\Windows\System32\cscapi.dll

To do that:

MovingDLL

We now have our original DLL as backup as well as our own malicous one

sytem32

♻️ 4. Restart explorer.exe

With the hijack in place, I ran:

taskkill /f /im explorer.exe start explorer.exe

And boom 💥 the messagebox popped. The DLL was successfully hijacked and executed as part of a trusted Windows process.

proof

✅ Why This Works


👀 Coming Up in Part 3…

So far we’ve done:

Next up:
What happens when we combine them?

In Part 3, I’ll chain the steganographic image loader from Part 1 with the DLL hijack from Part 2, meaning: