<?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 - Articles by Kirti Sodhi</title>
        <link>https://www.elastic.co/es/security-labs</link>
        <description>Trusted security news &amp; research from the team at Elastic.</description>
        <lastBuildDate>Thu, 05 Mar 2026 22:21:01 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <image>
            <title>Elastic Security Labs - Articles by Kirti Sodhi</title>
            <url>https://www.elastic.co/es/security-labs/assets/security-labs-thumbnail.png</url>
            <link>https://www.elastic.co/es/security-labs</link>
        </image>
        <copyright>© 2026. Elasticsearch B.V. All Rights Reserved</copyright>
        <item>
            <title><![CDATA[Using LLMs and ESRE to find similar user sessions]]></title>
            <link>https://www.elastic.co/es/security-labs/using-llms-and-esre-to-find-similar-user-sessions</link>
            <guid>using-llms-and-esre-to-find-similar-user-sessions</guid>
            <pubDate>Tue, 19 Sep 2023 00:00:00 GMT</pubDate>
            <description><![CDATA[In our previous article, we explored using the GPT-4 Large Language Model (LLM) to condense Linux user sessions. In the context of the same experiment, we dedicated some time to examine sessions that shared similarities. These similar sessions can subsequently aid the analysts in identifying related suspicious activities.]]></description>
            <content:encoded><![CDATA[<h2>Using LLMs and ESRE to find similar user sessions</h2>
<p>In our <a href="https://www.elastic.co/es/security-labs/using-llms-to-summarize-user-sessions">previous article</a>, we explored using the GPT-4 Large Language Model (LLM) to condense complex Linux user sessions into concise summaries. We highlighted the key takeaways from our experiments, shedding light on the nuances of data preprocessing, prompt tuning, and model parameter adjustments. In the context of the same experiment, we dedicated some time to examine sessions that shared similarities. These similar sessions can subsequently aid the analysts in identifying related suspicious activities. We explored the following methods to find similarities in user sessions:</p>
<ul>
<li>In an endeavor to uncover similar user profiles and sessions, one approach we undertook was to categorize sessions according to the actions executed by users; we accomplished this by instructing the Language Model Model (LLM) to categorize user sessions into predefined categories</li>
<li>Additionally, we harnessed the capabilities of <a href="https://www.elastic.co/es/guide/en/machine-learning/current/ml-nlp-elser.html">ELSER</a> (Elastic’s retrieval model for semantic search) to execute a semantic search on the model summaries derived from the session summarization experiment</li>
</ul>
<p>This research focuses on our experiments using GPT-4 for session categorization and <a href="https://www.elastic.co/es/elasticsearch/elasticsearch-relevance-engine">ESRE</a> for semantic search.</p>
<h2>Leveraging GPT for Session Categorization</h2>
<p>We consulted a security research colleague with domain expertise to define nine categories for our dataset of 75 sessions. These categories generalize the main behaviors and significant features observed in the sessions. They include the following activities:</p>
<ul>
<li>Docker Execution</li>
<li>Network Operations</li>
<li>File Searches</li>
<li>Linux Command Line Usage</li>
<li>Linux Sandbox Application Usage</li>
<li>Pip Installations</li>
<li>Package Installations</li>
<li>Script Executions</li>
<li>Process Executions</li>
</ul>
<h2>Lessons learned</h2>
<p>For our experiments, we used a GPT-4 deployment in Azure AI Studio with a token limit of 32k. To explore the potential of the GPT model for session categorization, we conducted a series of experiments, directing the model to categorize sessions by inputting the same JSON summary document we used for the <a href="https://www.elastic.co/es/security-labs/using-llms-to-summarize-user-sessions">session summarization process</a>.</p>
<p>This effort included multiple iterations, during which we concentrated on enhancing prompts and <a href="https://help.openai.com/en/articles/6654000-best-practices-for-prompt-engineering-with-openai-api">Few-Shot</a> Learning. As for the model parameters, we maintained a <a href="https://txt.cohere.com/llm-parameters-best-outputs-language-ai/">Temperature of 0</a> in an effort to make the outputs less diverse.</p>
<h3>Prompt engineering</h3>
<p><em>Takeaway:</em> Including explanations for categories in the prompts does not impact the model's performance.</p>
<p>The session categorization component was introduced as an extension to the session summarization prompt. We explored the effect of incorporating contextual explanations for each category alongside the prompts. Intriguingly, our findings revealed that appending illustrative context did not significantly influence the model's performance, as compared to prompts devoid of such supplementary information.</p>
<p>Below is a template we used to guide the model's categorization process:</p>
<pre><code>You are a cybersecurity assistant, who helps Security analysts in summarizing activities that transpired in a Linux session. A summary of events that occurred in the session will be provided in JSON format. No need to explicitly list out process names and file paths. Summarize the session in ~3 paragraphs, focusing on the following: 
- Entities involved in the session: host name and user names.
- Overview of any network activity. What major source and destination ips are involved? Any malicious port activity?
- Overview of any file activity. Were any sensitive files or directories accessed?
- Highlight any other important process activity
- Looking at the process, network, and file activity, what is the user trying to do in the session? Does the activity indicate malicious behavior?

Also, categorize the below Linux session in one of the following 9 categories: Network, Script Execution, Linux Command Line Utility, File search, Docker Execution, Package Installations, Pip Installations, Process Execution and Linux Sandbox Application.

A brief description for each Linux session category is provided below. Refer to these explanations while categorizing the sessions.
- Docker Execution: The session involves command with docker operations, such as docker-run and others
- Network: The session involves commands with network operations
- File Search: The session involves file operations, pertaining to search
- Linux Command Line Utility: The session involves linux command executions
- Linux Sandbox Application: The session involves a sandbox application activity. 
- Pip Installations: The session involves python pip installations
- Package Installations: The session involves package installations or removal activities. This is more of apt-get, yum, dpkg and general command line installers as opposed to any software wrapper
- Script Execution: The session involves bash script invocations. All of these have pointed custom infrastructure script invocations
- Process Execution: The session focuses on other process executions and is not limited to linux commands. 
 ###
 Text: {your input here}
</code></pre>
<h3>Few-shot tuning</h3>
<p><em>Takeaway:</em> Adding examples for each category improves accuracy.</p>
<p>Simultaneously, we investigated the effectiveness of improving the model's performance by including one example for each category in the above prompt. This strategy resulted in a significant enhancement, notably boosting the model's accuracy by 20%.</p>
<h2>Evaluating GPT Categories</h2>
<p>The assessment of GPT categories is crucial in measuring the quality and reliability of the outcomes. In the evaluation of categorization results, a comparison was drawn between the model's categorization and the human categorization assigned by the security expert (referred to as &quot;Ground_Truth&quot; in the below image). We calculated the total accuracy based on the number of successful matches for categorization evaluation.</p>
<p><img src="https://www.elastic.co/es/security-labs/assets/images/using-llms-and-esre-to-find-similar-user-sessions/image2.png" alt="Evaluating Session Categories" /></p>
<p>We observed that GPT-4 faced challenges when dealing with samples bearing multiple categories. However, when assigning a single category, it aligned with the human categorization in 56% of cases. The &quot;Linux Command Line Utility&quot; category posed a particular challenge, with 47% of the false negatives, often misclassified as &quot;Process Execution&quot; or &quot;Script Execution.&quot; This discrepancy arose due to the closely related definitions of the &quot;Linux Command Line Utility&quot; and &quot;Process Execution&quot; categories and there may have also been insufficient information in the prompts, such as process command line arguments, which could have served as a valuable distinguishing factor for these categories.</p>
<p>Given the results from our evaluation, we conclude that we either need to tune the descriptions for each category in the prompt or provide more examples to the model via few-shot training. Additionally, it's worth considering whether GPT is the most suitable choice for classification, particularly within the context of the prompting paradigm.</p>
<h2>Semantic search with ELSER</h2>
<p>We also wanted to try <a href="https://www.elastic.co/es/guide/en/machine-learning/current/ml-nlp-elser.html#ml-nlp-elser">ELSER</a>, the Elastic Learned Sparse EncodeR for semantic search. Semantic search focuses on contextual meaning, rather than strictly exact keyword inputs, and ELSER is a retrieval model trained by Elastic that enables you to perform semantic search and retrieve more relevant results.</p>
<p>We tried some examples of semantic search questions on the session summaries. The session summaries were stored in an Elasticsearch index, and it was simple to download the ELSER model following an <a href="https://www.elastic.co/es/guide/en/machine-learning/current/ml-nlp-elser.html#ml-nlp-elser">official tutorial</a>. The tokens generated by ELSER are stored in the index, as shown in the image below:</p>
<p><img src="https://www.elastic.co/es/security-labs/assets/images/using-llms-and-esre-to-find-similar-user-sessions/image1.png" alt="Tokens generated by ELSER" /></p>
<p>Afterward, semantic search on the index was overall able to retrieve the most relevant events. Semantic search queries about the events included:</p>
<ul>
<li>Password related – yielding 1Password related logs</li>
<li>Java – yielding logs that used Java</li>
<li>Python – yielding logs that used Python</li>
<li>Non-interactive session</li>
<li>Interactive session</li>
</ul>
<p>An example of semantic search can be seen in the Dev Tools console through a <a href="https://www.elastic.co/es/guide/en/elasticsearch/reference/8.9/semantic-search-elser.html#text-expansion-query">text_expansion query</a>.</p>
<p><img src="https://www.elastic.co/es/security-labs/assets/images/using-llms-and-esre-to-find-similar-user-sessions/image5.png" alt="Example screenshot of using semantic search with the Elastic dev tools console" /></p>
<p>Some takeaways are:</p>
<ul>
<li>For semantic search, the prompt template can cause the summary to have too many unrelated keywords. For example, we wanted every summary to include an assessment of whether or not the session should be considered &quot;malicious&quot;, that specific word was always included in the resulting summary. Hence, the summaries of benign sessions and malicious sessions alike contained the word &quot;malicious&quot; through sentences like &quot;This session is malicious&quot; or &quot;This session is not malicious&quot;. This could have impacted the accuracy.</li>
<li>Semantic search seemed unable to differentiate effectively between certain related concepts, such as interactive vs. non-interactive. A small number of specific terms might not have been deemed important enough to the core meaning of the session summary for semantic search.</li>
<li>Semantic search works better than <a href="https://link.springer.com/referenceworkentry/10.1007/978-0-387-39940-9_921">BM25</a> for cases where the user doesn’t specify the exact keywords. For example, searching for &quot;Python&quot; or &quot;Java&quot; related logs and summaries is equally effective with both ELSER and BM25. However, ELSER could retrieve more relevant data when searching for “object oriented language” related logs. In contrast, using a keyword search for “object oriented language” doesn’t yield relevant results, as shown in the image below.</li>
</ul>
<p><img src="https://www.elastic.co/es/security-labs/assets/images/using-llms-and-esre-to-find-similar-user-sessions/image4.png" alt="Semantic search can yield more relevant results when keywords aren’t matching" /></p>
<h2>What's next</h2>
<p>We are currently looking into further improving summarization via <a href="https://arxiv.org/pdf/2005.11401.pdf">retrieval augmented generation (RAG)</a>, using tools in the <a href="https://www.elastic.co/es/guide/en/esre/current/index.html">Elastic Search and Relevance Engine</a> (ESRE). In the meantime, we’d love to hear about your experiments with LLMs, ESRE, etc. 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>.</p>
]]></content:encoded>
            <category>security-labs</category>
            <enclosure url="https://www.elastic.co/es/security-labs/assets/images/using-llms-and-esre-to-find-similar-user-sessions/photo-edited-03@2x.jpg" length="0" type="image/jpg"/>
        </item>
        <item>
            <title><![CDATA[Using LLMs to summarize user sessions]]></title>
            <link>https://www.elastic.co/es/security-labs/using-llms-to-summarize-user-sessions</link>
            <guid>using-llms-to-summarize-user-sessions</guid>
            <pubDate>Mon, 11 Sep 2023 00:00:00 GMT</pubDate>
            <description><![CDATA[In this publication, we will talk about lessons learned and key takeaways from our experiments using GPT-4 to summarize user sessions.]]></description>
            <content:encoded><![CDATA[<h2>Using LLMs to summarize user sessions</h2>
<p>With the introduction of the <a href="https://www.elastic.co/es/guide/en/security/current/security-assistant.html">AI Assistant</a> into the Security Solution in 8.8, the Security Machine Learning team at Elastic has been exploring how to optimize Security operations with LLMs like GPT-4. User session summarization seemed like the perfect use case to start experimenting with for several reasons:</p>
<ul>
<li>User session summaries can help analysts quickly decide whether a particular session's activity is worth investigating or not</li>
<li>Given the diversity of data that LLMs like GPT-4 are trained on, it is not hard to imagine that they have already been trained on <a href="https://en.wikipedia.org/wiki/Man_page">man pages</a>, and other open Security content, which can provide useful context for session investigation</li>
<li>Session summaries could potentially serve as a good supplement to the <a href="https://www.elastic.co/es/guide/en/security/current/session-view.html">Session View</a> tool, which is available in the Elastic Security Solution as of 8.2.</li>
</ul>
<p>In this publication, we will talk about lessons learned and key takeaways from our experiments using GPT-4 to summarize user sessions.</p>
<p>In our <a href="https://www.elastic.co/es/security-labs/using-llms-and-esre-to-find-similar-user-sessions">follow-on research</a>, we dedicated some time to examine sessions that shared similarities. These similar sessions can subsequently aid the analysts in identifying related suspicious activities.</p>
<h2>What is a session?</h2>
<p>In Linux, and other Unix-like systems, a &quot;user session&quot; refers to the period during which a user is logged into the system. A session begins when a user logs into the system, either via graphical login managers (GDM, LightDM) or via command-line interfaces (terminal, SSH).</p>
<p>Upon starting a Linux Kernel, a special process called the &quot;init' process is created, which is responsible for starting configured services such as databases, web servers, and remote access services such as <code>sshd</code>. These services, and any shells or processes spawned by them, are typically encapsulated within their own sessions and tied together by a single session ID (SID).</p>
<p>The detailed and chronological process information captured by sessions makes them an extremely useful asset for alerting, compliance, and threat hunting.</p>
<h2>Lessons learned</h2>
<p>For our experiments, we used a GPT-4 deployment with a 32k token limit available via Azure AI Studio. Tokens are basic units of text or code that LLMs use to process and generate language. Our goal here was to see how far we can get with user session summarization within the prompting paradigm alone. We learned some things along the way as it related to data processing, prompt engineering, hallucinations, parameter tuning, and evaluating the GPT summaries.</p>
<h3>Data processing</h3>
<p><em>Takeaway:</em> An aggregated JSON snapshot of the session is an effective input format for summarization.</p>
<p>A session here is simply a collection of process, network, file, and alert events. The number of events in a user session can range from a handful (&lt; 10) to hundreds of thousands. Each event log itself can be quite verbose, containing several hundred fields. For longer sessions with a large number of events, one can quickly run into token limits for models like GPT-4. Hence, passing raw logs as input to GPT-4 is not as useful for our specific use case. We saw this during experimentation, even when using tabular formats such as CSV, and using a small subset of fields in the logs.</p>
<p><img src="https://www.elastic.co/es/security-labs/assets/images/using-llms-to-summarize-user-sessions/image1.png" alt="Max token limit (32k) is reached for sessions containing a few hundred events" /></p>
<p>To get around this issue, we had to come up with an input format that retains as much of the session's context as possible, while also keeping the number of input tokens more or less constant irrespective of the length of the session. We experimented with several log de-duplication and aggregation strategies and found that an aggregated JSON snapshot of the session works well for summarization. An example document is as follows:</p>
<p><img src="https://www.elastic.co/es/security-labs/assets/images/using-llms-to-summarize-user-sessions/image3.jpg" alt="Aggregated JSON snapshot of session activity" /></p>
<p>This JSON snapshot highlights the most prominent activities in the session using de-duplicated lists, aggregate counts, and top-N (20 in our case) most frequent terms, with self-explanatory field names.</p>
<h3>Prompt engineering</h3>
<p><em>Takeaway:</em> Few-shot tuning with high-level instructions worked best.</p>
<p>Apart from data processing, most of our time during experimentation was spent on prompt tuning. We started with a basic prompt and found that the model had a hard time connecting the dots to produce a useful summary:</p>
<pre><code>You are an AI assistant that helps people find information.
</code></pre>
<p>We then tried providing very detailed instructions in the prompt but noticed that the model ignored some of the instructions:</p>
<pre><code>You are a cybersecurity assistant, who helps Security analysts in summarizing activities that transpired in a Linux session. A summary of events that occurred in the session will be provided in JSON format. No need to explicitly list out process names and file paths. Summarize the session in ~3 paragraphs, focusing on the following: 
- Entities involved in the session: host name and user names.
- Overview of any network activity. What major source and destination ips are involved? Any malicious port activity?
- Overview of any file activity. Were any sensitive files or directories accessed?
- Highlight any other important process activity
- Looking at the process, network, and file activity, what is the user trying to do in the session? Does the activity indicate malicious behavior?
</code></pre>
<p>Based on the above prompt, the model did not reliably adhere to the 3 paragraph request and also listed out process names and file paths which it was explicitly told not to do.</p>
<p>Finally, we landed on the following prompt that provided high-level instructions for the model:</p>
<pre><code>Analyze the following Linux user session, focusing on:      
- Identifying the host and user names      
- Observing activities and identifying key patterns or trends      
- Noting any indications of malicious or suspicious behavior such as tunneling or encrypted traffic, login failures, access to sensitive files, large number of file creations and deletions, disabling or modifying Security software, use of Shadow IT, unusual parent-child process executions, long-running processes
- Conclude with a comprehensive summary of what the user might be trying to do in the session, based on the process, network, and file activity     
 ###
 Text: {your input here}
</code></pre>
<p>We also noticed that the model follows instructions more closely when they're provided in user prompts rather than in the system prompts (a system prompt is the initial instruction to the model telling it how it should behave and the user prompts are the questions/queries asked by a user to the model). After the above prompt, we were happy with the content of the summaries, but the output format was inconsistent, with the model switching between paragraphs and bulleted lists. We were able to resolve this with <a href="https://arxiv.org/pdf/2203.04291.pdf">few-shot tuning</a>, by providing the model with two examples of user prompts vs. expected responses.</p>
<h3>Hallucinations</h3>
<p><em>Takeaway:</em> The model occasionally hallucinates while generating net new content for the summaries.</p>
<p>We observed that the model does not typically <a href="https://arxiv.org/pdf/2110.10819.pdf">hallucinate</a> while summarizing facts that are immediately apparent in the input such as user and host entities, network ports, etc. Occasionally, the model hallucinates while summarizing information that is not obvious, for example, in this case summarizing the overall user intent in the session. Some relatively easy avenues we found to mitigate hallucinations were as follows:</p>
<ul>
<li>Prompt the model to focus on specific behaviors while summarizing</li>
<li>Re-iterate that the model should fact-check its output</li>
<li>Set the <a href="https://learnprompting.org/docs/basics/configuration_hyperparameters">temperature</a> to a low value (less than or equal to 0.2) to get the model to generate less diverse responses, hence reducing the chances of hallucinations</li>
<li>Limit the response length, thus reducing the opportunity for the model to go off-track — This works especially  well if the length of the texts to be summarized is more or less constant, which it was in our case</li>
</ul>
<h3>Parameter tuning</h3>
<p><em>Takeaway:</em> Temperature = 0 does not guarantee determinism.</p>
<p>For summarization, we explored tuning parameters such as <a href="https://txt.cohere.com/llm-parameters-best-outputs-language-ai/">Temperature and Top P</a>, to get deterministic responses from the model. Our observations were as follows:</p>
<ul>
<li>Tuning both together is not recommended, and it's also difficult to observe the effect of each when combined</li>
<li>Solely setting the temperature to a low value (&lt; 0.2) without altering Top P is usually sufficient</li>
<li>Even setting the temperature to 0 does not result in fully deterministic outputs given the inherent non-deterministic nature of floating point calculations (see <a href="https://community.openai.com/t/a-question-on-determinism/8185">this</a> post from OpenAI for a more detailed explanation)</li>
</ul>
<h2>Evaluating GPT Summaries</h2>
<p>As with any modeling task, evaluating the GPT summaries was crucial in gauging the quality and reliability of the model outcomes. In the absence of standardized evaluation approaches and metrics for text generation, we decided to do a qualitative human evaluation of the summaries, as well as a quantitative evaluation using automatic metrics such as <a href="https://en.wikipedia.org/wiki/ROUGE_(metric)">ROUGE-L</a>, <a href="https://en.wikipedia.org/wiki/BLEU">BLEU</a>, <a href="https://en.wikipedia.org/wiki/METEOR">METEOR</a>, <a href="https://arxiv.org/abs/1904.09675">BERTScore</a>, and <a href="https://aclanthology.org/2020.eval4nlp-1.2/">BLANC</a>.</p>
<p>For qualitative evaluation, we had a Security Researcher write summaries for a carefully chosen (to get a good distribution of short and long sessions) set of 10 sessions, without any knowledge of the GPT summaries. Three evaluators were asked to compare the GPT summaries against the human-generated summaries using three key criteria:</p>
<ul>
<li>Factuality:  Examine if the model summary retains key facts of the session as provided by Security experts</li>
<li>Authenticity: Check for hallucinations</li>
<li>Consistency: Check the consistency of the model output i.e. all the responses share a stable format and produce the same level of detail</li>
</ul>
<p>Finally, each of the 10 summaries was assigned a final rating of &quot;Good&quot; or &quot;Bad&quot; based on a majority vote to combine the evaluators' choices.</p>
<p><img src="https://www.elastic.co/es/security-labs/assets/images/using-llms-to-summarize-user-sessions/image2.png" alt="Summarization evaluation matrix" /></p>
<p>While we recognize the small dataset size for evaluation, our qualitative assessment showed that GPT summaries aligned with human summaries 80% of the time. For the GPT summaries that received a &quot;Bad&quot; rating, the summaries didn't retain certain important facts because the aggregated JSON document only kept the top-N terms for certain fields.</p>
<p>The automated metrics didn't seem to match human preferences, nor did they reliably measure summary quality due to the structural differences between human and LLM-generated summaries, especially for reference-based metrics.</p>
<h2>What's next</h2>
<p>We are currently looking into further improving summarization via <a href="https://arxiv.org/pdf/2005.11401.pdf">retrieval augmented generation (RAG)</a>, using tools in the <a href="https://www.elastic.co/es/guide/en/esre/current/index.html">Elastic Search and Relevance Engine (ESRE)</a>. We also experimented with using LLMs to categorize user sessions. Stay tuned for Part 2 of this blog to learn more about those experiments!</p>
<p>In the meantime, we’d love to hear about your experiments with LLMs, ESRE, etc. 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/es/security-labs/assets/images/using-llms-to-summarize-user-sessions/photo-edited-01@2x.jpg" length="0" type="image/jpg"/>
        </item>
    </channel>
</rss>