1 little secret of mapi32.dll

The mapi32.dll is a stub DLL that acts as a proxy for MAPI API calls. Pretty much all its exported functions start with a GetProxyDllEx routine that tries very hard to find a target email client library that will deliver the requested functionality offered by a standardized MAPI interface.

The GetProxyDllEx routine is pretty complicated as it attempts to handle many cases – many of which are catering for various architectural choices Microsoft made around MAPI over last 3 decades. Okay, I lied, it’s actually more boring than complicated, and since I am always triggerhappy when it comes to quick wins, I will just describe one below.

As a side note, from a forensic perspective, the following registry entry may be of interest:

HKLM\SOFTWARE\Clients\Mail\AlwaysUseLegacyMapiRegistration

It determines how the MAPI provider DLL is being searched for. If it doesn’t exist, or the value is not 1, the search will focus primarily on the modern RoGetActivationFactory function; otherwise, it will search the MAPI providers the old-fashioned way (via Registry enumeration of HKLM\Software\Clients\Mail key).

Anyway, back to the quick win…

If we put the file mapisvc.inf in a PATH location, and attempt to load any MAPI API via rundll32.exe f.ex.:

rundll32 mapi32.dll, LaunchWizard

the mapi32.dll will try to load:

C:\Windows\System32\mapi32x.dll

This DLL may or not may be present on the OS, depending on the OS version. So it’s a bit of a Schrödinger phantom DLL. If you are lucky, and it doesn’t exist, it can be used to host a payload…

Note: the mapi32x.dll file name is hard coded and used in situations when a better MAPI DLL file cannot be found. In many cases there may be Email clients present on the system that will configure email client entries that will take precedence over mapi32x.dll, so YMMV and you simply need to test it for your specific scenario. Remember it’s a quick win, and these are usually low quality 🙂

1 little known secret of cliconfg.exe

This is a blast from the past.

Copy c:\WINDOWS\system32\cliconfg.exe to a folder of your choosing and execute it.

It will attempt to load a bunch of some very old-school DLLs:

  • C:\Windows\System32\DBMSRPCN.DLL
  • C:\Windows\System32\DBMSSPXN.DLL
  • C:\Windows\System32\DBMSADSN.DLL
  • C:\Windows\System32\DBMSVINN.DLL
  • C:\Windows\System32\DBMSGNET.DLL
  • C:\Windows\System32\DBMSSNET.DLL
  • C:\Windows\System32\DBMSQLGC.DLL
  • C:\Windows\System32\NTWDBLIB.DLL

The last one on the list is the one that executes code, so placing your payload inside C:\Windows\System32\NTWDBLIB.DLL is a guarantee that it will be executed when you run a copy of c:\WINDOWS\system32\cliconfg.exe from a different location.

I am lazy and am not researching the other ones, but I am sure it is most likely due to a lack of some specific export functions that my test DLLs miss to export that stop the code execution when these earlier DLLs are mapped to memory but not loaded.