域滲透——Hook PasswordChangeNotify
0x00 前言
在之前的文章中介紹了兩種維持域控權限的方法——SSP和Skeleton Key,這兩種方法均需要借助Mimikatz來實現,或多或少存在一些不足,所以這次接著介紹一個更加隱蔽且不需要使用Mimikatz的后門方法——Hook PasswordChangeNotify.
0x01 簡介
Hook PasswordChangeNotify這個概念最早是在2013年9月15日由clymb3r提出,通過Hook PasswordChangeNotify攔截修改的帳戶密碼。
需要了解的相關背景知識如下:
在修改域控密碼時會進行如下同步操作:
a. 當修改域控密碼時,LSA首先調用PasswordFileter來判斷新密碼是否符合密碼復雜度要求 b. 如果符合,LSA接著調用PasswordChangeNotify在系統上同步更新密碼
函數PasswordChangeNotify存在于rassfm.dll
rassfm.dll可理解為Remote Access Subauthentication dll,只存在于在Server系統下,xp、win7、win8等均不存在
可以使用dumpbin查看rassfm.dll導出函數來驗證結論2:
1dumpbin /exports c:\windows\system32\rassfm.dll
如圖
0x02 特點
對于之前介紹過的Security Support Provider,在實際使用過程中不可避免的會有以下不足:
安裝后需要重啟系統
需要在System32文件夾下放置dll
需要修改注冊表
而使用Hook PasswordChangeNotify卻有如下優點:
不需要重啟
不需要修改注冊表
甚至不需要在系統放置dll
可以說在隱蔽性上,使用Hook PasswordChangeNotify優于Security Support Provider
0x03 技術實現
根據clymb3r提供的poc,實現Hook PasswordChangeNotify共包含兩部分:
1、Hook dll
下載鏈接:
https://github.com/clymb3r/Misc-Windows-Hacking
(1)為PasswordChangeNotify創建一個inline Hook,將初始函數重定向到PasswordChangeNotifyHook
(2)在PasswordChangeNotifyHook中實現記錄密碼的操作,然后重新將控制權交給PasswordChangeNotify
2、dll注入
可以利用 Powershell tricks中的Process Injection將我們自己編寫的dll注入到lsass進程,實現Hook功能
0x04 實際測試
測試環境:
Server 2008 R2 x64
Server 2012 R2 x64
測試步驟:
1、生成Hook dll
poc下載地址:
https://github.com/clymb3r/Misc-Windows-Hacking
使用VS2015開發環境,MFC設置為在靜態庫中使用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
管理員權限執行:
1PowerShell.exe -ExecutionPolicy Bypass -File HookPasswordChangeNotify.ps1
如圖
4、自動記錄新密碼
在Server 2012 R2 x64下,手動修改域控密碼后
在C:\Windows\Temp下可以找到passwords.txt,其中記錄了新修改的密碼
如圖
在Server 2008 R2 x64下,同樣成功
如圖
0x05 小結
本文依舊是對常規功能做了演示,后續可自定義dll代碼實現更多高級功能,如自動上傳新密碼。
以下鏈接中的代碼可作為參考,其中實現了將獲取的新密碼上傳至Http服務器
http://carnal0wnage.attackresearch.com/2013/09/stealing-passwords-every-time-they.html
使用Hook PasswordChangeNotify來記錄新密碼,如果放在以前,進程注入的操作很容易被檢測,但是得益于Powershell應用的發展,通過Powershell來進程注入可以繞過常規的攔截。
當然,Hook PasswordChangeNotify僅僅是眾多Hook方法中的一個。
我已經Fork了clymb3r的代碼,并結合本文需要的代碼做了更新,下載地址如下:
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