<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Aniket Rajendra Trimbake</title>
    <description>The latest articles on Forem by Aniket Rajendra Trimbake (@aniket93).</description>
    <link>https://forem.com/aniket93</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1250708%2Fb3128771-49d2-495f-87e6-eab36ab95506.jpg</url>
      <title>Forem: Aniket Rajendra Trimbake</title>
      <link>https://forem.com/aniket93</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/aniket93"/>
    <language>en</language>
    <item>
      <title>Microsoft Sentinel : Using KQL to detect failed login on Linux</title>
      <dc:creator>Aniket Rajendra Trimbake</dc:creator>
      <pubDate>Sun, 07 Jan 2024 12:06:52 +0000</pubDate>
      <link>https://forem.com/aniket93/microsoft-sentinel-using-kql-to-detect-failed-login-on-linux-15p1</link>
      <guid>https://forem.com/aniket93/microsoft-sentinel-using-kql-to-detect-failed-login-on-linux-15p1</guid>
      <description>&lt;p&gt;Blog link at &lt;a href="https://dev.tourl"&gt;https://aniket18292.wixsite.com/cyber-art/post/detect-failed-logins-on-a-linux-machine-in-azure-using-microsoft-sentinel&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This article will explain how to generate alerts and incidents for failed logins on Linux machines. This can be particularly useful to the SOC Team during a brute force attack.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pre-Requisites&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;AMA/OmsAgent (Legacy) needs to be installed on the machine.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If using AMA, Data Collection Rule should be created to collect auth facility logs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If using Legacy agent, you can navigate to Log Analytics Workspace -&amp;gt; legacy Agents Management -&amp;gt; Syslog and make sure "auth" facility has been selected here.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Along with this, we can setup automations as well to get notified or take action on the attacker IP address whenever a failed login is detected and try to enrich the IP to aid investigation but for now let us create the rule and have a look at how the incident looks like.&lt;/p&gt;

&lt;p&gt;To create an analytic rule, navigate to Microsoft Sentinel -&amp;gt; Analytic Rules and from the top click on create NRT (Near-Realtime) Query rule. I am using NRT as failed login is a critical event and I would like to be notified as soon as possible. Usually with NRT, it takes around 2 minutes for an incident to be generated.&lt;/p&gt;

&lt;p&gt;You can give a name of your choice, following is my configuration.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjb6yn6zwxvecy5gmjowp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjb6yn6zwxvecy5gmjowp.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can now click on Next and use the following query.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Syslog&lt;br&gt;
| where Facility == 'auth' and SyslogMessage has 'failed password'&lt;br&gt;
| extend Account = tostring(extract("Failed password for (.*) from", 1, SyslogMessage))&lt;br&gt;
| extend PortNumber = tostring(extract("port (\\d+)", 1, SyslogMessage))&lt;br&gt;
| extend IpAddress = tostring(extract("from (\\d+\\.\\d+\\.\\d+\\.\\d+)", 1, SyslogMessage))&lt;br&gt;
| extend Protocol = tostring(extract("port \\d+ (.*)$", 1, SyslogMessage))&lt;br&gt;
| extend Description = iff(Account has "invalid","Failed Login from Invalid Account [Indicates brute force]", " Failed Login from Valid Account [Consider Password Change] [Could be legitimate attempt]")&lt;br&gt;
| project&lt;br&gt;
    IpAddress,&lt;br&gt;
    HostIP,&lt;br&gt;
    Account,&lt;br&gt;
    PortNumber,&lt;br&gt;
    Protocol,&lt;br&gt;
    HostName,&lt;br&gt;
    Computer,&lt;br&gt;
    ProcessID,&lt;br&gt;
    ProcessName,&lt;br&gt;
    Description&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I will try to explain the KQL query here.&lt;/p&gt;

&lt;p&gt;Firstly we filter syslog data to include only entries where the Facility is 'auth' and where SyslogMessage contains the string 'failed password'&lt;/p&gt;

&lt;p&gt;Next, we use use the extract function to pull specific information from the SyslogMessage field. Each extend statement creates a new column with extracted information.&lt;/p&gt;

&lt;p&gt;The Description column is created based on the content of the Account column. If the Account contains "invalid," it suggests a potential brute force attempt; otherwise, it implies a failed login from a valid account.&lt;/p&gt;

&lt;p&gt;Finally, the project statement selects specific columns to display in the output. This will be useful for entity mapping.&lt;/p&gt;

&lt;p&gt;Following are the entities mapped. Remember, it is very important to map entities in any analytic rule or else you wont be able to conduct any investigation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff142x1ksu1bj745lk79f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff142x1ksu1bj745lk79f.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Rest of the columns, I have mapped to Custom Details as there were no relevant fields for them in Entity Mapping.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F462ztx45wvt7cdys3hnz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F462ztx45wvt7cdys3hnz.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For Event Grouping section, I have decided to trigger an alert for each event.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fftiznz5ej09514pwkffy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fftiznz5ej09514pwkffy.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click Next and make sure that enable incidents is enabled. It is upto you whether you would like to group the alerts. Ideally, it is a good practice to do so.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo1u2kl4nvf3j3eta7zqw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo1u2kl4nvf3j3eta7zqw.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For automated response, I am using a playbook to enrich the IP address and block the attacker IP automatically at NSG level which I will cover in another article.&lt;/p&gt;

&lt;p&gt;Once done, you can hit the review and create button.&lt;/p&gt;

&lt;p&gt;Now, you can generated a failed login event on your linux machine and have an incident generated.&lt;/p&gt;

&lt;p&gt;I had exposed my VM to the public internet and there were lots of incidents generated. &lt;/p&gt;

&lt;p&gt;Following is one such incident&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpe8pyuxq4ph4tk0vqrpx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpe8pyuxq4ph4tk0vqrpx.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A sneak peek into the automation that I am using&lt;/p&gt;

&lt;p&gt;Incident description has been updated with relevant details of playbook actions and severity has been lowered as playbook has returned success state.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz421poho2ejviqnal3f8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz421poho2ejviqnal3f8.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's go and check out the task now, shall we?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq2n53j638f1ye8p945zc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq2n53j638f1ye8p945zc.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;An email has also been triggered for the same as we can see below &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvsrm879m8iovfpdb08f1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvsrm879m8iovfpdb08f1.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftyxu2wods7alibss0zn0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftyxu2wods7alibss0zn0.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I will release an article later on detailing the playbook and on how to fetch threat intel details.&lt;/p&gt;

&lt;p&gt;Cheers, and thanks for reading!&lt;/p&gt;

</description>
      <category>security</category>
      <category>azure</category>
      <category>sentinel</category>
      <category>microsoftsentinel</category>
    </item>
  </channel>
</rss>
