{"id":1729,"date":"2015-09-25T16:00:48","date_gmt":"2015-09-25T20:00:48","guid":{"rendered":"https:\/\/adsecurity.org\/?p=1729"},"modified":"2018-05-18T00:43:12","modified_gmt":"2018-05-18T04:43:12","slug":"mimikatz-dcsync-usage-exploitation-and-detection","status":"publish","type":"post","link":"https:\/\/adsecurity.org\/?p=1729","title":{"rendered":"Mimikatz DCSync Usage, Exploitation, and Detection"},"content":{"rendered":"<p><a href=\"https:\/\/adsecurity.org\/?p=1738\">Note: I presented on this AD persistence method at DerbyCon (2015).<\/a><\/p>\n<p>A major feature added to Mimkatz in August 2015 is &#8220;DCSync&#8221; which effectively &#8220;impersonates&#8221; a Domain Controller and requests account password data from the targeted Domain Controller. DCSync was written by Benjamin Delpy and Vincent Le Toux.<\/p>\n<p>The exploit method prior to DCSync was to run Mimikatz or Invoke-Mimikatz on a Domain Controller to get the KRBTGT password hash to create Golden Tickets. With Mimikatz&#8217;s DCSync and the appropriate rights, the attacker can pull the password hash, as well as previous password hashes, from a Domain Controller over the network without requiring interactive logon or copying off the Active Directory database file (ntds.dit).<\/p>\n<p>Special rights are required to run DCSync. Any member of Administrators, Domain Admins, or Enterprise Admins as well as Domain Controller computer accounts are able to run DCSync to pull password data. Note that Read-Only Domain Controllers are not\u00a0 allowed to pull password data for users by default.<\/p>\n<p><a href=\"https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/Mimikatz-DCSync-UserRights-DCR-Administrator-500-Dump2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1730\" src=\"https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/Mimikatz-DCSync-UserRights-DCR-Administrator-500-Dump2.jpg\" alt=\"Mimikatz-DCSync-UserRights-DCR-Administrator-500-Dump2\" width=\"691\" height=\"491\" srcset=\"https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/Mimikatz-DCSync-UserRights-DCR-Administrator-500-Dump2.jpg 691w, https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/Mimikatz-DCSync-UserRights-DCR-Administrator-500-Dump2-300x213.jpg 300w\" sizes=\"auto, (max-width: 691px) 100vw, 691px\" \/><\/a><\/p>\n<p>The credentials section in the graphic above shows the current NTLM hashes as well as the password history. This information can be valuable to an attacker since it can provide password creation strategies for users (if cracked).<\/p>\n<p><!--more--><\/p>\n<p><strong>Will&#8217;s post has great information on Red Team usage of Mimikatz DCSync:<\/strong><br \/>\n<a href=\"http:\/\/www.harmj0y.net\/blog\/redteaming\/mimikatz-and-dcsync-and-extrasids-oh-my\/\">Mimikatz and DCSync and ExtraSids, Oh My<\/a><\/p>\n<p>&nbsp;<\/p>\n<h4><b>How DCSync works:<\/b><\/h4>\n<ol>\n<li>Discovers Domain Controller in the specified domain name.<\/li>\n<li>Requests the Domain Controller replicate the user credentials via <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/dd207691.aspx\">GetNCChanges <\/a>(leveraging <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/cc228086.aspx\">Directory Replication Service (DRS) Remote Protocol<\/a>)<\/li>\n<\/ol>\n<p>I have previously done some packet captures for <a href=\"http:\/\/blogs.metcorpconsulting.com\/tech\/?p=923\">Domain Controller replication<\/a> and identified the intra-DC communication flow regarding how Domain Controllers replicate.<\/p>\n<p>The Samba Wiki describes the <a href=\"https:\/\/wiki.samba.org\/index.php\/DRSUAPI\">DSGetNCChanges function<\/a>:<\/p>\n<p><i>&#8220;The client DC sends a DSGetNCChanges request to the server when the first one wants to get AD objects updates from the second one. The response contains a set of updates that the client has to apply to its NC replica. <\/i><\/p>\n<p><i>It is possible that the set of updates is too large for only one response message. In those cases, multiple DSGetNCChanges requests and responses are done. This process is called replication cycle or simply cycle.&#8221;<\/i><\/p>\n<p><i>&#8220;When a DC receives a DSReplicaSync Request, then for each DC that it replicates from (stored in RepsFrom data structure) it performs a replication\u00a0cycle where it behaves like a client and makes DSGetNCChanges requests to that DC. So it gets up-to-date AD objects from each of the DC&#8217;s which it replicates from.&#8221;<\/i><\/p>\n<p>From MSDN:<\/p>\n<blockquote>\n<div id=\"mainSection\">\n<div id=\"mainBody\">\n<div id=\"collapseableSection\" class=\"section\">\n<p>The IDL_DRSGetNCChanges method replicates <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/cc228090.aspx#gt_b242435b-73cc-4c4e-95f0-b2a2ff680493\">updates<\/a> from an <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/cc228090.aspx#gt_325d116f-cdbe-4dbd-b7e6-769ba75bf210\">NC replica<\/a> on the server.<\/p>\n<div>\n<pre>\u00a0ULONG IDL_DRSGetNCChanges(\r\n\u00a0  [in, ref] DRS_HANDLE hDrs,\r\n\u00a0  [in] DWORD dwInVersion,\r\n\u00a0  [in, ref, switch_is(dwInVersion)] \r\n\u00a0    DRS_MSG_GETCHGREQ* pmsgIn,\r\n\u00a0  [out, ref] DWORD* pdwOutVersion,\r\n\u00a0  [out, ref, switch_is(*pdwOutVersion)] \r\n\u00a0    DRS_MSG_GETCHGREPLY* pmsgOut\r\n\u00a0);\r\n<\/pre>\n<\/div>\n<p><strong>hDrs: <\/strong>The <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/cc228090.aspx#gt_8a7f6700-8311-45bc-af10-82e10accd331\">RPC<\/a> context handle returned by the <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/cc228292.aspx\">IDL_DRSBind<\/a> method.<\/p>\n<p><strong>dwInVersion: <\/strong>Version of the request message.<\/p>\n<p><strong>pmsgIn: <\/strong>A pointer to the request message.<\/p>\n<p><strong>pdwOutVersion: <\/strong>A pointer to the version of the response message.<\/p>\n<p><strong>pmsgOut: <\/strong>A pointer to the response message.<\/p>\n<p><strong>Return Values: <\/strong>0 if successful, otherwise a <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/cc228090.aspx#gt_459db7bd-5066-44e3-89c1-f0e4806b7a1b\">Windows error code<\/a>.<\/p>\n<p><strong>Exceptions Thrown<\/strong>: This method might throw the following exceptions beyond those thrown by the underlying RPC protocol (as specified in <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/cc243560.aspx\">[MS-RPCE]<\/a>): ERROR_INVALID_HANDLE, ERROR_DS_DRS_EXTENSIONS_CHANGED, ERROR_DS_DIFFERENT_REPL_EPOCHS, and\u00a0 ERROR_INVALID_PARAMETER.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/blockquote>\n<p>&nbsp;<\/p>\n<h4><b><span style=\"text-decoration: underline;\">Delegating Rights to Pull Account data:<\/span><\/b><\/h4>\n<p>It is possible to use a regular domain user account to run DCSync. The combination of the following three rights need to be delegated at the domain level in order for the user account to successfully retrieve the password data with DCSync:<\/p>\n<ul>\n<li>Replicating Directory Changes (<a href=\"https:\/\/docs.microsoft.com\/en-us\/previous-versions\/windows\/it-pro\/windows-server-2003\/cc772673(v=ws.10)\">DS-Replication-Get-Changes<\/a>)<br \/>\n<em>Extended right needed to replicate only those changes from a given NC that are also replicated to the Global Catalog (which excludes secret domain data). This constraint is only meaningful for Domain NCs.<\/em><\/li>\n<li>Replicating Directory Changes All (<a href=\"https:\/\/docs.microsoft.com\/en-us\/previous-versions\/windows\/it-pro\/windows-server-2003\/cc772673(v=ws.10)\">DS-Replication-Get-Changes-All<\/a>)<br \/>\n<em>Control access right that allows the replication of all data in a given replication NC, including secret domain data.<\/em><\/li>\n<li><em>Replicating Directory Changes In Filtered Set (rare, only required in some environments)<\/em><\/li>\n<\/ul>\n<p><a href=\"https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/Mimikatz-DCSync-UserRights-DCR-DomainPermissionsConfig.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1731\" src=\"https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/Mimikatz-DCSync-UserRights-DCR-DomainPermissionsConfig.jpg\" alt=\"Mimikatz-DCSync-UserRights-DCR-DomainPermissionsConfig\" width=\"401\" height=\"376\" srcset=\"https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/Mimikatz-DCSync-UserRights-DCR-DomainPermissionsConfig.jpg 401w, https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/Mimikatz-DCSync-UserRights-DCR-DomainPermissionsConfig-300x281.jpg 300w\" sizes=\"auto, (max-width: 401px) 100vw, 401px\" \/><\/a><\/p>\n<p><em>Note that members of the Administrators and Domain Controller groups have these rights by default.<\/em><\/p>\n<p><a href=\"https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/DCSync-ADDomain-DefaultRights.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2876\" src=\"https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/DCSync-ADDomain-DefaultRights.png\" alt=\"DCSync-ADDomain-DefaultRights\" width=\"394\" height=\"298\" srcset=\"https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/DCSync-ADDomain-DefaultRights.png 637w, https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/DCSync-ADDomain-DefaultRights-300x227.png 300w\" sizes=\"auto, (max-width: 394px) 100vw, 394px\" \/><\/a><\/p>\n<h4><span style=\"text-decoration: underline;\"><strong>Pulling Password Data Using DCSync<\/strong><\/span><\/h4>\n<p>Once the account is delegated the ability to replicate objects, the account can run Mimikatz DCSync:<\/p>\n<blockquote><p>mimikatz &#8220;lsadump::dcsync \/domain:rd.adsecurity.org \/user:krbtgt&#8221;<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/Mimikatz-DCSync-UserRights-DCR-KRBTGT-Dump.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1926\" src=\"https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/Mimikatz-DCSync-UserRights-DCR-KRBTGT-Dump.jpg\" alt=\"Mimikatz-DCSync-UserRights-DCR-KRBTGT-Dump\" width=\"690\" height=\"501\" srcset=\"https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/Mimikatz-DCSync-UserRights-DCR-KRBTGT-Dump.jpg 690w, https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/Mimikatz-DCSync-UserRights-DCR-KRBTGT-Dump-300x218.jpg 300w\" sizes=\"auto, (max-width: 690px) 100vw, 690px\" \/><\/a><br \/>\nTargeting an admin account with DCSync can also provide the account&#8217;s password history (in hash format). Since there are LMHashes listed it may be possible to crack these and gain insight into the password strategy the admin uses. This may provide the attacker to guess the next password the admin uses if access is lost.<\/p>\n<blockquote><p>mimikatz &#8220;lsadump::dcsync \/domain:rd.adsecurity.org \/user:Administrator&#8221;<\/p><\/blockquote>\n<p><a href=\"https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/Mimikatz-DCSync-UserRights-DCR-Administrator-500-Dump2-021.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1927\" src=\"https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/Mimikatz-DCSync-UserRights-DCR-Administrator-500-Dump2-021.jpg\" alt=\"Mimikatz-DCSync-UserRights-DCR-Administrator-500-Dump2-02\" width=\"691\" height=\"491\" srcset=\"https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/Mimikatz-DCSync-UserRights-DCR-Administrator-500-Dump2-021.jpg 691w, https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/Mimikatz-DCSync-UserRights-DCR-Administrator-500-Dump2-021-300x213.jpg 300w\" sizes=\"auto, (max-width: 691px) 100vw, 691px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<h4><span style=\"text-decoration: underline;\"><b>Detecting DCSync usage<\/b><\/span><\/h4>\n<p>While there may be event activity that could be used to identify DCSync usage, the best detection method is through network monitoring.<\/p>\n<p><strong>Step 1: Identify all Domain Controller IP addresses and add to &#8220;Replication Allow List&#8221;.<\/strong><\/p>\n<p><span style=\"text-decoration: underline;\">PowerShell Active Directory module cmdlet:<\/span><\/p>\n<blockquote><p>Get-ADDomainController -filter * | select IPv4Address<\/p><\/blockquote>\n<p><span style=\"text-decoration: underline;\"><br \/>\nPowerShell:<\/span><\/p>\n<blockquote><p>[System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().DomainControllers | select IPAddress<\/p><\/blockquote>\n<p><span style=\"text-decoration: underline;\"><br \/>\nNslookup (if DC runs DNS):<\/span><\/p>\n<blockquote><p>nslookup<br \/>\nSet type=all<br \/>\n_ldap._tcp.dc._msdcs.DOMAIN.COM<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<p><strong>Step 2: Configure IDS to trigger if DsGetNCChange request originates an IP not on the &#8220;Replication Allow List&#8221; (list of DC IPs).<\/strong><\/p>\n<p><a href=\"https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/Mimikatz-DCSync-KRBTGT-PacketCapture-DSGetNCChanges.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1733\" src=\"https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/Mimikatz-DCSync-KRBTGT-PacketCapture-DSGetNCChanges.jpg\" alt=\"Mimikatz-DCSync-KRBTGT-PacketCapture-DSGetNCChanges\" width=\"1011\" height=\"383\" srcset=\"https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/Mimikatz-DCSync-KRBTGT-PacketCapture-DSGetNCChanges.jpg 1011w, https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/Mimikatz-DCSync-KRBTGT-PacketCapture-DSGetNCChanges-300x114.jpg 300w\" sizes=\"auto, (max-width: 1011px) 100vw, 1011px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/Mimikatz-DCSync-KRBTGT-PacketCapture-DSGetNCChanges02.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1732\" src=\"https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/Mimikatz-DCSync-KRBTGT-PacketCapture-DSGetNCChanges02.jpg\" alt=\"Mimikatz-DCSync-KRBTGT-PacketCapture-DSGetNCChanges02\" width=\"1002\" height=\"474\" srcset=\"https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/Mimikatz-DCSync-KRBTGT-PacketCapture-DSGetNCChanges02.jpg 1002w, https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/09\/Mimikatz-DCSync-KRBTGT-PacketCapture-DSGetNCChanges02-300x142.jpg 300w\" sizes=\"auto, (max-width: 1002px) 100vw, 1002px\" \/><\/a><\/p>\n<p>There are other tools that perform this same process so it&#8217;s better to focus on detecting the method instead of specific artifacts.<\/p>\n<p>Other tools that leverage GetNCChanges<\/p>\n<ul>\n<li>Impacket: <a href=\"https:\/\/github.com\/CoreSecurity\/impacket\">https:\/\/github.com\/CoreSecurity\/impacket<\/a><\/li>\n<li>DSInternals: <a href=\"https:\/\/www.dsinternals.com\/en\/retrieving-active-directory-passwords-remotely\/\">https:\/\/www.dsinternals.com\/en\/retrieving-active-directory-passwords-remotely\/<\/a><\/li>\n<\/ul>\n<p>Note that Full Control rights at the domain provides these rights as well, so limit who has domain-level admin rights.<\/p>\n<p>&nbsp;<\/p>\n<h4><span style=\"text-decoration: underline;\"><b>References:<\/b><\/span><\/h4>\n<ul>\n<li><a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/dd207691.aspx\">MSDN GetNCChanges<\/a><\/li>\n<li><a href=\"https:\/\/support.microsoft.com\/en-us\/kb\/303972\">How to grant the &#8220;Replicating Directory Changes&#8221; permission for the Microsoft Metadirectory Services ADMA service account <\/a><\/li>\n<li><a href=\"https:\/\/technet.microsoft.com\/en-us\/library\/Hh296982.aspx\">Grant Active Directory Domain Services permissions for profile synchronization in SharePoint Server 2013<\/a><\/li>\n<li><a href=\"http:\/\/support.microsoft.com\/kb\/891995\">How to poll for object attribute changes in Active Directory on Windows 2000 and Windows Server 2003\u00a0 <\/a><\/li>\n<li><a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/ms677626%28v=vs.85%29.aspx\">Polling for Changes Using the DirSync Control <\/a><\/li>\n<li><a href=\"http:\/\/www.harmj0y.net\/blog\/redteaming\/mimikatz-and-dcsync-and-extrasids-oh-my\/\">Mimikatz and DCSync and ExtraSids, Oh My<\/a><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Note: I presented on this AD persistence method at DerbyCon (2015). A major feature added to Mimkatz in August 2015 is &#8220;DCSync&#8221; which effectively &#8220;impersonates&#8221; a Domain Controller and requests account password data from the targeted Domain Controller. DCSync was written by Benjamin Delpy and Vincent Le Toux. The exploit method prior to DCSync was &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"https:\/\/adsecurity.org\/?p=1729\">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":[612,598,605,604,603,610,609,600,602,613,601,611,207,599,606,607,608],"class_list":["post-1729","post","type-post","status-publish","format-standard","hentry","category-activedirectorysecurity","category-microsoft-security","category-security-conference-presentationvideo","category-technical-reference","tag-dcerpc","tag-dcsync","tag-dcsyncasuser","tag-dcsyncrights","tag-detectdcsync","tag-domaincontrollerimpersonation","tag-drsuapi","tag-dsgetncchanges","tag-dsinternals","tag-gss-api","tag-impacket","tag-impersonatedc","tag-mimikatz","tag-mimikatzdcsync","tag-replicatingdirectorychanges","tag-replicatingdirectorychangesall","tag-replicatingdirectorychangesinfilteredset","item-wrap"],"_links":{"self":[{"href":"https:\/\/adsecurity.org\/index.php?rest_route=\/wp\/v2\/posts\/1729","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=1729"}],"version-history":[{"count":15,"href":"https:\/\/adsecurity.org\/index.php?rest_route=\/wp\/v2\/posts\/1729\/revisions"}],"predecessor-version":[{"id":3991,"href":"https:\/\/adsecurity.org\/index.php?rest_route=\/wp\/v2\/posts\/1729\/revisions\/3991"}],"wp:attachment":[{"href":"https:\/\/adsecurity.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1729"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/adsecurity.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1729"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/adsecurity.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1729"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}