积极答复者
WPF程序的dll注入攻击问题

问题
-
我遇到了一个dll注入攻击防范的问题
根据Microsoft的Guid: h ttps://blogs.techn et.microsoft.com/srd/201 0/08/23/more-information-about-the-dll-preloading-remote-attack-vector/
我在程序一开始调用SetDllDirectory(""), 试图把工作路径从dll search paths中移除. 但是在process monitor里观察发现并不管用
protected override void OnStartup(StartupEventArgs e) { NativeMethods.SetDllDirectory(null);
我自己做了个假的dll (CRYPTSP.dll) 试图注入, 发现确实被加载了, 时间是在我的WPF程序执行OnStartup之前. 所以调用SetDllDirectory可能不会起作用. 这些dll并不是在WPF程序中直接import的, 应该是在WPF程序调用的其他dll中引用的.
请问是否有办法解决这个问题? . 谢谢!
答案
-
你好,
>>你想解决什么?是要解决不能通过SetDllDirectory(null)移除dll的目录吗?
SetDllDirectory()方法通常适用于显式的加载DLL(LoadLibrary()方法),如果你隐式的加载dll,这个函数将不起作用。
在你的程序启动时设置这个方法将毫无用处,因为在这个OnStartup方法执行之前,你的程序所需的dll,已经加载。
>> 如果你想解决怎么防止DLL的注入问题?
我建议使用强名称的dll,所以对你的程序所需的DLL进行数字签名。并使用完全限定名的方式加载dll.
Assembly myDll =Assembly.Load("myDll, Version=1.0.0.1, Culture=neutral, PublicKeyToken=9b35aa32c18d4fb1");
Sincerely,
Bob
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.- 已标记为答案 水仓莉丝佳 2017年12月4日 8:46
全部回复
-
你好,
>>你想解决什么?是要解决不能通过SetDllDirectory(null)移除dll的目录吗?
SetDllDirectory()方法通常适用于显式的加载DLL(LoadLibrary()方法),如果你隐式的加载dll,这个函数将不起作用。
在你的程序启动时设置这个方法将毫无用处,因为在这个OnStartup方法执行之前,你的程序所需的dll,已经加载。
>> 如果你想解决怎么防止DLL的注入问题?
我建议使用强名称的dll,所以对你的程序所需的DLL进行数字签名。并使用完全限定名的方式加载dll.
Assembly myDll =Assembly.Load("myDll, Version=1.0.0.1, Culture=neutral, PublicKeyToken=9b35aa32c18d4fb1");
Sincerely,
Bob
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.- 已标记为答案 水仓莉丝佳 2017年12月4日 8:46
-
Hi,
>>cryptsp.dll , 似乎是被.net framework加载的而不是被我的程序加载的.
这个我不太清楚,这个DLL有可能.net framework的所依赖的dll, 因为共享程序集内存中只存在该程序集的同一份副本 ,所以有可能在你的程序之前就被加载了。
Sincerely,
Bob
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.