views:

76

answers:

3

Microsoft released Security Advisory (2269637) Insecure Library Loading Could Allow Remote Code Execution.

The note refers to a tool that will help to detect this problem and programming guidelines on Dynamic-Link Library Security.

How do these guidelines translate to .NET development? I assume this only affects Platform Invoke.

Does this remain the recommended way to import system libraries?

DllImport("user32.dll")]
+4  A: 

From that page:

Microsoft has issued guidance to developers in the MSDN article, Dynamic-Link Library Security, on how to correctly use the available application programming interfaces to prevent this class of vulnerability.

and

This issue only affects applications that do not load external libraries securely. Microsoft has previously published guidelines for developers in the MSDN article, Dynamic-Link Library Security, that recommend alternate methods to load libraries that are safe against these attacks.

You link to the same page in your question, so as long as you follow the guidelines outlined on that page your application should be secure. The notes about safe process search mode and the order of searching directories seem to be particularly relevant.

ChrisF
But how do you apply those to his User32.dll example? Safe search mode isn't per process, it's per session, and not really yours to play with. The DLL is loaded by the system before you get control so the search path is out of your hands too. As a manifest? Do you really want to add all of the system DLLs to your manifest? What's the correct portable way to specify the system directory in the manifest?
Rup
@Rup - See @Tim Robinson's answer. I don't think I could add any more than that.
ChrisF
+6  A: 

System DLLs like user32.dll are safe because they're in the KnownDLLs list in the registry. If you try to load a DLL called "user32", Windows is hard-coded to take the official copy from the system32 directory.

Tim Robinson
Right... but is the application the designated handler for specific file extensions? Like are you writing a movie player? Because if your not, then you cannot control the current working directory and there isn't an attack. You should really read up on an attack before posting, I'm 90% sure his app isn't affected and there is 1 and only 1 way to know for sure.
Rook
+2  A: 

Install your application and run H.D. Moore's tool. H.D. Moore discovered this attack pattern.

If your application isn't responsible for automatically executing a file extension, then you are not vulnerable. I bet that if you run this tool your app won't show up on the list of vulnerable applications.

Rook
Thanks for this useful recommendation!
Bernard Vander Beken