0x00前言上一篇介绍了两种维护域控制权的方法——SSP和SkeletonKey。这两种方法都需要借助Mimikatz来实现,或多或少存在不足,所以这次介绍一种不需要使用Mimikatz的更隐蔽的后门方法——HookPasswordChangeNotify.0x01介绍Hook的概念PasswordChangeNotify最早由clymb3r于2013年9月15日提出,通过HookPasswordChangeNotify拦截修改后的账号密码。需要了解的相关背景知识如下:修改域控密码时,会进行以下同步操作:a.在修改域控制密码时,LSA首先调用PasswordFileter判断新密码是否满足密码复杂度要求。b.如果是,LSA继续调用PasswordChangeNotify在系统上同步更新密码。函数PasswordChangeNotify存在于rassfm.dll中。Rassfm.dll可以理解为RemoteAccessSubauthenticationdll,只存在于Server系统中。在xp、win7、win8等中不存在,可以使用dumpbin查看rassfm.dll的导出函数来验证结论2:1dumpbin/exportsc:\windows\system32\rassfm.dll如图0x02FeaturesFor之前介绍过的SecuritySupportProvider,在实际使用过程中难免有以下不足:安装后需要重启系统dll需要放在System32文件夹下,需要修改注册表,但是使用HookPasswordChangeNotify有优点:无需重启,无需修改注册表,甚至无需在系统中放置dll。可以说使用HookPasswordChangeNotify在隐蔽性方面优于SecuritySupportProvider0x03技术实现根据clymb3r提供的poc,HookPasswordChangeNotify的实现包括两部分:1.Hookdll下载链接:https://github.com/clymb3r/Misc-Windows-Hacking(1)为PasswordChangeNotify创建一个inlineHook,将初始函数重定向到PasswordChangeNotifyHook(2)在PasswordChangeNotifyHook中实现记录密码的操作,然后重新将控制权交给PasswordChangeNotify2,dll注入可以使用Powershell中的ProcessInjectiontricks将我们自己的dll注入到lsass进程中实现HookFunction0x04实测测试环境:Server2008R2x64Server2012R2x64测试步骤:1.生成Hookdllpoc下载地址:https://github.com/clymb3r/Misc-Windows-Hacking使用VS2015开发环境,MFC设置为在静态库中使用MFC编译工程,生成HookPasswordChange.dll2,生成powershell脚本dll注入下载Powershelldll注入脚本https://github.com/clymb3r/PowerShell/blob/master/Invoke-ReflectivePEInjection/Invoke-ReflectivePEInjection.ps1在代码末尾添加如下代码:Invoke-ReflectivePEInjection-PEPathHookPasswordChange.dll–procnamelsass并命名为HookPasswordChangeNotify.ps13,HookPasswordChangeNotify上传HookPasswordChangeNotify.ps1和HookPasswordChange.dll管理员权限执行:1PowerShell.exe-ExecutionPolicyBypass-FileHookPasswordChangeNotify.ps1如图4,Server下自动记录新密码2012R2x64,手动修改域控密码后可以在C:\Windows\Temp下找到passwords.txt,里面记录了新修改的密码d密码如图。Server2008R2x64下,同样成功,如0x05所示。总结本文还是常规功能的演示,后面可以自定义dll代码实现更高级的功能,比如自动上传新密码。下面链接中的代码可以作为参考,实现将获取的新密码上传到Http服务器http://carnal0wnage.attackresearch.com/2013/09/stealing-passwords-every-time-they.html使用挂钩PasswordChangeNotify以记录新密码。如果放在过去,进程注入的操作很容易被察觉,但得益于Powershell应用的发展,通过Powershell进行进程注入可以绕过常规拦截。当然,HookPasswordChangeNotify只是众多Hook方法中的一种。我已经fork了clymb3r的代码,并用本文所需的代码对其进行了更新。下载地址如下:https://github.com/3gstudent/Hook-PasswordChangeNotify0x06参考资料https://clymb3r.wordpress.com/2013/09/15/intercepting-password-changes-with-function-hooking/http://carnal0wnage.attackresearch.com/2013/09/stealing-passwords-every-time-they.htmlhttp://www.processlibrary.com/en/directory/files/rassfm/305529/https://github.com/clymb3r/Misc-Windows-Hacking/tree/master/HookPasswordChangehttp://www.slideshare.net/nFrontSecurity/how-do-password-filters-work
