LoadLibrary 없이 메모리에서 DLL을 로드하고, 익스포트를 해석하며, 핫스왑 가능한 IPlugin ABI를 통해 호출을 디스패치하는 최소한의 Windows x64 리플렉티브 PE 매퍼입니다.
Windows x64용 리플렉티브 PE 매퍼, 모듈 스톰핑 엔진, 그리고 깔끔한 IPlugin ABI를 중심으로 구축된 멀티 플러그인 관리자입니다. 메모리의 바이트 버퍼에서 DLL을 매핑하고, 익스포트를 해석하며, 플러그인 함수를 호출합니다 — 익명 메모리에서(고전적 리플렉티브 로드) 또는 정상적으로 로드된 희생 DLL 내부에서(모듈 스톰핑) 호출할 수 있습니다. 동시 플러그인을 위한 PluginManager, 핫 리로드, 회피 계층 통합을 위한 WinApiTable 추상화, 그리고 2-프로세스 비콘 아키텍처를 갖춘 통합 슬립 마스크 모듈을 포함합니다.
모듈 스톰핑 경로는 회피 강화되어 있습니다: 섹션별 보호(no RWX), 프라이빗 매핑 정리, 원본 바이트 복원, 힙 스크러빙을 수행합니다. pe-sieve, Moneta, hollows_hunter, BeaconEye, YARA를 이용한 정리 후 스캔에서 스톰핑된 모듈에 대한 탐지 결과가 0건으로 나타납니다.
CMake 3.15+와 Windows에서의 MSVC, Clang 또는 MinGW 중 하나가 필요합니다.
# Configure (defaults to Release)
cmake -B build -G Ninja
# Build
cmake --build build
# The build produces:
# build/Modules/SleepMask/sleepmask.dll (sleep mask plugin)
# build/Testing/controller.exe (operator console)
# build/Testing/beacon.exe (headless beacon)
# build/Testing/harness.exe (plugin test harness)
디버그 빌드에서 전체 진단 출력을 사용하려면:
cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug
cmake --build build
.\controller.exe ..\Modules\SleepMask\sleepmask.dll .\beacon.exe
sleep mask DLL을 로드하는 헤드리스 비콘 프로세스를 생성합니다. 비콘은 자체 PE 이미지를 암호화 대상으로 자동 지정합니다. mask> 프롬프트에서 사용할 수 있는 명령:
info — show technique and target
set ekko — switch to Ekko (timer-queue ROP chain)
set kraken — switch to KrakenMask (APC trampoline)
test <ms> — one-shot self-test (allocate, encrypt, sleep, decrypt, verify)
run <ms> — start callback loop (sleep encrypted → wake → poll → execute → repeat)
echo <msg> — round-trip test
exit — terminate beacon
콜백 루프 모드(run 10000)에서는 비콘이 수면 상태일 때 명령을 입력하세요. 명령은 대기열에 쌓였다가 다음 기상 주기에 실행됩니다. 암호화된 수면 구간 동안 Process Hacker를 사용하여 비콘의 메모리를 검사하세요.
.\harness.exe
런타임 플러그인 관리를 위한 대화형 메뉴:
[1] Load plugin — pick ID, DLL path, engine (reflective/stomped)
[2] Unload plugin — by ID
[3] Execute plugin — by ID, with a command string
[4] Reload plugin — hot-swap a new DLL into an existing slot
[5] List plugins — shows count, names, versions, engine type
[6] Execute all — runs every loaded plugin with one command
[7] Scan commands — prints pe-sieve/moneta commands for this PID
[q] Quit
# Load multiple plugins and execute them
.\harness.exe --load cmd cmdplugin.dll --load echo echoplugin.dll --exec cmd whoami --exec echo "hello" --list
# Module stomping
.\harness.exe --load cmd cmdplugin.dll --stomp xpsservices.dll --exec cmd whoami
# Hot-reload test (counter resets after reload)
.\harness.exe --load counter counterplugin.dll --exec counter a --exec counter b --reload counter counterplugin.dll --exec counter "after-reload" --list
# Unload
.\harness.exe --load cmd cmdplugin.dll --exec cmd whoami --unload cmd --list --unload-all
1. MapImage(plugin) private reflective mapping
2. LoadLibrary(sacrificial) legitimate load, PEB entry
3. Save original .text bytes for later restoration
4. Copy plugin image -> .text contiguous image preserves RIP-relative offsets
5. Relocate stomped code fix addresses for new base
6. Patch entry point mov eax,1; ret (safe FreeLibrary)
7. Per-section protections RX / R / RW per section (never RWX)
8. Resolve exports from private mapping, return stomped addresses
9. Free private mapping eliminates floating PE artifact
10. Execute plugin code runs inside "sacrificial.dll"
11. Restore original .text bytes sacrificial code back in place
12. FreeLibrary(sacrificial) unloads the module
13. LoadLibrary(sacrificial) fresh load = clean file-backed pages
14. Scrub heap buffers zero saved bytes + raw DLL data
정리 후, 희생 DLL은 정상적으로 로드된 모듈과 구별할 수 없습니다. 페이지는 파일 기반(프라이빗이 아님)이며, 내용은 디스크상의 파일과 일치하고, 힙에 PE 아티팩트가 남지 않습니다.
| IOC | 완화 |
|---|---|
| RWX 메모리 영역 | 섹션별 보호: .text RX, .rdata R, .data RW |
| 프라이빗 실행 가능 메모리(플로팅 PE) | 내보내기 확인 후 프라이빗 매핑을 VirtualFree |
| 수정된 모듈 코드 | 원본 .text 바이트를 복원한 뒤, 깨끗한 파일 기반 페이지를 위해 FreeLibrary + LoadLibrary |
| 힙에 있는 PE 헤더 | 해제 전에 원시 DLL 버퍼와 저장된 바이트를 memset(0) |
| 언로드 시 DllMain 크래시 | 덮어쓰기 전에 진입점을 mov eax,1; ret로 패치 |
ReflectivePluginLoader/
├── CMakeLists.txt
├── Include/
│ ├── IPlugin.h Plugin ABI (TaskApi, IPlugin)
│ ├── Win32.h WinApiTable abstraction
│ ├── ReflectiveLoaderEngine.h PE mapper + export resolver + FreeImage
│ ├── StompedLoaderEngine.h Module stomping engine
│ └── PluginManager.h Multi-plugin lifecycle manager
├── Modules/
│ ├── CmdPlugin/ Command execution plugin
│ ├── EchoPlugin/ Echo plugin (multi-plugin demo)
│ ├── CounterPlugin/ Stateful counter (persistence demo)
│ └── SleepMask/
│ ├── sleepmask.cpp Unified sleep mask (Ekko + KrakenMask)
│ └── CMakeLists.txt
├── Examples/
│ ├── basic_load.cpp Minimal single-plugin load + execute
│ ├── multi_plugin.cpp Multiple plugins with lifecycle
│ ├── hot_reload.cpp Hot-reload with CounterPlugin
│ ├── custom_api_table.cpp Custom WinApiTable with logging wrappers
│ ├── module_stomping.cpp Load via module stomping engine
│ └── Makefile NMAKE build for standalone examples
├── Testing/
│ ├── main.cpp Interactive + CLI plugin harness
│ ├── controller.cpp Operator console (spawns beacon, pipe IPC)
│ ├── beacon.cpp Headless beacon (loads sleep mask, callback loop)
│ └── CMakeLists.txt
└── Tools/
└── file2hex.py DLL to C byte array converter
Modules/ 아래에 디렉터리를 만들고 IPlugin.h를 포함하세요.IPlugin 인터페이스를 구현하세요:#include "IPlugin.h"
class MyPlugin : public IPlugin {
public:
void init() const override { /* setup */ }
void execute(TaskApi* task) const override { /* work */ }
void cleanup() const override { /* tear */ }
};
다섯 개의 진입점(create_plugin, destroy_plugin, plugin_init, plugin_exec, plugin_cleanup)을 내보냅니다. CRT 안전 할당을 위해 HeapAlloc + placement new를 사용합니다.
선택적으로 메타데이터를 위해 plugin_info를 내보냅니다:
struct PluginInfo { const char* name; const char* version; const char* description; };
extern "C" __declspec(dllexport) PluginInfo __stdcall plugin_info() {
return { "myplugin", "2.0.3", "My plugin description" };
}
CMakeLists.txt를 추가하고 루트에서 add_subdirectory()로 등록합니다.희생 DLL의 .text 섹션은 플러그인의 가상 이미지 크기보다 커야 합니다. 프로세스에서 활발히 사용되거나 런타임에 무결성 검사를 받지 않아야 합니다.
좋은 후보: xpsservices.dll (1.8 MB .text), mscms.dll, colorui.dll, npmproxy.dll
나쁜 후보: ntdll.dll, kernel32.dll (활발히 사용됨), clr.dll (무결성 검사됨)
.text 섹션에 들어가야 함image