{"id":393,"date":"2024-03-23T07:16:41","date_gmt":"2024-03-23T07:16:41","guid":{"rendered":"https:\/\/jsec-rt.com\/?p=393"},"modified":"2024-07-08T22:53:31","modified_gmt":"2024-07-09T02:53:31","slug":"rt-ataques-conocidos-sobre-kerberos-parte-2-2","status":"publish","type":"post","link":"https:\/\/jsec-rt.com\/index.php\/en\/2024\/03\/23\/rt-ataques-conocidos-sobre-kerberos-parte-2-2\/","title":{"rendered":"RT &#8211; Known Kerberos attacks &#8211; Part 2"},"content":{"rendered":"\n<p>In this entry, we continue with some known attacks on Active Directory environments using Kerberos, mainly lateral movement and persistence.<\/p>\n\n\n\n<p>One of the oldest and most known ways of lateral movement is Pass the hash, where we use a user&#8217;s NTLM hash to gain access to resources or computers where the user has some level of privilege.<\/p>\n\n\n\n<p>As seen in a previous post, Pass the hash becomes quite critical, since it is not necessary for the attacker to know the user&#8217;s password in order to impersonate it, where the impact increases exponentially when using local administrator accounts, since, without the correct monitoring tools, it will be difficult to detect this type of attack.<\/p>\n\n\n\n<p>When an attacker gains access to a local administrator account, he could exploit PTH if the following conditions are met:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>There are other hosts with a shared password between local administrators and a compromised credential.<\/li>\n\n\n\n<li>Windows hosts allow remote authentication using local accounts.<\/li>\n\n\n\n<li>Local administrator accounts are enabled.<\/li>\n<\/ul>\n\n\n\n<p>However, there are advanced monitoring tools that could detect possible PTH attacks, both at the domain and local level. (Since PTH authentication is done using local administrators, access logs are not recorded in a domain controller, they stay on the computer, so a Blue Team would have to analyze the local logs of internal computers, or implement a SIEM to obtain all this information that is not being stored in the domain controllers).<\/p>\n\n\n\n<p>There are numerous articles on how to detect PTH or indications that can be observed in the access logs of the respective computers that suggest that this attack is being carried out.<\/p>\n\n\n\n<p>For this reason, we present in this post a slightly stealthier technique than PTH, called Pass the ticket.<\/p>\n\n\n\n<p>The Kerberos authentication flow is a bit complicated to explain in a nutshell (I don&#8217;t fully understand it yet enough to write confidently about it), but for this scenario, we&#8217;ll keep things simple.<\/p>\n\n\n\n<p>When a user authenticates through Kerberos, as a result, he gets a Ticket, either a service ticket or a &#8220;ticket granting ticket (TGT)&#8221;, this ticket could be considered as an identity document, which can be used in the internal domain to access certain resources without the need to authenticate with username and password.<\/p>\n\n\n\n<p>If an attacker gains control of one of these tickets, he can use it to impersonate the affected user and access internal domain resources as if he were the owner of the ticket.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Scenario 1 &#8211; Pass the ticket<\/h2>\n\n\n\n<p>In order to configure the vulnerable environment, the only thing we need to do is login into a host with multiple users, in my case, on the host &#8220;TECNOLOGIA01&#8221;.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"692\" src=\"https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-19-1024x692.png\" alt=\"\" class=\"wp-image-121\" srcset=\"https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-19-1024x692.png 1024w, https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-19-300x203.png 300w, https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-19-768x519.png 768w, https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-19.png 1202w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Exploitation<\/h2>\n\n\n\n<p>We can use the &#8220;impacket suite&#8221; to perform the attack, leveraging an existing script that automates the credential harvesting process.<\/p>\n\n\n\n<p>As it was mentioned in previous posts, the domain authentication information is stored in memory, specifically within the &#8220;LSASS&#8221; process, so if we dump the process, we can obtain this information.<\/p>\n\n\n\n<p>For this task, we can use multiple methods, to mention a few:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>From the GUI, we can create a dump using the task administrator.<\/li>\n\n\n\n<li>Using &#8220;Procdump&#8221; from Sysinternals. (procdump64.exe -accentual -ma lsass.exe -o lsass.dmp)<\/li>\n\n\n\n<li>Using &#8220;crackmapexec&#8221; modules. (LSASSY or procdump)<\/li>\n\n\n\n<li>Using a native DLL: C:\\Windows\\System32\\rundll32.exe C:\\windows\\System32\\comsvcs.dll, MiniDump <strong>PID-LSASS<\/strong> C:\\temp\\lsass.dmp full<\/li>\n\n\n\n<li>Other tools (Processdump from Cisco Jabber, SQLDumper from MSSQL, mimikatz, etc.)<\/li>\n<\/ul>\n\n\n\n<p>The script I mentioned before is called <strong>autoProc.py<\/strong>.<\/p>\n\n\n\n<p>Link: https:\/\/gist.github.com\/knavesec\/0bf192d600ee15f214560ad6280df556<\/p>\n\n\n\n<p>It&#8217;s recommended to edit the script, to set the correct path where the tool will look for the procdump binary.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"874\" height=\"324\" src=\"https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-20.png\" alt=\"\" class=\"wp-image-122\" srcset=\"https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-20.png 874w, https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-20-300x111.png 300w, https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-20-768x285.png 768w\" sizes=\"auto, (max-width: 874px) 100vw, 874px\" \/><\/figure>\n\n\n\n<p>This script will authenticate to the host through &#8220;wmiexec&#8221;, it&#8217;ll upload the &#8220;procdump&#8221; binary, execute it, downloads and deletes the output from the victim host and processes it using &#8220;pypykatz&#8221;.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"902\" height=\"372\" src=\"https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-21.png\" alt=\"\" class=\"wp-image-123\" srcset=\"https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-21.png 902w, https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-21-300x124.png 300w, https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-21-768x317.png 768w\" sizes=\"auto, (max-width: 902px) 100vw, 902px\" \/><\/figure>\n\n\n\n<p>Since we have administrative access on the &#8220;TECNOLOGIA01&#8221; host, we can execute &#8220;autoProc&#8221; to obtain the lsass dump from the host.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"965\" height=\"689\" src=\"https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-26.png\" alt=\"\" class=\"wp-image-128\" srcset=\"https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-26.png 965w, https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-26-300x214.png 300w, https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-26-768x548.png 768w\" sizes=\"auto, (max-width: 965px) 100vw, 965px\" \/><\/figure>\n\n\n\n<p>In this case, Windows defender is preventing the dump, so we&#8217;ll proceed to disable it remotely, as we did so on previous posts.<\/p>\n\n\n\n<p><strong>PS C:\\Windows\\System32&gt; Set-MPPreference -disableRealTimeMonitoring $true<\/strong><\/p>\n\n\n\n<p>Once the antivirus is disabled, we successfully obtain the required information.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"942\" height=\"719\" src=\"https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-27.png\" alt=\"\" class=\"wp-image-129\" srcset=\"https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-27.png 942w, https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-27-300x229.png 300w, https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-27-768x586.png 768w\" sizes=\"auto, (max-width: 942px) 100vw, 942px\" \/><\/figure>\n\n\n\n<p>This time, by specifying the &#8220;-k&#8221; flag on &#8220;pypykatz&#8221;, we&#8217;ll be able to extract the existing Kerberos tickets.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"479\" height=\"591\" src=\"https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-28.png\" alt=\"\" class=\"wp-image-130\" srcset=\"https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-28.png 479w, https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-28-243x300.png 243w\" sizes=\"auto, (max-width: 479px) 100vw, 479px\" \/><\/figure>\n\n\n\n<p>Listing the extracted tickets.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1017\" height=\"448\" src=\"https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-29.png\" alt=\"\" class=\"wp-image-131\" srcset=\"https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-29.png 1017w, https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-29-300x132.png 300w, https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-29-768x338.png 768w\" sizes=\"auto, (max-width: 1017px) 100vw, 1017px\" \/><\/figure>\n\n\n\n<p>We can observe that there are many service tickets, as well as TGT tickets for two users, <strong>Service_BD<\/strong> and <strong>Administrator<\/strong>, which we can use to impersonate these users.<\/p>\n\n\n\n<p>Since we extracted these tickets straight from a dump file, we need to convert the kerberos tickets from .kirbi to .ccache, we can do that by using the tool &#8220;kirby2ccache&#8221;, then we set up an environment variable named &#8220;KRB5CCNAME&#8221; pointing towards our new .ccache ticket and we execute &#8220;klist&#8221;, confirming the ticket is being recognized.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"229\" src=\"https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-30-1024x229.png\" alt=\"\" class=\"wp-image-132\" srcset=\"https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-30-1024x229.png 1024w, https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-30-300x67.png 300w, https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-30-768x172.png 768w, https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-30.png 1143w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>We try to spawn a semi-interactive shell through &#8220;wmiexec&#8221; on the domain controller using the extracted ticket.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"681\" height=\"799\" src=\"https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-31.png\" alt=\"\" class=\"wp-image-133\" srcset=\"https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-31.png 681w, https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-31-256x300.png 256w\" sizes=\"auto, (max-width: 681px) 100vw, 681px\" \/><\/figure>\n\n\n\n<p>By using the parameter &#8220;-k&#8221;, the tool will use the active kerberos ticket instead of a password, we should also use the parameter &#8220;-no-pass&#8221; to prevent any errors in the kerberos authentication procedure.<\/p>\n\n\n\n<p>The ticket works and we get a valid session on the domain controller, giving us full control over it without the need to obtain the password or NTLM hash of the domain admin.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">PERSISTENCE &#8211; GOLDEN TICKET<\/h2>\n\n\n\n<p>Since we have a valid domain admin kerberos ticket, we&#8217;ll use it to create a golden ticket and ensure persistence, which will give us access as a domain admin for a default time of 10 years, assuming the ticket wasn&#8217;t detected.<\/p>\n\n\n\n<p>To forge these tickets, we need the following bits of information.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>NTLM hash of the <strong>KRBTGT<\/strong> user<\/li>\n\n\n\n<li>Domain SID<\/li>\n\n\n\n<li>FQDN<\/li>\n\n\n\n<li><\/li>\n<\/ul>\n\n\n\n<p>Using <strong>impacket-secretsdump<\/strong>, we can obtain the <strong>KRBTGT<\/strong> user NTLM hash.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"827\" height=\"207\" src=\"https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-34.png\" alt=\"\" class=\"wp-image-136\" srcset=\"https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-34.png 827w, https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-34-300x75.png 300w, https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-34-768x192.png 768w\" sizes=\"auto, (max-width: 827px) 100vw, 827px\" \/><\/figure>\n\n\n\n<p>The &#8220;<strong>-just-dc-user&#8221; <\/strong>parameter will allow us to extract a single user hash from the NTDS.dit database.<\/p>\n\n\n\n<p><strong>KRBTGT<\/strong>: 7f9b6cfb&#8230;&#8230;bf1<\/p>\n\n\n\n<p>To extract the domain SID, we can also use impacket suite, in this case, &#8220;lookupsid&#8221;.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"610\" height=\"591\" src=\"https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-35.png\" alt=\"\" class=\"wp-image-137\" srcset=\"https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-35.png 610w, https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-35-300x291.png 300w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/figure>\n\n\n\n<p>To obtain this information, we can use any valid user within the domain, even low privileged ones.<\/p>\n\n\n\n<p>Domain SID: S-1-5-21&#8230;..13415<\/p>\n\n\n\n<p>For the FQDN, we can spawn a remote session on the Domain Controller and query the operating system through WMIC.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"848\" height=\"804\" src=\"https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-36.png\" alt=\"\" class=\"wp-image-138\" srcset=\"https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-36.png 848w, https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-36-300x284.png 300w, https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-36-768x728.png 768w\" sizes=\"auto, (max-width: 848px) 100vw, 848px\" \/><\/figure>\n\n\n\n<p>FQDN: jsec.local<\/p>\n\n\n\n<p>Now we can forge our golden ticket using impacket suite, &#8220;ticketer&#8221;.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"238\" src=\"https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-37-1024x238.png\" alt=\"\" class=\"wp-image-139\" srcset=\"https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-37-1024x238.png 1024w, https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-37-300x70.png 300w, https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-37-768x179.png 768w, https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-37.png 1160w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>impacket-ticketer -nthash HASH-KRBTGT -domain-sid SID -domain FQDN USER<\/p>\n\n\n\n<p>We&#8217;ll create a ticket for the domain user &#8216;DC01$&#8217; and save it as &#8220;<strong>DC01$.ccache<\/strong>&#8220;.<\/p>\n\n\n\n<p>We export the ticket with &#8220;export KRB5CCNAME=&#8217;.\/DC01$.ccache'&#8221; and dump the NTDS.dit database once again.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"702\" src=\"https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-38-1024x702.png\" alt=\"\" class=\"wp-image-140\" srcset=\"https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-38-1024x702.png 1024w, https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-38-300x206.png 300w, https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-38-768x527.png 768w, https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-38.png 1126w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>We get all of the domain users NTLM hashes, confirming the validity of our ticket.<\/p>\n\n\n\n<p>It&#8217;s important to note that we don&#8217;t even need to impersonate a valid domain user, we can create the ticket for a non-existing user and we&#8217;ll still have Domain Admin privileges, because of the way the ticket is forged.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"691\" src=\"https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-39-1024x691.png\" alt=\"\" class=\"wp-image-141\" srcset=\"https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-39-1024x691.png 1024w, https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-39-300x203.png 300w, https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-39-768x518.png 768w, https:\/\/jsec-rt.com\/wp-content\/uploads\/2022\/06\/image-39.png 1225w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>We generated a new ticket for the user &#8220;<strong>goldenticket<\/strong>&#8220;, which doesn&#8217;t exist in the current domain, but the access is still granted.<\/p>\n\n\n\n<p>These are some of the known Kerberos attacks, mainly for lateral movement and persistence.<\/p>\n\n\n\n<p>In future posts, we&#8217;ll explore slightly more complicated scenarios (Constrained delegation, Domain Admin to Enterprise Admin, etc.).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this entry, we continue with some known attacks on Active Directory environments using Kerberos, mainly lateral movement and persistence. One of the oldest and most known ways of lateral movement is Pass the hash, where we use a user&#8217;s NTLM hash to gain access to resources or computers where <a href=\"https:\/\/jsec-rt.com\/index.php\/en\/2024\/03\/23\/rt-ataques-conocidos-sobre-kerberos-parte-2-2\/\" class=\"btn-link\">Continue Reading<i class=\"ion-ios-arrow-right\"><\/i><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22],"tags":[28,30],"class_list":["post-393","post","type-post","status-publish","format-standard","hentry","category-p-rt-en","tag-english","tag-rt"],"_links":{"self":[{"href":"https:\/\/jsec-rt.com\/index.php\/wp-json\/wp\/v2\/posts\/393","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jsec-rt.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jsec-rt.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jsec-rt.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jsec-rt.com\/index.php\/wp-json\/wp\/v2\/comments?post=393"}],"version-history":[{"count":1,"href":"https:\/\/jsec-rt.com\/index.php\/wp-json\/wp\/v2\/posts\/393\/revisions"}],"predecessor-version":[{"id":421,"href":"https:\/\/jsec-rt.com\/index.php\/wp-json\/wp\/v2\/posts\/393\/revisions\/421"}],"wp:attachment":[{"href":"https:\/\/jsec-rt.com\/index.php\/wp-json\/wp\/v2\/media?parent=393"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jsec-rt.com\/index.php\/wp-json\/wp\/v2\/categories?post=393"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jsec-rt.com\/index.php\/wp-json\/wp\/v2\/tags?post=393"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}