{"id":1714,"date":"2015-09-10T15:58:51","date_gmt":"2015-09-10T19:58:51","guid":{"rendered":"https:\/\/adsecurity.org\/?p=1714"},"modified":"2017-12-30T12:47:27","modified_gmt":"2017-12-30T17:47:27","slug":"sneaky-active-directory-persistence-11-directory-service-restore-mode-dsrm","status":"publish","type":"post","link":"https:\/\/adsecurity.org\/?p=1714","title":{"rendered":"Sneaky Active Directory Persistence #11: Directory Service Restore Mode (DSRM)"},"content":{"rendered":"<p>The content in this post describes a method by which an attacker could persist administrative access to Active Directory after having Domain Admin level rights for 5 minutes.<\/p>\n<p><a href=\"https:\/\/adsecurity.org\/?p=1632\">I presented on this AD persistence method in Las Vegas at DEF CON 23 (2015).<\/a><\/p>\n<p><a href=\"https:\/\/adsecurity.org\/?p=1929\">Complete list of Sneaky Active Directory Persistence Tricks posts <\/a><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"text-decoration: underline;\"><strong>The Directory Restore Mode Account<\/strong><\/span><\/p>\n<p>Every Domain Controller has an internal \u201cBreak glass\u201d local administrator account to DC called the Directory Services Restore Mode (DSRM) account. The DSRM password set when DC is promoted and is rarely changed. The primary method to change the DSRM password on a Domain Controller involves running the ntdsutil command line tool.<\/p>\n<p>Beginning with hotfix <a href=\"http:\/\/support.microsoft.com\/kb\/961320\">KB961320<\/a> on Windows Server 2008, there is now the option to synchronize the DSRM password on a DC with a specific domain account. Note that this must be performed every time the password is changed; it does not create an automatic sync partnership.<\/p>\n<p><!--more--><\/p>\n<p><span style=\"text-decoration: underline;\"><a href=\"https:\/\/support.microsoft.com\/en-us\/kb\/322672\">Changing the DSRM Account Password:<\/a><\/span><\/p>\n<p>Run the following command on every DC (or remotely against every DC by replacing &#8220;null&#8221; with DC name)<\/p>\n<ul>\n<li>NTDSUTIL<\/li>\n<li>set dsrm password<\/li>\n<li>reset password on server null<\/li>\n<li>&lt;PASSWORD&gt;<\/li>\n<li><i>Q <\/i><\/li>\n<li><i>Q<\/i><\/li>\n<\/ul>\n<p><span style=\"text-decoration: underline;\"><a href=\"http:\/\/blogs.technet.com\/b\/askds\/archive\/2009\/03\/11\/ds-restore-mode-password-maintenance.aspx\">Synchronize the DSRM Account Password with a Domain Account (2k8 &amp; newer)<\/a>:<br \/>\n<\/span>In an elevated CMD prompt where you have logged on as a Domain Admin, run:<\/p>\n<p>NTDSUTIL<br \/>\nSET DSRM PASSWORD<br \/>\nSYNC FROM DOMAIN ACCOUNT <i>&lt;your user here&gt;<br \/>\n<\/i>Q<br \/>\nQ<\/p>\n<p><span style=\"text-decoration: underline;\"><strong><br \/>\nUsing DSRM to Backdoor Active Directory<br \/>\n<\/strong><\/span><\/p>\n<p>What&#8217;s interesting about the DSRM password is that the DSRM account is actually &#8220;Administrator&#8221;. <em>This means that once an attacker has the DSRM password for a Domain Controller (or DCs), it&#8217;s possible to use this account to logon to the Domain Controller over the network as a local administrator.<\/em><\/p>\n<p>We can confirm this with Mimikatz by creating a new AD user with a known password. Set the DSRM acount password sync from the domain user account and compare the hashes.<\/p>\n<p>DSRMTest NTLM Password Hash: 2b391dfc6690cc38547d74b8bd8a5b49<br \/>\nAdministrator (500) Local Account NTLM Password Hash: 2b391dfc6690cc38547d74b8bd8a5b49<\/p>\n<p>The second graphic shows a local Administrator account on the DC called &#8220;Administrator&#8221; with the same password hash as the DSRMTest domain user account.<\/p>\n<p><a href=\"https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/SneakyPersistence-DSRM-Mimikatz-DSRMTeast-And-Administrator.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1716\" src=\"https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/SneakyPersistence-DSRM-Mimikatz-DSRMTeast-And-Administrator.jpg\" alt=\"SneakyPersistence-DSRM-Mimikatz-DSRMTeast-And-Administrator\" width=\"988\" height=\"657\" srcset=\"https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/SneakyPersistence-DSRM-Mimikatz-DSRMTeast-And-Administrator.jpg 988w, https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/SneakyPersistence-DSRM-Mimikatz-DSRMTeast-And-Administrator-300x199.jpg 300w\" sizes=\"auto, (max-width: 988px) 100vw, 988px\" \/><\/a><\/p>\n<p>Note: The local SAM file is located here: C:\\Windows\\System32\\config\\SAM<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"text-decoration: underline;\"><b>Using DSRM Credentials<\/b><\/span><\/p>\n<p>Once you know the DSRM account password (local Administrator account on the DC), there are a few tricks to how it can be used.<\/p>\n<p><span style=\"text-decoration: underline;\">Logging on to a DC with the DSRM account:<\/span><\/p>\n<ol>\n<li>Restart in Directory Services Restore Mode (<i>bcdedit \/set safeboot dsrepair<\/i>)<\/li>\n<li>Access DSRM without rebooting (Windows Server 2008 and newer)\n<ol>\n<li>Set the registry key DsrmAdminLogonBehavior to 1<\/li>\n<li>Stop the Active Directory service<\/li>\n<li>Logon using DSRM credentials on the console.<\/li>\n<\/ol>\n<\/li>\n<li>Access DSRM without rebooting (Windows Server 2008 and newer)\n<ol>\n<li>Set the registry key DsrmAdminLogonBehavior to 2<\/li>\n<li>Logon using DSRM credentials on the console.<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>Access DSRM without Rebooting:<\/p>\n<p>PowerShell New-ItemProperty \u201cHKLM:\\System\\CurrentControlSet\\Control\\Lsa\\\u201d -Name \u201cDsrmAdminLogonBehavior\u201d -Value 2 -PropertyType DWORD<\/p>\n<p>The registry value is located at HKLM\\System\\CurrentControlSet\\Control\\Lsa\\DSRMAdminLogonBehavior. Its possible values are:<\/p>\n<ul>\n<li>0 (default): You can only use the DSRM administrator account if the DC is started in DSRM.<\/li>\n<li>1: You can use the DSRM administrator account to log on if the local AD DS service is stopped.<\/li>\n<li>2: You can always use the DSRM administrator account (This setting isn&#8217;t recommended, because password policies don&#8217;t apply to the DSRM administrator account).<\/li>\n<\/ul>\n<p>The capability of DSRM account credential is explored further in the post &#8220;<a href=\"https:\/\/adsecurity.org\/?p=1785\">Sneaky Active Directory Persistence #13: DSRM Persistence v2<\/a>&#8220;.<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"text-decoration: underline;\"><b>Using DSRM Credentials over the network<\/b><\/span><\/p>\n<p>It is possible to use the DSRM Credentials over the network.<\/p>\n<p>When Windows 2000 and Active Directory were released, DSRM being limited to console logon was a good security method. Today, however, there are several methods to logon to a system &#8220;at the console&#8221;:<\/p>\n<ol>\n<li>Virtualization Client\n<ol>\n<li>VMWare Remote Console (TCP 903)<\/li>\n<li>Hyper-V VM Connection (TCP 5900)<\/li>\n<\/ol>\n<\/li>\n<li>Out of Band Management (Lights Out, etc)<\/li>\n<li>Network KVM<\/li>\n<li>Remote Desktop Client when connecting to the &#8220;Console&#8221; which is &#8220;mstsc \/console&#8221; prior to Windows Server 2008 and &#8220;mstsc \/admin&#8221; with Windows Server 2008 and newer. Tested on Windows Server 2008 R2. Windows Server 2012R2 seems to refuse DSRM logon via RDP console.<\/li>\n<\/ol>\n<p><a href=\"https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/SneakyPersistence-DSRM-RDP-MSTSC-Admin.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1749\" src=\"https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/SneakyPersistence-DSRM-RDP-MSTSC-Admin.jpg\" alt=\"SneakyPersistence-DSRM-RDP-MSTSC-Admin\" width=\"301\" height=\"178\" srcset=\"https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/SneakyPersistence-DSRM-RDP-MSTSC-Admin.jpg 474w, https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/SneakyPersistence-DSRM-RDP-MSTSC-Admin-300x177.jpg 300w\" sizes=\"auto, (max-width: 301px) 100vw, 301px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/SneakyPersistence-DSRM-RDP-MSTSC-Admin-ADSDC01-Administrator-03.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1751\" src=\"https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/SneakyPersistence-DSRM-RDP-MSTSC-Admin-ADSDC01-Administrator-03.jpg\" alt=\"SneakyPersistence-DSRM-RDP-MSTSC-Admin-ADSDC01-Administrator-03\" width=\"387\" height=\"267\" srcset=\"https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/SneakyPersistence-DSRM-RDP-MSTSC-Admin-ADSDC01-Administrator-03.jpg 628w, https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/SneakyPersistence-DSRM-RDP-MSTSC-Admin-ADSDC01-Administrator-03-300x207.jpg 300w\" sizes=\"auto, (max-width: 387px) 100vw, 387px\" \/><\/a><\/p>\n<p>Once logged in as the local DC&#8217;s DSRM account (DC local admin), we can confirm we are on a DC and that this is the DC&#8217;s local administrator account. not a domain account.<\/p>\n<p><a href=\"https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/SneakyPersistence-DSRM-GetDC-ADSDC01-Whoami-DSRM.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1750\" src=\"https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/SneakyPersistence-DSRM-GetDC-ADSDC01-Whoami-DSRM.jpg\" alt=\"SneakyPersistence-DSRM-GetDC-ADSDC01-Whoami-DSRM\" width=\"963\" height=\"519\" srcset=\"https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/SneakyPersistence-DSRM-GetDC-ADSDC01-Whoami-DSRM.jpg 963w, https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/SneakyPersistence-DSRM-GetDC-ADSDC01-Whoami-DSRM-300x162.jpg 300w\" sizes=\"auto, (max-width: 963px) 100vw, 963px\" \/><\/a><\/p>\n<p>Further proof that this is not a domain account.<\/p>\n<p><a href=\"https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/SneakyPersistence-DSRM-Not-A-Domain-Admin-On-DC.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1753\" src=\"https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/SneakyPersistence-DSRM-Not-A-Domain-Admin-On-DC.jpg\" alt=\"SneakyPersistence-DSRM-Not-A-Domain-Admin-On-DC\" width=\"349\" height=\"166\" srcset=\"https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/SneakyPersistence-DSRM-Not-A-Domain-Admin-On-DC.jpg 349w, https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/SneakyPersistence-DSRM-Not-A-Domain-Admin-On-DC-300x143.jpg 300w\" sizes=\"auto, (max-width: 349px) 100vw, 349px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"text-decoration: underline;\"><b>Detection<\/b><\/span><\/p>\n<ul>\n<li>Monitor event logs relating to DSRM password change and usage\n<ul>\n<li>4794: An attempt was made to set the Directory Services Restore Mode administrator password (requires account management\/user management subcategory auditing enabled in 2008 R2 and newer).<\/li>\n<\/ul>\n<\/li>\n<li>Monitor the registry location and alert on values of 1 or 2\n<ul>\n<li>HKLM\\System\\CurrentControlSet\\Control\\Lsa\\DSRMAdminLogonBehavior<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><span style=\"text-decoration: underline;\"><strong>References:<\/strong><\/span><\/p>\n<ul>\n<li><a href=\"http:\/\/blogs.technet.com\/b\/askds\/archive\/2009\/03\/11\/ds-restore-mode-password-maintenance.aspx\">http:\/\/blogs.technet.com\/b\/askds\/archive\/2009\/03\/11\/ds-restore-mode-password-maintenance.aspx<\/a><\/li>\n<li>https:\/\/technet.microsoft.com\/en-us\/library\/cc754363.aspx<\/li>\n<li><a href=\"http:\/\/policelli.com\/blog\/archive\/2009\/03\/25\/back-to-the-basics-securing-the-directory-services-restore-mode-account\/\">http:\/\/policelli.com\/blog\/archive\/2009\/03\/25\/back-to-the-basics-securing-the-directory-services-restore-mode-account\/<\/a><\/li>\n<li>http:\/\/windowsitpro.com\/en\/changing-password-dcs-dsrm-and-recovery-console-administrator-account<\/li>\n<li>http:\/\/windowsitpro.com\/windows-server\/q-how-do-i-make-directory-services-restore-mode-dsrm-administrator-password-work-my-w<\/li>\n<li>https:\/\/technet.microsoft.com\/en-us\/library\/cc816897(v=ws.10).aspx<\/li>\n<li>http:\/\/blogs.metcorpconsulting.com\/tech\/?p=501<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The content in this post describes a method by which an attacker could persist administrative access to Active Directory after having Domain Admin level rights for 5 minutes. I presented on this AD persistence method in Las Vegas at DEF CON 23 (2015). Complete list of Sneaky Active Directory Persistence Tricks posts &nbsp; The Directory &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"https:\/\/adsecurity.org\/?p=1714\">Continue reading<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[565,11,234,2],"tags":[20,537,113,544,86,518,542,589,593,590,594,595,591,207,597,596,592],"class_list":["post-1714","post","type-post","status-publish","format-standard","hentry","category-activedirectorysecurity","category-microsoft-security","category-security-conference-presentationvideo","category-technical-reference","tag-activedirectory","tag-activedirectoryattack","tag-activedirectorysecurity","tag-adpersistence","tag-adsecurity","tag-defcon","tag-defcon23","tag-directoryservicesrestoremode","tag-directoryservicesrestoremodepassword","tag-dsrm","tag-dsrmlogon","tag-dsrmnetworklogon","tag-dsrmpassword","tag-mimikatz","tag-sneakyactivedirectorypersistence","tag-sneakyadpersistence","tag-toryattack","item-wrap"],"_links":{"self":[{"href":"https:\/\/adsecurity.org\/index.php?rest_route=\/wp\/v2\/posts\/1714","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/adsecurity.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/adsecurity.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/adsecurity.org\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/adsecurity.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1714"}],"version-history":[{"count":14,"href":"https:\/\/adsecurity.org\/index.php?rest_route=\/wp\/v2\/posts\/1714\/revisions"}],"predecessor-version":[{"id":3901,"href":"https:\/\/adsecurity.org\/index.php?rest_route=\/wp\/v2\/posts\/1714\/revisions\/3901"}],"wp:attachment":[{"href":"https:\/\/adsecurity.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1714"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/adsecurity.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1714"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/adsecurity.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1714"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}