<?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 Bastradamus on Medium]]></title>
        <description><![CDATA[Stories by Bastradamus on Medium]]></description>
        <link>https://medium.com/@bastradamus?source=rss-a58a1b990a97------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ESOe8e4tpNAez9q-R0QfPA.png</url>
            <title>Stories by Bastradamus on Medium</title>
            <link>https://medium.com/@bastradamus?source=rss-a58a1b990a97------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 20:51:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bastradamus/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[Detecting Microsoft Self-Service Password reset attacks]]></title>
            <link>https://medium.com/@bastradamus/detecting-microsoft-self-service-password-reset-attacks-69f1043ceaec?source=rss-a58a1b990a97------2</link>
            <guid isPermaLink="false">https://medium.com/p/69f1043ceaec</guid>
            <category><![CDATA[microsoft-security]]></category>
            <category><![CDATA[entra-id]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[cloud]]></category>
            <dc:creator><![CDATA[Bastradamus]]></dc:creator>
            <pubDate>Mon, 23 Feb 2026 12:17:31 GMT</pubDate>
            <atom:updated>2026-02-24T07:56:51.217Z</atom:updated>
            <content:encoded><![CDATA[<p>Hunting and Detecting Entra SSPR Social Engineering Attacks with KQL</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TcWQm4EuNyFwm1zI" /><figcaption>Photo by <a href="https://unsplash.com/@davidpisnoy?utm_source=medium&amp;utm_medium=referral">David Pisnoy</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Introduction</h3><p>Microsoft Entra self-service password reset (SSPR) gives users the ability to change or reset their password, with no administrator or help desk involvement. If Microsoft Entra ID locks a user’s account or they forget their password, they can follow prompts to unblock themselves and get back to work.</p><p>This ability reduces help desk calls and loss of productivity when a user can’t sign in to their device or an application.</p><h4>That’s a great feature, less overhead for IT Support but what are the risks and how can attackers abuse this ?</h4><p>Well let’s start at explaining the attack flow, for the attack flow i’m referencing a great blog post by <a href="https://www.blackhillsinfosec.com/social-engineering-and-microsoft-sspr/">Black Hills InfoSec</a>.</p><h4>Prerequisites</h4><ul><li>The organization must have SSPR enabled within their Entra ID tenant configuration.</li><li>A working Microsoft Entra tenant with at least a Microsoft Entra ID P1 license is required for password reset.</li></ul><p>Organizations can configure a variety of authentication methods for Microsoft Entra SSPR, including mobile app notifications, verification codes via the authenticator app, email, SMS, and more. In addition, administrators can define how many methods are required to complete a password reset. For example, users might be required to approve a push notification and provide a verification code sent via email.</p><h4>User view</h4><p>Below is an example of what a user sees during a self-service password reset. Two possible URLs may be used:</p><ul><li>URL #1: <a href="https://aka.ms/sspr">https://aka.ms/sspr</a></li><li>URL #2: <a href="https://passwordreset.microsoftonline.com/">https://passwordreset.microsoftonline.com/</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/634/1*VatiADr1E8ksV8Bt_fo_Ww.png" /><figcaption>Photo by Microsoft</figcaption></figure><h3>Attack flow</h3><p>Now let’s walk through the attack flow:</p><ol><li>The attacker performs reconnaissance and checks to see if the target’s tenant has Microsoft SSPR enabled — by checking any of the URLs.</li><li>If successful, the different reset options will appear that allow you to specify how you would like to reset the user’s password.</li><li>And now the Social Engineering part comes in to play, the attacker calls the user and claiming to be from IT Support or the Security department.</li><li>The attacker guides the user into approving the MFA prompts as part of a “verification” process.</li><li>After the MFA is approved, the attacker resets the user’s password via SSPR.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/515/1*1fkD6mGONXei4-2IoFr_PQ.png" /><figcaption>Photo by Black Hills InfoSec</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/471/1*Hh4JlQahiwPo8yLjmNdv2A.png" /><figcaption>Photo by Black Hills InfoSec</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/298/1*cotgvjEXaAoIockQKauXyg.png" /><figcaption>Photo by Black Hills InfoSec</figcaption></figure><p>6. The attacker logs into Microsoft 365 with the new password, then lies to the user and says they did not receive the first push and will need the employee to send another.</p><p>7. To keep the user quiet, the attacker gives the user “their new password” and instructs them to reset all devices and then change it again later.</p><p>8. The user feels in control, and so the call goes unreported while the attacker now has initial access.</p><h3>Threat hunting</h3><p>Now for the fun part: how do we detect the attack flow described above ?</p><p>We’ll start by building a KQL hunting query before refining it into a fully tuned detection rule. This approach will give you a feeling of the (il)legitimate activity in your (customer) environment:</p><pre>AuditLogs<br>| where Category == &quot;UserManagement&quot;<br>| where OperationName contains &quot;Self-service password reset flow activity progress&quot;<br>| extend ini = parse_json(InitiatedBy)<br>| mv-expand ini<br>| extend <br>    InitiatedUPN = tolower(tostring(ini.user.userPrincipalName)),<br>    FromIP = tostring(ini.user.ipAddress)<br>| extend GeoIPInfo = geo_info_from_ip_address(FromIP)<br>| extend country = tostring(parse_json(GeoIPInfo).country)<br>| extend ID = parse_json(TargetResources)<br>| mv-expand ID<br>| extend UPN = tolower(tostring(ID.userPrincipalName))<br>| summarize<br>    FirstSeen = min(TimeGenerated),<br>    LastSeen = max(TimeGenerated),<br>    FlowStepCount = count(),<br>    UniqueFlowSteps = dcount(ResultDescription),<br>    FlowSteps = make_list(ResultDescription),<br>    IPs = make_set(FromIP),<br>    IPCount = dcount(FromIP),<br>    Countries = make_set(country) <br>by UPN <br>| sort by UniqueFlowSteps</pre><p>What makes this interesting is that when you zoom in on the Unique flow steps, <a href="https://attack.mitre.org/tactics/TA0043/"><strong>reconnaissance</strong></a><strong> </strong>activity becomes immediately visible. In many cases, a high volume of entries showing only a UniqueFlowStep value of 2 is a strong indicator of malicious activity.</p><ol><li>User submitted their User ID;</li><li>User was presented with verification options.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*am7uXvwIxqFRe4jUC1xCzA.png" /><figcaption>Result snippet</figcaption></figure><h4>Follow-up correlation when finalizing the hunt:</h4><ol><li>Zoom in on Source IPs and Countries;</li><li>Filter out your corporate public IP range;</li><li>Spot successul password reset flows within the Result Description: “<strong>User successfully reset password</strong>”;</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/486/1*uI_ooZfXfxBvtxddk1m_0w.png" /></figure><h3>Detection</h3><p>Hunting is great, but how do we translate those findings into a precise KQL detection rule ? To reduce false positives and ensure meaningful events, I’ll incorporate the following factors into the detection logic:</p><ol><li>Focus only on succesful SSPR flows;</li><li>Enrich with Sign-in logs (e.g. timespan sign-in correlation is within 30 minutes after password reset);</li><li>Exclude Entra ID domain-joined / registered devices;</li><li>Exclude corporate public IP range;</li></ol><h4>Detection rule:</h4><pre>let ExcludedIPs = dynamic([&quot;12.12.12.12&quot;,&quot;13.13.13.13&quot;]); // Exclude your Corporate IP range.<br>// Successful SSPR flow<br>let sspr =<br>AuditLogs<br>| where Category == &quot;UserManagement&quot;<br>| where OperationName == &quot;Self-service password reset flow activity progress&quot;<br>| where ResultDescription == &quot;User successfully reset password&quot;<br>| extend ini = parse_json(InitiatedBy)<br>| mv-expand ini<br>| extend InitiatedUPN = tolower(tostring(ini.user.userPrincipalName))<br>| extend SSPR_IP = tostring(ini.user.ipAddress)<br>| extend GeoIPInfo = geo_info_from_ip_address(SSPR_IP)<br>| extend SSPR_country = tostring(parse_json(GeoIPInfo).country)<br>| extend TR = parse_json(TargetResources)<br>| mv-expand TR<br>| extend UPN = tolower(tostring(TR.userPrincipalName))<br>| project<br>    SSPR_Time = TimeGenerated,<br>    UPN,<br>    InitiatedUPN,<br>    SSPR_IP,<br>    SSPR_country,<br>    OperationName, ResultDescription;<br>let signin =<br>// Sign-in logs enrichment<br>SigninLogs<br>| where ResultType == 0<br>| extend DeviceInfo = parse_json(DeviceDetail)<br>| extend trustType = tostring(DeviceInfo.trustType)<br>| extend SignIn_IP = tostring(IPAddress)<br>| where trustType !in (&quot;Azure AD joined&quot;, &quot;Azure AD registered&quot;)<br>| project<br>    SignIn_Time = TimeGenerated,<br>    SignInUPN = tolower(UserPrincipalName),<br>    SignIn_IP,<br>    AppDisplayName,<br>    ClientAppUsed,<br>    ConditionalAccessStatus,<br>    RiskLevelAggregated,<br>    Location,<br>    DeviceName = tostring(DeviceInfo.displayName),<br>    trustType;<br>// Correlation<br>sspr<br>| join kind=inner signin<br>    on $left.UPN == $right.SignInUPN<br>| where SignIn_Time &gt;= SSPR_Time<br>| where SignIn_Time &lt;= SSPR_Time + 30m // Optionally set timespan stricter. <br>| extend MinutesAfterReset =<br>    datetime_diff(&quot;minute&quot;, SignIn_Time, SSPR_Time)<br>| summarize<br>    SignInIPs = make_set(SignIn_IP, 10),<br>    FirstSignIn = min(SignIn_Time),<br>    LastSignIn = max(SignIn_Time),<br>    Apps = make_set(AppDisplayName, 10),<br>    ClientApps = make_set(ClientAppUsed, 10),<br>    SignInCount = count()<br>by<br>    OperationName,<br>    ResultDescription,<br>    SSPR_country,<br>    SSPR_Time,<br>    UPN,<br>    InitiatedUPN,<br>    SSPR_IP<br>| extend MinutesAfterReset =<br>    datetime_diff(&quot;minute&quot;, FirstSignIn, SSPR_Time)<br>| sort by SSPR_Time desc </pre><p>We end up with a solid detection rule. Keep in mind that factors such as Conditional Access policies, enabled authentication methods, tenant configuration all influence both the logic and the rule outcomes.</p><h3>Prevention</h3><p>Prevention is always better than Detection. My advice would be to take a look at:</p><ol><li>Turning off push notifications entirely;</li><li>Turn off SMS / mobile phone authentication options (to reduce risk of SIM swapping);</li><li>Configure more than 1 authentication method for SSPR;</li><li>If push notifications are still used within the environment &gt; configure additional context in Authenticator notifications, see below example of how that looks:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/322/1*Zaz8ru4ayzCXM3yZ8en-Pw.png" /><figcaption>Example notification with additional context configured.</figcaption></figure><p>That’s it. Hope you found some useful insights or at least enjoyed the read.</p><h3>References</h3><ul><li><strong>BHIS blog post</strong>:</li></ul><p><a href="https://www.blackhillsinfosec.com/social-engineering-and-microsoft-sspr/">Social Engineering and Microsoft SSPR: The Road to Pwnage is Paved with Good Intentions - Black Hills Information Security, Inc.</a></p><ul><li><strong>Configure additional context in Authenticator notifications</strong></li></ul><p><a href="https://learn.microsoft.com/en-us/entra/identity/authentication/how-to-mfa-additional-context">Use additional context in Authenticator notifications - Microsoft Entra ID</a></p><h4><a href="https://bastradamus.com/subscribe">Subscribe</a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=69f1043ceaec" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Critical Vulnerabilities in React and Next.js: Security Advisory]]></title>
            <link>https://medium.com/@bastradamus/critical-vulnerabilities-in-react-and-next-js-security-advisory-01a3de27f1e2?source=rss-a58a1b990a97------2</link>
            <guid isPermaLink="false">https://medium.com/p/01a3de27f1e2</guid>
            <category><![CDATA[vulnerability]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[shodan]]></category>
            <category><![CDATA[cve]]></category>
            <dc:creator><![CDATA[Bastradamus]]></dc:creator>
            <pubDate>Wed, 03 Dec 2025 22:42:41 GMT</pubDate>
            <atom:updated>2026-02-23T13:09:02.333Z</atom:updated>
            <content:encoded><![CDATA[<h3>Critical Vulnerabilities in React and Next.js: CVE-2025–55182</h3><p>Getting the Scope of the Vulnerability and Identifying Global Exposure via Shodan.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zz7Eh48LnlHQ4g04XtNxJA.png" /></figure><h3>Intro</h3><p>On November 29th, Lachlan Davidson reported a security vulnerability in React that allows unauthenticated remote code execution by exploiting a flaw in how React decodes payloads sent to React Server Function endpoints.</p><p>Even if your app does not implement any React Server Function endpoints it may still be vulnerable if your app supports <strong>React Server Components</strong>.</p><h3>CVE &amp; CVSS Score</h3><p>React is one of the most extensively used web application development technologies and the vulnerability allows for unauthenticated remote code execution (RCE) on the server due to insecure deserialization.</p><p>The vulnerability has been identified in the React Server Components (RSC) “Flight” protocol, affecting the React 19 ecosystem and frameworks that implement it, most notably Next.js. It has been assigned <a href="https://nvd.nist.gov/vuln/detail/CVE-2025-55182"><strong>CVE-2025–55182</strong></a> (React) and <a href="https://nvd.nist.gov/vuln/detail/CVE-2025-66478">CVE-2025–66478</a> (Next.js) <strong>BUT </strong>this one was <a href="https://nvd.nist.gov/vuln/detail/CVE-2025-66478">rejected</a> due to being the same vulnerability, however they are (both) carrying the highest possible CVSS score of 10.0.</p><h4>That’s bad</h4><p>The vulnerability exists in the default configuration of affected applications, meaning standard deployments are immediately at risk. Due to the high severity and the ease of exploitation, immediate patching is required.</p><p>According to <a href="https://www.wiz.io/blog/critical-vulnerability-in-react-cve-2025-55182">Wiz</a>:</p><blockquote>To maintain ecosystem safety while patches are applied, we are currently withholding specific details; the details provided here are intended solely to assist defenders in prioritizing remediation and understanding the risk. We will be updating this blog with additional information as it comes to light.</blockquote><blockquote>The framework itself is present in 69% of environments. Notably, 61% of those environments have public applications running Next.js, meaning that 44% of all cloud environments have publicly exposed Next.js instances.</blockquote><h3>Vulnerability Description</h3><p>An unauthenticated attacker could send a malicious HTTP request to any Server Function endpoint, which, when processed by React, could lead to remote code execution <strong>on the server.</strong> However, even if a Server Function endpoint isn’t implemented, exploitation could still be possible via <strong>React Server Components</strong>. This flaw could allow attackers to remotely execute arbitrary code, severely compromising the integrity of affected applications.</p><p>The vulnerability is in React versions 19.0, 19.1.0, 19.1.1 and 19.2.0 of:</p><ul><li>react-server-dom-webpack</li><li>react-server-dom-parcel</li><li>react-server-dom-turbopack</li></ul><h4>For your info, see the React (vulnerable) versions per release date:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/407/1*4eGrQlDood0xIfG2hIi-rg.png" /></figure><p>If you are using the packages mentioned above, <a href="https://react.dev/blog/2025/12/03/critical-security-vulnerability-in-react-server-components"><strong>upgrade immediately</strong></a>. This vulnerability was fixed in versions 19.0.1, 19.1.2, and 19.2.1. If your application’s React code does not use a server, your application is not vulnerable to this vulnerability. Likewise, if your application does not use a framework, bundler, or bundler plugin that supports React Server Components, your application is not affected.</p><p>The following React frameworks and bundlers are affected:</p><ul><li>Next</li><li>React Router</li><li>Yours</li><li>@parcel/rsc</li><li>@vitejs/plugin-rsc</li><li>rwsdk</li></ul><p>The vulnerability also affects Next.js with App Router (CVE-2025–66478). The vulnerability is present in Next.js versions 14.3.0-canary, 15.x, and 16.x, and is fixed in the following patched versions: 14.3.0-canary.88, 15.0.5, 15.1.9, 15.2.6, 15.3.6, 15.4.8, 15.5.7, and 16.0.7.</p><h3>Shodan safari</h3><p>To identify web applications built with React, the following Shodan query should give a solid starting point:</p><pre>http.html:&quot;id=\&quot;root\&quot;&quot;</pre><p>This is because most React apps are rendered into one main HTML element, like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/419/1*CvNhi9Ab_DHTcEEpfuF7Xg.png" /><figcaption>Example of React web app</figcaption></figure><h3>Results:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/673/1*yaGK9Bh-yMyUtXHZQY_5OQ.png" /></figure><blockquote><strong>Disclaimer</strong>: above Shodan query of course does not guarantee a vulnerable configuration.</blockquote><h4>Sources</h4><ul><li><a href="https://react.dev/blog/2025/12/03/critical-security-vulnerability-in-react-server-components">https://react.dev/blog/2025/12/03/critical-security-vulnerability-in-react-server-components</a></li><li><a href="https://www.wiz.io/blog/critical-vulnerability-in-react-cve-2025-55182">https://www.wiz.io/blog/critical-vulnerability-in-react-cve-2025-55182</a></li><li><a href="https://nvd.nist.gov/vuln/detail/CVE-2025-55182">https://nvd.nist.gov/vuln/detail/CVE-2025-55182</a></li></ul><blockquote><em>And if you’re interested in staying up to date on the latest threats and trends, exploited vulnerabilities or exotic blog posts check out </em><strong><em>ThreatSenze</em></strong><em>:</em></blockquote><p><a href="https://threatsenze.com/">ThreatSenze - Your daily dose of security threats and trends</a></p><h4><a href="https://bastradamus.com/subscribe">Subscribe</a></h4><p>To receive the latest developments ✅</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=01a3de27f1e2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Detecting WinRAR zero-day exploitation: CVE-2025–8088]]></title>
            <link>https://medium.com/@bastradamus/detecting-winrar-zero-day-exploitation-cve-2025-8088-eac533120a91?source=rss-a58a1b990a97------2</link>
            <guid isPermaLink="false">https://medium.com/p/eac533120a91</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[exploitation]]></category>
            <category><![CDATA[windows]]></category>
            <category><![CDATA[cve]]></category>
            <category><![CDATA[microsoft-security]]></category>
            <dc:creator><![CDATA[Bastradamus]]></dc:creator>
            <pubDate>Tue, 12 Aug 2025 14:57:35 GMT</pubDate>
            <atom:updated>2025-08-15T19:34:18.908Z</atom:updated>
            <content:encoded><![CDATA[<p>Detecting CVE-2025–8088 post-exploitation attempts with Defender XDR via KQL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vClD26Fz3OXFc7U1" /><figcaption>Photo by <a href="https://unsplash.com/@theblowup?utm_source=medium&amp;utm_medium=referral">the blowup</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Intro</h3><p><a href="https://www.welivesecurity.com/en/eset-research/update-winrar-tools-now-romcom-and-others-exploiting-zero-day-vulnerability/">ESET researchers</a> have discovered a vulnerability in WinRAR, which is observed being exploited in the wild. The vulnerability is an path traversal vulnerability, made possible with the use of alternate data streams. They have released a <a href="https://www.welivesecurity.com/en/eset-research/update-winrar-tools-now-romcom-and-others-exploiting-zero-day-vulnerability/">report</a> yesterday.</p><h4>Patch</h4><p>If you, your users or customers use WinRAR or other affected components such as the Windows versions of its command line utilities, UnRAR.dll, or the portable UnRAR source code, upgrade immediately to the latest version.</p><p>The patched and latest version of WinRAR is version 7.13, see latest:</p><p><a href="https://www.win-rar.com/singlenewsview.html?&amp;L=0&amp;tx_ttnews%5Btt_news%5D=283&amp;cHash=a64b4a8f662d3639dec8d65f47bc93c5">WinRAR 7.13 Final released</a></p><h3>Audience</h3><p>Since the previous vulnerable version of WinRAR (v7.12) is patched and it’s final release is available per 30–07–2025, I hope most organizations, if WinRAR is used, are running the latest patched version.</p><p>But still, please read through if you or fellow defenders are working with products in the Microsoft security suite (e.g. Defender XDR, MS Sentinel) and want to query your endpoint logs for any historic and potential signs of post-exploitation attempts related to the WinRAR vulnerability.</p><p>Both ESET and Talos attribute below post-exploitation techniques to the RomCom group (also known as Storm-0978, Tropical Scorpius, or UNC2596).</p><p>Let’s dive in 🧵</p><h3>Detection angles based on threat reports</h3><p>So I’m constructing detection possibilities based on two threat reports:</p><ol><li><a href="https://www.welivesecurity.com/en/eset-research/update-winrar-tools-now-romcom-and-others-exploiting-zero-day-vulnerability/">https://www.welivesecurity.com/en/eset-research/update-winrar-tools-now-romcom-and-others-exploiting-zero-day-vulnerability/</a></li><li><a href="https://blog.talosintelligence.com/uat-5647-romcom/">https://blog.talosintelligence.com/uat-5647-romcom/</a></li></ol><h4>Angle #1: Mythic agent execution chain</h4><blockquote>In the first execution chain, the malicious LNK file Updater.lnk adds the registry value HKCU\SOFTWARE\Classes\CLSID\{1299CF18-C4F5–4B6A-BB0F-2299F0398E27}\InprocServer32 and sets it to %TEMP%\msedge.dll.</blockquote><p>So after a victim launches the malicious .rar file there are expected traces in certain registry keys.</p><p>Firstly, %TEMP% translates to C:\Users\&lt;username&gt;\AppData\Local\Temp. Combined with monitoring references in the InprocServer32 registry value data should do the trick:</p><pre>DeviceRegistryEvents<br>| where RegistryKey has_all (&quot;InprocServer32&quot;,&quot;CLSID&quot;)<br>and RegistryValueData has @&quot;AppData\Local\Temp&quot; // %TEMP% translation</pre><h4>Angle #2: SnipBot variant execution chain</h4><blockquote>In the second execution chain, the malicious LNK file Display Settings.lnk runs %LOCALAPPDATA%\ApbxHelper.exe.</blockquote><blockquote>Execution of the shellcode only proceeds if a specific registry value (68 for this sample) is present in the HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\RecentDocs\ registry key.</blockquote><p>This time, %LOCALAPPDATA% translates to C:\Users\&lt;username&gt;\AppData\Local. Let’s make sure to detect additional alternatives within \AppData\Local\ and add this to the previous query section.</p><p>Additionally we can add an <strong>or </strong>statement for the Recent Docs anti-analysis technique mentioned in the ESET report:</p><blockquote>If at least 69 documents were recently opened, next-stage shellcode is decrypted using the registry key name (e.g., 68, but converted from string to integer).</blockquote><pre>DeviceRegistryEvents<br>| where RegistryKey has_all (&quot;InprocServer32&quot;,&quot;CLSID&quot;) <br>and RegistryValueData has_any (@&quot;AppData\Local\Temp&quot;,@&quot;AppData\Local\&quot;)<br>or RegistryKey has @&quot;SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\RecentDocs\&quot; <br>and RegistryValueName == 68</pre><h4>Angle #3: MeltingClaw execution chain</h4><p>Lastly, reported by ESET in regard to the WinRAR exploitation campaign but originally tracked by Talos as an C++ based variant tracked as “MeltingClaw”.</p><blockquote>The next-stage payload, ShadyHammock, is dropped to a similar location such as: C:\Users\&lt;user&gt;\AppData\Local\AppTemp\libapi.dll</blockquote><blockquote>This DLL is loaded into explorer[.]exe by specifying it in the registry key:</blockquote><blockquote>HKEY_USERS\S-1-..-CLASSES\CLSID\{F82B4EF1–93A9–4DDE-8015-F7950A1A6E31}\InprocServer32\</blockquote><p>Above query already covers these post-exploitation indicators:</p><ol><li>Registry key InprocServer32</li><li>Verbose file-drop location: AppData\Local\</li></ol><h3>Final detection query</h3><p>I expect that below query enables a great starting point for threat hunting within most environments but of course, verify first before deploying as an detection rule. Specify or whitelist certain expected file locations in registry values (e.g. AppData\Local\Programs\&lt;programname&gt; might be expected and benign).</p><pre>//whitelisting common or expected entries. Define more entries depending on your environment.<br>let exclusions = dynamic([@&quot;\AppData\Local\Microsoft\&quot;]); <br>DeviceRegistryEvents<br>| where not (RegistryValueData has_any (exclusions))<br>| where RegistryKey has_all (&quot;InprocServer32&quot;,&quot;CLSID&quot;) <br>and RegistryValueData has_any (@&quot;AppData\Local\Temp&quot;,@&quot;AppData\Local\&quot;,@&quot;%TEMP%&quot;,@&quot;%LOCALAPPDATA%&quot;) <br>or RegistryKey has @&quot;SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\RecentDocs\&quot; <br>and RegistryValueName == 68<br>| project-reorder TimeGenerated, DeviceName, InitiatingProcessAccountName, ActionType, RegistryKey, RegistryValueData, RegistryValueType</pre><h3>Bonus query</h3><p>Since it is reported that the various payloads were transfered via (Spear) Phishing campaigns, you can also hunt for the prevalence of both .dat and .rar mail attachments in your environment via the following Query:</p><pre>EmailEvents<br>| join EmailAttachmentInfo<br>on $left. NetworkMessageId ==  $right.NetworkMessageId<br>| where FileType == &quot;rar&quot; or FileType == &quot;dat&quot;<br>| where DeliveryAction == &#39;Delivered&#39;<br>| join DeviceFileEvents<br>on $left.FileName ==  $right.FileName<br>| project-reorder DeliveryAction, Subject, FileName, FileExtension, EmailDirection, ThreatTypes, FolderPath, InitiatingProcessFileName, PreviousFileName</pre><p>That’s it. I hope you enjoyed the read, I’d be happy to hear your thoughts or feedback. Cheers &amp; Stay safe.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/447/1*KTWprx9x9zAUo-C7YCgsWQ.png" /></figure><h4><a href="https://bastradamus.medium.com/subscribe"><strong>Subscribe</strong></a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eac533120a91" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Detecting device code phishing in Google Security Operations]]></title>
            <link>https://systemweakness.com/detecting-device-code-phishing-in-google-security-operations-9bf1c282cff0?source=rss-a58a1b990a97------2</link>
            <guid isPermaLink="false">https://medium.com/p/9bf1c282cff0</guid>
            <category><![CDATA[phishing]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[opsec]]></category>
            <category><![CDATA[google]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Bastradamus]]></dc:creator>
            <pubDate>Thu, 22 May 2025 20:10:29 GMT</pubDate>
            <atom:updated>2026-02-23T13:09:24.649Z</atom:updated>
            <content:encoded><![CDATA[<p>Creating a YARA-L detection rule for device code phishing attacks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WNtEznlRLTfquPcq" /><figcaption>Photo by <a href="https://unsplash.com/@kasiade?utm_source=medium&amp;utm_medium=referral">Kasia Derenda</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>This week, I’ve seen device code phishing being mentioned again on social media platforms, so I want to do a quick focus session to outline how you can detect this activity within Google Security Operations (SecOps).</p><blockquote>I covered how to simulate a device code phishing attack in a previous post here:</blockquote><p><a href="https://bastradamus.com/azure-entra-id-token-manipulation-ca156e9cd26e">Azure &amp; Entra ID token manipulation</a></p><h3>What are device codes</h3><p>Device codes we’re originally designed to be used to authenticate on TV’s, printers or IoT devices:</p><blockquote>The Microsoft identity platform supports the device authorization grant, which allows users to sign in to input-constrained devices such as a smart TV, IoT device, or a printer. To enable this flow, the device has the user visit a webpage in a browser on another device to sign in. Once the user signs in, the device is able to get access tokens and refresh tokens as needed.</blockquote><p>Device code phishing involves threat actors abusing the device code authentication flow to trick users and gain unauthorized access.</p><h4>Prevention is always better than Detection.</h4><p>Creating a Conditional Access policy to help prevent this form of phishing in Azure/Entra ID is, of course, recommended, for this, check out this very informative post by Jeffrey Appel:</p><p><a href="https://jeffreyappel.nl/how-to-protect-against-device-code-flow-abuse-storm-2372-attacks-and-block-the-authentication-flow/">How to protect against Device Code Flow abuse (Storm-2372 attacks) and block the authentication flow</a></p><p>However, security policies are not always implemented within organizations. Luckily there are some great angles to create a detection rule for this activity. To create an effective rule, we first need data sources that generate the necessary logs. Since we’ll be creating a detection rule with Google SecOps I’m going to use Gmail as the professional email service. For the identity and access management service there is obviously Entra-ID or formerly known and still widely referenced: Azure AD.</p><h4>Data sources:</h4><ol><li><strong>Google workspace (Gmail)</strong></li></ol><p>For data onboarding documentation, click <a href="https://cloud.google.com/chronicle/docs/ingestion/cloud/workspace-to-chronicle">here</a>.</p><p>2. <strong>Azure AD / Entra-ID sign-in logs</strong></p><p>For data onboarding documentation, refer to my earlier post <a href="https://bastradamus.com/data-feeds-in-google-secops-siem-formerly-chronicle-ec391824373a">here</a>.</p><p>The Microsoft threat intel team wrote a great research blog about Device Code phishing campaigns this year, including detection possibilities in KQL. I’m referencing this article as the main source of inspiration:</p><ul><li><a href="https://www.microsoft.com/en-us/security/blog/2025/02/13/storm-2372-conducts-device-code-phishing-campaign/">https://www.microsoft.com/en-us/security/blog/2025/02/13/storm-2372-conducts-device-code-phishing-campaign/</a></li></ul><h4>First UDM search — Gmail</h4><p>Before I develop a detection rule in SecOps I first construct a UDM search. Let’s start by scanning for e-mails containing one of the two possible URLs used in the attack:</p><ul><li>microsoft.com/devicelogin</li><li>login.microsoftonline.com/common/oauth2/deviceauth</li></ul><p>Also let’s only focus on the following user actions that took place:</p><pre>71 - A user took an action in the inbox after receiving the message. Post-delivery actions include opening a message, clicking a link in a message, and downloading an attachment. <br>9 - A link in the message body was clicked.</pre><h3>UDM #1</h3><pre>metadata.vendor_name = &quot;Google Workspace&quot;<br>metadata.product_name = &quot;gmail&quot; nocase<br>about.url = /microsoft.com\/devicelogin/ or<br>about.url = /oauth2\/deviceauth/<br>//user clicks phishing URL<br>about.labels.value = /71|9/   </pre><h4>Second UDM search — Entra-ID</h4><blockquote>For an overview of Azure/Entra-ID error codes, click <a href="https://learn.microsoft.com/en-us/entra/identity-platform/reference-error-codes#aadsts-error-codes">here</a>.</blockquote><p>Now let’s zoom in on a specific Entra ID error code: <strong>50199</strong>:</p><blockquote>The user was asked to confirm that this app is the application they intended to sign into. This is a security feature that helps prevent spoofing attacks. This occurs because a system webview has been used to request a token for a native application.</blockquote><h3>UDM #2</h3><pre>metadata.vendor_name = &quot;Microsoft&quot;<br>metadata.product_name = &quot;Azure AD&quot;<br>//Entra error code 50199: The user was asked to confirm that this app is the application they intended to sign into.<br>security_result.rule_id = &quot;50199&quot;</pre><p>Now ideally you’ll see zero hits in your environment obviously, however seeing hits on the 50199 error code is definitely not a sign of compromise, there are plenty benign scenarios. It’s all about joining events that makes this detection rule valuable and accurate.</p><p>So let’s get to it 🛠</p><h4>The key takeways for below detection rule are:</h4><ul><li>To minimize false positives only zoom in on certain user actions.</li><li>Join both Gmail &amp; Entra ID variables.</li><li>Validate error code 50199 followed by a successful authentication event.</li></ul><h3>YARA-L rule</h3><pre>rule devicecode_phishing_attack {<br><br>  meta:<br>    author = &quot;Bastradamus&quot;<br>    description = &quot;Detects strong indicators of a successful device code phishing attack.&quot;<br>    severity = &quot;High&quot;<br>    priority = &quot;High&quot;<br>    type = &quot;alert&quot;<br>    data_source = &quot;Workspace Activity, azure ad&quot;<br>    reference = &quot;https://systemweakness.com/detecting-device-code-phishing-in-google-security-operations-9bf1c282cff0&quot;<br>    mitre_attack_tactic = &quot;Initial Access&quot;<br>    mitre_attack_technique = &quot;Phishing&quot;<br>    mitre_attack_url = &quot;https://attack.mitre.org/techniques/T1566/&quot;<br><br>  events:<br>    $email.network.email.to = $user<br>    $email.metadata.vendor_name = &quot;Google Workspace&quot;<br>    $email.metadata.product_name = &quot;gmail&quot; nocase<br>    $email.about.url = /microsoft.com\/devicelogin/ or<br>    $email.about.url = /oauth2\/deviceauth/<br>    //user clicks the device code phish URL.<br>    $email.about.labels.value = /71|9/   <br>    <br>    $entra.metadata.vendor_name = &quot;Microsoft&quot;<br>    $entra.metadata.product_name = &quot;Azure AD&quot;<br>    //Entra error code 50199: The user was asked to confirm that this app is the application they intended to sign into.<br>    $entra.security_result.rule_id = /^(0|50199)$/<br><br>    //join<br>    $email.network.email.to = $entra.target.user.userid<br><br>  match:<br>    //Time window based on the fact that the device code expires within 15 minutes. Added an extra 60 seconds, because.<br>    $user over 16m<br><br>  outcome:<br>    $mitre_attack_tactic = array_distinct(&quot;Initial Access&quot;)<br>    $mitre_attack_technique = array_distinct(&quot;Phishing&quot;)<br>    $mitre_attack_technique_id = array_distinct(&quot;T1566&quot;)<br>    $target_user_distinct_count = count_distinct($user)<br>    $target_user_count = count($user)<br>    $principal_ip = array_distinct($email.principal.ip)<br>    $sender_from = array_distinct($email.principal.network.email.from)<br>    $recipient = array_distinct($email.network.email.to)<br><br>  condition:<br>    $email and $entra<br><br>}</pre><blockquote>For the most recent version of the detection rule, see the rule in the Google Cloud’s Github repository:</blockquote><p><a href="https://github.com/chronicle/detection-rules/blob/main/rules/community/microsoft/entra_id/entra_id_devicecode_phishing_attack.yaral">detection-rules/rules/community/microsoft/entra_id/entra_id_devicecode_phishing_attack.yaral at main · chronicle/detection-rules</a></p><p><strong>Result snippet:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YBiNDZ_nGwTOnyvnUyqEHA.png" /></figure><h4>Interesting fields to take into account:</h4><ul><li>Source IP</li><li>User agent</li><li>Email subject name</li><li>Entra-ID error codes in a timely order (50199 followed by 0, meaning a successful authentication chain).</li></ul><p>That’s it, keeping it short and actionable. Hope you found some useful insights or at least enjoyed the read.</p><h4>Additional resources:</h4><ul><li>Google SecOps Detection rule wiki &amp; Yara-L rule builder:</li></ul><p><a href="https://secops.wiki/">Google SecOps Detection Rule Wiki</a></p><ul><li>Microsoft Entra-ID authentication and authorization error codes:</li></ul><p><a href="https://learn.microsoft.com/en-us/entra/identity-platform/reference-error-codes#aadsts-error-codes">Microsoft Entra authentication &amp; authorization error codes - Microsoft identity platform</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/538/1*J9fZBF0p8Cy8ADuuCRVNsw.png" /></figure><h4><a href="https://bastradamus.com/subscribe">Subscribe</a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9bf1c282cff0" width="1" height="1" alt=""><hr><p><a href="https://systemweakness.com/detecting-device-code-phishing-in-google-security-operations-9bf1c282cff0">Detecting device code phishing in Google Security Operations</a> was originally published in <a href="https://systemweakness.com/">System Weakness</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ADFS Recon: Mapping an Organization’s service providers]]></title>
            <link>https://medium.com/@bastradamus/exploring-active-directory-federation-services-adfs-40b5787c453e?source=rss-a58a1b990a97------2</link>
            <guid isPermaLink="false">https://medium.com/p/40b5787c453e</guid>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[active-directory]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[cloud]]></category>
            <dc:creator><![CDATA[Bastradamus]]></dc:creator>
            <pubDate>Sat, 19 Apr 2025 08:48:04 GMT</pubDate>
            <atom:updated>2025-04-19T08:55:24.331Z</atom:updated>
            <content:encoded><![CDATA[<p>A look into Active Directory Federation Services reconnaissance attacks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6GmvGrE3TV3x0xmP" /><figcaption>Photo by <a href="https://unsplash.com/@lavievagabonde?utm_source=medium&amp;utm_medium=referral">Jasmin Schreiber</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Attackers gather information about organizations before constructing targeted Attacks. There are many ways to gather information about an organization, the goal for adversaries in general, of course, is to gather as much useful information as possible about the target organization. Such as domain details, network information, user accounts, IT services and relationships with other business operations, to name a few.</p><p>In my opinion, ADFS (Active Directory Federation Services) can hold quite some information about an organization’s IT operations as well. However, there isn’t much publicly available. It’s fairly straight forward to check if a domain is managed or federated, grab some general info, but when it comes to ADFS specifically ? As far as I know, not a whole lot is possible during the <a href="https://attack.mitre.org/tactics/TA0043/"><strong>Reconnaissance</strong></a> phase.</p><h3>Overview of ADFS</h3><p>ADFS is an identity access solution that provides client computers (internal or external to your network) with seamless SSO access to protected Internet-facing applications or services, even when the user accounts and applications are located in completely different networks or organizations.</p><p>When an application or service is in one network and a user account is in another network, typically the user is prompted for secondary credentials when he or she attempts to access the application or service. These secondary credentials represent the user’s identity in the realm where the application or service resides. They are usually required by the Web server that hosts the <strong>application </strong>or <strong>service </strong>so that it can make the most appropriate authorization decision.</p><p>With Microsoft Entra-ID, organizations these days are less likely to choose for such an federated on-prem configuration, which requires a large and complex infrastructure. However, many organizations still rely on ADFS, and migration projects often take a lot of time and effort.</p><h4>ADFS Endpoints</h4><p>ADFS uses various endpoints which provide access to the federation server functionality of ADFS, such as publishing federation metadata. By testing metadata endpoints, you can determine if the ADFS server is responding to web requests. Example:</p><ul><li>https://sts.company_name.com/adfs/services/trust/mex</li></ul><p>There’s also the IdP-initiated sign-on page endpoint, which can be used to check if (SSO) authentication is working. This test is done by navigating to the page and signing in:</p><ul><li>https://sts.company_name.com/adfs/ls/idpinitiatedsignon.aspx</li></ul><h3>The IdP-initiated sign-on page</h3><p>In Windows Server 2016+ configurations, the IdP-initiated Sign-on page is disabled by default. However, since many administrators rely on this page for testing SSO functionality this endpoint is often (temporarily) enabled and forgotten.</p><h4>You’ll see where this is going</h4><p>Yes, so the part I&#39;m highlighting in this post is… this IdP-initiated sign-on page. Nothing fancy but I stumbled upon this a while back and find it interesting, I also haven’t seen any blogs covering this topic. Now that could be that adversaries or red teamers just don’t find the information worth it, or that it’s just not widely known in that perspective.</p><p>Why is the information potentially valuable to construct an attack ? Let’s look into this a bit more, let us take Tesla as an example company. The endpoint I&#39;ve showed earlier has the following structure: https://sts.company_name.com/adfs/ls/idpinitiatedsignon.aspx</p><p>Now the ADFS subdomains may vary, for example they can be configured as: adfs.tesla.com, sso.tesla.com, sts.tesla.com and so on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Gvh7fZYXKlQ1qq4pBxoPMA.png" /><figcaption>Web view</figcaption></figure><p>About a year ago I&#39;ve created a simple Powershell script that automates the process of gathering information about a company using ADFS:</p><p><a href="https://github.com/madret/ADFS-Enum">GitHub - madret/ADFS-Enum: ADFS service provider (relying party) information enumerator</a></p><p>What the script does is simply checking if ADFS is in use and if so, what service providers are linked to the IdP-initiated sign-on page. Service providers (or relying parties) are basically <strong>applications </strong>configured for SSO within the company.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_CzCC39NtVfmP-Jpc_sbaA.png" /><figcaption>Script view</figcaption></figure><p>So this gives information about what applications and/or services the company uses, the information can, for example, be used in a later stage for constructing social engineering attacks or exploiting vulnerabilities in the <strong>applications </strong>listed.</p><p>The next example of another company’s IdP-initiated sign-on page is more verbose, compared to the Tesla web view:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C03_nC7Rek0rWyI_2t7ELQ.png" /></figure><p>And the script output looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uk_URd64uMhhTrFl9qladA.png" /></figure><h3>Conclusion</h3><p>Now, this is by no means a critical information-leaking vulnerability, it’s somewhat by design. However, this endpoint doesn’t need to be publicly accessible, and as shown above, it allows attackers to gather a certain (unnecessary) amount of information about the organization.</p><h3>Defender tip</h3><p>I always advice to disable the <strong>IdpInitiatedSignonPage</strong> endpoint from being publicly accessible, due to the fact that this can give unnecessary information about applications used within the corporate environment. To do so, an admin can run the following PowerShell command to configure the ADFS Farm:</p><p>Set-AdfsProperties –EnableIdpInitiatedSignonPage $False</p><p><a href="https://learn.microsoft.com/en-us/windows-server/identity/ad-fs/troubleshooting/ad-fs-tshoot-initiatedsignon">Troubleshoot AD FS IdP-Initiated Sign-In</a></p><p>That&#39;s it, I hope you had a bit of fun reading this post and learned something in the process.</p><blockquote>If you’re interested in daily Security dashboarding &amp; staying up to date on the latest threats and trends, exploited vulnerabilities and exotic blog posts check out <strong>ThreatSenze</strong>:</blockquote><p><a href="https://threatsenze.com/">ThreatSenze - Your daily dose of security threats and trends</a></p><p><a href="https://bastradamus.medium.com/subscribe"><strong>Subscribe</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=40b5787c453e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data feeds in Google SecOps SIEM (formerly Chronicle)]]></title>
            <link>https://medium.com/@bastradamus/data-feeds-in-google-secops-siem-formerly-chronicle-ec391824373a?source=rss-a58a1b990a97------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec391824373a</guid>
            <category><![CDATA[siem]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[google-secops]]></category>
            <category><![CDATA[cloud-security]]></category>
            <category><![CDATA[microsoft-security]]></category>
            <dc:creator><![CDATA[Bastradamus]]></dc:creator>
            <pubDate>Mon, 17 Mar 2025 15:00:29 GMT</pubDate>
            <atom:updated>2025-04-14T08:57:28.536Z</atom:updated>
            <content:encoded><![CDATA[<p>Setup a data feed for ingesting Microsoft Entra ID logs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7IrKnitbAOu2bO3P" /><figcaption>Photo by <a href="https://unsplash.com/@alinnnaaaa?utm_source=medium&amp;utm_medium=referral">Alina Grubnyak</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In this blog I’ll walk through setting up a Data feed in Google Security Operations. Google SecOps can be divided into two areas, SIEM (fka Chronicle) and SOAR (fka Siemplify). This post will only touch a portion of the SIEM area, you can use data feeds to ingest log data into your Google SecOps instance.</p><p>SecOps SIEM supports a set of data feeds which can pull data from static external locations (for example, Amazon S3) and<strong> third party APIs</strong> (for example, Microsoft Entra ID). These data feeds send logs directly to the Google Security Operations SIEM ingestion service. Each data feed has its own set of <a href="https://cloud.google.com/chronicle/docs/reference/feed-management-api#azure-ad">prerequisites</a> that must be completed prior to setting up the feed in Google Security Operations.</p><p>Each feed that you create is composed of a data <strong>source type</strong> and a <strong>log type</strong>. Google Cloud Storage, third-party APIs, and HTTP-accessible files are examples of source types. For each data source type that Google supports, it also supports specific log types. Default parsers in SecOps use <a href="https://cloud.google.com/chronicle/docs/ingestion/parser-list/supported-default-parsers#with-default-parser">ingestion labels</a>.</p><p>Check out the official documentation for API reference details and in our case, MS Entra-ID specifically (although in the documentation still referenced as Azure AD).</p><p><a href="https://cloud.google.com/chronicle/docs/reference/feed-management-api#azure-ad">Feed management API | Google Security Operations | Google Cloud</a></p><p>As we continue let me define scopes and differentiate the various log types that are currently supported and that we can pull from Azure via the third party API method:</p><ol><li>Microsoft Azure Active Directory Sign-ins (<a href="https://learn.microsoft.com/en-us/entra/identity/monitoring-health/concept-sign-ins">Sign-in logs</a>);<br>&gt; <strong>Log type</strong>: Azure AD<br>&gt; <strong>Ingestion label</strong>: Azure_AD</li><li>Microsoft Azure Active Directory Audit (<a href="https://learn.microsoft.com/en-us/purview/audit-log-activities">Audit logs</a>);<br>&gt; <strong>Log type</strong>: Azure AD Directory Audit<br>&gt; <strong>Ingestion label</strong>: AZURE_AD_AUDIT</li><li>Microsoft Azure Active Directory Organizational Context (<a href="https://graphpermissions.merill.net/permission/Directory.Read.All?tabs=apiv1%2CadminConsentRequestPolicy1">directory information</a> about users, groups &amp; devices);<br>&gt; <strong>Log type</strong>: Azure AD Organizational context<br>&gt; <strong>Ingestion label</strong>: AZURE_AD_CONTEXT</li></ol><p>There are two requirements in order to configure data ingestion:</p><ol><li>Configure an application in the Microsoft Entra-ID tenant;</li></ol><p><a href="https://learn.microsoft.com/en-us/entra/identity-platform/quickstart-register-app?tabs=certificate%2Cexpose-a-web-api">Quickstart: Register an app in Microsoft Entra ID - Microsoft identity platform</a></p><p>2. Configure the data feed(s) in the Google SecOps portal.</p><p><a href="https://cloud.google.com/chronicle/docs/reference/feed-management-api#azure-ad">Feed management API | Google Security Operations | Google Cloud</a></p><h3>1. Configure application in Microsoft Azure Tenant</h3><p><strong>Prerequisites:</strong></p><ul><li>An Azure AD Premium P1 or P2 license.</li><li>The Azure account must be at least a <a href="https://learn.microsoft.com/en-us/entra/identity/role-based-access-control/permissions-reference#application-developer">Application Developer</a>.</li></ul><blockquote>Collecting sign-in logs via the Microsoft Graph API requires an enterprise (P1,P2) license, if you have a general license but still want to test out the feed configuration, it’s possible to setup the collection of audit logs (AZURE_AD_AUDIT).</blockquote><h4>Stage 1.1 App registration</h4><ol><li>Sign in to your <a href="https://entra.microsoft.com/">Entra-ID</a> / <a href="https://portal.azure.com/">Azure portal</a> environment.</li><li>In the search bar type: app registration and select “+ <em>New registration</em>”.</li><li>Choose a name for your application.</li><li>Under supported account types, specify who can use the application, Microsoft recommends the first option “Accounts in this organizational directory only”</li><li>Set an Redirect URI: https://localhost will do. For security reasons, the authentication server won’t redirect users or send tokens to a URI that isn’t added to the app registration, for more info check out <a href="https://learn.microsoft.com/en-us/entra/identity-platform/reply-url#should-i-add-a-redirect-uri-to-an-app-registration">MS docs</a>.</li><li>Click Register:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AM6xzR2WQHGk-55V6sT_bA.png" /><figcaption>Portal view</figcaption></figure><h4>Stage 1.2 App permissions</h4><ol><li>From within your application view go to &gt; API permissions</li><li>Add a permission</li><li>Select <strong>Microsoft Graph</strong></li><li>Select Application permissions (not the delegated box)</li><li>In the permission search box select the following:</li></ol><p>AuditLog.Read.All Directory.Read.All SecurityEvents.Read.All .</p><p>6. Add permissions</p><p>7. Grant admin consent. The application is then authorized to call APIs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JrWz_hQobE14fPqtqHS_Gg.png" /><figcaption>Permission view</figcaption></figure><h4>Stage 1.3 App credentials</h4><p>In order to configure the data feed in SecOps we need 3 things:</p><ul><li>Tenant ID: the Entra-ID / Azure AD directory where the application is registered in.</li><li>Application ID (Client ID).</li><li>Client secret.</li></ul><ol><li>From within your application view go to &gt; Certificates &amp; Secrets</li><li>Click “<em>+ New client secret</em>”</li><li>Name the secret and set an expiration limit (usually 24 months)</li><li>Press Add</li><li>You’ll be greeted with your <strong>secret </strong>value, copy and safely store this value immediately because when you change your view it is gone and can never be displayed again.</li><li>Now the Secret ID is not the client ID, to get the necessary Client ID click on your left side Overview &gt; Application (client) ID.</li><li>The last value we need is the Tenant ID, if you type in Tenant in the search bar &gt; Tenant properties. You’ll see the Tenant ID.</li></ol><blockquote>Fun fact: You can retrieve the Tenant ID of any organization if you know its domain. Check out the OSINT web feature of aadinternals:</blockquote><p><a href="https://aadinternals.com/osint/">OSINT</a></p><p>Great, so now that you set up the necessary configuration from within the Microsoft tenant it’s time to configure the data feed in the Google SecOps platform.</p><h3>2. Configure data feed(s) in SecOps</h3><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*6sONUXKK0NLwyeZ8p2ucdg.png" /><figcaption>SecOps portal view</figcaption></figure><ol><li>From within the portal select SIEM Settings &gt; Feeds &gt; Add new</li><li>Enter a unique <strong>name </strong>for the feed</li><li>Select <strong>Third party API</strong> as Source type</li><li>Select <strong>Azure AD</strong> as Log type and click Next</li><li>Configure the 3 necessary parameters and click Next</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zUDHgeBEVQALvVf9wrtgTA.png" /><figcaption>Necessary input parameters</figcaption></figure><p>6. Click Submit.</p><p>Give your brand new feed a minute or so and it will show from<strong> InProgress</strong> to <strong>Active</strong> and starts pulling data in<strong>. </strong>If the feed status gives a failure you can inspect the reason by hovering over the question mark icon or by pressing the three dots and select view feed.</p><p>We can run a quick UDM search to verify incoming data by monitoring the log type or ingestion label: metadata.log_type = &quot;AZURE_AD&quot;</p><p>That’s it, I hope you took away something valuable from this post. If anything, feel free to reach out, I’d be happy to help and am always open to any feedback.</p><blockquote>From here, you can set up additional feeds with the various Azure log types mentioned earlier, using the same Microsoft application for API authentication. You can also extend the app’s permissions by adding Office 365 management permissions to collect Unified Audit Logs (UAL) from SharePoint, Exchange, Teams, etc. For this, refer to the following documentation:</blockquote><p><a href="https://cloud.google.com/chronicle/docs/ingestion/default-parsers/collect-microsoft365">Collect Microsoft 365 logs | Google Security Operations | Google Cloud</a></p><h3>Additional resources</h3><ul><li>Highly recommended resource for exploring detailed information about Microsoft Graph API permissions:</li></ul><p><a href="https://graphpermissions.merill.net/permission/">Microsoft Graph Permissions Explorer</a></p><ul><li>Google SecOps Detection rule wiki &amp; Yara-L rule builder:</li></ul><p><a href="https://secops.wiki/">Google SecOps Detection Rule Wiki</a></p><p><a href="https://bastradamus.medium.com/subscribe"><strong>Subscribe</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iEYaJRAmWZXjbJ4Y-FFtPw.png" /><figcaption>a meme a day keeps the doctor away</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec391824373a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Finding Abandoned & Forgotten AWS S3 buckets]]></title>
            <link>https://medium.com/@bastradamus/finding-abandoned-forgotten-aws-s3-buckets-4d60d8fe1975?source=rss-a58a1b990a97------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d60d8fe1975</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[amazon]]></category>
            <category><![CDATA[s3-bucket]]></category>
            <dc:creator><![CDATA[Bastradamus]]></dc:creator>
            <pubDate>Tue, 11 Feb 2025 07:49:57 GMT</pubDate>
            <atom:updated>2025-02-11T07:49:57.059Z</atom:updated>
            <content:encoded><![CDATA[<p>Introductory and how to look for potentially abandoned AWS S3 buckets in your environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Yr4YFImzsP-IJ6kG" /><figcaption>Photo by <a href="https://unsplash.com/@galen_crout?utm_source=medium&amp;utm_medium=referral">Galen Crout</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>I will keep this one rather brief and straight to the point, this blog is inspired by research done by the awesome team at <a href="https://labs.watchtowr.com/">watchTowr</a>. I recommend reading the blog post below first:</p><p><a href="https://labs.watchtowr.com/8-million-requests-later-we-made-the-solarwinds-supply-chain-attack-look-amateur/">8 Million Requests Later, We Made The SolarWinds Supply Chain Attack Look Amateur</a></p><p>What the team at watchTowr discovered was that around 150 Amazon S3 buckets — once used in commercial and open-source software, government systems, and infrastructure deployment pipelines — were left forgotten and abandoned.</p><h4><strong>Why is this newsworthy ?</strong></h4><p>Well, it creates an opportunity for bad actors to register an S3 bucket with the exact same name. Any incoming requests still aimed at the abandoned buckets and referenced filenames could be exploited to host malicious files.</p><p>While this is a known bug, known as an “S3 bucket takeover” and was also covered earlier by <a href="https://www.trustwave.com/en-us/resources/blogs/spiderlabs-blog/amazon-aws-s3-bucket-take-over/">Trustwave</a>, it remains a realistic risk for organizations.</p><h4><strong>Abandonded S3 bucket scenario</strong></h4><ul><li>Endpoints within an organization query an, once legitimate, S3 bucket for software updates:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-AEJifyuzWEsG--M4cz0gg.png" /><figcaption>Simple infographic</figcaption></figure><p>If the organization later decides -or forgets- to let the bucket expire, but it remains referenced across the enterprise network or even in the public domain, it obviously creates a security risk.</p><h4><strong>Example XML response when a bucket is expired (or never existed):</strong></h4><pre>&lt;Error&gt;<br>&lt;Code&gt;NoSuchBucket&lt;/Code&gt;<br>&lt;Message&gt;The specified bucket does not exist&lt;/Message&gt;<br>&lt;BucketName&gt;sensitive-organization&lt;/BucketName&gt;<br>&lt;RequestId&gt;GUVFVFWHFGNOBTHFFGEVAT&lt;/RequestId&gt;<br>&lt;HostId&gt;Kkliowrejaf9203r9adsfadfhlasdf=&lt;/HostId&gt;<br>&lt;/Error&gt;</pre><h4>The naming convention of S3 buckets may vary</h4><p>The difference between <a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html#path-style-access">path-style</a> (1) and <a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html#virtual-hosted-style-access">virtual-hosted-style</a> (2) URLs is how the bucket name is included in the URL:</p><p>1. https://s3.&lt;region&gt;.amazonaws.com/&lt;bucket&gt;/&lt;key&gt;</p><p>2. https://&lt;bucket&gt;.&lt;region&gt;.s3.amazonaws.com/&lt;key&gt;</p><blockquote>Having the bucket name in the host has the advantage of using DNS to route different buckets to different IP addresses. If the bucket name is in the path, all requests have to go to one IP address even for different buckets. That is the reason <strong>path-style URLs</strong> are considered <strong>legacy </strong>(but not yet deprecated).</blockquote><p>Some regions like US East us-east-1 have a legacy global endpoint that doesn&#39;t need a region code in the hostname:</p><pre># Legacy hostname with path-style<br>https://s3.amazonaws.com/&lt;bucket&gt;/&lt;key&gt;<br># Legacy hostname with virtual-hosted-style<br>https://&lt;bucket&gt;.s3.amazonaws.com/&lt;key&gt;</pre><h3>The “Attack” stages</h3><p>So the attack is fairly straight forward:</p><ol><li>Attacker finds expired bucket(s) from target organization(s);</li><li>Attacker registers an S3 bucket with the same name (this is possible since the bucket expired and now no longer exists);</li><li>Attacker enables logging (AWS CloudTrail);</li><li>Attacker analyzes the queries still flooding in;</li><li>Attacker hosts malicious files with the same names as queried (images, PDFs, executables, etc).</li></ol><p>I thought i’d demonstrate the setup steps but like i mentioned earlier, it’s really straightforward. The fun part is actually discovering abandoned S3 buckets and analyze what is still being requested. For discovery, this can be done by querying Shodan, Censys, Google dorking or searching through GitHub repositories or issues.<strong> </strong>Once a potential target is identified, setting up an (public) <strong>S3 bucket</strong> and enabling <strong>CloudTrail</strong> is done within minutes.</p><p>For analysis, a simple query within <strong>CloudTrail &gt; Lake &gt; Query</strong> can help track and understand activity within the bucket:</p><pre>SELECT *<br>FROM &lt;event_data_store_ID&gt;<br>WHERE eventSource = &#39;s3.amazonaws.com&#39;<br>    AND eventName IN (<br>        &#39;DeleteObject&#39;,<br>        &#39;PutObject&#39;,<br>        &#39;CopyObject&#39;,<br>        &#39;GetObject&#39;<br>    )<br>    AND element_at(requestParameters, &#39;bucketName&#39;) = &#39;sensitive-bucket&#39;</pre><h4>Results:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WxLzLKQkuKKWB3KaowryPw.png" /><figcaption>Result snippet</figcaption></figure><p>So here we can see multiple endpoints still attempting to access PDF files. No shocker but fun for demonstration purposes.</p><h3>Detective value</h3><p>Security and IT teams can query their organization’s network for endpoints attempting to access expired S3 buckets that will return, for example an <strong>404 Not Found</strong> error. Identifying these endpoints might indicate outdated dependencies, potential misconfigurations or may lead to other findings.</p><p>Use firewall, web server and/or Endpoint logs, with below example being a not-so-resource-friendly query:</p><pre>(*s3.amazonaws.com/* OR s3.*.amazonaws.com/*) AND &quot;404 Not Found&quot;</pre><p>This is just an example to get started but can lead to interesting findings.</p><p><strong>Thanks for making it this far </strong>🦉</p><blockquote>While you’re here, if you like security dashboarding and staying up 2 speed of the latest CVEs, exploited vulnerabilities and exotic blog posts check out <strong>ThreatSenze</strong>:</blockquote><p><a href="https://threatsenze.com/">ThreatSenze - Your daily dose of security threats and trends</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OAENzZ82wFhJX3UhaKCH8Q.png" /><figcaption>a meme a day keeps the doctor away</figcaption></figure><p><a href="https://bastradamus.medium.com/subscribe"><strong>Subscribe</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d60d8fe1975" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Incident Response in Microsoft Entra ID (formerly Azure AD)]]></title>
            <link>https://medium.com/@bastradamus/incident-response-in-microsoft-entra-id-formerly-azure-ad-1102ddacc2aa?source=rss-a58a1b990a97------2</link>
            <guid isPermaLink="false">https://medium.com/p/1102ddacc2aa</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[microsoft-security]]></category>
            <category><![CDATA[cyber]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[azure]]></category>
            <dc:creator><![CDATA[Bastradamus]]></dc:creator>
            <pubDate>Mon, 16 Dec 2024 11:09:38 GMT</pubDate>
            <atom:updated>2025-10-23T11:12:32.146Z</atom:updated>
            <content:encoded><![CDATA[<p>Compromised user account edition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kLGZRIoHo8r9tjhdewAidg.png" /></figure><p>So in this blog I will be testing and validating certain incident response actions in regards to a compromised user account scenario within Microsoft Entra ID.</p><p>The scenario and scope will be:</p><ul><li>Compromised user account;</li><li>MFA enabled;</li><li>Microsoft Entra ID tenant (formerly Azure AD);</li><li>All manual response actions, automation for now is out of scope.</li></ul><h4><strong>Why ?</strong></h4><p>Identity-based attacks are a top risk for organizations, numerous threat and incident reports highlight that adversaries appear to focus even more on stolen credentials via <a href="https://www.recordedfuture.com/research/initial-access-brokers-key-to-rise-in-ransomware-attacks">initial-access-broker (IAB)</a> services identified in the criminal underground. Most initial access sales involve credentials purchased<strong> </strong>through dark web forums and marketplaces and may contain usernames, passwords, session cookies and security tokens.</p><p>It is therefore very likely that security teams will eventually deal with stolen credentials and compromised user accounts, so having clear and validated response procedures are essential.</p><h4>NIST Incident Response framework</h4><p>The response actions in this blogpost, in regards to the <a href="https://csrc.nist.gov/">NIST</a> IR framework, fall under <strong>Containment</strong>, <strong>Eradication </strong>and <strong>Recovery.</strong> The framework combines these<strong> </strong>into a single step for recovering from and mitigating cybersecurity incidents.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UFrwx7Bc-SmtZnrGqHe1Vw.png" /><figcaption>NIST Incident Response framework</figcaption></figure><h4>Testing &amp; Validating</h4><p>Looking at above framework, one of the <strong>Containment &amp; Eradication </strong>goals would be that of preventing the incident from spreading, yet more technical actions are not always validated or tested, leaving room for assumptions. On the topic of an account compromise, I have spoken with people in the past across things like: <em>“should an account disable and password reset be enough”</em> ? Or <em>“what happens with an access token when a user account gets re-enabled”</em> ? And <em>“what about the lifetime of security tokens, when a password reset is performed”</em> ?</p><p>So imagine yourself, during a cyber incident, after certain response actions have been taken — are you, as a defender, truly confident that the response actions worked as expected, or does some doubt remain ?</p><p>Well, in this blog I aim to test and validate both the above and additional questions. Let’s draw a comparison to Mythbusters, in the sense that we’re aiming to take away any myths or assumptions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S9_Ik4uv-W69OW_D3tbkXg.png" /><figcaption>For any readers not familiar with Mythbusters.. :)</figcaption></figure><h3>🔱 Scenario 🔱</h3><p>During a weekend shift a security analyst observed a user with multiple risky sign-ins and was labeled as a “Risky user” within the corporate Tenant.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fM9SeQpxARQhe_bujZo39g.png" /><figcaption>Risky sign-in example</figcaption></figure><h4>What and why is a user at risk?</h4><p>A user becomes a risky user when:</p><ul><li>They have one or more risky sign-ins;</li><li>They have one or more <a href="https://learn.microsoft.com/en-us/entra/id-protection/concept-identity-protection-risks">risks</a> detected on their account.</li></ul><p>After initial triage by the analyst the user account appears compromised, in order to mitigate the risk — <em>as soon as possible</em> — let’s follow Microsoft’s documentation on<strong> </strong><a href="https://learn.microsoft.com/en-us/entra/id-protection/howto-identity-protection-investigate-risk#how-to-investigate-risky-users"><strong>how to investigate risk in Microsoft Entra ID protection</strong></a><strong>:</strong></p><p><a href="https://learn.microsoft.com/en-us/entra/id-protection/howto-identity-protection-investigate-risk#how-to-investigate-risky-users">Investigate risk Microsoft Entra ID Protection - Microsoft Entra ID Protection</a></p><p>So the advised response actions from above documentation that I want to test and verify are:</p><ol><li><strong>Reset password</strong> — This action revokes user’s current sessions.</li><li><strong>Block user</strong> — This action blocks a user from signing in if attacker has access to a password or ability to perform MFA.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mjyaToFD8IAF2FJQogtFfw.png" /><figcaption>Investigation and risk remediation framework — Microsoft</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WYwx8f0LpvD_cOCX_xl3Rg.png" /><figcaption>Entra ID Risky user view.</figcaption></figure><p>Since beforehand you don’t always know what kind of access the attacker has, I will test above response actions together with the following <strong>credential access combinations</strong>. This way every response action will have multiple validation factors:</p><ol><li>Username + Password + MFA credentials;</li><li>Access token;</li><li>Refresh token.</li></ol><blockquote>If you’d like to read a bit more on Access &amp; Refresh tokens, check out my previous blog:</blockquote><p><a href="https://medium.com/@bastradamus/azure-entra-id-token-manipulation-ca156e9cd26e">Azure &amp; Entra ID token manipulation</a></p><h3>Action 1: Reset password 🔄</h3><p><strong>Assumption</strong>: This action will revoke user’s current sessions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IwqT_75sMfZrXMsoOY8KRQ.png" /><figcaption>Performing the password reset.</figcaption></figure><p>From the moment the action is processed by Azure (took ±50 seconds) as shown in the audit logs section the attacker is not able to open any new login session, as expected, good. But does this kill all current sessions as described in the documentation ?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f5HQbRtNd9wF7iAiZRp9PA.png" /><figcaption>Printscreen of Audit logs when the password reset is processed.</figcaption></figure><p>I indeed get an error when trying to fetch resources from within the Azure/M365 portal. So the password reset action really does revoke current sessions.. it seems..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EBwLjY_WEht2wKyjfDyK_g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8TFO3oF-YHMScIOyECnEyw.png" /><figcaption>Two errors popping up in the Azure portal GUI</figcaption></figure><p>Amazing, there also is an <a href="https://learn.microsoft.com/en-us/entra/identity-platform/reference-error-codes#aadsts-error-codes"><strong>error code</strong></a> to look into: AADSTS160021, although the description seems a bit over the top.</p><blockquote><strong>AADSTS160021: </strong>AppSessionSelectionInvalidSessionNotExist — Application requested a user session that doesn’t exist. This issue can be resolved by <strong>creating a new Azure account</strong>.</blockquote><p>Now let’s have a look at what happens to security tokens, I’ve got tokens for both API endpoints still supported by Microsoft. There is the most current and actively developed API called the <strong>Microsoft Graph API</strong>, but there also still is the <strong>Azure AD Graph API.</strong></p><p>Fun fact.. it took <strong>8:47 minutes</strong> for my Access token for the Microsoft Graph API to get revoked. But again, yes, so far it does seem the action revokes current sessions:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O8ePuVfWeYYFT1BZCx0URA.png" /><figcaption>Postman view: 401 Unauthorized.</figcaption></figure><h3>What about access to legacy API endpoints ?</h3><p>Well.. The <strong>Azure AD Graph API</strong> security tokens stay alive.. That’s a fun finding. This means that an attacker can continue to explore the environment by running tools like AAD Internals, ROADtools, query the tenant manually with HTTP requests, try to escalate privileges, you name it. All by interacting with the Azure AD Graph API, without anyone noticing it, since there is no logging available for this legacy API.</p><p>For example, with the following GET request you’re able to fetch all users in a tenant (dependent on token permissions):</p><pre>GET https://graph.windows.net/&lt;tenant ID&gt;/users?api-version=1.6<br>Host: graph.windows.net<br>Authorization: Bearer &lt;access_token&gt;<br>Content-Type: application/json</pre><p>Alrighty, very interesting stuff and if you ask me, crucial to be aware of.</p><h4>So this assumption is Busted ❌</h4><p>Microsoft’s documentation is almost correct by stating that by performing the password reset action from the risky users view, it revokes sessions. For the most part.. it does not apply for Azure AD legacy API sessions and/or tokens.</p><h4>Azure AD Graph API</h4><p>Check out below docs if you’re interested to read a bit more about this API:</p><p><a href="https://learn.microsoft.com/en-us/previous-versions/azure/ad/graph/api/api-catalog">Azure AD Graph API Reference</a></p><h4>FYI</h4><p>The thing with legacy or deprecated APIs is that they eventually.. retire.</p><blockquote>Azure AD Graph will be fully retired after <a href="https://techcommunity.microsoft.com/blog/identity/june-2024-update-on-azure-ad-graph-api-retirement/4094534">June 30, 2025</a>, and no API requests will function at this point, regardless of the application’s configuration.</blockquote><h3>Action 2: Block user ⛔</h3><p><strong>Assumption</strong>: This action blocks a user from signing in if attacker has access to a password or ability to perform MFA.</p><p>Let’s continue where we left off.. what if we now block the same victim user account. The account should not be able to perform any querying or authentication right?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/574/1*Gu1ODYx5W5gTCPMdRlnxFw.png" /></figure><p>And that’s correct, the account is disabled and i now also lose my AAD Graph API access and any ability to perform authentication:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DcM4cfMcVVAh7Bn8-i7gDA.png" /></figure><p>OK, so the security team responded by resetting the password, blocking/disabling the user account and thereby killing the ability to perform any authentication. The victim later receives his/her new set of credentials and gets re-enabled.</p><h4>What about after re-enabling the account ? What happens then..</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*Iosn_wytGQi84LjYeodoHQ.png" /></figure><p>Tokens for the AAD Graph API get re-enabled with it, both <strong>Access </strong>and <strong>Refresh </strong>tokens can be utilized to enable persistence. This is where security and IT teams should be cautious since it’s dangerous to think you eradicated a threat while it’s not fully remediated and the cycle may start again..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yspJbFDZnSOcBSBeCrEs3w.png" /><figcaption>200 OK by performing a GET request to the AAD Graph API</figcaption></figure><h3>Revoking sessions explicitly</h3><p>So in order to respond to these incidents effectively, security teams and IT teams can revoke user sessions from the Azure or Entra ID portal:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RMyOP_OA9kr1DkKGuWzmJQ.png" /><figcaption>Revoke sessions action</figcaption></figure><p>And this also kills my Azure AD graph API session:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QVR2hxML3uJ0BOrHMirOxw.png" /></figure><p>But.. what about refresh tokens ? Do these get killed by revoking sessions ?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7FawXkhh6Qhp248r5XWoWw.png" /></figure><p>Yes they indeed do.</p><p>It’s also possible to make use of the Microsoft Graph API to revoke sessions programmatically with the correct permissions, check out:</p><p><a href="https://learn.microsoft.com/en-us/graph/api/user-revokesigninsessions?view=graph-rest-1.0&amp;tabs=http#http-request">user: revokeSignInSessions - Microsoft Graph v1.0</a></p><h3>What have we tested and validated ?</h3><p>When responding to a compromised user account, the reset password action as described in Microsoft’s Entra ID protection documentation appears to indeed revoke sessions.. except when it doesn’t entirely. The initial response actions should therefore be <strong>followed by</strong> the<strong> </strong>Revoke Sessions action in the Azure, Entra ID portal or programmatically.</p><p><strong>What about automating response actions ? Well, that’s for another time.</strong></p><p>And there is more to responding to a compromised user account incident, like investigating e-mail forwarding/inbox rules, app consent, additional account anomalies and more fun stuff. Any organization should develop their own Incident response playbooks but teams at Microsoft have developed a few as well. Refer to the resources below.</p><p>And of course, you test and validate described procedures in place 😉</p><ul><li><a href="https://learn.microsoft.com/en-us/security/operations/incident-response-overview#response-best-practices">Incident response overview</a></li><li><a href="https://learn.microsoft.com/en-us/security/operations/incident-response-playbooks">Incident response playbooks</a></li><li><a href="https://learn.microsoft.com/en-us/defender-office-365/responding-to-a-compromised-email-account#step-1-reset-the-users-password">Responding to a Compromised Email Account - Microsoft Defender for Office 365</a></li></ul><p>Thanks for making it this far 👻</p><p><a href="https://bastradamus.medium.com/subscribe"><strong>Subscribe</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Gb2Xab6iA1KhFhN28ewnyg.png" /><figcaption>:)</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1102ddacc2aa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Azure & Entra ID token manipulation]]></title>
            <link>https://medium.com/@bastradamus/azure-entra-id-token-manipulation-ca156e9cd26e?source=rss-a58a1b990a97------2</link>
            <guid isPermaLink="false">https://medium.com/p/ca156e9cd26e</guid>
            <category><![CDATA[microsoft-security]]></category>
            <category><![CDATA[cloud-security]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Bastradamus]]></dc:creator>
            <pubDate>Mon, 25 Nov 2024 07:37:12 GMT</pubDate>
            <atom:updated>2026-02-23T13:08:25.641Z</atom:updated>
            <content:encoded><![CDATA[<p>Access tokens + Refresh tokens edition</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*l_VvmOM9FQt2DnXt" /><figcaption>Photo by <a href="https://unsplash.com/@chuttersnap?utm_source=medium&amp;utm_medium=referral">CHUTTERSNAP</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Audience</h3><p>This blog is for security enthusiasts, professionals, hobbyists and anyone with a curiosity for cloud security.</p><h3>Introduction</h3><p>While i’m not a red teamer or offensive specialist, this post focuses on manipulating and comparing parts of security tokens from an offensive perspective. By now a while back i was simulating token-based attack techniques to develop detection mechanisms when i stumbled upon some findings.</p><p>In this blog i’ll be covering two attack scenario’s and two types of security tokens within the Microsoft Identity platform. First is the <strong>Access token</strong> which grants access to specific resources on behalf of an authenticated user. Secondly when the user acquires an access token to access a resource, the user also receives a <strong>Refresh token</strong> which is used to obtain new access and refresh token pairs when the current access token expires.</p><h3>Token theft attacks</h3><p>Phishing remains the most common identity-based <a href="https://cloud.google.com/blog/topics/threat-intelligence/m-trends-2024">initial infection vector</a> for any organization. Attackers can acquire credentials through various methods. Techniques like device code phishing and adversary in the middle attacks are prevalent for some years now. Zooming in on the token theft attack chain, I&#39;d say the most common ways attackers acquire security tokens are:</p><ul><li>Adversary In The Middle (AITM) attacks;</li><li>(Dynamic) Device code phishing attacks;</li><li>Malware infections (e.g. stealers).</li></ul><h4>Tools &amp; behavior</h4><p>During my research phase my goal was to create behavioral detection rules left behind by a variety of cloud-based offensive tools. Detection rules are out of scope for this blog i will however use a small portion of the capabilities of the following tools:</p><ul><li><a href="https://github.com/dirkjanm/ROADtools">Roadtools</a></li><li><a href="https://github.com/rvrsh3ll/TokenTactics">Tokentactics</a></li><li><a href="https://github.com/BloodHoundAD/AzureHound">Azurehound</a></li></ul><h3>Access vs. Refresh tokens</h3><p>I will not go into detail on token mechanisms but let’s do a basic refresher.</p><h4>Access token</h4><p>An access token is an authentication mechanism that grants specific permissions to access resources. When you authenticate to Entra ID (formerly Azure AD) or another Identity Provider (IDP), you receive a token. This token acts as your key to access applications or services securely.</p><p>For a token to be valid, it must be signed by a trusted issuer. Token handling often takes place in the browser or through APIs, enabling seamless communication and authorization between systems. Understanding how tokens work and ensuring their proper management is essential for maintaining secure access in modern cloud environments.</p><h4>Refresh token</h4><p>A refresh token is a credential used to obtain new access tokens without requiring the user or application to reauthenticate. When you authenticate to Entra ID (formerly Azure AD) or another Identity Provider (IDP) you likely also receive a refresh token alongside the access token.</p><p>Unlike access tokens, which have a short lifetime (± 1 hour), refresh tokens are designed for long-term use (e.g. 90 days). They allow applications to request new access tokens as needed, keeping sessions active without additional login prompts.</p><p><strong>OK, let’s dive in</strong> 🧺</p><h3>💥 Scenario 💥</h3><p>So imagine a realistic scenario of an attacker that acquired an <strong>Access + Refresh</strong> token pair, BUT.. the access token is expired.. Therefore must rely on the refresh token for obtaining a new access token to access victim resources.</p><p>I want to run two attack scenario’s, with the second scenario uncovering a fun distinction and the comparing and manipulation bit comes into play.</p><ol><li>Device code phish:<br>&gt; Token pair obtained of some application;</li><li>Malware stealer attack:<br>&gt; Token pair of a browser session obtained.</li></ol><p>The tools i mentioned earlier are easily capable of obtaining a new access token with a refresh token. With below command examples i’ve used <a href="https://learn.microsoft.com/en-us/graph/overview">msgraph </a>as the application to authenticate to.</p><p><strong>ROADtools:</strong></p><pre>roadtx gettokens --refresh-token &lt;token&gt; -r msgraph</pre><p><strong>TokenTactics</strong>:</p><pre>Invoke-RefreshToGraphToken -domain victim-org.com -refreshToken &lt;token&gt;</pre><h3>Scenario 1: Refresh token from device code phish</h3><p>This scenario describes the way an attacker obtained a token pair via device code phishing.</p><p>Typical flow of device code phish:</p><ol><li>Attacker populates device code:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8Fu1FOHPSayPVSS-ieudrA.png" /><figcaption>Populating device code</figcaption></figure><p>2. Now the attacker needs to send the code + URL (https://microsoft.com/devicelogin) to the victim, via e-mail or other channels, crafting a phishing e-mail. The lured victim enters the device code and proceeds with the authentication steps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OzfOgkD5TP9x-ZAeD3iGFA.png" /><figcaption>From the victims perspective</figcaption></figure><p>3. After the victim authenticates, the attacker receives the token pair as seen below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*41HsTuNVBNPavdp8xJbIqg.png" /><figcaption>Attacker receives Access &amp; Refresh token pair</figcaption></figure><p>4. And lastly the attacker can execute the refresh command in order to obtain new tokens and stay persistent within the victims domain:</p><pre>Invoke-RefreshToGraphToken -domain victim-org.com -refreshToken &lt;token&gt;</pre><p>Check, check, check. Other than an account takeover no abnormalities here. Now let’s have a look at the next scenario.</p><h3>Scenario 2: Refresh token from browser session</h3><p>This scenario describes the way an attacker obtained a token pair from a browser session. In this case, a session from the <a href="http://portal.azure.com/">Azure portal</a>.</p><p>First, let’s have a look at where to find the <strong>token payload</strong> from a browser session, so you can experiment some yourself.</p><p>From an authenticated session (M365 or Azure) go to:</p><ol><li><a href="https://portal.azure.com./">https://portal.azure.com</a>;</li><li>Press F12 / developer tools;</li><li>Click the Network tab;</li><li>In the search bar type “token” and click the Payload tab:</li></ol><blockquote>Each token can have a different endpoint in the scope value, more on this later.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OmlVjrSYc9UjwuNX4IzeZg.png" /><figcaption>Token payload</figcaption></figure><p>5. Now switch to Response and here you can see both token values:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LL_MchFSuOQesZKL2JfRdQ.png" /><figcaption>Response, containing token values</figcaption></figure><blockquote>Access tokens are JSON Web Tokens, A JWT contains three segments separated by the . character. The first segment is the <strong>header</strong>, the second is the <strong>body</strong>, and the third is the <strong>signature</strong>. To decode your token and get information about any JWT token, go to <a href="https://jwt.io/">https://jwt.io</a> or <a href="https://jwt.ms/">https://jwt.ms</a>.</blockquote><p>OK, let’s decode the Access token acquired from the browser session:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*znFfm5SidQFuVsZ8zYkLNg.png" /><figcaption>Decoded snippet of Access token</figcaption></figure><p>In order to use a refresh token the request needs certain values in it’s header and body, like the Application ID or Client ID, check out <a href="https://learn.microsoft.com/en-us/troubleshoot/entra/entra-id/governance/verify-first-party-apps-sign-in#application-ids-of-commonly-used-microsoft-applications">a translated list of verified app IDs</a>. In our case the application name is not a surprise since we’ve fetched it directly from the Azure Portal:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XJ8wCMI_qU0Mb4HSQI9RgA.png" /><figcaption>App ID or Client ID</figcaption></figure><p>Armed with a valid access token, it let’s an attacker run <strong>Azurehound</strong>, <strong>ROADtools </strong>or other tools (AADInternals, Graphrunner, etc) for mapping out or discover organizations resources. ROADtools for now is the more stealthier tool due to the fact that it is using the (almost) <a href="https://techcommunity.microsoft.com/blog/identity/important-update-azure-ad-graph-api-retirement/4090534">deprecated Azure AD graph API</a> endpoint instead of the MS graph API. Tools that use the MS Graph API will leave traces when monitoring the <a href="https://techcommunity.microsoft.com/blog/microsoftsecurityexperts/hunting-with-microsoft-graph-activity-logs/4234632">MS graph API activity logs</a>.</p><p>But in our scenario.. the access token is expired, so let’s look at some ways of refreshing the obtained token pair. While we’re at it, let’s do some extra testing. Let’s try both API endpoints and see if there are any surprising errors. I’ll be running refresh commands with the earlier mentioned tools.</p><h4>Both API endpoints:</h4><ul><li>MS graph API (<em>graph.microsoft.com</em>)</li><li>AAD graph API (<em>graph.windows.net</em>)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HAlpeJbVZhEULgPEIB4oLQ.png" /><figcaption>MS Graph API response</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nf7WH2KutFNSEM2NEHbNbw.png" /><figcaption>AAD graph API response</figcaption></figure><h4><a href="https://github.com/rvrsh3ll/TokenTactics"><strong>TokenTactics</strong></a></h4><p>The Refresh command should now be:</p><pre>Invoke-RefreshToAzureManagementToken -domain organization.com -ClientId c44b4083-3bb0-49c1-b47d-974e53cbdf3c -refreshToken &lt;token&gt;</pre><ul><li>Refresh token from the MS graph API ✅</li><li>Refresh token from the AAD graph API ✅</li></ul><p>Refresh commands with both tokens succeeded in receiving new token pairs.</p><p><a href="https://github.com/dirkjanm/ROADtools"><strong>ROADtools</strong></a></p><p>The Refresh command should be:</p><pre>roadtx gettokens --refresh-token &lt;token&gt; -r &lt;App_ID&gt;</pre><p>Trying to refresh with the MS Graph token results in the following error message:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xu2ENnGTvftJUphtb-st5Q.png" /><figcaption>Error message #1: MS Graph</figcaption></figure><p>This makes sense since ROADtools makes use of the AAD Graph API, so the MS graph refresh token appears <strong>invalid</strong>. You can check out the different Entra ID error codes <a href="https://learn.microsoft.com/en-us/entra/identity-platform/reference-error-codes#aadsts-error-codes">here</a>.</p><ul><li>Refresh token from the MS graph API ❌</li></ul><p>So if you’re an attacker and only acquired tokens for the MS graph API endpoint.. <em>you need to try another refresh method</em>.. Luckily for us we’ve obtained tokens for BOTH endpoints. Let’s try it against the AAD Graph API:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_yx31cqyg76EgdZ3fyYq1A.png" /><figcaption>Error message #2: AAD Graph</figcaption></figure><ul><li>Refresh token from the AAD graph API ❌</li></ul><p>So, the request was valid, aimed at the correct endpoint.. but this time we receive the following error:</p><p><em>Error during authentication: </em><strong>AADSTS9002327: </strong><em>Tokens issued for the ‘</em><strong><em>Single-Page Application</em></strong><em>’ client-type may only be redeemed via </em><strong><em>cross-origin requests</em></strong><em>.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/487/1*LgqWIJ1rRuTgn68I6WTDGA.png" /><figcaption>:)</figcaption></figure><p>So two things in the error response stand out here, let’s remember these for later:</p><ol><li>SPA — Single Page Application</li><li>CORS — Cross Origin Requests</li></ol><p><a href="https://bloodhound.readthedocs.io/en/latest/data-collection/azurehound.html"><strong>AzureHound</strong></a></p><p>Now for the AzureHound part, i’m not going to request a new access token but rather use the refresh token to run the tool and try to fetch resources (devices, apps, users, etc). AzureHound can do this with a refresh token via the following command:</p><pre>./azurehound -r &quot;&lt;refresh_token&gt;&quot; list --tenant &quot;example.onmicrosoft.com&quot; -o output.json</pre><ul><li>Refresh token from the MS graph API ❌</li><li>Refresh token from the AAD graph API ❌</li></ul><p>Using both refresh tokens results in error code <strong>AADSTS7000</strong>, looking at the error code overview <a href="https://learn.microsoft.com/en-us/entra/identity-platform/reference-error-codes#aadsts-error-codes">here</a>, we can see two potential reasons:</p><ul><li>Token binding header is empty</li><li>Token binding hash does not match</li></ul><p>If this was a refresh token from another application like a backend resource as MSGraph it will run and fetch information as desired and should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eQmGypMiMXpDMG0orikekw.png" /><figcaption>AzureHound output snippet</figcaption></figure><h3>Token manipulation</h3><p>I’ve reproduced the <a href="https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-auth-code-flow#redirect-uris-for-single-page-apps-spas">SPA </a>error by crafting a request with <a href="https://www.postman.com/">Postman</a> to look into the issue a bit more, let’s check it out:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uB4imD5qHtIcPjQJinbEyg.png" /><figcaption>POST request + Headers</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lAEMIC6DbFcEgNKy77FrMQ.png" /><figcaption>request Body</figcaption></figure><ul><li><strong>POST </strong>request to https://login.microsoftonline.com/common/oauth2/v2.0/token</li><li><strong>Headers </strong>application/x-www-url-form-urlencoded</li><li><strong>Body </strong>needs to contain:<br>&gt; grant_type<br>&gt; client_id (App ID)<br>&gt; refresh_token<br>&gt; scope (AAD Graph api endpoint)</li></ul><h4><strong>Send</strong>..</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tSTEN9uZdDCtD7BU6BsBoA.png" /></figure><p>And there we can see the same error code <strong>AADSTS9002327</strong>. Now this is where the fun starts and what got me digging into some Microsoft documentation because i haven’t read about this anywhere else. So reading the following documentation on <a href="https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-auth-code-flow#redirect-uris-for-single-page-apps-spas">Redirect URIs for single-page apps (SPAs)</a>, the following section contains the answer:</p><blockquote>To ensure security and best practices, the Microsoft identity platform returns an error if you attempt to use a spa redirect URI without an Origin header. Similarly, the Microsoft identity platform also prevents the use of client credentials in all flows in the presence of an Origin header, to ensure that secrets aren&#39;t used from within the browser.</blockquote><p>So it needs the <strong>origin </strong>value in the header of the request. Now the earlier <strong>AADSTS7000 </strong>error makes more sense as well<strong> </strong>since the expected token header is incomplete. Let’s add the Origin key with ANY value since that’s not important:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N3JWwEMM5myqPyau0VGLCw.png" /><figcaption>200 OK + new token pair</figcaption></figure><p>Pretty cool 🎉 Within the response we can obtain both Access and Refresh tokens. For this example i’ve used the <em>graph.windows.net</em> (<strong>AAD Graph</strong>) endpoint, the same works for the <strong>MS Graph</strong> endpoint but you’d have to change the scope to the correct endpoint.</p><p>Looking back, we’ve done some exploring and seen different characteristics of tools, tokens and APIs. Gaining a solid understanding of basic token mechanisms is very valuable for both defenders and attackers.</p><p>I hope you found this insightful or was entertained by the above. If you have any feedback or additional thoughts, I’d be happy to hear either one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/462/1*gFhVReu4c6KYE_77snrGfA.png" /></figure><h4><a href="https://bastradamus.com/subscribe">Subscribe</a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ca156e9cd26e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to create a Detection Engineering Lab — Part 2]]></title>
            <link>https://medium.com/@bastradamus/how-to-create-a-detection-engineering-lab-part-2-3bdbb2c873d6?source=rss-a58a1b990a97------2</link>
            <guid isPermaLink="false">https://medium.com/p/3bdbb2c873d6</guid>
            <category><![CDATA[elasticsearch]]></category>
            <category><![CDATA[detection-engineering]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Bastradamus]]></dc:creator>
            <pubDate>Tue, 19 Nov 2024 09:00:28 GMT</pubDate>
            <atom:updated>2026-02-23T13:09:54.259Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to create a Detection Engineering Lab — Part 2</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*acInioQa-3Enyny8" /><figcaption>Photo by <a href="https://unsplash.com/@snapsbyclark?utm_source=medium&amp;utm_medium=referral">Clark Van Der Beken</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4><a href="https://medium.com/@bastradamus/how-to-create-a-detection-engineering-lab-part-1-8dacc52001b5">Find part 1 here.</a></h4><p>Welcome back to <strong>part 2</strong> of the series. In this part, we’ll cover:</p><ul><li>Deploying the Elastic stack on Docker;</li><li>Using Docker Compose to simplify the container deployment process with the necessary configuration files;</li><li>Setting up a virtual machine and installing the Elastic Agent for log forwarding;</li><li>Creating our first detection rule to put everything into action.</li></ul><p>I hope you’ve had a chance to set up the environment as outlined in <a href="https://medium.com/@bastradamus/how-to-create-a-detection-engineering-lab-part-1-8dacc52001b5"><strong>Part 1</strong></a>. If not, that’s ok, it’s also possible to setup the Lab if you choose to run Docker Desktop or another way. Or just read on out of curiosity.</p><h4>Technical requirements:</h4><p>In this part, a (Windows) virtual machine will serve as the <strong>host</strong> for generating example logs that will be forwarded to the Elastic environment. The VM will be the only thing that runs from your device, the rest will be hosted and run in the cloud.</p><ul><li><a href="https://www.virtualbox.org/">Virtualbox </a>or <a href="https://www.vmware.com/products/desktop-hypervisor/workstation-and-fusion">VMWare workstation</a> software;</li><li>4 GB RAM assigned to VM (minimum recommendation);</li><li>60 GB disk space assigned to VM;</li></ul><p><strong>OK, let’s dive right in</strong> 🙂</p><h3>Step 1: Download Github repository</h3><p>Github provides a way to download the entire <a href="https://github.com/madret/elastic"><strong>repository</strong></a><strong> </strong>as a compressed .tar.gz file. You can use wget to download the repo and then extract it in your Docker environment.</p><ol><li>Login to your Docker droplet or Docker desktop environment;</li><li>In your terminal change to a desired directory <br>(e.g. cd /home/&lt;username&gt;/);</li><li>Download the repo and extract the files:<br>&gt; wget &quot;https://github.com/madret/elastic/archive/refs/heads/main.tar.gz&quot; <br>&gt; tar -xzvf main.tar.gz</li></ol><p>This will result in the creation of a directory named <strong>elastic-main</strong> and the following folder and file structure within:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mhY8j37fN6TpdswRLoZ1QA.png" /><figcaption>elastic-main structure</figcaption></figure><p>The <strong>esk </strong>directory holds the configuration for the elasticsearch and kibana containers, the <strong>fleet </strong>directory for the fleet server to manage Elastic Agents. Certificates will be out of scope for this setup.</p><h3>Step 2: Configure credentials</h3><p>Both docker compose files use environment variables files (.env), this helps with maintenance but also safeguards credentials when sharing the docker compose config files without exposing passwords.</p><p>Default environment variables content within the <strong>esk </strong>directory:</p><pre>ELASTIC_PASSWORD=&lt;&lt;set password&gt;&gt;<br>KIBANA_PASSWORD=&lt;&lt;set password&gt;&gt;<br>STACK_VERSION=8.16.0<br>CLUSTER_NAME=docker-cluster<br>LICENSE=basic<br>ES_PORT=9200<br>KIBANA_PORT=5601<br>MEM_LIMIT=2147483648<br>XPACK_ENCRYPTEDSAVEDOBJECTS_ENCRYPTIONKEY=&lt;&lt;random 32 character string&gt;&gt;<br>XPACK_SECURITY_ENCRYPTIONKEY=&lt;&lt;random 32 character string&gt;&gt;<br>XPACK_REPORTING_ENCRYPTIONKEY=&lt;&lt;random 32 character string&gt;&gt;</pre><ol><li>Update the .env file and set the credentials for the values in &lt;&lt;brackets&gt;&gt;. Open your <a href="https://bitwarden.com/">password manager</a> and save the credentials. The <strong>elastic</strong> password is the one that you’ll be using to sign into the web interface later on.</li><li>Now that you’ve updated the <strong>5 values</strong> in the .env file with the credentials of your choosing you’re ready to spin up the containers via docker compose.</li></ol><h3>Step 3: Spin up the Elastic containers</h3><p>In the following examples, commands that typically require sudo will be shown without it. Ideally you’ve setup a user account with the necessary privileges, while running as the <strong>root</strong> user gives you complete control over a system it is also dangerous and possibly destructive. — <a href="https://www.digitalocean.com/community/tutorials/how-to-add-and-delete-users-on-ubuntu-20-04">how to add users on ubuntu.</a></p><ol><li>Move to the esk directory where the .env and docker compose files are located and run:<br>&gt; docker compose up -d<br>this will start up the elastic and kibana containers. When the containers have a status of <em>running</em> you can move on to enter the web interface.</li></ol><p>The -dflag stands for <strong>detached mode</strong>. When this flag is used, Docker Compose runs the containers in the background and returns control of the terminal to you immediately, instead of displaying the logs and keeping the terminal attached to the container’s processes. However running the command without the -d flag results in verbosity and can be used for debugging.</p><p>2. Browse to http://&lt;your-docker-host-IP&gt;:5601, you should be greeted with a login portal;</p><p>3. Login with username <strong>elastic</strong> and the <strong>password</strong> as defined in your<strong> .env</strong> file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O9EV1ctSj7Q51jMXsut5sw.png" /><figcaption>Login portal view</figcaption></figure><p>I won’t go into detail but if you’re exposing the web interface to the internet think about IP <a href="https://en.wikipedia.org/wiki/Whitelist">whitelisting</a> your public IP address (or ISP range) as a security measure with a Firewall rule.</p><p><strong>You’ve now successfully set up the main part of the elastic stack</strong> 🎉</p><h3>Step 4: Configure Fleet server</h3><ol><li>While still logged in to the kibana web portal browse to:<br>http://&lt;your-docker-host-IP&gt;:5601/app/fleet/agents</li><li>This will show the configuration window of “<strong>Add a Fleet Server</strong>”.</li><li>The <strong>fleet server host</strong> value should be your your-docker-host-IP withport 8220 (e.g. <a href="https://IP:8220);">https://IP_Address:8220</a>).</li><li>Press “<strong>Generate Fleet server policy</strong>”, this will show an installation script. We’ll need the Linux Tar option, but only copy the --fleet-server-service-token value:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ADdpdNZ-dQHa66UWUA8ReA.png" /></figure><p>5. Go back to your Docker host and paste the service token value into the <strong>.env</strong> file located in the <strong>fleet </strong>directory:</p><pre>FLEET_SERVER_SERVICE_TOKEN=&lt;&lt;your service token generated from kibana&gt;&gt; </pre><p>6. Now that the <strong>.env</strong> file is updated with the correct token, we can connect the fleet server. Make sure that you’re in the <strong>fleet </strong>directory where the correct <strong>docker-compose.yaml </strong>file is located and run: <br>&gt; docker compose up -d</p><p>If you’d like to list all your containers whether they are running, stopped, or in another state, run the command:<br>&gt; docker ps -a</p><p><strong>Go back to the web portal and wait for it…</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2_a1KU22iinA18I7ZTAaxA.png" /><figcaption>Fleet server connected</figcaption></figure><p>7. Lastly we should modify the <a href="https://www.elastic.co/guide/en/fleet/current/es-output-settings.html">output settings</a> of the Fleet configuration, the Elasticsearch URLs where Elastic Agents will send data to by default are exposed on port 9200 for self-managed clusters. However instead of the default <strong>localhost</strong> make sure to configure the correct IP address of your Docker instance. See below example and verify your IP + port settings:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G9kNYiHu_OMXvwtA6y0avQ.png" /></figure><p>8. Now click the edit pencil of the outputs config and modify the <em>advanced YAML configuration</em>, by adding:<br>&gt; ssl.verification_mode: none &amp; click “<strong>Save and apply settings</strong>”.</p><h3>Step 5: Install Elastic agent on virtual machine</h3><p>Before proceeding with this section, you’ll need to have <strong>VirtualBox or VMWare </strong>installed on your system and a Windows Virtual Machine (VM) configured.</p><ol><li>While still logged in to the kibana web portal browse to:<br>http://&lt;your-docker-host-IP&gt;:5601/app/fleet/agents</li><li>Select ”<strong>Add Agent</strong>”. An agent enrolment section opens. Create a new policy (e.g. “WINOS”) and select <strong>Enroll in Fleet (recommended)</strong> — <em>Enroll in Elastic Agent in Fleet to automatically deploy updates and centrally manage the agent.</em></li><li>For <strong>step 3</strong> select the appropriate platform, in our case <strong>Windows</strong>. This will generate powershell commands that need to be executed on the Virtual Machine in an elevated prompt. One addition however is appending the insecure flag, the --insecure flag tells the Elastic Agent to bypass the certificate validation step. Which is not recommended in production environments but setting up certificates is out of scope for this blog. To read more about setting up certificates check out the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/security-basic-setup-https.html">Elastic docs</a>.</li><li>On the virtual machine open a powershell window as Administrator, paste the commands + --insecure and hit Enter. The Elastic agent download process starts.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QcKmS40hTX4pS47l90uPag.png" /></figure><p>5. After the agent is successfully installed and <strong>incoming data is confirmed</strong>, you can inspect the agent policy settings by browsing to: <br>http://&lt;your-docker-host-IP&gt;:5601/app/fleet/policies and selecting the policy.</p><p>We will focus on Windows event logs, it’s possible to modify the default settings by going into Advanced options to select more custom desired Event IDs. Knowing the most useful event IDs for the right use case is extremely valuable for developing detections. For additional information on collecting and parsing event logs from any Windows event log channel with the Elastic Agent, check out the following <a href="https://www.elastic.co/docs/current/integrations/winlog">Elastic documentation</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-t6NP21s4HN8FkeVnHtQ7g.png" /><figcaption>Policy view</figcaption></figure><p>6. Verify the incoming events by going to the Discover section in Kibana, browse to http://&lt;your-docker-host-IP&gt;:5601/app/discover or just select <strong>Discover </strong>from the search bar. On your left you should see numerous available fields populated.</p><p>Time to <strong>discover</strong> the various event logs<strong> </strong>🎉</p><h3>Step 6: Build first detection query</h3><p>OK, let’s come up with a simplified detection case. Detection assignments can come via different ways, an example can be due to a CISA advisory got released and higher management or a customer may ask “<em>do we detect this</em>” ? For this case we’re referencing this <a href="https://www.cisa.gov/news-events/cybersecurity-advisories/aa23-347a">CISA advisory</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2TbN-K4wLtmZ3o0WYde5Mw.png" /><figcaption>Snippet of CISA advisory</figcaption></figure><h4>6.1 Generate example logs</h4><p>For this example I&#39;ve configured a <a href="https://www.elastic.co/guide/en/fleet/current/view-integration-policies.html">custom integration</a> for a Microsoft-Windows-PowerShell/Operational channel. This captures, for example, event ID 4104 — <strong>Powershell Script block logging</strong>. Script block logging records blocks of code as they are executed by the PowerShell engine, thereby capturing the full contents of code executed by an attacker, including scripts and commands. To read more about Powershell logging, check out t<a href="https://cloud.google.com/blog/topics/threat-intelligence/greater-visibility/">his awesome article by Mandiant</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G_83EGppbBGSH9HcClmHkA.png" /><figcaption>Agent policy integration</figcaption></figure><p>So i’ve simulated a reconnaissance “attack” via Powershell by running a script from the PS command-line, generating an Event ID 4104 log entry.</p><h4>6.2 Detection:</h4><p>Looking back at the assignment at hand, detect 4 variants of the <em>whoami </em>command executed from the command-line. Without going into processes or procedures. Let’s keep it simple and straightforward:</p><ol><li>We’ll take <a href="https://learn.microsoft.com/en-us/windows-server/identity/ad-ds/manage/component-updates/command-line-process-auditing#configuration">Event ID 4688 for process creation events with command-line logging</a> enabled together with the Powershell Event ID 4104 as mentioned earlier.</li><li>Now add wildcards to the <em>whoami </em>variants and our query should be:</li></ol><pre>(event.code: 4688 OR event.code: 4104) <br>AND (message: &quot;*whoami /priv*&quot; OR message: &quot;*whoami /all*&quot; OR <br>message: &quot;*whoami /groups*&quot; OR message: &quot;*whoami /domain*&quot;)</pre><p>Let’s hit Enter and….</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mqVmZRBpBqPWGSHRVddssA.png" /><figcaption>Tabular view of the Discover section in Elastic</figcaption></figure><p>We can see a hit on the whoami /priv variant from my super malicious powershell script. Again, this is a simplified way to get familiar with creating some Detection logic and a small touch of the Kibana Query Language, one of many query languages out there.</p><p>And there you have it. You’re all set to research, explore, test and develop various techniques in an environment you setup yourself. I hope you found <a href="https://medium.com/@bastradamus/how-to-create-a-detection-engineering-lab-part-1-8dacc52001b5">this series</a> interesting and took away something valuable from it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fgDY3olpqwuj69lQTggrsA.png" /><figcaption>a meme a day keeps the doctor away</figcaption></figure><h4><a href="https://bastradamus.com/subscribe">Subscribe</a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3bdbb2c873d6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>