<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel>
        <title>Elastic Security Labs - Machine Learning</title>
        <link>https://www.elastic.co/kr/security-labs</link>
        <description>Trusted security news &amp; research from the team at Elastic.</description>
        <lastBuildDate>Tue, 21 Jul 2026 08:52:42 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <image>
            <title>Elastic Security Labs - Machine Learning</title>
            <url>https://www.elastic.co/kr/security-labs/assets/security-labs-thumbnail.png</url>
            <link>https://www.elastic.co/kr/security-labs</link>
        </image>
        <copyright>© 2026. elasticsearch B.V. All Rights Reserved</copyright>
        <item>
            <title><![CDATA[Detect domain generation algorithm (DGA) activity with new Kibana integration]]></title>
            <link>https://www.elastic.co/kr/security-labs/detect-domain-generation-algorithm-activity-with-new-kibana-integration</link>
            <guid>detect-domain-generation-algorithm-activity-with-new-kibana-integration</guid>
            <pubDate>Wed, 17 May 2023 00:00:00 GMT</pubDate>
            <description><![CDATA[We have added a DGA detection package to the Integrations app in Kibana. In a single click, you can install and start using the DGA model and associated assets, including ingest pipeline configurations, anomaly detection jobs, and detection rules.]]></description>
            <content:encoded><![CDATA[<p>Searching for a way to help protect your network from potential domain generation algorithm (DGA) attacks? Look no further — a DGA detection package is now available in the Integrations app in Kibana.</p>
<p>In a single click, users can install and start using the DGA model and associated assets, including ingest pipeline configurations, anomaly detection jobs, and detection rules. Read on for step-by-step instructions on installing and fully enabling the DGA package.</p>
<p>[Related article: <a href="https://www.elastic.co/kr/blog/automating-security-protections-rapid-response-to-malware">Automating the Security Protections rapid response to malware</a>]</p>
<h1>What is a DGA?</h1>
<p>A DGA is a technique employed by many malware authors to ensure that infection of a client machine evades defensive measures. The goal of this technique is to hide the communication between an infected client machine and the command and control (C &amp; C or C2) server by using hundreds or thousands of randomly generated domain names, of which one will ultimately resolve to the IP address of a C &amp; C server.</p>
<p>To more easily visualize what’s occurring in a DGA attack, imagine for a moment you’re a soldier on a battlefield. Like many soldiers, you have communication gear that uses radio frequencies for communication. Your enemy may try to disrupt your communications by jamming your radio frequencies. One way to devise a countermeasure for this is by frequency hopping — using a radio system that changes frequencies very quickly during the course of a transmission. To the enemy, the frequency changes appear to be random and unpredictable, so they are hard to jam.</p>
<p>DGAs are like a frequency-hopping communication channel for malware. They change domains so frequently that blocking the malware’s C2 communication channel becomes infeasible by means of DNS domain name blocking. There are simply too many randomly generated DNS names to successfully identify and block them.</p>
<p>This technique emerged in the world of malware with force in 2009, when the “Conficker” worm began using a very large number of randomly generated domain names for communication. The worm’s authors developed this countermeasure after a consortium of security researchers interrupted the worm’s C2 channel by shutting down the DNS domains it was using for communication. DNS mitigation was also performed in the case of the 2017 WannaCry ransomware global outbreak.</p>
<h1>Getting started</h1>
<p>We have released the model and the associated assets — including the pipelines, anomaly detection configurations, and detection rules — to the Integrations app in Kibana as of 8.0. We will be maintaining this format moving forward.</p>
<p>If you don’t have an Elastic Cloud cluster but would like to start experimenting with the released ProblemChild package, you can start a <a href="https://cloud.elastic.co/registration">free 14-day trial</a> of Elastic Cloud.</p>
<p>We will now look at the steps to get DGA up and running in your environment in a matter of minutes using the released DGA package.</p>
<h3>Step 1: Installing the package assets</h3>
<p>In Kibana, the Integrations app now includes the DGA detection package. To install the assets, click the <strong>Install DGA assets</strong> button under the <strong>Settings</strong> tab. This will install all of the artifacts necessary to use the DGA model to generate alerts when DGA activity is detected in your network data.</p>
<p><img src="https://www.elastic.co/kr/security-labs/assets/images/detect-domain-generation-algorithm-activity-with-new-kibana-integration/blog-elastic-DGA-1.png" alt="" /></p>
<p><img src="https://www.elastic.co/kr/security-labs/assets/images/detect-domain-generation-algorithm-activity-with-new-kibana-integration/blog-elastic-DGA-2.jpg" alt="" /></p>
<p>Once installation is complete, you can navigate to <strong>Stack Management &gt; Ingest Pipelines</strong> and see that the <strong><code>&lt;version-number&gt;-ml\_dga\_ingest\_pipeline</code></strong> has been installed and can now be used to enrich incoming ingest data. The ingest pipeline leverages the <strong><code>&lt;version-number&gt;-ml\_dga\_inference\_pipeline</code></strong> to do this.</p>
<p><img src="https://www.elastic.co/kr/security-labs/assets/images/detect-domain-generation-algorithm-activity-with-new-kibana-integration/blog-elastic-DGA-3.png" alt="" /></p>
<p>Similarly, the installed DGA model can now be seen in <strong>Machine Learning &gt; Model Management &gt; Trained Models</strong>.</p>
<p><img src="https://www.elastic.co/kr/security-labs/assets/images/detect-domain-generation-algorithm-activity-with-new-kibana-integration/blog-elastic-DGA-4.jpg" alt="" /></p>
<h3>Step 2: Enriching your data</h3>
<p>Now you are ready to ingest your data using the ingest pipeline. The supervised model will analyze and enrich incoming data containing DNS events with a DGA score.</p>
<p>This pipeline is designed to work with data containing DNS events — such as <a href="https://www.elastic.co/kr/beats/packetbeat">packetbeat</a> data — which contain these ECS fields: dns.question.name and dns.question.registered_domain. You can add the installed ingest pipeline to an Elastic beat by adding a simple <a href="https://www.elastic.co/kr/guide/en/elasticsearch/reference/current/ingest.html#pipelines-for-beats">configuration setting</a>.</p>
<p>If you already have an ingest pipeline associated with your indices, you can use a <a href="https://www.elastic.co/kr/guide/en/elasticsearch/reference/current/pipeline-processor.html">pipeline processor</a> to integrate the DGA ingest pipeline into your existing pipeline.</p>
<p>You will also want to add the following mappings to the beat you chose:</p>
<pre><code>{
  &quot;properties&quot;: {
    &quot;ml_is_dga&quot;: {
      &quot;properties&quot;: {
        &quot;malicious_prediction&quot;: {
          &quot;type&quot;: &quot;long&quot;
        },
        &quot;malicious_probability&quot;: {
          &quot;type&quot;: &quot;float&quot;
        }
      }
    }
  }
}
</code></pre>
<p>You can do this under <strong>Stack Management &gt; Index Management &gt; Component Templates.</strong> Templates that can be edited to add custom components will be marked with a <em>@custom</em> suffix. Edit the <em>@custom</em> component template for your Elastic beat by pasting the above JSON blob in the <strong>Load JSON</strong> flyout.</p>
<p><img src="https://www.elastic.co/kr/security-labs/assets/images/detect-domain-generation-algorithm-activity-with-new-kibana-integration/Screen_Shot_2022-07-29_at_8.37.43_AM.jpeg" alt="" /></p>
<p><img src="https://www.elastic.co/kr/security-labs/assets/images/detect-domain-generation-algorithm-activity-with-new-kibana-integration/Screen_Shot_2022-07-29_at_8.38.11_AM.jpeg" alt="" /></p>
<p>You should now see that the model enriches incoming DNS events with the following fields:</p>
<ul>
<li>
<p><strong>Ml_is_dga.malicious_prediction:</strong> A value of “1” indicates the DNS domain is predicted to be the result of malicious DGA activity. A value of “0” indicates it is predicted to be benign.</p>
</li>
<li>
<p><strong>Ml_is_dga.malicious_probability:</strong> A probability score, between 0 and 1, that the DNS domain is the result of malicious DGA activity.</p>
</li>
</ul>
<p>If you want an immediate way to test that the ingest pipeline is working as expected with your data, you can use a few sample documents with the <a href="https://www.elastic.co/kr/guide/en/elasticsearch/reference/current/simulate-pipeline-api.html">simulate pipeline API</a> and confirm you see the <strong>ml_is_dga</strong> fields.</p>
<h3>Step 3: Running anomaly detection</h3>
<p>The package includes a pre-configured anomaly detection job. This machine learning (ML) job examines the DGA scores produced by the supervised DGA model and looks for anomalous patterns of unusually high scores for a particular source IP address. These events are assigned an anomaly score.</p>
<p>To run this job on your enriched data, go to <strong>Machine Learning &gt; Anomaly Detection</strong>. When you create a job using the job wizard, you should see an option to Use preconfigured jobswith a card for DGA. After selecting the card, you will see the pre-configured anomaly detection job that can be run. Note this job is only useful for indices that have been enriched by the ingest pipeline.</p>
<h3>Step 4: Enabling the rules</h3>
<p>To maximize the benefit of the DGA framework, activate the installed detection rules. They are triggered when certain conditions for the supervised model or anomaly detection job are satisfied. The complete list of the installed rules can be found in the <strong>Overview</strong> page of the package itself or in the latest experimental detections <a href="https://github.com/elastic/detection-rules/releases/tag/ML-experimental-detections-20211130-7">release</a>.</p>
<p>To fully leverage the included preconfigured anomaly detection job, enable the complementary rule: <em>Potential DGA Activity.</em> This will create an anomaly-based alert in the detection page in the security app.</p>
<p>The preconfigured anomaly detection job and complementary rule are both available in the detection rules repo <a href="https://github.com/elastic/detection-rules/releases">releases</a>. To enable and use the installed rules, navigate to <strong>Security &gt; Rules</strong> and select <em>Load Elastic prebuild rules and timeline templates</em>.</p>
<p><img src="https://www.elastic.co/kr/security-labs/assets/images/detect-domain-generation-algorithm-activity-with-new-kibana-integration/blog-elastic-DGA-5.jpg" alt="" /></p>
<h1>Get in touch</h1>
<p>We’d love for you to try out ProblemChild and give us feedback as we work on adding new capabilities to it. If you run into any issues during the process, please reach out to us on our <a href="https://ela.st/slack">community Slack channel</a>, <a href="https://discuss.elastic.co/c/security">discussion forums</a>, or even our <a href="https://github.com/elastic/detection-rules">open detections repository</a>.</p>
<p>You can always experience the latest version of <a href="https://www.elastic.co/kr/elasticsearch/service">Elasticsearch Service</a> on Elastic Cloud and follow along with this blog to set up the ProblemChild framework in your environment for your Windows process event data. And take advantage of our <a href="https://www.elastic.co/kr/training/elastic-security-quick-start">Quick Start training</a> to set yourself up for success. Start your <a href="https://cloud.elastic.co/registration">free trial of Elastic Cloud</a> today to get access to the platform. Happy experimenting!</p>
]]></content:encoded>
            <category>security-labs</category>
            <enclosure url="https://www.elastic.co/kr/security-labs/assets/images/detect-domain-generation-algorithm-activity-with-new-kibana-integration/library-branding-elastic-stack-midnight-1680x980-no-logo.jpg" length="0" type="image/jpg"/>
        </item>
        <item>
            <title><![CDATA[Automating the Security Protections rapid response to malware]]></title>
            <link>https://www.elastic.co/kr/security-labs/automating-security-protections-rapid-response-to-malware</link>
            <guid>automating-security-protections-rapid-response-to-malware</guid>
            <pubDate>Wed, 01 Mar 2023 00:00:00 GMT</pubDate>
            <description><![CDATA[See how we’ve been improving the processes that allow us to make updates quickly in response to new information and propagate those protections to our users, with the help of machine learning models.]]></description>
            <content:encoded><![CDATA[<p>Cyber attacks on corporate networks were <a href="https://www.forbes.com/sites/chuckbrooks/2022/01/21/cybersecurity-in-2022--a-fresh-look-at-some-very-alarming-stats/?sh=675676ea6b61">&lt;u&gt;up 50% in 2021&lt;/u&gt;</a>, and it’s <a href="https://www.govtech.com/blogs/lohrmann-on-cybersecurity/the-top-22-security-predictions-for-2022">&lt;u&gt;expected that 2022 will see more of the same&lt;/u&gt;</a>. <a href="https://www.elastic.co/kr/endpoint-security/">&lt;u&gt;Elastic Endpoint Security&lt;/u&gt;</a> includes a variety of protection layers to ensure maximum coverage against different types of malware. There have been a few examples recently of the need for <a href="https://www.elastic.co/kr/blog/elastic-protects-against-data-wiper-malware-targeting-ukraine-hermeticwiper">&lt;u&gt;fast, accurate updates&lt;/u&gt;</a> of user environments in order to protect against the latest malware. Here at Elastic, we’ve been improving the processes that allow us to make updates quickly in response to new information and propagate those protections to our users.</p>
<p>As part of our security solution, we use a machine learning model to help us detect malware based on known characteristics. Since machine learning is never perfect, we deploy supplemental artifacts, including lists of known file hashes that range from malicious to benign. There are two scenarios when we might need to update these lists, which we’ll cover here. Using these, teams can experience a much faster response to malware.</p>
<p>[Related article: <a href="https://www.elastic.co/kr/blog/sandboxing-anti-malware-products-for-fun-and-profit">&lt;u&gt;Sandboxing anti-malware products for fun and profit&lt;/u&gt;</a>]</p>
<h2>Scenario 1: The model isn’t perfect</h2>
<p>This happens pretty rarely, since our model has True Negative rates of 99.8%. But no model is perfect, and our True Positive rates vary from 99% (which is great) down to 97.9%, due to noisy data — particularly large bursts of near-duplicates. In applying machine learning to cybersecurity, data drift is an ever-present challenge and part of what makes it such an interesting problem.</p>
<p>There are a couple of ways we can find out if our model is doing the wrong thing:</p>
<ol>
<li><strong>User feedback.</strong></li>
</ol>
<p>A user sends us an email telling us that a piece of custom software is being flagged as malware, but is actually safe.</p>
<ol start="2">
<li><strong>Telemetry data coming back from our model running on customers’ machines.</strong></li>
</ol>
<p>We look at the volume and velocity of alerts, using Elastic’s Anomaly Detection feature to let us know if there is a sudden spike from a particular file. We also use patterns to help us confirm if an alert is coming from a single noisy machine, a test cluster, or a legitimate threat.</p>
<p>The advantage of using lists as a backstop to machine learning is that it’s a fast and easy way to make sure our customers are protected from new malware, as well as protecting them from unnecessary noise from false positives.</p>
<h2>Scenario 2: New forms of malware appear</h2>
<p>We typically find out about new kinds of malware from either security news/community resources, or our own Security Intelligence and Analytics team identifying new kinds of malware.</p>
<p>When this happens, we can easily deploy small changes to lists. We update the model separately, because that takes longer.</p>
<p>We’ve been steadily adding more automation to make this process of deploying updated lists to customers smoother and faster, with the goal of making it easy for anyone on the team to create and deploy an update. We’ve also been working on making the process of updating the model easier and faster.</p>
<h2>Threats yet discovered…</h2>
<p>The Elastic Security Intelligence and Analytics team continues to research and respond to groundbreaking threats in its mission to help Elastic customers and the broader security community. If you’re using <a href="https://www.elastic.co/kr/security?utm_source=log4j+hub+blog&amp;utm_medium=embed+link&amp;utm_campaign=log4j_hub_blog&amp;utm_id=log4j&amp;utm_content=elastic+security">&lt;u&gt;Elastic Security&lt;/u&gt;</a> already, you can expect to see our latest findings in the newsfeed within the platform. We’ll also post our latest findings on <a href="https://www.elastic.co/kr/blog">&lt;u&gt;elastic.co/blog&lt;/u&gt;</a>.</p>
<p>Ready to become part of the Elastic Security community and take advantage of the team’s leading threat research? Get started with a free <a href="https://cloud.elastic.co/registration?utm_source=log4j+hub+blog&amp;utm_medium=embed+link&amp;utm_campaign=log4j_hub_blog&amp;utm_id=log4j&amp;utm_content=trail">&lt;u&gt;14-day trial of Elastic Cloud&lt;/u&gt;</a> or <a href="https://www.elastic.co/kr/downloads/?utm_source=log4j+hub+blog&amp;utm_medium=embed+link&amp;utm_campaign=log4j_hub_blog&amp;utm_id=log4j&amp;utm_content=download">&lt;u&gt;download&lt;/u&gt;</a> the self-managed version of the Elastic Stack for free.</p>
]]></content:encoded>
            <category>security-labs</category>
            <enclosure url="https://www.elastic.co/kr/security-labs/assets/images/automating-security-protections-rapid-response-to-malware/blog-security-endpoint-720x420.png" length="0" type="image/png"/>
        </item>
        <item>
            <title><![CDATA[Detecting Living-off-the-land attacks with new Elastic Integration]]></title>
            <link>https://www.elastic.co/kr/security-labs/detecting-living-off-the-land-attacks-with-new-elastic-integration</link>
            <guid>detecting-living-off-the-land-attacks-with-new-elastic-integration</guid>
            <pubDate>Wed, 01 Mar 2023 00:00:00 GMT</pubDate>
            <description><![CDATA[We added a Living off the land (LotL) detection package to the Integrations app in Kibana. In a single click, you can install and start using the ProblemChild model and associated assets including anomaly detection configurations and detection rules.]]></description>
            <content:encoded><![CDATA[<p>It is becoming more common that adversary attacks consist of more than a standalone executable or script. Advanced attacker techniques, like “living off the land” (LotL) that appear normal in isolation become more suspicious when observed in a parent-child context. If you are running Windows in your environment, it is important to have a system for detecting these types of attacks. Traditional heuristic-based detections, though effective in detecting a single event, often fail to generalize across a multi-step attack. At Elastic we have trained a Living off the Land classifier, anomaly detection jobs and security detection rules to help our security professionals discover LotL attacks.</p>
<p>With the advent of <a href="https://www.elastic.co/kr/integrations/">Integration packages</a> in the Elastic stack we can now deliver the full, customizable package that includes the LotL classification model, anomaly detection job configurations, detection rules, and inference pipelines to make it easier to install and get up and running the entire end-to-end data pipeline from collecting windows events to alerting on potential Lotl attacks. We will walk you through how we set it up so you can try it yourself.</p>
<h1>ProblemChild: Recap</h1>
<p>In an earlier blog post, we talked about how to use<a href="https://www.elastic.co/kr/blog/problemchild-generate-alerts-to-detect-living-off-the-land-attacks">the detection rules repository command line interface (CLI), to set up the ProblemChild framework and get it up and running in your environment</a>. We have now added a <a href="https://docs.elastic.co/integrations/problemchild">Living off the land (LotL) detection package</a> to the Integrations app in Kibana. In a single click, you can install and start using the ProblemChild model and associated assets including anomaly detection configurations and detection rules.</p>
<p>As outlined in the <a href="https://www.elastic.co/kr/blog/problemchild-generate-alerts-to-detect-living-off-the-land-attacks">previous blog</a>, ProblemChild is a framework built using the Elastic Stack to detect LotL activity. LotL attacks are generally tricky to detect, given that attackers leverage seemingly benign software already present in the target environment to fly under the radar. The lineage of processes spawned in your environment can provide a strong signal in the event of an ongoing attack.</p>
<p>The supervised machine learning (ML) component of ProblemChild leverages process lineage information present in your Windows process event metadata to classify events as malicious or benign using <a href="https://www.elastic.co/kr/guide/en/machine-learning/current/ml-dfa-classification.html#ml-inference-class">Inference</a> at the time of ingest. Anomaly detection is then applied to detect rare processes among those detected as malicious by the supervised model. Finally, detection rules alert on rare parent-child process activity as an indication of LotL attacks.</p>
<p>The sheer volume and variety of events seen in organizations poses a challenge for detecting LotL attacks using rules and heuristics, making an ML-based framework such as ProblemChild a great solution.</p>
<h2>Getting Started</h2>
<p>We have released the model and the associated assets - including the pipelines, anomaly detection configurations, and detection rules - to the Integrations app in Kibana as of 8.0. We will be maintaining this format moving forward.</p>
<p>If you don’t have an Elastic Cloud cluster but would like to start experimenting with the released ProblemChild package, you can start a <a href="https://cloud.elastic.co/registration">free 14-day trial</a> of Elastic Cloud.</p>
<p>We will now look at the steps to get ProblemChild up and running in your environment in a matter of minutes using the released Living off the land (LotL) detection package.</p>
<h3>Step 1: Installing the package assets</h3>
<p>In Kibana, the Integrations app now includes the LotL Attack Detection package. To install the assets, click the <code>Install LotL Attack Detection assets</code> button under the <code>Settings</code> tab.</p>
<p>This will install all of the artifacts necessary to use the ProblemChild model to generate alerts when LotL activity is detected in your environment.</p>
<p><img src="https://www.elastic.co/kr/security-labs/assets/images/detecting-living-off-the-land-attacks-with-new-elastic-integration/blog-elastic-living-off-the-land-attack-1.png" alt="To install the assets, click the Install LotL Attack Detection assets button under the Settings tab." /></p>
<p><img src="https://www.elastic.co/kr/security-labs/assets/images/detecting-living-off-the-land-attacks-with-new-elastic-integration/blog-elastic-detecting-lotl-attacks-2.png" alt="To install the assets, click the Install LotL Attack Detection assets button under the Settings tab." /></p>
<p>Once installation is complete, you can navigate to <strong>Stack Management &gt; Ingest Pipelines</strong> and see that the <strong><code>&lt;version-number&gt;-problem\_child\_ingest\_pipeline</code></strong> has been installed and can now be used to enrich incoming ingest data. The ingest pipeline leverages the <strong><code>&lt;version-number&gt;-problem\_child\_inference\_pipeline</code></strong> in order to do this.</p>
<p><img src="https://www.elastic.co/kr/security-labs/assets/images/detecting-living-off-the-land-attacks-with-new-elastic-integration/blog-elastic-detecting-lotl-attacks-3.png" alt="Once installation is complete, you can navigate to Stack Management &gt; Ingest Pipelines and see that the &lt;version-number&gt;-problem_child_ingest_pipeline has been installed and can now be used to enrich incoming ingest data." /></p>
<p>Similarly, the installed ProblemChild model can now be seen in <strong>Machine Learning &gt; Model Management &gt; Trained Models</strong></p>
<p><img src="https://www.elastic.co/kr/security-labs/assets/images/detecting-living-off-the-land-attacks-with-new-elastic-integration/blog-elastic-detecting-lotl-attacks-4.jpg" alt="Similarly, the installed ProblemChild model can now be seen in Machine Learning &gt; Model Management &gt; Trained Models" /></p>
<h3>Step 2: Enriching your data</h3>
<p>Now you are ready to ingest your data using the ingest pipeline. This will enrich your incoming data with predictions from the machine learning model.</p>
<p>This pipeline is designed to work with Windows process event data such as <a href="https://www.elastic.co/kr/downloads/beats/winlogbeat">Winlogbeat data</a>. You can add the installed ingest pipeline to an Elastic beat by adding a simple <a href="https://www.elastic.co/kr/guide/en/elasticsearch/reference/current/ingest.html#pipelines-for-beats">configuration setting</a>.</p>
<p>If you already have an ingest pipeline associated with your indices, you can use a <a href="https://www.elastic.co/kr/guide/en/elasticsearch/reference/current/pipeline-processor.html">pipeline processor</a> to integrate the ProblemChild ingest pipeline into your existing pipeline.</p>
<p>You will also want to add the following mappings to the Elastic beat you chose:</p>
<pre><code>{
  &quot;properties&quot;: {
    &quot;problemchild&quot;: {
      &quot;properties&quot;: {
        &quot;prediction&quot;: {
          &quot;type&quot;: &quot;long&quot;
        },
        &quot;prediction_probability&quot;: {
          &quot;type&quot;: &quot;float&quot;
        }
      }
    },
    &quot;blocklist_label&quot;: {
      &quot;type&quot;: &quot;long&quot;
    }
  }
}

</code></pre>
<p>You can do this under <strong>Stack Management &gt; Index Management &gt; Component Templates.</strong> Templates that can be edited to add custom components will be marked with a <em>@custom</em> suffix. Edit the <em>@custom</em> component template for your Elastic beat by pasting the above JSON blob in the <strong>Load JSON</strong> flyout.</p>
<p><img src="https://www.elastic.co/kr/security-labs/assets/images/detecting-living-off-the-land-attacks-with-new-elastic-integration/Screen_Shot_2022-07-29_at_8.13.52_AM.jpeg" alt="" /></p>
<p><img src="https://www.elastic.co/kr/security-labs/assets/images/detecting-living-off-the-land-attacks-with-new-elastic-integration/Screen_Shot_2022-07-29_at_8.14.10_AM.jpeg" alt="" /></p>
<p>You should now see that the model enriches incoming Windows process events with the following fields:</p>
<p><strong>problemchild.prediction</strong></p>
<ul>
<li>A value of 1 indicates that the event is predicted to be malicious and a value of “0” indicates that the event is predicted to be benign.</li>
</ul>
<p><strong>prediction_probability</strong></p>
<ul>
<li>A value between 0 and 1 indicating the confidence of the model in its prediction. The higher the value, the higher the confidence.</li>
</ul>
<p><strong>blocklist_label</strong></p>
<ul>
<li>A value of 1 indicates that the event is malicious because one or more terms in the command line arguments matched a blocklist.</li>
</ul>
<p>If you want an immediate way to test that the ingest pipeline is working as expected with your data, you can use a few sample documents with the <a href="https://www.elastic.co/kr/guide/en/elasticsearch/reference/current/simulate-pipeline-api.html">simulate pipeline API</a> and confirm you see the <strong>problemchild</strong> fields.</p>
<h3>Step 3: Running anomaly detection</h3>
<p>The package includes several preconfigured anomaly detection jobs. These jobs enable you to find the rarest events among those detected as malicious by the supervised model in order to decide which events require immediate attention from your analysts.</p>
<p>To run these jobs on your enriched data, go to <strong>Machine Learning &gt; Anomaly Detection</strong>. When you create a job using the job wizard, you should see an option to Use preconfigured jobs with a card for LotL Attacks. After selecting the card, you will see several preconfigured anomaly detection jobs that can be run. Note these jobs are only useful for indices that have been enriched by the ingest pipeline.</p>
<h3>Step 4: Enabling the rules</h3>
<p>To maximize the benefit of the ProblemChild framework, activate the installed detection rules. They are triggered when certain conditions for the supervised model or anomaly detection jobs are satisfied. The complete list of the installed rules can be found in the <strong>Overview</strong> page of the package itself or in the latest experimental detections <a href="https://github.com/elastic/detection-rules/releases/tag/ML-experimental-detections-20211130-7">release</a>.</p>
<p>In order to enable and use the installed rules, you can navigate to <strong>Security &gt; Rules</strong> and select <code>_Load Elastic prebuild rules and timeline templates</code>_.</p>
<p><img src="https://www.elastic.co/kr/security-labs/assets/images/detecting-living-off-the-land-attacks-with-new-elastic-integration/blog-elastic-detecting-lotl-attacks-5.png" alt="In order to enable and use the installed rules, you can navigate to Security &gt; Rules and select Load Elastic prebuild rules and timeline templates." /></p>
<p>Note that there are search rules as well as ML job rules. The search rules are triggered by the supervised model, for example this rule:</p>
<p><img src="https://www.elastic.co/kr/security-labs/assets/images/detecting-living-off-the-land-attacks-with-new-elastic-integration/blog-elastic-detecting-lotl-attacks-6.jpg" alt="The above rule matches on any Windows process event for which the supervised model or its blocklist has a prediction value of 1 (malicious)." /></p>
<p>The above rule matches on any Windows process event for which the supervised model or its blocklist has a prediction value of 1 (malicious).</p>
<p>The ML job rules are triggered by anomalies found by the anomaly detection jobs that you set up in Step 3 — for example, this rule:</p>
<p><img src="https://www.elastic.co/kr/security-labs/assets/images/detecting-living-off-the-land-attacks-with-new-elastic-integration/blog-elastic-detecting-lotl-attacks-6.jpg" alt="The above rule is triggered each time the anomaly detection job problem_child_rare_process_by_host detects an anomaly with an anomaly score greater than or equal to 75." /></p>
<p>The above rule is triggered each time the anomaly detection job problem_child_rare_process_by_host detects an anomaly with an anomaly score greater than or equal to 75.</p>
<h1>Summary</h1>
<p>As mentioned in the first blog post, the supervised ML component of ProblemChild is trained to predict a value of 1 (malicious) on processes or command line arguments that can be used for LotL attacks. This does not mean that everything that the supervised model predicts with a value 1 indicates LotL activity. The prediction value of 1 should be interpreted more as “this could be potentially malicious,” instead of “this is definitely LotL activity.”</p>
<p>The real beauty of ProblemChild is in the anomaly detection, wherein it surfaces rare parent-child process relationships from among the events the supervised model marked as suspicious. This not only helps in reducing the number of false positives, but also helps security analysts focus on a smaller, more targeted list for triage.</p>
<p>You could of course start with the search rules, which will alert directly on the results of the supervised model. If the number of alerts from these rules is manageable and you have the time and resources to drill into these alerts, you might not need to enable the anomaly detection jobs. However, if you then notice that these rules are producing too many alerts (which is usually the case in most large organizations), you may benefit from enabling the anomaly detection jobs and their corresponding rules.</p>
<h1>Get in touch with us</h1>
<p>We’d love for you to try out ProblemChild and give us feedback as we work on adding new capabilities to it. If you run into any issues during the process, please reach out to us on our <a href="https://ela.st/slack">community Slack channel</a>, <a href="https://discuss.elastic.co/c/security">discussion forums</a> or even our <a href="https://github.com/elastic/detection-rules">open detections repository</a>.</p>
<p>You can always experience the latest version of <a href="https://www.elastic.co/kr/elasticsearch/service">Elasticsearch Service</a> on Elastic Cloud and follow along with this blog to set up the ProblemChild framework in your environment for your Windows process event data. And take advantage of our <a href="https://www.elastic.co/kr/training/elastic-security-quick-start">Quick Start training</a> to set yourself up for success. Happy experimenting!</p>
]]></content:encoded>
            <category>security-labs</category>
            <enclosure url="https://www.elastic.co/kr/security-labs/assets/images/detecting-living-off-the-land-attacks-with-new-elastic-integration/security-threat-hunting-incidence-response-1200x628.jpg" length="0" type="image/jpg"/>
        </item>
        <item>
            <title><![CDATA[Identifying beaconing malware using Elastic]]></title>
            <link>https://www.elastic.co/kr/security-labs/identifying-beaconing-malware-using-elastic</link>
            <guid>identifying-beaconing-malware-using-elastic</guid>
            <pubDate>Wed, 01 Mar 2023 00:00:00 GMT</pubDate>
            <description><![CDATA[In this blog, we walk users through identifying beaconing malware in their environment using our beaconing identification framework.]]></description>
            <content:encoded><![CDATA[<p>The early stages of an intrusion usually include initial access, execution, persistence, and command-and-control (C2) beaconing. When structured threats use zero-days, these first two stages are often not detected. It can often be challenging and time-consuming to identify persistence mechanisms left by an advanced adversary as we saw in the <a href="https://www.elastic.co/kr/blog/elastic-security-provides-free-and-open-protections-for-sunburst">2020 SUNBURST supply chain compromise</a>. Could we then have detected SUNBURST in the initial hours or days by finding its C2 beacon?</p>
<p>The potential for beaconing detection is that it can serve as an early warning system and help discover novel persistence mechanisms in the initial hours or days after execution. This allows defenders to disrupt or evict the threat actor before they can achieve their objectives. So, while we are not quite &quot;left of boom&quot; by detecting C2 beaconing, we can make a big difference in the outcome of the attack by reducing its overall impact.</p>
<p>In this blog, we talk about a beaconing identification framework that we built using Painless and aggregations in the Elastic Stack. The framework can not only help threat hunters and analysts monitor network traffic for beaconing activity, but also provides useful indicators of compromise (IoCs) for them to start an investigation with. If you don’t have an Elastic Cloud cluster but would like to try out our beaconing identification framework, you can start a <a href="https://cloud.elastic.co/registration">free 14-day trial</a> of Elastic Cloud.</p>
<h2><strong>Beaconing — A primer</strong></h2>
<p>An enterprise's defense is only as good as its firewalls, antivirus, endpoint detection and intrusion detection capabilities, and SOC (Security Operations Center) — which consists of analysts, engineers, operators administrators, etc. who work round the clock to keep the organization secure. Malware however, enters enterprises in many different ways and uses a variety of techniques to go undetected. An increasingly common method being used by adversaries nowadays to evade detection is to use C2 beaconing as a part of their attack chain, given that it allows them to blend into networks like a normal user.</p>
<p>In networking, beaconing is a term used to describe a continuous cadence of communication between two systems. In the context of malware, beaconing is when malware periodically calls out to the attacker's C2 server to get further instructions on tasks to perform on the victim machine. The frequency at which the malware checks in and the methods used for the communications are configured by the attacker. Some of the common protocols used for C2 are HTTP/S, DNS, SSH, and SMTP, as well as common cloud services like Google, Twitter, Dropbox, etc. Using common protocols and services for C2 allows adversaries to masquerade as normal network traffic and hence evade firewalls.</p>
<p>While on the surface beaconing can appear similar to normal network traffic, it has some unique traits with respect to timing and packet size, which can be modeled using standard statistical and signal processing techniques.</p>
<p>Below is an example of a Koadic C2 beacon, which serves the malicious payload using the DLL host process. As you can see, the payload beacons consistently at an interval of 10 minutes, and the source, as well as destination packet sizes, are almost identical.</p>
<p><img src="https://www.elastic.co/kr/security-labs/assets/images/identifying-beaconing-malware-using-elastic/1-koadic-beacon.png" alt="Example of a Koadic C2 beacon" /></p>
<p>It might seem like a trivial task to catch C2 beaconing if all beacons were as neatly structured and predictable as the above. All one would have to look for is periodicity and consistency in packet sizes. However, malware these days is not as straightforward.</p>
<p><img src="https://www.elastic.co/kr/security-labs/assets/images/identifying-beaconing-malware-using-elastic/2-emotet-beacon.jpg" alt="Example of an Emotet beacon" /></p>
<p>Most sophisticated malware nowadays adds a &quot;jitter&quot; or randomness to the beacon interval, making the signal more difficult to detect. Some malware authors also use longer beacon intervals. The beaconing identification framework we propose accounts for some of these elusive modifications to traditional beaconing behavior.</p>
<h2><strong>Our approach</strong></h2>
<p>We’ve discussed a bit about the why and what — in this section we dig deeper into how we identify beaconing traffic. Before we begin, it is important to note that beaconing is merely a communication characteristic. It is neither good nor evil by definition. While it is true that malware heavily relies on beaconing nowadays, a lot of legitimate software also exhibits beaconing behaviour.</p>
<p>While we have made efforts to reduce false positives, this framework should be looked at as a means for beaconing identification to help reduce the search space for a threat hunt, not as a means for detection. That said, indicators produced by this framework, when combined with other IoCs, can potentially be used to detect on malicious activity.</p>
<p>The beacons we are interested in comprise traffic from a single running process on a particular host machine to one or more external IPs. Given that the malware can have both short (order of seconds) and long (order of hours or days) check-in intervals, we will restrict our attention to a time window that works reasonably for both and attempt to answer the question: “What is beaconing in my environment right now or recently?” We have also parameterized the inputs to the framework to allow users to configure important settings like time window, etc. More on this in upcoming sections.</p>
<p>When dealing with large data sets, such as network data for an enterprise, you need to think carefully about what you can measure, which allows you to scale effectively. Scaling has several facets, but for our purposes, we have the following requirements:</p>
<ol>
<li>Work can be parallelised over different shards of data stored on different machines</li>
<li>The amount of data that needs to move around to compute what is needed must be kept manageable.</li>
</ol>
<p>Multiple approaches have been suggested for detecting beaconing characteristics, but not all of them satisfy these constraints. For example, a popular choice for detecting beacon timing characteristics is to measure the interval between events. This proves to be too inefficient to use on large datasets because the events can't be processed across multiple shards.</p>
<p>Driven by the need to scale, we chose to detect beaconing by bucketing the data in the time window to be analyzed. We gather the event count and average bytes sent and received in each bucket. These statistics can be computed in MapReduce fashion and values from different shards can be combined at the coordinating node of an Elasticsearch query.</p>
<p>Furthermore, by controlling the ratio between the bucket and window lengths, the data we pass per running process has predictable memory consumption, which is important for system stability. The whole process is illustrated diagrammatically below:</p>
<p><img src="https://www.elastic.co/kr/security-labs/assets/images/identifying-beaconing-malware-using-elastic/3-bucketing-data.jpg" alt="Bucketing data for analysis" /></p>
<p>A key attribute of beaconing traffic is it often has similar netflow bytes for the majority of its communication. If we average the bytes over all the events that fall in a single bucket, the average for different buckets will in fact be even more similar. This is just the law of large numbers in action. A good way to measure similarity of several positive numbers (in our case these are average bucket netflow bytes) is using a statistic called the <a href="https://en.wikipedia.org/wiki/Coefficient_of_variation">coefficient of variation</a> (COV). This captures the average relative difference between the values and their mean. Because this is a relative value, a COV closer to 0 implies that values are tightly clustered around their mean.</p>
<p>We also found that occasional spikes in the netflow bytes in some beacons were inflating the COV statistic. In order to rectify this, we simply discarded low and high percentile values when computing the COV, which is a standard technique for creating a robust statistic. We threshold the value of this statistic to be significantly less than one to detect this characteristic of beacons.</p>
<p>For periodicity, we observed that signals displayed one of two characteristics when we viewed the bucket counts. If the period was less than the time bucket length (i.e. high frequency beacons), then the count showed little variation from bucket to bucket. If the period was longer than the time bucket length (i.e. low frequency beacons), then the signal had high autocorrelation. Let's discuss these in detail.</p>
<p>To test for high frequency beacons, we use a statistic called <a href="https://en.wikipedia.org/wiki/Index_of_dispersion">relative variance</a> (RV). The rate of many naturally occurring phenomena are well described by a <a href="https://en.wikipedia.org/wiki/Poisson_distribution#Occurrence_and_applications">Poisson distribution</a>. The reason for this is that if events arrive randomly at a constant average rate and the occurrence of one event doesn’t affect the chance of others occurring, then their count in a fixed time interval must be Poisson distributed.</p>
<p>Just to underline this point, it doesn’t matter the underlying mechanisms for that random delay between events (making a coffee, waiting for your software to build, etc.)— if those properties hold, their rate distribution is always the same. Therefore, we expect that the bucket counts to be Poisson distributed for much of the traffic in our network, but not for beacons, which are much more regular. A feature of the Poisson distribution is that its variance is equal to its average, i.e. its RV is 1. Loosely, this means that if the RV of our bucket counts is closer to 0, the signal is more regular than a Poisson process.</p>
<p><a href="https://en.wikipedia.org/wiki/Autocorrelation">Autocorrelation</a> is a useful statistic for understanding when a time series repeats itself. The basic idea behind autocorrelation is to compare the time series values to themselves after shifting them in time. Specifically, it is the covariance between the two sets of values (which is larger when they are more similar), normalized by dividing it by the square root of the variances of the two sets, which measures how much the values vary among themselves.</p>
<p>This process is illustrated schematically below. We apply this to the time series comprising the bucket counts: if the signal is periodic then the time bucketed counts must also repeat themselves. The nice thing about autocorrelation from our perspective is that it is capable of detecting any periodic pattern. For example, the events don’t need to be regularly spaced but might repeat like two events occurring close to one another in time, followed by a long gap and so on.</p>
<p><img src="https://www.elastic.co/kr/security-labs/assets/images/identifying-beaconing-malware-using-elastic/4-diagramming-representation.jpg" alt="" /></p>
<p>We don’t know the shift beforehand that will maximize the similarity between the two sets of values, so we search over all shifts for the maximum. This, in effect, is the period of the data — the closer its autocorrelation is to one, the closer the time series is to being truly periodic. We threshold the autocorrelation close to one to test for low frequency beacons.</p>
<p>Finally, we noted that most beaconing malware these days incorporates jitter. How does autocorrelation deal with this? Well first off, autocorrelation isn’t a binary measure — it is a sliding scale: the closer the value is to 1 the more similar the two sets of values are to one another. Even if they are not identical but similar it can still be close to one. In fact, we can do better than this by modelling how random jitter affects autocorrelation and undoing its effect. Provided the jitter isn’t too large, the process to do this turns out to be about as complex as just finding the maximum autocorrelation.</p>
<p>In our implementation, we’ve made the percentage configurable, although one would always use a small-ish percentage to avoid flagging too much traffic as periodic. If you'd like to dig into the gory details of our implementation, all the artifacts are available as a GitHub <a href="https://github.com/elastic/detection-rules/releases/tag/ML-Beaconing-20211216-1">release</a> in our detection rules repository.</p>
<h2><strong>How do we do this using Elasticsearch?</strong></h2>
<p>Elasticsearch has some very powerful tools for ad hoc data analysis. The <a href="https://www.elastic.co/kr/guide/en/elasticsearch/reference/current/search-aggregations-metrics-scripted-metric-aggregation.html">scripted metric aggregation</a> is one of them. The nice thing about this aggregation is that it allows you to write custom Painless scripts to derive different metrics about your data. We used the aggregation to script out the beaconing tests.</p>
<p>In a typical environment, the cardinality of the distinct processes running across endpoints is rather high. Trying to run an aggregation that partitions by every running process is therefore not feasible. This is where another feature of the Elastic Stack comes in handy. A <a href="https://www.elastic.co/kr/guide/en/elasticsearch/reference/current/transforms.html">transform</a> is a complex aggregation which paginates through all your data and writes results to a destination index.</p>
<p>There are various basic operations available in transforms, one of them being partitioning data at scale. In our case, we partitioned our network event logs by host and process name and ran our scripted metric aggregation against each host-process name pair. The transform also writes out various beaconing related indicators and statistics. A sample document from the resulting destination index is as follows:</p>
<p><img src="https://www.elastic.co/kr/security-labs/assets/images/identifying-beaconing-malware-using-elastic/5-sample-beaconing.jpg" alt="Sample document produced by the beaconing transform" /></p>
<p>As you can see, the document contains valuable beaconing-related information about the process. First off, the beacon_stats.is_beaconing indicator says whether or not we found the process to be beaconing. If it is, as in the case above, the document will also contain important metadata, such as the frequency of the beacon. The indicator beacon_stats.periodic says whether or not the signal is a low-frequency beacon, while the indicator beacon_stats.low_count_variation indicates whether or not it is a high-frequency beacon.</p>
<p>Furthermore, the indicators beacon_stats.low_source_bytes_variation and low_destination_bytes_variation indicate whether or not the source and destination bytes sent during the beaconing communication were more or less uniform. Finally, you will also notice the beaconing_score indicator, which is a value from 1-3, representing the number of beaconing tests satisfied by the process for that time period.</p>
<p>Writing such metadata out to an index also means that you can search for different facets of beaconing software in your environment. For example, if you want to search for low frequency beaconing processes in your environment, you would query for documents where the beacon_stats.periodic indicator is true and beacon_stats.low_count_variation is false. You can also build second order analytics on top of the indexed data, such as using <a href="https://www.elastic.co/kr/guide/en/kibana/current/xpack-ml-anomalies.html">anomaly detection</a> to find rare beaconing processes, or using a <a href="https://www.elastic.co/kr/guide/en/elasticsearch/reference/current/search-aggregations-bucket-significantterms-aggregation.html">significant terms aggregation</a> to detect lateral movement of beaconing malware in your environment.</p>
<p>Finally, we’ve included several dashboards for your threat hunters and analysts to use for monitoring beaconing activity in your environment. These can be found in the <a href="https://github.com/elastic/detection-rules/releases/tag/ML-Beaconing-20211216-1">release package</a> as well.</p>
<h2><strong>Tuning parameters and filtering</strong></h2>
<p>Advanced users can also tune important parameters to the scripted metric aggregation in the transforms, like jitter percentage, time window, etc. If you'd like to change the default parameters, all you would need to do is delete the transform, change the parameters, and restart it. The parameters you can tune are as follows:</p>
<ul>
<li>number_buckets_in_range: The number of time buckets we split the time window into. You need enough to ensure you get reasonable estimates for the various statistics, but too many means the transform will use more memory and compute.</li>
<li>time_bucket_length: The length of each time bucket. This controls the time window, so the larger this value the longer the time window. You might set this longer if you want to check for very low frequency beacons.</li>
<li>number_destination_ips: The number of destination IPs to gather in the results. Setting this higher increases the transform resource usage.</li>
<li>max_beaconing_bytes_cov: The maximum coefficient of variation in the payload bytes for the low source and destination bytes variance test. Setting this higher will increase the chance of detecting traffic as beaconing, so would likely increase <a href="https://en.wikipedia.org/wiki/Precision_and_recall">recall</a> for malicious C2 beacons. However, it will also reduce the <a href="https://en.wikipedia.org/wiki/Precision_and_recall">precision</a> of the test.</li>
<li>max_beaconing_count_rv: The maximum relative variance in the bucket counts for the high frequency beacon test. As with max_beaconing_bytes_cov, we suggest tuning this parameter based on the kind of tradeoff you want between precision and recall.</li>
<li>truncate_at: The lower and upper fraction of bucket values discarded when computing max_beaconing_bytes_cov and max_beaconing_count_rv. This allows you to ignore occasional changes in traffic patterns. However, if you retain too small a fraction of the data, these tests will be unreliable.</li>
<li>min_beaconing_count_autocovariance: The minimum autocorrelation of the signal for the low frequency beacon test. Lowering this value will likely result in an increase in recall for malicious C2 beacons, at the cost of reduced test precision. As with some of the other parameters mentioned above, we suggest tuning this parameter based on the kind of tradeoff you want between precision and recall.</li>
<li>max_jitter: The maximum amount by which we assume that a periodic beacon is jittered, as a fraction of its period.</li>
</ul>
<p>You can also make changes to the transform query. We currently look for beaconing activity over a 6h time range, but you can change this to a different time range. As mentioned previously, beaconing is not a characteristic specific to malware and a lot of legitimate, benign processes also exhibit beaconing-like activity.</p>
<p>In order to curb the false positive rate, we have included a starter list of filters in the transform query to exclude known benign beaconing processes that we observed during testing, and a list of IPs that fall into two categories:</p>
<ol>
<li>The source IP is local and the destination is remote</li>
<li>For certain Microsoft processes, the destination IP is in a Microsoft block</li>
</ol>
<p>You can add to this list based on what you see in your environment.</p>
<h2><strong>Evaluation</strong></h2>
<p>In order to measure the effectiveness of our framework as a reduced search space for beaconing activity, we wanted to test two aspects:</p>
<ol>
<li>Does the framework flag actual malicious beaconing activity?</li>
<li>By how much does the framework reduce the search space for malicious beacons?</li>
</ol>
<p>In order to test the performance on malware beacons, we ran the transform on some synthetic data as well as some real malware! We set up test ranges for Emotet and Koadic, and also tested it on NOBELIUM logs we had from several months ago. The results from the real malware tests are worth mentioning here.</p>
<p><img src="https://www.elastic.co/kr/security-labs/assets/images/identifying-beaconing-malware-using-elastic/6-beaconing-metadata.jpg" alt="Beaconing metadata for NOBELIUM" /></p>
<p>For NOBELIUM, the beaconing transform catches the offending process, rundll32.exe, as well as the two destination IPs, 192.99.221.77 and 83.171.237.173, which were among the main IoCs for NOBELIUM.</p>
<p>For Koadic and Emotet as well, the transform was able to flag the process as well as the known destination IPs on which the test C2 listeners were running. The characteristics of each of the beacons were different. For example, Koadic was a straightforward, high-frequency beacon that satisfied all the beaconing criteria being checked in the transform i.e. periodicity, as well as low variation of source and destination bytes. Emotet was slightly trickier since it was a low frequency beacon with a high jitter percentage. But we were able to detect it due to the low variation in the source bytes of the beacon.</p>
<p>To test the amount of reduction in search space, we ran the transform over three weeks on an internal cluster that was receiving network event logs from ~ 2k hosts during the testing period. We measured the reduction in search space based on the number of network event log messages, processes, and hosts an analyst or threat hunter would have to sift through before and after running the transform, in order to identify malicious beacons. The numbers are as follows:</p>
<p><img src="https://www.elastic.co/kr/security-labs/assets/images/identifying-beaconing-malware-using-elastic/7-search-space-reduction.jpg" alt="Search space reduction metrics as a result of the beaconing transform" /></p>
<p>While the reduction in search space is obvious, another point to note is the scale of data that the transforms are able to churn through comfortably, which becomes an important aspect to consider, especially in production environments. Additionally, we have also released dashboards (available in the <a href="https://github.com/elastic/detection-rules/releases/tag/ML-Beaconing-20211216-1">release package</a>), which track metrics like prevalence of the beaconing processes, etc. that can help make informed decisions about further filtering of the search space.</p>
<p>While the released dashboards, and the statistics in the above table are based on cases where the beacon_stats.is_beaconing indicator is true i.e. beacons that satisfy either of the beaconing tests, threat hunters may want to further streamline their search by starting with the most obvious beaconing-like cases and then moving on to the less obvious ones. This can be done by filtering and searching by the beacon_stats.beaconing_score indicator instead of beacon_stats.is_beaconing, where a score of 3 indicates a typical beacon (satisfying tests for periodicity as well as low variation in packet bytes), and score of 1 indicates a less obvious beacon (satisfying only one of the three tests).</p>
<p>For reference, we observed the following on our internal cluster:</p>
<p><img src="https://www.elastic.co/kr/security-labs/assets/images/identifying-beaconing-malware-using-elastic/Screen_Shot_2022-01-06_at_4.36.40_PM.jpg" alt="Streamlining your threat hunt using the Beaconing Score indicator" /></p>
<h2>What's next</h2>
<p>We’d love for you to try out our beaconing identification framework and give us feedback as we work on improving it. If you run into any issues during the process, please reach out to us on our <a href="https://ela.st/slack">community Slack channel</a>, <a href="https://discuss.elastic.co/c/security">discussion forums</a>, or even our <a href="https://github.com/elastic/detection-rules">open detections repository</a>. Stay tuned for Part 2 of this blog, where we’ll cover going from identifying beaconing activity to actually detecting on malicious beacons!</p>
<p>Try out our beaconing identification framework with a <a href="https://cloud.elastic.co/registration">free 14-day trial</a> of Elastic Cloud.</p>
]]></content:encoded>
            <category>security-labs</category>
            <enclosure url="https://www.elastic.co/kr/security-labs/assets/images/identifying-beaconing-malware-using-elastic/blog-thumbnail-securitymaze.jpg" length="0" type="image/jpg"/>
        </item>
        <item>
            <title><![CDATA[Getting the Most Out of Transformers in Elastic]]></title>
            <link>https://www.elastic.co/kr/security-labs/getting-the-most-out-of-transforms-in-elastic</link>
            <guid>getting-the-most-out-of-transforms-in-elastic</guid>
            <pubDate>Tue, 23 Aug 2022 00:00:00 GMT</pubDate>
            <description><![CDATA[In this blog, we will briefly talk about how we fine-tuned a transformer model meant for a masked language modeling (MLM) task, to make it suitable for a classification task.]]></description>
            <content:encoded><![CDATA[<h2>Preamble</h2>
<p>In 8.3, our Elastic Stack Machine Learning team introduced a way to import <a href="https://www.elastic.co/kr/guide/en/machine-learning/master/ml-nlp-model-ref.html">third party Natural Language Processing (NLP) models</a> into Elastic. As security researchers, we HAD to try it out on a security dataset. So we decided to build a model to identify malicious command lines by fine-tuning a pre-existing model available on the <a href="https://huggingface.co/models">Hugging Face model hub</a>.</p>
<p>Upon finding that the fine-tuned model was performing (surprisingly!) well, we wanted to see if it could replace or be combined with our previous <a href="https://www.elastic.co/kr/blog/problemchild-detecting-living-off-the-land-attacks">tree-based model</a> for detecting Living off the Land (LotL) attacks. But first, we had to make sure that the throughput and latency of this new model were reasonable enough for real-time inference. This resulted in a series of experiments, the results of which we will detail in this blog.</p>
<p>In this blog, we will briefly talk about how we fine-tuned a transformer model meant for a masked language modeling (MLM) task, to make it suitable for a classification task. We will also look at how to import custom models into Elastic. Finally, we’ll dive into all the experiments we did around using the fine-tuned model for real-time inference.</p>
<h2>NLP for command line classification</h2>
<p>Before you start building NLP models, it is important to understand whether an <a href="https://www.ibm.com/cloud/learn/natural-language-processing">NLP</a> model is even suitable for the task at hand. In our case, we wanted to classify command lines as being malicious or benign. Command lines are a set of commands provided by a user via the computer terminal. An example command line is as follows:</p>
<pre><code>**move test.txt C:\**
</code></pre>
<p>The above command moves the file <strong>test.txt</strong> to the root of the **C:** directory.</p>
<p>Arguments in command lines are related in the way that the co-occurrence of certain values can be indicative of malicious activity. NLP models are worth exploring here since these models are designed to understand and interpret relationships in natural (human) language, and since command lines often use some natural language.</p>
<h2>Fine-tuning a Hugging Face model</h2>
<p>Hugging Face is a data science platform that provides tools for machine learning (ML) enthusiasts to build, train, and deploy ML models using open source code and technologies. Its model hub has a wealth of models, trained for a variety of NLP tasks. You can either use these pre-trained models as-is to make predictions on your data, or fine-tune the models on datasets specific to your <a href="https://www.ibm.com/cloud/learn/natural-language-processing">NLP</a> tasks.</p>
<p>The first step in fine-tuning is to instantiate a model with the model configuration and pre-trained weights of a specific model. Random weights are assigned to any task-specific layers that might not be present in the base model. Once initialized, the model can be trained to learn the weights of the task-specific layers, thus fine-tuning it for your task. Hugging Face has a method called <a href="https://huggingface.co/docs/transformers/v4.21.1/en/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained</a> that allows you to instantiate a model from a pre-trained model configuration.</p>
<p>For our command line classification model, we created a <a href="https://huggingface.co/docs/transformers/model_doc/roberta">RoBERTa</a> model instance with encoder weights copied from the <a href="https://huggingface.co/roberta-base">roberta-base</a> model, and a randomly initialized sequence classification head on top of the encoder:</p>
<p><strong>model = RobertaForSequenceClassification.from_pretrained('roberta-base', num_labels=2)</strong></p>
<p>Hugging Face comes equipped with a <a href="https://huggingface.co/docs/transformers/v4.21.0/en/main_classes/tokenizer">Tokenizers</a> library consisting of some of today's most used tokenizers. For our model, we used the <a href="https://huggingface.co/docs/transformers/model_doc/roberta#transformers.RobertaTokenizer">RobertaTokenizer</a> which uses <a href="https://en.wikipedia.org/wiki/Byte_pair_encoding">Byte Pair Encoding</a> (BPE) to create tokens. This tokenization scheme is well-suited for data belonging to a different domain (command lines) from that of the tokenization corpus (English text). A code snippet of how we tokenized our dataset using <strong>RobertaTokenizer</strong> can be found <a href="https://gist.github.com/ajosh0504/4560af91adb48212402300677cb65d4a#file-tokenize-py">here</a>. We then used Hugging Face's <a href="https://huggingface.co/docs/transformers/v4.21.0/en/main_classes/trainer#transformers.Trainer">Trainer</a> API to train the model, a code snippet of which can be found <a href="https://gist.github.com/ajosh0504/4560af91adb48212402300677cb65d4a#file-train-py">here</a>.</p>
<p>ML models do not understand raw text. Before using text data as inputs to a model, it needs to be converted into numbers. Tokenizers group large pieces of text into smaller semantically useful units, such as (but not limited to) words, characters, or subwords — called token —, which can, in turn, be converted into numbers using different encoding techniques.</p>
<blockquote>
<ul>
<li>Check out <a href="https://youtu.be/_BZearw7f0w">this</a> video (2:57 onwards) to review additional pre-processing steps that might be needed after tokenization based on your dataset.</li>
<li>A complete tutorial on how to fine-tune pre-trained Hugging Face models can be found <a href="https://huggingface.co/docs/transformers/training">here</a>.</li>
</ul>
</blockquote>
<h2>Importing custom models into Elastic</h2>
<p>Once you have a trained model that you are happy with, it's time to import it into Elastic. This is done using <a href="https://www.elastic.co/kr/guide/en/elasticsearch/client/eland/current/machine-learning.html">Eland</a>, a Python client and toolkit for machine learning in Elasticsearch. A code snippet of how we imported our model into Elastic using Eland can be found <a href="https://gist.github.com/ajosh0504/4560af91adb48212402300677cb65d4a#file-import-py">here</a>.<br />
You can verify that the model has been imported successfully by navigating to <strong>Model Management \&gt; Trained Models</strong> via the Machine Learning UI in Kibana:</p>
<p><img src="https://www.elastic.co/kr/security-labs/assets/images/getting-the-most-out-of-transforms-in-elastic/Imported_model_in_the_Trained_Models_UI.png" alt="Imported model in the Trained Models UI" /></p>
<h2>Using the Transformer model for inference — a series of experiments</h2>
<p>We ran a series of experiments to evaluate whether or not our Transformer model could be used for real-time inference. For the experiments, we used a dataset consisting of ~66k command lines.</p>
<p>Our first inference run with our fine-tuned <strong>RoBERTa</strong> model took ~4 hours on the test dataset. At the outset, this is much slower than the tree-based model that we were trying to beat at ~3 minutes for the entire dataset. It was clear that we needed to improve the throughput and latency of the PyTorch model to make it suitable for real-time inference, so we performed several experiments:</p>
<h3>Using multiple nodes and threads</h3>
<p>The latency numbers above were observed when the models were running on a single thread on a single node. If you have multiple Machine Learning (ML) nodes associated with your Elastic deployment, you can run inference on multiple nodes, and also on multiple threads on each node. This can significantly improve the throughput and latency of your models.</p>
<p>You can change these parameters while starting the trained model deployment via the <a href="https://www.elastic.co/kr/guide/en/elasticsearch/reference/master/start-trained-model-deployment.html">API</a>:</p>
<pre><code>**POST \_ml/trained\_models/\\&lt;model\_id\\&gt;/deployment/\_start?number\_of\_allocations=2&amp;threa ds\_per\_allocation=4**
</code></pre>
<p><strong>number_of_allocations</strong> allows you to set the total number of allocations of a model across machine learning nodes and can be used to tune model throughput. <strong>threads_per_allocation</strong> allows you to set the number of threads used by each model allocation during inference and can be used to tune model latency. Refer to the <a href="https://www.elastic.co/kr/guide/en/elasticsearch/reference/master/start-trained-model-deployment.html">API documentation</a> for best practices around setting these parameters.</p>
<p>In our case, we set the <strong>number_of_allocations</strong> to <strong>2</strong> , as our cluster had two ML nodes and <strong>threads_per_allocation</strong> to <strong>4</strong> , as each node had four allocated processors.</p>
<p>Running inference using these settings <strong>resulted in a 2.7x speedup</strong> on the original inference time.</p>
<h3>Dynamic quantization</h3>
<p>Quantizing is one of the most effective ways of improving model compute cost, while also reducing model size. The idea here is to use a reduced precision integer representation for the weights and/or activations. While there are a number of ways to trade off model accuracy for increased throughput during model development, <a href="https://pytorch.org/tutorials/intermediate/dynamic_quantization_bert_tutorial.html">dynamic quantization</a> helps achieve a similar trade-off after the fact, thus saving on time and resources spent on iterating over the model training.</p>
<p>Eland provides a way to dynamically quantize your model before importing it into Elastic. To do this, simply pass in quantize=True as an argument while creating the TransformerModel object (refer to the code snippet for importing models) as follows:</p>
<pre><code>**# Load the custom model**
**tm = TransformerModel(&quot;model&quot;, &quot;text\_classification&quot;, quantize=True)**
</code></pre>
<p>In the case of our command line classification model, we observed the model size drop from 499 MB to 242 MB upon dynamic quantization. Running inference on our test dataset using this model <strong>resulted in a 1.6x speedup</strong> on the original inference time, for a slight drop in model <a href="https://en.wikipedia.org/wiki/Sensitivity_and_specificity"><strong>sensitivity</strong></a> (exact numbers in the following section) <strong>.</strong></p>
<h3>Knowledge Distillation</h3>
<p><a href="https://towardsdatascience.com/knowledge-distillation-simplified-dd4973dbc764">Knowledge Distillation</a> is a way to achieve model compression by transferring knowledge from a large (teacher) model to a smaller (student) one while maintaining validity. At a high level, this is done by using the outputs from the teacher model at every layer, to backpropagate error through the student model. This way, the student model learns to replicate the behavior of the teacher model. Model compression is achieved by reducing the number of parameters, which is directly related to the latency of the model.</p>
<p>To study the effect of knowledge distillation on the performance of our model, we fine-tuned a <a href="https://huggingface.co/distilroberta-base">distilroberta-base</a> model (following the same procedure described in the fine-tuning section) for our command line classification task and imported it into Elastic. <strong>distilroberta-base</strong> has 82 million parameters, compared to its teacher model, <strong>roberta-base</strong> , which has 125 million parameters. The model size of the fine-tuned <strong>DistilRoBERTa</strong> model turned out to be <strong>329</strong> MB, down from <strong>499</strong> MB for the <strong>RoBERTa</strong> model.</p>
<p>Upon running inference with this model, we <strong>observed a 1.5x speedup</strong> on the original inference time and slightly better model sensitivity (exact numbers in the following section) than the fine-tuned roberta-base model.</p>
<h3>Dynamic quantization and knowledge distillation</h3>
<p>We observed that dynamic quantization and model distillation both resulted in significant speedups on the original inference time. So, our final experiment involved running inference with a quantized version of the fine-tuned <strong>DistilRoBERTa</strong> model.</p>
<p>We found that this <strong>resulted in a 2.6x speedup</strong> on the original inference time, and slightly better model sensitivity (exact numbers in the following section). We also observed the model size drop from <strong>329</strong> MB to <strong>199</strong> MB after quantization.</p>
<h2>Bringing it all together</h2>
<p>Based on our experiments, dynamic quantization and model distillation resulted in significant inference speedups. Combining these improvements with distributed and parallel computing, we were further able to <strong>reduce the total inference time on our test set from four hours to 35 minutes</strong>. However, even our fastest transformer model was still several magnitudes slower than the tree-based model, despite using significantly more CPU resources.</p>
<p>The Machine Learning team here at Elastic is introducing an inference caching mechanism in version 8.4 of the Elastic Stack, to save time spent on performing inference on repeat samples. These are a common occurrence in real-world environments, especially when it comes to Security. With this optimization in place, we are optimistic that we will be able to use transformer models alongside tree-based models in the future.</p>
<p>A comparison of the sensitivity (true positive rate) and specificity (true negative rate) of our tree-based and transformer models shows that an ensemble of the two could potentially result in a more performant model:</p>
<table>
<thead>
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>Model</td>
<td>Sensitivity (%)</td>
<td>False Negative Rate (%)</td>
<td>Specificity (%)</td>
<td>False Positive Rate (%)</td>
</tr>
<tr>
<td>Tree-based</td>
<td>99.53</td>
<td>0.47</td>
<td>99.99</td>
<td>0.01</td>
</tr>
<tr>
<td>RoBERTa</td>
<td>99.57</td>
<td>0.43</td>
<td>97.76</td>
<td>2.24</td>
</tr>
<tr>
<td>RoBERTa quantized</td>
<td>99.56</td>
<td>0.44</td>
<td>97.64</td>
<td>2.36</td>
</tr>
<tr>
<td>DistilRoBERTa</td>
<td>99.68</td>
<td>0.32</td>
<td>98.66</td>
<td>1.34</td>
</tr>
<tr>
<td>DistilRoBERTa quantized</td>
<td>99.69</td>
<td>0.31</td>
<td>98.71</td>
<td>1.29</td>
</tr>
</tbody>
</table>
<p>As seen above, the tree-based model is better suited for classifying benign data while the transformer model does better on malicious samples, so a weighted average or voting ensemble could work well to reduce the total error by averaging the predictions from both the models.</p>
<h2>What's next</h2>
<p>We plan to cover our findings from inference caching and model ensembling in a follow-up blog. Stay tuned!</p>
<p>In the meanwhile, we’d love to hear about models you're building for inference in Elastic. If you'd like to share what you're doing or run into any issues during the process, please reach out to us on our <a href="https://ela.st/slack">community Slack channel</a>and <a href="https://discuss.elastic.co/c/security">discussion forums</a>. Happy experimenting!</p>
]]></content:encoded>
            <category>security-labs</category>
            <enclosure url="https://www.elastic.co/kr/security-labs/assets/images/getting-the-most-out-of-transforms-in-elastic/machine-learning-1200x628px-2021-notext.jpg" length="0" type="image/jpg"/>
        </item>
    </channel>
</rss>