域滲透——Hook PasswordChangeNotify
0x00 前言
在之前的文章中介紹了兩種維持域控權(quán)限的方法——SSP和Skeleton Key,這兩種方法均需要借助Mimikatz來(lái)實(shí)現(xiàn),或多或少存在一些不足,所以這次接著介紹一個(gè)更加隱蔽且不需要使用Mimikatz的后門方法——Hook PasswordChangeNotify.
0x01 簡(jiǎn)介
Hook PasswordChangeNotify這個(gè)概念最早是在2013年9月15日由clymb3r提出,通過(guò)Hook PasswordChangeNotify攔截修改的帳戶密碼。
需要了解的相關(guān)背景知識(shí)如下:
在修改域控密碼時(shí)會(huì)進(jìn)行如下同步操作:
a. 當(dāng)修改域控密碼時(shí),LSA首先調(diào)用PasswordFileter來(lái)判斷新密碼是否符合密碼復(fù)雜度要求 b. 如果符合,LSA接著調(diào)用PasswordChangeNotify在系統(tǒng)上同步更新密碼
函數(shù)PasswordChangeNotify存在于rassfm.dll
rassfm.dll可理解為Remote Access Subauthentication dll,只存在于在Server系統(tǒng)下,xp、win7、win8等均不存在
可以使用dumpbin查看rassfm.dll導(dǎo)出函數(shù)來(lái)驗(yàn)證結(jié)論2:
1dumpbin /exports c:\windows\system32\rassfm.dll
如圖
0x02 特點(diǎn)
對(duì)于之前介紹過(guò)的Security Support Provider,在實(shí)際使用過(guò)程中不可避免的會(huì)有以下不足:
安裝后需要重啟系統(tǒng)
需要在System32文件夾下放置dll
需要修改注冊(cè)表
而使用Hook PasswordChangeNotify卻有如下優(yōu)點(diǎn):
不需要重啟
不需要修改注冊(cè)表
甚至不需要在系統(tǒng)放置dll
可以說(shuō)在隱蔽性上,使用Hook PasswordChangeNotify優(yōu)于Security Support Provider
0x03 技術(shù)實(shí)現(xiàn)
根據(jù)clymb3r提供的poc,實(shí)現(xiàn)Hook PasswordChangeNotify共包含兩部分:
1、Hook dll
下載鏈接:
https://github.com/clymb3r/Misc-Windows-Hacking
(1)為PasswordChangeNotify創(chuàng)建一個(gè)inline Hook,將初始函數(shù)重定向到PasswordChangeNotifyHook
(2)在PasswordChangeNotifyHook中實(shí)現(xiàn)記錄密碼的操作,然后重新將控制權(quán)交給PasswordChangeNotify
2、dll注入
可以利用 Powershell tricks中的Process Injection將我們自己編寫的dll注入到lsass進(jìn)程,實(shí)現(xiàn)Hook功能
0x04 實(shí)際測(cè)試
測(cè)試環(huán)境:
Server 2008 R2 x64
Server 2012 R2 x64
測(cè)試步驟:
1、生成Hook dll
poc下載地址:
https://github.com/clymb3r/Misc-Windows-Hacking
使用VS2015開(kāi)發(fā)環(huán)境,MFC設(shè)置為在靜態(tài)庫(kù)中使用MFC
編譯工程,生成HookPasswordChange.dll
2、生成dll注入的powershell腳本
下載Powershell的dll注入腳本
https://github.com/clymb3r/PowerShell/blob/master/Invoke-ReflectivePEInjection/Invoke-ReflectivePEInjection.ps1
在代碼尾部添加如下代碼:
Invoke-ReflectivePEInjection -PEPath HookPasswordChange.dll –procname lsass
并命名為HookPasswordChangeNotify.ps1
3、Hook PasswordChangeNotify
上傳HookPasswordChangeNotify.ps1和HookPasswordChange.dll
管理員權(quán)限執(zhí)行:
1PowerShell.exe -ExecutionPolicy Bypass -File HookPasswordChangeNotify.ps1
如圖
4、自動(dòng)記錄新密碼
在Server 2012 R2 x64下,手動(dòng)修改域控密碼后
在C:\Windows\Temp下可以找到passwords.txt,其中記錄了新修改的密碼
如圖
在Server 2008 R2 x64下,同樣成功
如圖
0x05 小結(jié)
本文依舊是對(duì)常規(guī)功能做了演示,后續(xù)可自定義dll代碼實(shí)現(xiàn)更多高級(jí)功能,如自動(dòng)上傳新密碼。
以下鏈接中的代碼可作為參考,其中實(shí)現(xiàn)了將獲取的新密碼上傳至Http服務(wù)器
http://carnal0wnage.attackresearch.com/2013/09/stealing-passwords-every-time-they.html
使用Hook PasswordChangeNotify來(lái)記錄新密碼,如果放在以前,進(jìn)程注入的操作很容易被檢測(cè),但是得益于Powershell應(yīng)用的發(fā)展,通過(guò)Powershell來(lái)進(jìn)程注入可以繞過(guò)常規(guī)的攔截。
當(dāng)然,Hook PasswordChangeNotify僅僅是眾多Hook方法中的一個(gè)。
我已經(jīng)Fork了clymb3r的代碼,并結(jié)合本文需要的代碼做了更新,下載地址如下:
https://github.com/3gstudent/Hook-PasswordChangeNotify
0x06 參考資料
https://clymb3r.wordpress.com/2013/09/15/intercepting-password-changes-with-function-hooking/
http://carnal0wnage.attackresearch.com/2013/09/stealing-passwords-every-time-they.html
http://www.processlibrary.com/en/directory/files/rassfm/305529/
https://github.com/clymb3r/Misc-Windows-Hacking/tree/master/HookPasswordChange
http://www.slideshare.net/nFrontSecurity/how-do-password-filters-work